xref: /trunk/main/setup_native/scripts/update.sh (revision ff3f4ebc)
1cdf0e10cSrcweir#!/bin/sh
29f22d7c2SAndrew Rist# *************************************************************
39f22d7c2SAndrew Rist#
49f22d7c2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
59f22d7c2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
69f22d7c2SAndrew Rist#  distributed with this work for additional information
79f22d7c2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
89f22d7c2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
99f22d7c2SAndrew Rist#  "License"); you may not use this file except in compliance
109f22d7c2SAndrew Rist#  with the License.  You may obtain a copy of the License at
119f22d7c2SAndrew Rist#
129f22d7c2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
139f22d7c2SAndrew Rist#
149f22d7c2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
159f22d7c2SAndrew Rist#  software distributed under the License is distributed on an
169f22d7c2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
179f22d7c2SAndrew Rist#  KIND, either express or implied.  See the License for the
189f22d7c2SAndrew Rist#  specific language governing permissions and limitations
199f22d7c2SAndrew Rist#  under the License.
209f22d7c2SAndrew Rist#
219f22d7c2SAndrew Rist# *************************************************************
22cdf0e10cSrcweir
23cdf0e10cSrcweirGNOMEXCMDS="/usr/bin/gksu"
24cdf0e10cSrcweirGNOMECMDS="/usr/bin/gnome-terminal /opt/gnome/bin/gnome-terminal"
25cdf0e10cSrcweirKDEXCMDS="/usr/bin/kdesu /opt/kde/bin/kdesu /opt/kde?/bin/kdesu"
26cdf0e10cSrcweirKDECMDS="/usr/bin/konsole /opt/kde/bin/konsole /opt/kde?/bin/konsole"
27cdf0e10cSrcweirMISCCMDS="/usr/bin/x-terminal-emulator /usr/X11/bin/xterm /usr/openwin/bin/xterm"
28cdf0e10cSrcweir
29cdf0e10cSrcweirTITLE='${PRODUCTNAME} update'
30cdf0e10cSrcweir
31cdf0e10cSrcweir#
32cdf0e10cSrcweir# Usage
33cdf0e10cSrcweir#
34cdf0e10cSrcweir
35cdf0e10cSrcweirUsage () {
36cdf0e10cSrcweir  if [ "`basename $0`" = "update" ]; then
37cdf0e10cSrcweir    echo "Usage: `basename $0` [<path to ${PRODUCTNAME} installation>]"
38cdf0e10cSrcweir  fi
39cdf0e10cSrcweir  echo
40cdf0e10cSrcweir  exit 2
41cdf0e10cSrcweir}
42cdf0e10cSrcweir
43cdf0e10cSrcweirmake_tempfile() {
44cdf0e10cSrcweir
45cdf0e10cSrcweir  # Always prefer mktemp when available
46cdf0e10cSrcweir  if [ -x "$MKTEMP" ]; then
47cdf0e10cSrcweir    "$MKTEMP" "/tmp/$1.XXXXXX"
48cdf0e10cSrcweir  else
49cdf0e10cSrcweir    TMPCMD="/tmp/$1.$$"
50cdf0e10cSrcweir    touch $TMPCMD
51cdf0e10cSrcweir    echo $TMPCMD
52cdf0e10cSrcweir  fi
53cdf0e10cSrcweir
54cdf0e10cSrcweir}
55cdf0e10cSrcweir
56cdf0e10cSrcweir#
57cdf0e10cSrcweir# make_command_file - generate a command file to pass to xterm & co
58cdf0e10cSrcweir#
59cdf0e10cSrcweirrun_in_terminal () {
60cdf0e10cSrcweir
61*ff3f4ebcSOliver-Rainer Wittmann  TMPCMD=`make_tempfile 'Apache_OpenOffice-Online-Update'`
62cdf0e10cSrcweir
63cdf0e10cSrcweir  cat >> $TMPCMD
64cdf0e10cSrcweir
65cdf0e10cSrcweir  cat >> $TMPCMD << \EOF
66cdf0e10cSrcweirif [ $? -eq 0 -a ! -z "$DISPLAY" ]; then
67cdf0e10cSrcweir  echo
68cdf0e10cSrcweir  echo "Press <Enter> to close this window"
69cdf0e10cSrcweir  read DUMMY
70cdf0e10cSrcweirfi
71cdf0e10cSrcweirEOF
72cdf0e10cSrcweir
73cdf0e10cSrcweir  cat >> $TMPCMD << EOF
74cdf0e10cSrcweirrm -f $TMPCMD
75cdf0e10cSrcweirEOF
76cdf0e10cSrcweir
77cdf0e10cSrcweir  chmod a+x $TMPCMD
78cdf0e10cSrcweir  exec "$@" -e $TMPCMD
79cdf0e10cSrcweir}
80cdf0e10cSrcweir
81cdf0e10cSrcweir#
82cdf0e10cSrcweir# run the command line passed as positional parameters either via
83cdf0e10cSrcweir# gksu/kdesu or via su command in a terminal emulator.
84cdf0e10cSrcweir#
85cdf0e10cSrcweirelevate() {
86cdf0e10cSrcweir
87cdf0e10cSrcweir  TITLEOPT=""
88cdf0e10cSrcweir  GEOMOPT=""
89cdf0e10cSrcweir  case `basename $XTERM` in
90cdf0e10cSrcweir    "xterm")
91cdf0e10cSrcweir      TITLEOPT="-title"
92cdf0e10cSrcweir      GEOMOPT="-geometry "
93cdf0e10cSrcweir      ;;
94cdf0e10cSrcweir    "gnome-terminal" | "konsole" | "x-terminal-emulator")
95cdf0e10cSrcweir      TITLEOPT="--title"
96cdf0e10cSrcweir      GEOMOPT="--geometry="
97cdf0e10cSrcweir      ;;
98cdf0e10cSrcweir  esac
99cdf0e10cSrcweir
100cdf0e10cSrcweir  case `basename $SU` in
101cdf0e10cSrcweir    "kdesu" )
102cdf0e10cSrcweir      # --caption
103cdf0e10cSrcweir      SUOPT="-t"
104cdf0e10cSrcweir      ;;
105cdf0e10cSrcweir    "gksu" )
106cdf0e10cSrcweir      # --title
107cdf0e10cSrcweir      SUOPT=""
108cdf0e10cSrcweir      ;;
109cdf0e10cSrcweir    "su" )
110cdf0e10cSrcweir      SUOPT="- root -c"
111cdf0e10cSrcweir      ;;
112cdf0e10cSrcweir  esac
113cdf0e10cSrcweir
114cdf0e10cSrcweir  ( echo "echo The application \"$@\" will update your ${PRODUCTNAME} installation."
115cdf0e10cSrcweir    echo "echo"
116cdf0e10cSrcweir    echo "$SU" "$SUOPT" "$@"
117cdf0e10cSrcweir  ) | run_in_terminal "$XTERM" "$TITLEOPT" "$TITLE" ${GEOMOPT}+300+300
118cdf0e10cSrcweir}
119cdf0e10cSrcweir
120cdf0e10cSrcweir
121cdf0e10cSrcweirupdate_pkg() {
122*ff3f4ebcSOliver-Rainer Wittmann  ADMINFILE=`make_tempfile 'Apache_OpenOffice-Online-Update-admin'`
123cdf0e10cSrcweir
124cdf0e10cSrcweircat >> $ADMINFILE << EOF
125cdf0e10cSrcweiraction=nocheck
126cdf0e10cSrcweirconflict=nocheck
127cdf0e10cSrcweirsetuid=nocheck
128cdf0e10cSrcweiridepend=nocheck
129cdf0e10cSrcweirrdepend=nocheck
130cdf0e10cSrcweirmail=
131cdf0e10cSrcweirEOF
132cdf0e10cSrcweir
133cdf0e10cSrcweir  PKGLIST=""
134cdf0e10cSrcweir  for i in `cd $1; ls -d *`; do
135cdf0e10cSrcweir    pkginfo -q $i && PKGLIST="$PKGLIST $i"
136cdf0e10cSrcweir  done
137cdf0e10cSrcweir
138cdf0e10cSrcweir  pkgrm -n -a $ADMINFILE $PKGLIST
139cdf0e10cSrcweir  pkgadd -n -a $ADMINFILE -d $1 $PKGLIST
140cdf0e10cSrcweir
141cdf0e10cSrcweir  rm -f $ADMINFILE
142cdf0e10cSrcweir}
143cdf0e10cSrcweir
144cdf0e10cSrcweir#
145cdf0e10cSrcweir# main
146cdf0e10cSrcweir#
147cdf0e10cSrcweir
148cdf0e10cSrcweirCMD="`basename $0`"
149cdf0e10cSrcweirBASEDIR="`dirname $0`"
150cdf0e10cSrcweirABSBASEDIR="`cd $BASEDIR; pwd`"
151cdf0e10cSrcweir
152cdf0e10cSrcweirif [ -z "$DISPLAY" ]; then
153cdf0e10cSrcweir  SU="su"
154cdf0e10cSrcweir  XTERM=""
155cdf0e10cSrcweirelse
156cdf0e10cSrcweir  # define search order depending on the desktop in use ..
157cdf0e10cSrcweir  if [ "`uname -s`" = "SunOS" ]; then
158cdf0e10cSrcweir    XPROP=/usr/openwin/bin/xprop
159cdf0e10cSrcweir    GREP=/usr/xpg4/bin/grep
160cdf0e10cSrcweir    MKTEMP=/usr/bin/mktemp
161cdf0e10cSrcweir  else
162cdf0e10cSrcweir    if [ -x /usr/X11/bin/xprop ]; then
163cdf0e10cSrcweir	  XPROP=/usr/X11/bin/xprop
164cdf0e10cSrcweir	else
165cdf0e10cSrcweir      XPROP=/usr/bin/xprop
166cdf0e10cSrcweir	fi
167cdf0e10cSrcweir    GREP=grep
168cdf0e10cSrcweir    MKTEMP=/bin/mktemp
169cdf0e10cSrcweir  fi
170cdf0e10cSrcweir
171cdf0e10cSrcweir  # use desktop specific tools where possible, but prefer X11 su over terminal emulators
172cdf0e10cSrcweir  if $XPROP -root | $GREP -q '^KWIN_RUNNING'; then
173cdf0e10cSrcweir    SULIST="$KDEXCMDS $GNOMEXCMDS"
174cdf0e10cSrcweir    XTERMLIST="$KDECMDS $MISCCMDS"
175cdf0e10cSrcweir  else
176cdf0e10cSrcweir    SULIST="$GNOMEXCMDS $KDEXCMDS"
177cdf0e10cSrcweir    XTERMLIST="$GNOMECMDS $MISCCMDS"
178cdf0e10cSrcweir  fi
179cdf0e10cSrcweir
180cdf0e10cSrcweir  # search for the first available terminal emulator
181cdf0e10cSrcweir  for i in $XTERMLIST; do
182cdf0e10cSrcweir    if [ -x $i ]; then
183cdf0e10cSrcweir      XTERM=$i
184cdf0e10cSrcweir      break
185cdf0e10cSrcweir    fi
186cdf0e10cSrcweir  done
187cdf0e10cSrcweir
188cdf0e10cSrcweir  # we prefer gksu or kdesu if available
189cdf0e10cSrcweir  SU="su"
190cdf0e10cSrcweir  for i in $SULIST; do
191cdf0e10cSrcweir    if [ -x $i ]; then
192cdf0e10cSrcweir      SU=$i
193cdf0e10cSrcweir      break
194cdf0e10cSrcweir    fi
195cdf0e10cSrcweir  done
196cdf0e10cSrcweirfi
197cdf0e10cSrcweir
198cdf0e10cSrcweirif [ "$CMD" = "update" ]; then
199cdf0e10cSrcweir  if [ $# -gt 0 ]; then
200cdf0e10cSrcweir    [ -d $1 -a $# -eq 1 ] || Usage
201cdf0e10cSrcweir    elevate "$ABSBASEDIR/$CMD"
202cdf0e10cSrcweir  else
203cdf0e10cSrcweir    if [ -d "$BASEDIR/RPMS" ]; then
204cdf0e10cSrcweir      # do not use --hash as the control sequence to edit the current line does not work
205cdf0e10cSrcweir      # in our setup (at least not with kdesu)
206cdf0e10cSrcweir      rpm -v --freshen `find "$BASEDIR"/RPMS -name '*.rpm'`
207cdf0e10cSrcweir    elif [ -d "$BASEDIR/DEBS" ]; then
208cdf0e10cSrcweir	  dpkg --install --selected-only --recursive "$BASEDIR"/DEBS
209cdf0e10cSrcweir    elif [ -d "$BASEDIR/packages" ]; then
210cdf0e10cSrcweir      update_pkg "$BASEDIR/packages"
211cdf0e10cSrcweir    fi
212cdf0e10cSrcweir  fi
213cdf0e10cSrcweirelse
214cdf0e10cSrcweir  Usage
215cdf0e10cSrcweirfi
216