#!/bin/bash # # $Header: /var/cvsroot/gentoo/src/installer/bin/installer,v 1.4 2006/07/19 23:43:25 wolf31o2 Exp $ # # This is the installer script that we will use to determine whether or not # we are running in X or as root. A good portion of this script was ripped # from the loki_setup setup.sh script, as it already did most of what I was # looking to do. installer_root=/opt/installer # Allow X xhost +localhost 2>/dev/null # patching utf-8 locales if test ! ${UTF8FIX} ; then LANG=`echo ${LANG} | sed 's/[\@\.].*$//'` fi # Go to the proper setup directory (if not already there) #cd `dirname $0` cd $installer_root/bin # call installer with -auth when ran through su/xsu/sudo auth=0 if [ "${1}" == "-auth" ]; then auth=1 shift fi # we see if we were called with a specific front-end launch= if [ "${1}" == "gtk" ]; then launch=gtk shift elif [ "${1}" == "dialog" ]; then launch=dialog shift fi # Find the installation program # try_run INSTALLER_NAME [PARAMETERS_PASSED] # INSTALLER_NAME: installer-gtk or installer-dialog # PARAMETERS_PASSED: additional arguments passed to the setup script try_run() { setup=$1 shift failed=0 "$setup" "$@" 2>/dev/null failed="$?" return "$failed" } if [ "$auth" -eq 0 ]; then GOT_ROOT=`id -u` if [ "$GOT_ROOT" != "0" ]; then # first we try sudo try_run /usr/bin/sudo env DISPLAY=":0.0" su -c "$installer_root/bin/installer -auth ${launch}" status="$?" if [ "$status" -eq 0 ]; then exit 0 elif [ "$status" -eq 1 ]; then try_run /usr/bin/gnomesu -u root -c "sh $installer_root/bin/installer -auth ${launch}" status="$?" # If try_run successfully executed gnomesu, it will return gnomesu's # exit code. if [ "$status" -eq 0 ]; then exit 0 elif [ "$status" -eq 1 ]; then try_run /usr/bin/xsu -e -a -u root -c "sh $installer_root/bin/installer -auth ${launch}" status="$?" # xsu returns 2 if ran and cancelled (i.e. the user 'doesn't # want' to auth). it will return 0 if the command was executed # correctly # summing up, if we get 1, something failed if [ "$status" -eq 0 ]; then exit 0 elif [ "$status" -eq 1 ]; then # xsu wasn't found, or failed to run # if xsu actually ran and the auth was cancelled, # $status is 2 echo "You need to run this installation as the super user." echo "Please enter the root password." try_run /bin/su root -c "export DISPLAY=$DISPLAY;sh $installer_root/bin/installer -auth ${launch}" status="$?" if [ "$status" -eq 0 ]; then # the auth command was properly executed exit 0 else exit 1 fi elif [ "$status" -eq 3 ]; then # the auth failed or was canceled # we don't want to even start the setup if not root echo "Please run this installation as the super user" exit 1 fi elif [ "$status" -eq 3 ]; then echo "Please run this installation as the super user" exit 1 fi fi fi fi if [ -z "${launch}" ]; then # Try to run the gtk installer try_run /usr/bin/installer-gtk $args $* status=$? if [ $status -eq 1 ]; then try_run /usr/bin/installer-dialog $args $* || { if [ $status -ne 2 ]; then echo "The setup program seems to have failed" fi status=1 } fi else # Try to run the installer script asked for when launched try_run /usr/bin/installer-${launch} $args $* || { if [ $status -ne 2 ]; then echo "The setup program seems to have failed" fi status=1 } fi exit $status