Update ooo320-m1
[ooovba.git] / setup_native / scripts / update.sh
blob176352d4979c1a7875d652eca736de28cb7596c6
1 #!/bin/sh
3 GNOMEXCMDS="/usr/bin/gksu"
4 GNOMECMDS="/usr/bin/gnome-terminal /opt/gnome/bin/gnome-terminal"
5 KDEXCMDS="/usr/bin/kdesu /opt/kde/bin/kdesu /opt/kde?/bin/kdesu"
6 KDECMDS="/usr/bin/konsole /opt/kde/bin/konsole /opt/kde?/bin/konsole"
7 MISCCMDS="/usr/bin/x-terminal-emulator /usr/X11/bin/xterm /usr/openwin/bin/xterm"
9 TITLE='${PRODUCTNAME} update'
12 # Usage
15 Usage () {
16 if [ "`basename $0`" = "update" ]; then
17 echo "Usage: `basename $0` [<path to ${PRODUCTNAME} installation>]"
19 echo
20 exit 2
23 make_tempfile() {
25 # Always prefer mktemp when available
26 if [ -x "$MKTEMP" ]; then
27 "$MKTEMP" "/tmp/$1.XXXXXX"
28 else
29 TMPCMD="/tmp/$1.$$"
30 touch $TMPCMD
31 echo $TMPCMD
37 # make_command_file - generate a command file to pass to xterm & co
39 run_in_terminal () {
41 TMPCMD=`make_tempfile 'OpenOffice.org-Online-Update'`
43 cat >> $TMPCMD
45 cat >> $TMPCMD << \EOF
46 if [ $? -eq 0 -a ! -z "$DISPLAY" ]; then
47 echo
48 echo "Press <Enter> to close this window"
49 read DUMMY
51 EOF
53 cat >> $TMPCMD << EOF
54 rm -f $TMPCMD
55 EOF
57 chmod a+x $TMPCMD
58 exec "$@" -e $TMPCMD
62 # run the command line passed as positional parameters either via
63 # gksu/kdesu or via su command in a terminal emulator.
65 elevate() {
67 TITLEOPT=""
68 GEOMOPT=""
69 case `basename $XTERM` in
70 "xterm")
71 TITLEOPT="-title"
72 GEOMOPT="-geometry "
74 "gnome-terminal" | "konsole" | "x-terminal-emulator")
75 TITLEOPT="--title"
76 GEOMOPT="--geometry="
78 esac
80 case `basename $SU` in
81 "kdesu" )
82 # --caption
83 SUOPT="-t"
85 "gksu" )
86 # --title
87 SUOPT=""
89 "su" )
90 SUOPT="- root -c"
92 esac
94 ( echo "echo The application \"$@\" will update your ${PRODUCTNAME} installation."
95 echo "echo"
96 echo "$SU" "$SUOPT" "$@"
97 ) | run_in_terminal "$XTERM" "$TITLEOPT" "$TITLE" ${GEOMOPT}+300+300
101 update_pkg() {
102 ADMINFILE=`make_tempfile 'OpenOffice.org-Online-Update-admin'`
104 cat >> $ADMINFILE << EOF
105 action=nocheck
106 conflict=nocheck
107 setuid=nocheck
108 idepend=nocheck
109 rdepend=nocheck
110 mail=
113 PKGLIST=""
114 for i in `cd $1; ls -d *`; do
115 pkginfo -q $i && PKGLIST="$PKGLIST $i"
116 done
118 pkgrm -n -a $ADMINFILE $PKGLIST
119 pkgadd -n -a $ADMINFILE -d $1 $PKGLIST
121 rm -f $ADMINFILE
125 # main
128 CMD="`basename $0`"
129 BASEDIR="`dirname $0`"
130 ABSBASEDIR="`cd $BASEDIR; pwd`"
132 if [ -z "$DISPLAY" ]; then
133 SU="su"
134 XTERM=""
135 else
136 # define search order depending on the desktop in use ..
137 if [ "`uname -s`" = "SunOS" ]; then
138 XPROP=/usr/openwin/bin/xprop
139 GREP=/usr/xpg4/bin/grep
140 MKTEMP=/usr/bin/mktemp
141 else
142 if [ -x /usr/X11/bin/xprop ]; then
143 XPROP=/usr/X11/bin/xprop
144 else
145 XPROP=/usr/bin/xprop
147 GREP=grep
148 MKTEMP=/bin/mktemp
151 # use desktop specific tools where possible, but prefer X11 su over terminal emulators
152 if $XPROP -root | $GREP -q '^KWIN_RUNNING'; then
153 SULIST="$KDEXCMDS $GNOMEXCMDS"
154 XTERMLIST="$KDECMDS $MISCCMDS"
155 else
156 SULIST="$GNOMEXCMDS $KDEXCMDS"
157 XTERMLIST="$GNOMECMDS $MISCCMDS"
160 # search for the first available terminal emulator
161 for i in $XTERMLIST; do
162 if [ -x $i ]; then
163 XTERM=$i
164 break
166 done
168 # we prefer gksu or kdesu if available
169 SU="su"
170 for i in $SULIST; do
171 if [ -x $i ]; then
172 SU=$i
173 break
175 done
178 if [ "$CMD" = "update" ]; then
179 if [ $# -gt 0 ]; then
180 [ -d $1 -a $# -eq 1 ] || Usage
181 elevate "$ABSBASEDIR/$CMD"
182 else
183 if [ -d "$BASEDIR/RPMS" ]; then
184 # do not use --hash as the control sequence to edit the current line does not work
185 # in our setup (at least not with kdesu)
186 rpm -v --freshen `find "$BASEDIR"/RPMS -name '*.rpm'`
187 elif [ -d "$BASEDIR/DEBS" ]; then
188 dpkg --install --selected-only --recursive "$BASEDIR"/DEBS
189 elif [ -d "$BASEDIR/packages" ]; then
190 update_pkg "$BASEDIR/packages"
193 else
194 Usage