1#!/bin/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 23GNOMEXCMDS="/usr/bin/gksu" 24GNOMECMDS="/usr/bin/gnome-terminal /opt/gnome/bin/gnome-terminal" 25KDEXCMDS="/usr/bin/kdesu /opt/kde/bin/kdesu /opt/kde?/bin/kdesu" 26KDECMDS="/usr/bin/konsole /opt/kde/bin/konsole /opt/kde?/bin/konsole" 27MISCCMDS="/usr/bin/x-terminal-emulator /usr/X11/bin/xterm /usr/openwin/bin/xterm" 28 29TITLE='${PRODUCTNAME} update' 30 31# 32# Usage 33# 34 35Usage () { 36 if [ "`basename $0`" = "update" ]; then 37 echo "Usage: `basename $0` [<path to ${PRODUCTNAME} installation>]" 38 fi 39 echo 40 exit 2 41} 42 43make_tempfile() { 44 45 # Always prefer mktemp when available 46 if [ -x "$MKTEMP" ]; then 47 "$MKTEMP" "/tmp/$1.XXXXXX" 48 else 49 TMPCMD="/tmp/$1.$$" 50 touch $TMPCMD 51 echo $TMPCMD 52 fi 53 54} 55 56# 57# make_command_file - generate a command file to pass to xterm & co 58# 59run_in_terminal () { 60 61 TMPCMD=`make_tempfile 'Apache_OpenOffice-Online-Update'` 62 63 cat >> $TMPCMD 64 65 cat >> $TMPCMD << \EOF 66if [ $? -eq 0 -a ! -z "$DISPLAY" ]; then 67 echo 68 echo "Press <Enter> to close this window" 69 read DUMMY 70fi 71EOF 72 73 cat >> $TMPCMD << EOF 74rm -f $TMPCMD 75EOF 76 77 chmod a+x $TMPCMD 78 exec "$@" -e $TMPCMD 79} 80 81# 82# run the command line passed as positional parameters either via 83# gksu/kdesu or via su command in a terminal emulator. 84# 85elevate() { 86 87 TITLEOPT="" 88 GEOMOPT="" 89 case `basename $XTERM` in 90 "xterm") 91 TITLEOPT="-title" 92 GEOMOPT="-geometry " 93 ;; 94 "gnome-terminal" | "konsole" | "x-terminal-emulator") 95 TITLEOPT="--title" 96 GEOMOPT="--geometry=" 97 ;; 98 esac 99 100 case `basename $SU` in 101 "kdesu" ) 102 # --caption 103 SUOPT="-t" 104 ;; 105 "gksu" ) 106 # --title 107 SUOPT="" 108 ;; 109 "su" ) 110 SUOPT="- root -c" 111 ;; 112 esac 113 114 ( echo "echo The application \"$@\" will update your ${PRODUCTNAME} installation." 115 echo "echo" 116 echo "$SU" "$SUOPT" "$@" 117 ) | run_in_terminal "$XTERM" "$TITLEOPT" "$TITLE" ${GEOMOPT}+300+300 118} 119 120 121update_pkg() { 122 ADMINFILE=`make_tempfile 'Apache_OpenOffice-Online-Update-admin'` 123 124cat >> $ADMINFILE << EOF 125action=nocheck 126conflict=nocheck 127setuid=nocheck 128idepend=nocheck 129rdepend=nocheck 130mail= 131EOF 132 133 PKGLIST="" 134 for i in `cd $1; ls -d *`; do 135 pkginfo -q $i && PKGLIST="$PKGLIST $i" 136 done 137 138 pkgrm -n -a $ADMINFILE $PKGLIST 139 pkgadd -n -a $ADMINFILE -d $1 $PKGLIST 140 141 rm -f $ADMINFILE 142} 143 144# 145# main 146# 147 148CMD="`basename $0`" 149BASEDIR="`dirname $0`" 150ABSBASEDIR="`cd $BASEDIR; pwd`" 151 152if [ -z "$DISPLAY" ]; then 153 SU="su" 154 XTERM="" 155else 156 # define search order depending on the desktop in use .. 157 if [ "`uname -s`" = "SunOS" ]; then 158 XPROP=/usr/openwin/bin/xprop 159 GREP=/usr/xpg4/bin/grep 160 MKTEMP=/usr/bin/mktemp 161 else 162 if [ -x /usr/X11/bin/xprop ]; then 163 XPROP=/usr/X11/bin/xprop 164 else 165 XPROP=/usr/bin/xprop 166 fi 167 GREP=grep 168 MKTEMP=/bin/mktemp 169 fi 170 171 # use desktop specific tools where possible, but prefer X11 su over terminal emulators 172 if $XPROP -root | $GREP -q '^KWIN_RUNNING'; then 173 SULIST="$KDEXCMDS $GNOMEXCMDS" 174 XTERMLIST="$KDECMDS $MISCCMDS" 175 else 176 SULIST="$GNOMEXCMDS $KDEXCMDS" 177 XTERMLIST="$GNOMECMDS $MISCCMDS" 178 fi 179 180 # search for the first available terminal emulator 181 for i in $XTERMLIST; do 182 if [ -x $i ]; then 183 XTERM=$i 184 break 185 fi 186 done 187 188 # we prefer gksu or kdesu if available 189 SU="su" 190 for i in $SULIST; do 191 if [ -x $i ]; then 192 SU=$i 193 break 194 fi 195 done 196fi 197 198if [ "$CMD" = "update" ]; then 199 if [ $# -gt 0 ]; then 200 [ -d $1 -a $# -eq 1 ] || Usage 201 elevate "$ABSBASEDIR/$CMD" 202 else 203 if [ -d "$BASEDIR/RPMS" ]; then 204 # do not use --hash as the control sequence to edit the current line does not work 205 # in our setup (at least not with kdesu) 206 rpm -v --freshen `find "$BASEDIR"/RPMS -name '*.rpm'` 207 elif [ -d "$BASEDIR/DEBS" ]; then 208 dpkg --install --selected-only --recursive "$BASEDIR"/DEBS 209 elif [ -d "$BASEDIR/packages" ]; then 210 update_pkg "$BASEDIR/packages" 211 fi 212 fi 213else 214 Usage 215fi 216