xref: /AOO41X/main/setup_native/scripts/install_solaris.sh (revision 83dd286e65dfee14f9559817079a0e7acce3c8f9)
1*83dd286eSPedro Giffuni#!/usr/bin/env bash
2cdf0e10cSrcweir
3cdf0e10cSrcweirADD="no"
4cdf0e10cSrcweirLINK="no"
5cdf0e10cSrcweirUPDATE="no"
6cdf0e10cSrcweirUSAGE="Usage: $0 [-a] [-l] [-h] <pkg-source-dir> <office-installation-dir>"
7cdf0e10cSrcweir
8cdf0e10cSrcweirhelp()
9cdf0e10cSrcweir{
10cdf0e10cSrcweir  echo
11cdf0e10cSrcweir  echo "User Mode Installation script for developer and knowledgeable early access tester"
12cdf0e10cSrcweir  echo
13cdf0e10cSrcweir  echo "This installation method is not intended for use in a production environment!"
14cdf0e10cSrcweir  echo "Using this script is unsupported and completely at your own risk"
15cdf0e10cSrcweir  echo
16cdf0e10cSrcweir  echo "Usage:" $0 "<pkg-source-dir> <office-installation-dir> [-l]"
17cdf0e10cSrcweir  echo "    <pkg-source-dir>:       directory *only* containing the Solaris pkg packages to be installed"
18cdf0e10cSrcweir  echo "                            or language pack shell script containing the Solaris pkg packages"
19cdf0e10cSrcweir  echo "    <office-installation-dir>: directory to where the office and the pkg database will get installed into"
20cdf0e10cSrcweir  echo
21cdf0e10cSrcweir  echo "Optional Parameter:"
22cdf0e10cSrcweir  echo "    -a :              add to an existing <office-installation-dir>"
23cdf0e10cSrcweir  echo "    -l :              create a link \"soffice\" in $HOME"
24cdf0e10cSrcweir  echo "    -h :              output this help"
25cdf0e10cSrcweir}
26cdf0e10cSrcweir
27cdf0e10cSrcweirtry_to_unpack_languagepack_file()
28cdf0e10cSrcweir{
29cdf0e10cSrcweir  FILENAME=$PACKAGE_PATH
30cdf0e10cSrcweir
31cdf0e10cSrcweir  # Checking, if $FILENAME is a language pack.
32cdf0e10cSrcweir  # String "language package" has to exist in the shell script file.
33cdf0e10cSrcweir  # If this is no language pack, the installation is not supported
34cdf0e10cSrcweir
35cdf0e10cSrcweir  SEARCHSTRING=`head -n 10 $FILENAME | grep "language package"`
36cdf0e10cSrcweir
37cdf0e10cSrcweir  if [ ! -z "$SEARCHSTRING" ]
38cdf0e10cSrcweir  then
39cdf0e10cSrcweir    echo "First parameter $FILENAME is a language pack";
40cdf0e10cSrcweir  else
41cdf0e10cSrcweir    printf "\nERROR: First parameter $FILENAME is a file, but no language pack shell script.\n"
42cdf0e10cSrcweir    echo $USAGE
43cdf0e10cSrcweir    exit 2
44cdf0e10cSrcweir  fi
45cdf0e10cSrcweir
46cdf0e10cSrcweir  echo "Unpacking shell script $FILENAME"
47cdf0e10cSrcweir  # TAILLINE=`head -n 20 $FILENAME | sed --quiet 's/linenum=//p'`
48cdf0e10cSrcweir  TAILLINE=`head -n 20 $FILENAME | sed -n 's/linenum=//p'`
49cdf0e10cSrcweir
50cdf0e10cSrcweir  if [ -x "/usr/bin/mktemp" ]  # available in Solaris 10
51cdf0e10cSrcweir  then
52cdf0e10cSrcweir    UNPACKDIR=`mktemp -d`
53cdf0e10cSrcweir  else
54cdf0e10cSrcweir    UNPACKDIR=/var/tmp/install_$$
55cdf0e10cSrcweir    mkdir $UNPACKDIR
56cdf0e10cSrcweir  fi
57cdf0e10cSrcweir
58cdf0e10cSrcweir  echo $UNPACKDIR
59cdf0e10cSrcweir  tail +$TAILLINE $FILENAME | gunzip | (cd $UNPACKDIR; tar xvf -)
60cdf0e10cSrcweir
61cdf0e10cSrcweir  # Setting the new package path, in which the packages exist
62cdf0e10cSrcweir  PACKAGE_PATH=$UNPACKDIR
63cdf0e10cSrcweir
64cdf0e10cSrcweir  # Setting variable UPDATE, because an Office installation has to exist, if a language pack shall be installed
65cdf0e10cSrcweir  UPDATE="yes"
66cdf0e10cSrcweir}
67cdf0e10cSrcweir
68cdf0e10cSrcweirpkg_error()
69cdf0e10cSrcweir{
70cdf0e10cSrcweir  # pkg command failed, check for admin log and report help
71cdf0e10cSrcweir  if [ -f /tmp/.ai.pkg.zone.lock-afdb66cf-1dd1-11b2-a049-000d560ddc3e ]
72cdf0e10cSrcweir  then
73cdf0e10cSrcweir    echo "####################################################################"
74cdf0e10cSrcweir    echo "#     Installation failed due to stale administrative lock         #"
75cdf0e10cSrcweir    echo "####################################################################"
76cdf0e10cSrcweir    printf "\nERROR: please remove the following file first:\n"
77cdf0e10cSrcweir	ls -l /tmp/.ai.pkg.zone.lock-afdb66cf-1dd1-11b2-a049-000d560ddc3e
78cdf0e10cSrcweir  fi
79cdf0e10cSrcweir  rm -f $GETUID_SO
80cdf0e10cSrcweir  exit 1
81cdf0e10cSrcweir}
82cdf0e10cSrcweir
83cdf0e10cSrcweirget_pkg_list()
84cdf0e10cSrcweir{
85cdf0e10cSrcweir  cd $1; ls -1
86cdf0e10cSrcweir}
87cdf0e10cSrcweir
88cdf0e10cSrcweir#
89cdf0e10cSrcweir# this script is for userland not for root
90cdf0e10cSrcweir#
91cdf0e10cSrcweir
92cdf0e10cSrcweirif [ $UID -eq 0 ]
93cdf0e10cSrcweirthen
94cdf0e10cSrcweir  printf "\nThis script is for installation without administrative rights only\nPlease use pkgadd/patchadd to install as root\n"
95cdf0e10cSrcweir  help
96cdf0e10cSrcweir  exit 2
97cdf0e10cSrcweirfi
98cdf0e10cSrcweir
99cdf0e10cSrcweirwhile getopts "alh" VALUE
100cdf0e10cSrcweirdo
101cdf0e10cSrcweir  echo $VALUE
102cdf0e10cSrcweir  case $VALUE in
103cdf0e10cSrcweir    a)      ADD="yes"; break;;
104cdf0e10cSrcweir    h)      help; exit 0;;
105cdf0e10cSrcweir    l)      LINK="yes"; break;;
106cdf0e10cSrcweir    ?)      echo $USAGE; exit 2;;
107cdf0e10cSrcweir  esac
108cdf0e10cSrcweirdone
109cdf0e10cSrcweirshift `expr $OPTIND - 1`
110cdf0e10cSrcweir
111cdf0e10cSrcweirif [ $# != 2 ]
112cdf0e10cSrcweirthen
113cdf0e10cSrcweir  echo $USAGE
114cdf0e10cSrcweir  exit 2
115cdf0e10cSrcweirfi
116cdf0e10cSrcweir
117cdf0e10cSrcweir# Determine whether this is a patch or a regular install set ..
118cdf0e10cSrcweir/bin/bash -c "ls $1/*/patchinfo >/dev/null 2>&1"
119cdf0e10cSrcweirif [ "$?" = 0 ]
120cdf0e10cSrcweirthen
121cdf0e10cSrcweir  UPDATE="yes"
122cdf0e10cSrcweir  PATCH_PATH="$1"
123cdf0e10cSrcweir  PATCH_INFO_LIST=`/bin/bash -c "cd $1; ls */patchinfo"`
124cdf0e10cSrcweir  PATCH_LIST=`for i in ${PATCH_INFO_LIST}; do dirname $i; done`
125cdf0e10cSrcweirelif [ -f "$1/patchinfo" ]
126cdf0e10cSrcweirthen
127cdf0e10cSrcweir  UPDATE="yes"
128cdf0e10cSrcweir  PATCH_PATH=`dirname "$1"`
129cdf0e10cSrcweir  PATCH_LIST=`basename "$1"`
130cdf0e10cSrcweirelse
131cdf0e10cSrcweir  if [ -d "$1/packages" ]
132cdf0e10cSrcweir  then
133cdf0e10cSrcweir    PACKAGE_PATH="$1/packages"
134cdf0e10cSrcweir  else
135cdf0e10cSrcweir    PACKAGE_PATH=$1
136cdf0e10cSrcweir  fi
137cdf0e10cSrcweir
138cdf0e10cSrcweir  #
139cdf0e10cSrcweir  # If the first parameter is a shell script (download installation set), the packages have to
140cdf0e10cSrcweir  # be unpacked into temp directory
141cdf0e10cSrcweir  #
142cdf0e10cSrcweir  if [ -f "$PACKAGE_PATH" ]
143cdf0e10cSrcweir  then
144cdf0e10cSrcweir    try_to_unpack_languagepack_file
145cdf0e10cSrcweir  fi
146cdf0e10cSrcweir
147cdf0e10cSrcweir  #
148cdf0e10cSrcweir  # Create sed filter script for unwanted packages
149cdf0e10cSrcweir  #
150cdf0e10cSrcweir
151cdf0e10cSrcweir  cat > /tmp/userinstall_filer.$$ << EOF
152cdf0e10cSrcweir/SUNWadabas/d
153cdf0e10cSrcweir/^SUNWj[0-9]/d
154cdf0e10cSrcweir/-desktop-int/d
155cdf0e10cSrcweir/-shared-mime-info/d
156cdf0e10cSrcweir/-cde/d
157cdf0e10cSrcweirEOF
158cdf0e10cSrcweir
159cdf0e10cSrcweir  # Do not install gnome-integration package on systems without GNOME
160cdf0e10cSrcweir  pkginfo -q SUNWgnome-vfs
161cdf0e10cSrcweir  if [ $? -ne 0 ]
162cdf0e10cSrcweir  then
163cdf0e10cSrcweir
164cdf0e10cSrcweir    echo '/-gnome/d' >> /tmp/userinstall_filer.$$
165cdf0e10cSrcweir  fi
166cdf0e10cSrcweir
167cdf0e10cSrcweir  # pkgdep sorts the packages based on their dependencies
168cdf0e10cSrcweir  PKGDEP="`dirname $0`/pkgdep"
169cdf0e10cSrcweir  if [ ! -x $PKGDEP ]; then
170cdf0e10cSrcweir    PKGDEP="get_pkg_list"
171cdf0e10cSrcweir  fi
172cdf0e10cSrcweir
173cdf0e10cSrcweir  #
174cdf0e10cSrcweir  # Get the list of packages to install
175cdf0e10cSrcweir  #
176cdf0e10cSrcweir
177cdf0e10cSrcweir  PKG_LIST=`$PKGDEP $PACKAGE_PATH | sed -f  /tmp/userinstall_filer.$$`
178cdf0e10cSrcweir  rm -f /tmp/userinstall_filer.$$
179cdf0e10cSrcweir
180cdf0e10cSrcweir  if [ -z "$PKG_LIST" ]
181cdf0e10cSrcweir  then
182cdf0e10cSrcweir    printf "\n$0: No packages found in $PACKAGE_PATH\n"
183cdf0e10cSrcweir    exit 2
184cdf0e10cSrcweir  fi
185cdf0e10cSrcweir
186cdf0e10cSrcweir  echo "Packages found:"
187cdf0e10cSrcweir  for i in $PKG_LIST ; do
188cdf0e10cSrcweir    echo $i
189cdf0e10cSrcweir  done
190cdf0e10cSrcweirfi
191cdf0e10cSrcweir
192cdf0e10cSrcweirINSTALL_ROOT=$2
193cdf0e10cSrcweirif [ "$UPDATE" = "yes" ]
194cdf0e10cSrcweirthen
195cdf0e10cSrcweir  if [ ! -d ${INSTALL_ROOT}/var/sadm/install/admin ]
196cdf0e10cSrcweir  then
197cdf0e10cSrcweir    printf "\n$0: No package database in ${INSTALL_ROOT}.\n"
198cdf0e10cSrcweir    exit 2
199cdf0e10cSrcweir  fi
200cdf0e10cSrcweirelse
201cdf0e10cSrcweir  if [ "$ADD" = "no" ]
202cdf0e10cSrcweir  then
203cdf0e10cSrcweir    rmdir ${INSTALL_ROOT} 2>/dev/null
204cdf0e10cSrcweir    if [ -d ${INSTALL_ROOT} ]
205cdf0e10cSrcweir    then
206cdf0e10cSrcweir      printf "\n$0: ${INSTALL_ROOT} exists and is not empty.\n"
207cdf0e10cSrcweir      exit 2
208cdf0e10cSrcweir    fi
209cdf0e10cSrcweir  fi
210cdf0e10cSrcweir  mkdir -p ${INSTALL_ROOT}/var/sadm/install/admin
211cdf0e10cSrcweirfi
212cdf0e10cSrcweir
213cdf0e10cSrcweir# Previous versions of this script did not write this file
214cdf0e10cSrcweirif [ ! -f ${INSTALL_ROOT}/var/sadm/install/admin/default ]
215cdf0e10cSrcweirthen
216cdf0e10cSrcweir  cat > ${INSTALL_ROOT}/var/sadm/install/admin/default << EOF
217cdf0e10cSrcweiraction=nocheck
218cdf0e10cSrcweirconflict=nocheck
219cdf0e10cSrcweirsetuid=nocheck
220cdf0e10cSrcweiridepend=nocheck
221cdf0e10cSrcweirmail=
222cdf0e10cSrcweirEOF
223cdf0e10cSrcweirfi
224cdf0e10cSrcweir
225cdf0e10cSrcweirif [ ! "${INSTALL_ROOT:0:1}" = "/" ]; then
226cdf0e10cSrcweir  INSTALL_ROOT=`cd ${INSTALL_ROOT}; pwd`
227cdf0e10cSrcweirfi
228cdf0e10cSrcweir
229cdf0e10cSrcweir# This script must exist to make extension registration work
230cdf0e10cSrcweir# always overwrite to get the latest version.
231cdf0e10cSrcweirmkdir -p ${INSTALL_ROOT}/usr/lib
232cdf0e10cSrcweircat > ${INSTALL_ROOT}/usr/lib/postrun << \EOF
233cdf0e10cSrcweir#!/bin/sh
234cdf0e10cSrcweirset -e
235cdf0e10cSrcweir
236cdf0e10cSrcweir# Override UserInstallation in bootstraprc for unopkg ..
237cdf0e10cSrcweirUserInstallation='$BRAND_BASE_DIR/../UserInstallation'
238cdf0e10cSrcweirexport UserInstallation
239cdf0e10cSrcweir
240cdf0e10cSrcweirif [ -x /usr/bin/mktemp ]
241cdf0e10cSrcweirthen
242cdf0e10cSrcweir  CMD=`/usr/bin/mktemp /tmp/userinstall.XXXXXX`
243cdf0e10cSrcweirelse
244cdf0e10cSrcweir  CMD=/tmp/userinstall.$$; echo "" > $CMD
245cdf0e10cSrcweirfi
246cdf0e10cSrcweir
247cdf0e10cSrcweirsed -e 's|/opt/|${PKG_INSTALL_ROOT}/opt/|g' > $CMD
248cdf0e10cSrcweir/bin/sh -e $CMD
249cdf0e10cSrcweirrm -f $CMD
250cdf0e10cSrcweirEOF
251cdf0e10cSrcweirchmod +x ${INSTALL_ROOT}/usr/lib/postrun 2>/dev/null
252cdf0e10cSrcweir
253cdf0e10cSrcweir# create local tmp directory to install on S10
254cdf0e10cSrcweirLOCAL_TMP=
255cdf0e10cSrcweirif [ -x /usr/bin/mktemp ]
256cdf0e10cSrcweirthen
257cdf0e10cSrcweir  LOCAL_TMP=`mktemp -d`
258cdf0e10cSrcweir  rmdir ${INSTALL_ROOT}/tmp 2>/dev/null
259cdf0e10cSrcweir  ln -s ${LOCAL_TMP} ${INSTALL_ROOT}/tmp
260cdf0e10cSrcweirfi
261cdf0e10cSrcweir
262cdf0e10cSrcweir#
263cdf0e10cSrcweir# the tail of the script contains a shared object for overloading the getuid()
264cdf0e10cSrcweir# and a few other calls
265cdf0e10cSrcweir#
266cdf0e10cSrcweir
267cdf0e10cSrcweirGETUID_SO=/tmp/getuid.so.$$
268cdf0e10cSrcweirlinenum=???
269cdf0e10cSrcweirtail +$linenum $0 > $GETUID_SO
270cdf0e10cSrcweir
271cdf0e10cSrcweir#
272cdf0e10cSrcweir# Perform the installation
273cdf0e10cSrcweir#
274cdf0e10cSrcweirif [ "$UPDATE" = "yes" ]
275cdf0e10cSrcweirthen
276cdf0e10cSrcweir  # restore original "bootstraprc" prior to patching
277cdf0e10cSrcweir  for i in ${PKG_LIST}; do
278cdf0e10cSrcweir    my_dir=${INSTALL_ROOT}`pkgparam -d ${PACKAGE_PATH} "$i" BASEDIR`
279cdf0e10cSrcweir    find "$my_dir" -type f -name bootstraprc.orig -exec sh -ce 'mv "$0" `dirname "$0"`/bootstraprc' {} \;
280cdf0e10cSrcweir  done
281cdf0e10cSrcweir
282cdf0e10cSrcweir  # copy INST_RELEASE file
283cdf0e10cSrcweir  if [ ! -f ${INSTALL_ROOT}/var/sadm/system/admin/INST_RELEASE ]
284cdf0e10cSrcweir  then
285cdf0e10cSrcweir    mkdir -p ${INSTALL_ROOT}/var/sadm/system/admin 2>/dev/null
286cdf0e10cSrcweir    cp -f /var/sadm/system/admin/INST_RELEASE ${INSTALL_ROOT}/var/sadm/system/admin/INST_RELEASE
287cdf0e10cSrcweir  fi
288cdf0e10cSrcweir
289cdf0e10cSrcweir  # The case UPDATE="yes" is valid for patch installation and for language packs.
290cdf0e10cSrcweir  # For patches the variable PKG_LIST is empty, for language packs it is not empty.
291cdf0e10cSrcweir  # Patches have to be installed with patchadd, language packs with pkgadd
292cdf0e10cSrcweir
293cdf0e10cSrcweir  if [ -z "${PKG_LIST}" ]
294cdf0e10cSrcweir  then
295cdf0e10cSrcweir    LD_PRELOAD_32=$GETUID_SO /usr/sbin/patchadd -R ${INSTALL_ROOT} -M ${PATCH_PATH} ${PATCH_LIST} 2>&1 | grep -v '/var/sadm/patch' || pkg_error
296cdf0e10cSrcweir  else
297cdf0e10cSrcweir    LD_PRELOAD_32=$GETUID_SO /usr/sbin/pkgadd -d ${PACKAGE_PATH} -R ${INSTALL_ROOT} ${PKG_LIST} >/dev/null || pkg_error
298cdf0e10cSrcweir  fi
299cdf0e10cSrcweir
300cdf0e10cSrcweirelse
301cdf0e10cSrcweir
302cdf0e10cSrcweir  # Create BASEDIR directories to avoid manual user interaction
303cdf0e10cSrcweir  for i in ${PKG_LIST}; do
304cdf0e10cSrcweir    mkdir -m 0755 -p ${INSTALL_ROOT}`pkgparam -d ${PACKAGE_PATH} $i BASEDIR` 2>/dev/null
305cdf0e10cSrcweir  done
306cdf0e10cSrcweir
307cdf0e10cSrcweir  if [ ! "${INSTALL_ROOT:0:1}" = "/" ]; then
308cdf0e10cSrcweir    INSTALL_ROOT=`cd ${INSTALL_ROOT}; pwd`
309cdf0e10cSrcweir  fi
310cdf0e10cSrcweir
311cdf0e10cSrcweir  echo "####################################################################"
312cdf0e10cSrcweir  echo "#     Installation of the found packages                           #"
313cdf0e10cSrcweir  echo "####################################################################"
314cdf0e10cSrcweir  echo
315cdf0e10cSrcweir  echo "Path to the packages       : " $PACKAGE_PATH
316cdf0e10cSrcweir  echo "Path to the installation   : " $INSTALL_ROOT
317cdf0e10cSrcweir
318cdf0e10cSrcweir  LD_PRELOAD_32=$GETUID_SO /usr/sbin/pkgadd -d ${PACKAGE_PATH} -R ${INSTALL_ROOT} ${PKG_LIST} >/dev/null || pkg_error
319cdf0e10cSrcweirfi
320cdf0e10cSrcweir
321cdf0e10cSrcweirrm -f $GETUID_SO
322cdf0e10cSrcweirrm -f /tmp/.ai.pkg.zone.lock*
323cdf0e10cSrcweir
324cdf0e10cSrcweir# remove local tmp directory
325cdf0e10cSrcweirif [ ! -z ${LOCAL_TMP} ]
326cdf0e10cSrcweirthen
327cdf0e10cSrcweir  rm -f ${LOCAL_TMP}/.ai.pkg.zone.lock*
328cdf0e10cSrcweir  rmdir ${LOCAL_TMP}
329cdf0e10cSrcweir  rm -f ${INSTALL_ROOT}/tmp
330cdf0e10cSrcweir  mkdir ${INSTALL_ROOT}/tmp
331cdf0e10cSrcweirfi
332cdf0e10cSrcweir
333cdf0e10cSrcweir#
334cdf0e10cSrcweir# Create a link into the users home directory
335cdf0e10cSrcweir#
336cdf0e10cSrcweir
337cdf0e10cSrcweirif [ "$LINK" = "yes" ]
338cdf0e10cSrcweirthen
339cdf0e10cSrcweir  rm -f $HOME/soffice 2>/dev/null
340cdf0e10cSrcweir  find `cd "$INSTALL_ROOT" && pwd` -name soffice -type f -perm -u+x -exec /bin/sh -ce 'ln -sf "$0" "$HOME/soffice" && echo "Creating link from $0 to $HOME/soffice"' {} \;
341cdf0e10cSrcweirfi
342cdf0e10cSrcweir
343cdf0e10cSrcweir# patch the "bootstraprc" to create a self-containing installation
344cdf0e10cSrcweirfor i in ${PKG_LIST}; do
345cdf0e10cSrcweir  my_dir=${INSTALL_ROOT}`pkgparam -d ${PACKAGE_PATH} "$i" BASEDIR`
346cdf0e10cSrcweir  find "$my_dir" -type f -name bootstraprc -exec sh -ce 'test ! -f "$0".orig && mv "$0" "$0".orig && sed '\''s,^UserInstallation=$SYSUSERCONFIG.*,UserInstallation=$BRAND_BASE_DIR/../UserInstallation,'\'' "$0".orig > "$0"' {} \;
347cdf0e10cSrcweirdone
348cdf0e10cSrcweir
349cdf0e10cSrcweir# if an unpack directory exists, it can be removed now
350cdf0e10cSrcweirif [ ! -z "$UNPACKDIR" ]
351cdf0e10cSrcweirthen
352cdf0e10cSrcweir  # for i in ${PKG_LIST}; do
353cdf0e10cSrcweir  #   cd $UNPACKDIR; rm -rf $i
354cdf0e10cSrcweir  # done
355cdf0e10cSrcweir  # rmdir $UNPACKDIR
356cdf0e10cSrcweir
357cdf0e10cSrcweir  rm -rf $UNPACKDIR
358cdf0e10cSrcweir  echo "Removed temporary directory $UNPACKDIR"
359cdf0e10cSrcweirfi
360cdf0e10cSrcweir
361cdf0e10cSrcweirecho
362cdf0e10cSrcweirecho "Installation done ..."
363cdf0e10cSrcweirexit 0
364cdf0e10cSrcweir
365