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