update credits
[LibreOffice.git] / setup_native / scripts / update.sh
blobaac202fe6781c7f6af16df9b76ab33b254e3a70d
1 #!/bin/sh
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 GNOMEXCMDS="/usr/bin/gksu"
21 GNOMECMDS="/usr/bin/gnome-terminal /opt/gnome/bin/gnome-terminal"
22 KDEXCMDS="/usr/bin/kdesu /opt/kde/bin/kdesu /opt/kde?/bin/kdesu"
23 KDECMDS="/usr/bin/konsole /opt/kde/bin/konsole /opt/kde?/bin/konsole"
24 MISCCMDS="/usr/bin/x-terminal-emulator /usr/X11/bin/xterm /usr/openwin/bin/xterm"
26 TITLE='${PRODUCTNAME} update'
29 # Usage
32 Usage () {
33 if [ "`basename $0`" = "update" ]; then
34 echo "Usage: `basename $0` [<path to ${PRODUCTNAME} installation>]"
36 echo
37 exit 2
40 make_tempfile() {
42 # Always prefer mktemp when available
43 if [ -x "$MKTEMP" ]; then
44 "$MKTEMP" "/tmp/$1.XXXXXX"
45 else
46 TMPCMD="/tmp/$1.$$"
47 touch $TMPCMD
48 echo $TMPCMD
54 # make_command_file - generate a command file to pass to xterm & co
56 run_in_terminal () {
58 TMPCMD=`make_tempfile 'OpenOffice.org-Online-Update'`
60 cat >> $TMPCMD
62 cat >> $TMPCMD << \EOF
63 if [ $? -eq 0 -a ! -z "$DISPLAY" ]; then
64 echo
65 echo "Press <Enter> to close this window"
66 read DUMMY
68 EOF
70 cat >> $TMPCMD << EOF
71 rm -f $TMPCMD
72 EOF
74 chmod a+x $TMPCMD
75 exec "$@" -e $TMPCMD
79 # run the command line passed as positional parameters either via
80 # gksu/kdesu or via su command in a terminal emulator.
82 elevate() {
84 TITLEOPT=""
85 GEOMOPT=""
86 case `basename $XTERM` in
87 "xterm")
88 TITLEOPT="-title"
89 GEOMOPT="-geometry "
91 "gnome-terminal" | "konsole" | "x-terminal-emulator")
92 TITLEOPT="--title"
93 GEOMOPT="--geometry="
95 esac
97 case `basename $SU` in
98 "kdesu" )
99 # --caption
100 SUOPT="-t"
102 "gksu" )
103 # --title
104 SUOPT=""
106 "su" )
107 SUOPT="- root -c"
109 esac
111 ( echo "echo The application \"$@\" will update your ${PRODUCTNAME} installation."
112 echo "echo"
113 echo "$SU" "$SUOPT" "$@"
114 ) | run_in_terminal "$XTERM" "$TITLEOPT" "$TITLE" ${GEOMOPT}+300+300
118 update_pkg() {
119 ADMINFILE=`make_tempfile 'LibreOffice-Online-Update-admin'`
121 cat >> $ADMINFILE << EOF
122 action=nocheck
123 conflict=nocheck
124 setuid=nocheck
125 idepend=nocheck
126 rdepend=nocheck
127 mail=
130 PKGLIST=""
131 for i in `cd $1; ls -d *`; do
132 pkginfo -q $i && PKGLIST="$PKGLIST $i"
133 done
135 pkgrm -n -a $ADMINFILE $PKGLIST
136 pkgadd -n -a $ADMINFILE -d $1 $PKGLIST
138 rm -f $ADMINFILE
142 # main
145 CMD="`basename $0`"
146 BASEDIR="`dirname $0`"
147 ABSBASEDIR="`cd $BASEDIR; pwd`"
149 if [ -z "$DISPLAY" ]; then
150 SU="su"
151 XTERM=""
152 else
153 # define search order depending on the desktop in use ..
154 if [ "`uname -s`" = "SunOS" ]; then
155 XPROP=/usr/openwin/bin/xprop
156 GREP=/usr/xpg4/bin/grep
157 MKTEMP=/usr/bin/mktemp
158 else
159 if [ -x /usr/X11/bin/xprop ]; then
160 XPROP=/usr/X11/bin/xprop
161 else
162 XPROP=/usr/bin/xprop
164 GREP=grep
165 MKTEMP=/bin/mktemp
168 # use desktop specific tools where possible, but prefer X11 su over terminal emulators
169 if $XPROP -root | $GREP -q '^KWIN_RUNNING'; then
170 SULIST="$KDEXCMDS $GNOMEXCMDS"
171 XTERMLIST="$KDECMDS $MISCCMDS"
172 else
173 SULIST="$GNOMEXCMDS $KDEXCMDS"
174 XTERMLIST="$GNOMECMDS $MISCCMDS"
177 # search for the first available terminal emulator
178 for i in $XTERMLIST; do
179 if [ -x $i ]; then
180 XTERM=$i
181 break
183 done
185 # we prefer gksu or kdesu if available
186 SU="su"
187 for i in $SULIST; do
188 if [ -x $i ]; then
189 SU=$i
190 break
192 done
195 if [ "$CMD" = "update" ]; then
196 if [ $# -gt 0 ]; then
197 [ -d $1 -a $# -eq 1 ] || Usage
198 elevate "$ABSBASEDIR/$CMD"
199 else
200 if [ -d "$BASEDIR/RPMS" ]; then
201 # do not use --hash as the control sequence to edit the current line does not work
202 # in our setup (at least not with kdesu)
203 rpm -v --freshen `find "$BASEDIR"/RPMS -name '*.rpm'`
204 elif [ -d "$BASEDIR/DEBS" ]; then
205 dpkg --install --selected-only --recursive "$BASEDIR"/DEBS
206 elif [ -d "$BASEDIR/packages" ]; then
207 update_pkg "$BASEDIR/packages"
210 else
211 Usage