diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2013-01-09 20:39:06 -0500 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2013-01-09 20:39:06 -0500 |
commit | 34f231cc66bc746228fe367712447058d76757b3 (patch) | |
tree | 637f72962ef8f7ea36a6fee28455ec93ce2aefb5 /indra/viewer_components/updater/scripts | |
parent | bf55755262244c7c36df781d2e093b4109f6ecbf (diff) |
MAINT-1481: remove linux-updater; move logic to Linux update_install
Now that the viewer's own background updater logic is responsible for
downloading a new installer, the only functionality we still use in
linux-updater that couldn't be expressed more simply in bash is the UI. But
since most Linux distros capable of running SL at all have zenity, and all
will have xmessage, we can handle even the UI part. Add xmenity wrapper script
so update_install doesn't have to care which is present, and make the bash
script that used to launch linux-updater do the real work.
Diffstat (limited to 'indra/viewer_components/updater/scripts')
-rw-r--r-- | indra/viewer_components/updater/scripts/linux/update_install | 151 | ||||
-rwxr-xr-x | indra/viewer_components/updater/scripts/linux/xmenity | 55 |
2 files changed, 200 insertions, 6 deletions
diff --git a/indra/viewer_components/updater/scripts/linux/update_install b/indra/viewer_components/updater/scripts/linux/update_install index e0505a9f72..7c08966830 100644 --- a/indra/viewer_components/updater/scripts/linux/update_install +++ b/indra/viewer_components/updater/scripts/linux/update_install @@ -1,10 +1,149 @@ #! /bin/bash -INSTALL_DIR=$(cd "$(dirname "$0")/.." ; pwd) -export LD_LIBRARY_PATH="$INSTALL_DIR/lib" -bin/linux-updater.bin --file "$1" --dest "$INSTALL_DIR" --name "Second Life Viewer" --stringsdir "$INSTALL_DIR/skins/default/xui/en" --stringsfile "strings.xml" -if [ $? -ne 0 ] - then echo $3 >> "$2" +# @file update_install +# @author Nat Goodspeed +# @date 2013-01-09 +# @brief Update the containing Second Life application bundle to the version in +# the specified tarball. +# +# This bash implementation is derived from the previous linux-updater.bin +# application. +# +# $LicenseInfo:firstyear=2013&license=viewerlgpl$ +# Copyright (c) 2013, Linden Research, Inc. +# $/LicenseInfo$ + +tarball="$1" # the file to install +markerfile="$2" # create this file on failure +mandatory="$3" # what to write to markerfile on failure + +function log { + # our log file will be open as stderr -- but until we set up that + # redirection, logging to stderr is better than nothing + echo "$*" 1>&2 +} + +function status { + log "$@" + # Prefix with '#' so xmenity will recognize it as a status message + echo "#$*" +} + +function fail { + # Log the message + log "$@" + # tell subsequent viewer things went south + echo "$mandatory" > "$markerfile" + # add boilerplate + local msg="An error occurred while updating Second Life: +$* +Please download the latest viewer from www.secondlife.com." + # Restate test from xmenity to detect whether we can use zenity or must + # fall back to xmessage + zenpath="$(which zenity)" + if [ -n "$zenpath" -a -x "$zenpath" ] + then "$zenpath" --error --title "Second Life Viewer Updater" \ + --width=320 --height=120 --text="$msg" + else xmessage -buttons -OK:2 -center "$msg" + fi + exit 1 +} + +function sudo_mv { + # If we have write permission to both parent directories, shouldn't need + # sudo. + if [ -w "$(dirname "$1")" -a -w "$(dirname "$2")" ] + then mv "$1" "$2" || fail "Couldn't move $1 to $2" + else # use one of the likely sudo programs + sudo="$(which gksudo)" + if [ -z "$sudo" ] + then sudo="$(which kdesu)" + fi + if [ -z "$sudo" ] + then # couldn't find either one, just try it anyway + mv "$1" "$2" || fail "Couldn't move $1 to $2" + else # even with sudo, could fail, e.g. different filesystems + "$sudo" mv "$1" "$2" || fail "Couldn't move $1 to $2" + fi + fi +} + +# empty array +cleanups=() + +function cleanup { + # wacky bash syntax for appending to array + cleanups[${#cleanups[*]}]="$*" +} + +function onexit { + for action in "${cleanups[@]}" + do # don't quote, support actions consisting of multiple words + $action + done +} + +trap 'onexit' EXIT + +mydir="$(dirname "$0")" +# We happen to know that the viewer specifies a marker-file pathname within +# the logs directory. +logsdir="$(dirname "$markerfile")" +logname="$logsdir/updater.log" + +# move aside old updater.log; we're about to create a new one +[ -f "$logname" ] && mv "$logname" "$logname.old" + +# Set up redirections for this script such that stderr is logged, while +# special stdout messages drive our UI, as described in xmenity. +exec 2> "$logname" | "$mydir/xmenity" +# Piping to xmenity requires that we end with a line consisting of the string +# "100" to terminate zenity progress bar. +cleanup echo 100 + +# Rather than setting up a special pipeline to timestamp every line of stderr, +# produce header lines into log file indicating timestamp and the arguments +# with which we were invoked. +date 1>&2 +log "$0 $*" + +# Log every command we execute, along with any stderr it might produce +set -x + +status 'Installing Second Life...' + +# Creating tempdir under /tmp means it's possible that tempdir is on a +# different filesystem than INSTALL_DIR. One is tempted to create tempdir on a +# path derived from `dirname INSTALL_DIR`, but then we might need to add +# another sudo prompt to create it. +tempdir="/tmp/$(basename "$0").$$" +tempinstall="$tempdir/install" +mkdir -p "$tempinstall" || fail "Couldn't create $tempinstall" +cleanup rm -rf "$tempdir" + +# If we already knew the name of the tarball's top-level directory, we could +# just move that when all was said and done. Since we don't, untarring to the +# 'install' subdir with --strip 1 effectively renames that top-level +# directory. +tar --strip 1 -xjf "$tarball" -C "$tempinstall" || fail "Untar command failed" + +INSTALL_DIR="$(cd "$mydir/.." ; pwd)" + +# Considering we're launched from a subdirectory of INSTALL_DIR, would be +# surprising if it did NOT already exist... +if [ -f "$INSTALL_DIR" ] +then backup="$INSTALL_DIR.backup" + backupn=1 + while [ -f "$backup" ] + do backup="$INSTALL_DIR.backup.$backupn" + ((backupn += 1)) + done + sudo_mv "$INSTALL_DIR" "$backup" fi +# We unpacked the tarball into tempinstall. Move that. +sudo_mv "$tempinstall" "$INSTALL_DIR" + +rm -f "$tarball" -rm -f "$1" +# launch the updated viewer +"$INSTALL_DIR/secondlife" & diff --git a/indra/viewer_components/updater/scripts/linux/xmenity b/indra/viewer_components/updater/scripts/linux/xmenity new file mode 100755 index 0000000000..c0c033904c --- /dev/null +++ b/indra/viewer_components/updater/scripts/linux/xmenity @@ -0,0 +1,55 @@ +#!/bin/bash + +# @file xmenity +# @author Nat Goodspeed +# @date 2013-01-09 +# @brief Provide progress UI for bash scripts (e.g. update_install) using +# zenity if available, xmessage if not. +# +# $LicenseInfo:firstyear=2013&license=viewerlgpl$ +# Copyright (c) 2013, Linden Research, Inc. +# $/LicenseInfo$ + +# This script invokes either zenity --progress or, if zenity is unavailable, +# wraps xmessage in a zenity-like interface. That is its mutant power. +# Pass $1 as the title for your zenity box. It is ignored by xmessage. +# Send updates on stdin: +# A line containing only a decimal integer from 0 - 100 sets that progress. +# End with 100 to tell zenity to terminate. +# A line starting with '#' replaces the progress text. +# All other stdin lines are ignored. + +zenpath="$(which zenity)" +if [ -n "$zenpath" -a -x "$zenpath" ] +then # if executable zenity is on PATH, run that instead of this. + exec "$zenpath" --progress --title="$1" --auto-close --width=320 --height=120 +fi + +# Arriving here means we don't have zenity available. The remainder of this +# script is the xmessage wrapper. + +# We operate by leaving one background xmessage process running. This is the +# pid of that process. +xmpid="" + +function clear_message { + [ -n "$xmpid" ] && kill $xmpid + xmpid="" +} + +# Cancel any pending xmessage, regardless of how we exit. +trap 'clear_message' EXIT + +while read line +do # terminate like zenity --progress + [ "$line" == "100" ] && break + # ignore everything but replacement text + nohash="${line#'#'}" + # if stripping leading hash doesn't change line, it doesn't have one + [ "$nohash" == "$line" ] && continue + # clear any previous message + clear_message + # put up a new xmessage and capture its pid + xmessage -buttons OK:2 -center "$nohash" & + xmpid=$! +done |