xref: /aoo42x/main/setup_native/scripts/update.sh (revision cdf0e10c)
1#!/bin/sh
2
3GNOMEXCMDS="/usr/bin/gksu"
4GNOMECMDS="/usr/bin/gnome-terminal /opt/gnome/bin/gnome-terminal"
5KDEXCMDS="/usr/bin/kdesu /opt/kde/bin/kdesu /opt/kde?/bin/kdesu"
6KDECMDS="/usr/bin/konsole /opt/kde/bin/konsole /opt/kde?/bin/konsole"
7MISCCMDS="/usr/bin/x-terminal-emulator /usr/X11/bin/xterm /usr/openwin/bin/xterm"
8
9TITLE='${PRODUCTNAME} update'
10
11#
12# Usage
13#
14
15Usage () {
16  if [ "`basename $0`" = "update" ]; then
17    echo "Usage: `basename $0` [<path to ${PRODUCTNAME} installation>]"
18  fi
19  echo
20  exit 2
21}
22
23make_tempfile() {
24
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
32  fi
33
34}
35
36#
37# make_command_file - generate a command file to pass to xterm & co
38#
39run_in_terminal () {
40
41  TMPCMD=`make_tempfile 'OpenOffice.org-Online-Update'`
42
43  cat >> $TMPCMD
44
45  cat >> $TMPCMD << \EOF
46if [ $? -eq 0 -a ! -z "$DISPLAY" ]; then
47  echo
48  echo "Press <Enter> to close this window"
49  read DUMMY
50fi
51EOF
52
53  cat >> $TMPCMD << EOF
54rm -f $TMPCMD
55EOF
56
57  chmod a+x $TMPCMD
58  exec "$@" -e $TMPCMD
59}
60
61#
62# run the command line passed as positional parameters either via
63# gksu/kdesu or via su command in a terminal emulator.
64#
65elevate() {
66
67  TITLEOPT=""
68  GEOMOPT=""
69  case `basename $XTERM` in
70    "xterm")
71      TITLEOPT="-title"
72      GEOMOPT="-geometry "
73      ;;
74    "gnome-terminal" | "konsole" | "x-terminal-emulator")
75      TITLEOPT="--title"
76      GEOMOPT="--geometry="
77      ;;
78  esac
79
80  case `basename $SU` in
81    "kdesu" )
82      # --caption
83      SUOPT="-t"
84      ;;
85    "gksu" )
86      # --title
87      SUOPT=""
88      ;;
89    "su" )
90      SUOPT="- root -c"
91      ;;
92  esac
93
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
98}
99
100
101update_pkg() {
102  ADMINFILE=`make_tempfile 'OpenOffice.org-Online-Update-admin'`
103
104cat >> $ADMINFILE << EOF
105action=nocheck
106conflict=nocheck
107setuid=nocheck
108idepend=nocheck
109rdepend=nocheck
110mail=
111EOF
112
113  PKGLIST=""
114  for i in `cd $1; ls -d *`; do
115    pkginfo -q $i && PKGLIST="$PKGLIST $i"
116  done
117
118  pkgrm -n -a $ADMINFILE $PKGLIST
119  pkgadd -n -a $ADMINFILE -d $1 $PKGLIST
120
121  rm -f $ADMINFILE
122}
123
124#
125# main
126#
127
128CMD="`basename $0`"
129BASEDIR="`dirname $0`"
130ABSBASEDIR="`cd $BASEDIR; pwd`"
131
132if [ -z "$DISPLAY" ]; then
133  SU="su"
134  XTERM=""
135else
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
146	fi
147    GREP=grep
148    MKTEMP=/bin/mktemp
149  fi
150
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"
158  fi
159
160  # search for the first available terminal emulator
161  for i in $XTERMLIST; do
162    if [ -x $i ]; then
163      XTERM=$i
164      break
165    fi
166  done
167
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
174    fi
175  done
176fi
177
178if [ "$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"
191    fi
192  fi
193else
194  Usage
195fi
196