1*b1cdbd2cSJim Jagielski#!/sbin/sh
2*b1cdbd2cSJim Jagielski# *************************************************************
3*b1cdbd2cSJim Jagielski#
4*b1cdbd2cSJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
5*b1cdbd2cSJim Jagielski#  or more contributor license agreements.  See the NOTICE file
6*b1cdbd2cSJim Jagielski#  distributed with this work for additional information
7*b1cdbd2cSJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
8*b1cdbd2cSJim Jagielski#  to you under the Apache License, Version 2.0 (the
9*b1cdbd2cSJim Jagielski#  "License"); you may not use this file except in compliance
10*b1cdbd2cSJim Jagielski#  with the License.  You may obtain a copy of the License at
11*b1cdbd2cSJim Jagielski#
12*b1cdbd2cSJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
13*b1cdbd2cSJim Jagielski#
14*b1cdbd2cSJim Jagielski#  Unless required by applicable law or agreed to in writing,
15*b1cdbd2cSJim Jagielski#  software distributed under the License is distributed on an
16*b1cdbd2cSJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17*b1cdbd2cSJim Jagielski#  KIND, either express or implied.  See the License for the
18*b1cdbd2cSJim Jagielski#  specific language governing permissions and limitations
19*b1cdbd2cSJim Jagielski#  under the License.
20*b1cdbd2cSJim Jagielski#
21*b1cdbd2cSJim Jagielski# *************************************************************
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski. /lib/svc/share/smf_include.sh
24*b1cdbd2cSJim Jagielski
25*b1cdbd2cSJim Jagielski#The start method is used for installing and updating the
26*b1cdbd2cSJim Jagielski#extensions. The service keeps a list
27*b1cdbd2cSJim Jagielski#(share/extensions/install/installed) of the extensions which were
28*b1cdbd2cSJim Jagielski#already installed. During installation, the bundled extensions are
29*b1cdbd2cSJim Jagielski#copied to the install folder (share/extensions/install). Finally this
30*b1cdbd2cSJim Jagielski#service, which is part of the office installation package, will be
31*b1cdbd2cSJim Jagielski#started and the start "method" of this script is called. Then all
32*b1cdbd2cSJim Jagielski#extensions in the "install" folder are checked if they are already
33*b1cdbd2cSJim Jagielski#installed by reading the list "installed". Because the list is empty
34*b1cdbd2cSJim Jagielski#at this time, all the extensions will be installed.
35*b1cdbd2cSJim Jagielski#
36*b1cdbd2cSJim Jagielski#If this service is restarted then the script checks if there is an
37*b1cdbd2cSJim Jagielski#extensions which is not yet installed, that is there is no entry for
38*b1cdbd2cSJim Jagielski#it in the 'installed' file. Only if this is the case then that
39*b1cdbd2cSJim Jagielski#extensions will be installed and its path is added to 'installed'.
40*b1cdbd2cSJim Jagielski#
41*b1cdbd2cSJim Jagielski#In case of an update, new versions of existing extensions and
42*b1cdbd2cSJim Jagielski#completely new extensions may be copied to the 'install' folder. Also
43*b1cdbd2cSJim Jagielski#a new 'installed' file will be copied which replaces the existing
44*b1cdbd2cSJim Jagielski#file. The new 'installed' file does not contain any entries of
45*b1cdbd2cSJim Jagielski#installed extensions. Therefore the next time when the start method is
46*b1cdbd2cSJim Jagielski#run all extensions contained in share/extensions/install will be
47*b1cdbd2cSJim Jagielski#installed.
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim Jagielski#Create the folder which contains the temporary user installation
50*b1cdbd2cSJim JagielskiINSTDIR=`/usr/bin/mktemp -d "/tmp/userinstall.XXXXXX"`
51*b1cdbd2cSJim Jagielski
52*b1cdbd2cSJim JagielskiOOO_BASE_DIR="/opt/openoffice/basis${OOOBASEVERSION}"
53*b1cdbd2cSJim Jagielski
54*b1cdbd2cSJim Jagielskicase "$1" in
55*b1cdbd2cSJim Jagielski'start')
56*b1cdbd2cSJim Jagielski    EXTENSIONDIR=/opt/openoffice${OOOBRANDPACKAGEVERSION}/share/extension/install
57*b1cdbd2cSJim Jagielski    for FILE in $EXTENSIONDIR/*.oxt
58*b1cdbd2cSJim Jagielski    do
59*b1cdbd2cSJim Jagielski	#We check if the file exist, because if there is no extension
60*b1cdbd2cSJim Jagielski	#then $FILE will contain "<..>/*.oxt"
61*b1cdbd2cSJim Jagielski	if [ -f "$FILE" ]; then
62*b1cdbd2cSJim Jagielski            #Determine if this extension is already installed. We do
63*b1cdbd2cSJim Jagielski	    #that by checking the file "installed" which contains a
64*b1cdbd2cSJim Jagielski	    #list of all installed extensions including the full path
65*b1cdbd2cSJim Jagielski	    EXTENSIONFILE=`basename $FILE`
66*b1cdbd2cSJim Jagielski	    INSTALLED=`sed -n "/$EXTENSIONFILE/p" $EXTENSIONDIR/installed`
67*b1cdbd2cSJim Jagielski
68*b1cdbd2cSJim Jagielski	    if [ -z "$INSTALLED" ]; then
69*b1cdbd2cSJim Jagielski	        #We have not found the name of the extension in the
70*b1cdbd2cSJim Jagielski		#list. That is, it has not been installed (with unopkg) yet.
71*b1cdbd2cSJim Jagielski		#Therefore we do it now.
72*b1cdbd2cSJim Jagielski		echo installing $FILE
73*b1cdbd2cSJim Jagielski		/opt/openoffice${OOOBRANDPACKAGEVERSION}/program/unopkg add --shared --bundled "$FILE" '-env:UserInstallation=file://$INSTDIR' '-env:UNO_JAVA_JFW_INSTALL_DATA=$OOO_BASE_DIR/share/config/javasettingsunopkginstall.xml' '-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1'
74*b1cdbd2cSJim Jagielski		#Let us remember that this extensions has been installed
75*b1cdbd2cSJim Jagielski		#by adding the path name of the extension to the file
76*b1cdbd2cSJim Jagielski		#installed
77*b1cdbd2cSJim Jagielski		echo $FILE >> $EXTENSIONDIR/installed
78*b1cdbd2cSJim Jagielski	    fi
79*b1cdbd2cSJim Jagielski	fi
80*b1cdbd2cSJim Jagielski    done
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski    #Now check for extensions which need to be uninstalled
83*b1cdbd2cSJim Jagielski    #(unopkg). This is the case if the list of extensions in the file
84*b1cdbd2cSJim Jagielski    #installed contains the name of an extension which does not exist
85*b1cdbd2cSJim Jagielski    #in the the folder <..>/share/extension/install.
86*b1cdbd2cSJim Jagielski#     LINE=""
87*b1cdbd2cSJim Jagielski#     NEWCONTENT=""
88*b1cdbd2cSJim Jagielski#     REMOVED=""
89*b1cdbd2cSJim Jagielski#     LIST=`cat $EXTENSIONDIR/installed`
90*b1cdbd2cSJim Jagielski#     #remove blank lines
91*b1cdbd2cSJim Jagielski#     LIST=`echo "$LIST" | sed '/^[:blank:]*$/d'`
92*b1cdbd2cSJim Jagielski
93*b1cdbd2cSJim Jagielski#     echo "$LIST" |  while [ 1 ]
94*b1cdbd2cSJim Jagielski#     do
95*b1cdbd2cSJim Jagielski# 	read LINE || break
96*b1cdbd2cSJim Jagielski# 	if [ ! -f "$LINE" ]; then
97*b1cdbd2cSJim Jagielski# 	    #The extension file has been removed from
98*b1cdbd2cSJim Jagielski# 	    #share/extension/install. Now we remove the installed
99*b1cdbd2cSJim Jagielski# 	    #extension
100*b1cdbd2cSJim Jagielski# 	    echo removing `basename $LINE`
101*b1cdbd2cSJim Jagielski# 	    /opt/openoffice${OOOBRANDPACKAGEVERSION}/program/unopkg remove --shared --bundled "`basename $LINE`" '-env:UserInstallation=file://$INSTDIR' '-env:UNO_JAVA_JFW_INSTALL_DATA=$OOO_BASE_DIR/share/config/javasettingsunopkginstall.xml' '-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1'
102*b1cdbd2cSJim Jagielski# 	    REMOVED=1
103*b1cdbd2cSJim Jagielski# 	else
104*b1cdbd2cSJim Jagielski# 	    NEWCONTENT+=$LINE
105*b1cdbd2cSJim Jagielski# 	    NEWCONTENT+="\n"
106*b1cdbd2cSJim Jagielski# 	fi
107*b1cdbd2cSJim Jagielski#     done
108*b1cdbd2cSJim Jagielski
109*b1cdbd2cSJim Jagielski#     #Write the new list to the file "installed". It now has all names
110*b1cdbd2cSJim Jagielski#     #remove which refered to previously removed extensions (removed
111*b1cdbd2cSJim Jagielski#     #from .../share/extension/install)
112*b1cdbd2cSJim Jagielski#     if  [ "$REMOVED" ]; then
113*b1cdbd2cSJim Jagielski# 	#remove the last empty line
114*b1cdbd2cSJim Jagielski# 	NEWCONTENT=`echo "$NEWCONTENT" | sed '/^[:space:]*$/d'`
115*b1cdbd2cSJim Jagielski# 	echo "$NEWCONTENT" > $EXTENSIONDIR/installed
116*b1cdbd2cSJim Jagielski#     fi
117*b1cdbd2cSJim Jagielski
118*b1cdbd2cSJim Jagielski    ;;
119*b1cdbd2cSJim Jagielski    'stop')
120*b1cdbd2cSJim Jagielski	echo "#### stop ####"
121*b1cdbd2cSJim Jagielski	;;
122*b1cdbd2cSJim Jagielski    *)
123*b1cdbd2cSJim Jagielski	echo "Usage: $0 { start | stop }"
124*b1cdbd2cSJim Jagielski	exit 1
125*b1cdbd2cSJim Jagielski	;;
126*b1cdbd2cSJim Jagielskiesac
127*b1cdbd2cSJim Jagielski
128*b1cdbd2cSJim Jagielskiexit $SMF_EXIT_OK
129