PageRenderTime 142ms CodeModel.GetById 40ms app.highlight 41ms RepoModel.GetById 35ms app.codeStats 5ms

/indra/newview/linux_tools/install.sh

https://bitbucket.org/lindenlab/viewer-beta/
Shell | 106 lines | 81 code | 22 blank | 3 comment | 12 complexity | a249adcf3c1a15229d7f9032372b075f MD5 | raw file
  1#!/bin/bash
  2
  3# Install the Second Life Viewer. This script can install the viewer both
  4# system-wide and for an individual user.
  5
  6VT102_STYLE_NORMAL='\E[0m'
  7VT102_COLOR_RED='\E[31m'
  8
  9SCRIPTSRC=`readlink -f "$0" || echo "$0"`
 10RUN_PATH=`dirname "${SCRIPTSRC}" || echo .`
 11tarball_path=${RUN_PATH}
 12
 13function prompt()
 14{
 15    local prompt=$1
 16    local input
 17
 18    echo -n "$prompt"
 19
 20    while read input; do
 21        case $input in
 22            [Yy]* )
 23                return 1
 24                ;;
 25            [Nn]* )
 26                return 0
 27                ;;
 28            * )
 29                echo "Please enter yes or no."
 30                echo -n "$prompt"
 31        esac
 32    done
 33}
 34
 35function die()
 36{
 37    warn $1
 38    exit 1
 39}
 40
 41function warn()
 42{
 43    echo -n -e $VT102_COLOR_RED
 44    echo $1
 45    echo -n -e $VT102_STYLE_NORMAL
 46}
 47
 48function homedir_install()
 49{
 50    warn "You are not running as a privileged user, so you will only be able"
 51    warn "to install the Second Life Viewer in your home directory. If you"
 52    warn "would like to install the Second Life Viewer system-wide, please run"
 53    warn "this script as the root user, or with the 'sudo' command."
 54    echo
 55
 56    prompt "Proceed with the installation? [Y/N]: "
 57    if [[ $? == 0 ]]; then
 58	exit 0
 59    fi
 60
 61    install_to_prefix "$HOME/.secondlife-install"
 62    $HOME/.secondlife-install/etc/refresh_desktop_app_entry.sh
 63}
 64
 65function root_install()
 66{
 67    local default_prefix="/opt/secondlife-install"
 68
 69    echo -n "Enter the desired installation directory [${default_prefix}]: ";
 70    read
 71    if [[ "$REPLY" = "" ]] ; then
 72	local install_prefix=$default_prefix
 73    else
 74	local install_prefix=$REPLY
 75    fi
 76
 77    install_to_prefix "$install_prefix"
 78
 79    mkdir -p /usr/local/share/applications
 80    ${install_prefix}/etc/refresh_desktop_app_entry.sh
 81}
 82
 83function install_to_prefix()
 84{
 85    test -e "$1" && backup_previous_installation "$1"
 86    mkdir -p "$1" || die "Failed to create installation directory!"
 87
 88    echo " - Installing to $1"
 89
 90    cp -a "${tarball_path}"/* "$1/" || die "Failed to complete the installation!"
 91}
 92
 93function backup_previous_installation()
 94{
 95    local backup_dir="$1".backup-$(date -I)
 96    echo " - Backing up previous installation to $backup_dir"
 97
 98    mv "$1" "$backup_dir" || die "Failed to create backup of existing installation!"
 99}
100
101
102if [ "$UID" == "0" ]; then
103    root_install
104else
105    homedir_install
106fi