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