VirtualBox

Changeset 36658 in vbox for trunk


Ignore:
Timestamp:
Apr 12, 2011 3:40:51 PM (14 years ago)
Author:
vboxsync
Message:

Additions/linux/installer: shell script refactoring

Location:
trunk/src/VBox
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/Makefile.kmk

    r36518 r36658  
    7272 endif
    7373
     74 ifeq ($(KBUILD_TARGET),linux)
     75  INSTALLS += LnxAddIso-scripts
     76  LnxAddIso-scripts_INST    = bin/additions
     77  LnxAddIso-scripts_MODE    = a+rx,u+w
     78  LnxAddIso-scripts_SOURCES = \
     79        $(LnxAddIso-scripts_0_OUTDIR)/runasroot.sh \
     80        $(LnxAddIso-scripts_0_OUTDIR)/autorun.sh
     81  LnxAddIso-scripts_CLEAN = \
     82        $(LnxAddIso-scripts_0_OUTDIR)/runasroot.sh \
     83        $(LnxAddIso-scripts_0_OUTDIR)/autorun.sh
     84
     85  $$(LnxAddIso-scripts_0_OUTDIR)/runasroot.sh: \
     86        $(PATH_SUB_CURRENT)/../Installer/linux/runasroot.sh \
     87        $(PATH_SUB_CURRENT)/../Installer/linux/sh-utils.sh \
     88        | $$(dir $$@)
     89        $(QUIET)$(SED) \
     90            -e '/#include sh-utils.sh/ {' \
     91            -e "r $(PATH_ROOT)/src/VBox/Installer/linux/sh-utils.sh" \
     92            -e 'd' \
     93            -e '}' \
     94            --output $@ \
     95            $<
     96
     97  $$(LnxAddIso-scripts_0_OUTDIR)/autorun.sh: \
     98        $(PATH_SUB_CURRENT)/linux/installer/autorun.sh \
     99        $(PATH_SUB_CURRENT)/../Installer/linux/sh-utils.sh \
     100        | $$(dir $$@)
     101        $(QUIET)$(SED) \
     102            -e '/#include sh-utils.sh/ {' \
     103            -e "r $(PATH_ROOT)/src/VBox/Installer/linux/sh-utils.sh" \
     104            -e 'd' \
     105            -e '}' \
     106            --output $@ \
     107            $<
     108 endif # KBUILD_TARGET == linux
    74109 ifeq ($(KBUILD_TARGET),win)
    75110  #
  • trunk/src/VBox/Additions/linux/Makefile.kmk

    r36603 r36658  
    327327        $(VBOX_BRAND_LICENSE_TXT)=>LICENSE
    328328
    329 INSTALLS += AutoRun-sh
    330 AutoRun-sh_INST = bin/additions/
    331 AutoRun-sh_MODE = a+rx,u+w
    332 AutoRun-sh_SOURCES = \
    333         $(VBOX_REL_LNX_INST_SRC)runasroot.sh \
    334         $(VBOX_REL_LNX_ADD_INST)autorun.sh
    335 
    336329
    337330#
  • trunk/src/VBox/Additions/linux/installer/autorun.sh

    r36626 r36658  
    11#!/bin/sh
     2# $Id$
    23#
    34# VirtualBox Guest Additions installation script for *nix guests
     
    56
    67#
    7 # Copyright (C) 2009-2010 Oracle Corporation
     8# Copyright (C) 2009-2011 Oracle Corporation
    89#
    910# This file is part of VirtualBox Open Source Edition (OSE), as
     
    1819PATH=$PATH:/bin:/sbin:/usr/sbin
    1920
    20 # Deal with differing "which" semantics
    21 mywhich() {
    22     which "$1" 2>/dev/null | grep -v "no $1"
    23 }
    24 
    25 # Get the name and execute switch for a useful terminal emulator
    26 #
    27 # Sets $gxtpath to the emulator path or empty
    28 # Sets $gxttitle to the "title" switch for that emulator
    29 # Sets $gxtexec to the "execute" switch for that emulator
    30 # May clobber $gtx*
    31 # Calls mywhich
    32 getxterm() {
    33     # gnome-terminal uses -e differently to other emulators
    34     for gxti in "gnome-terminal --title -x" "konsole --title -e" "xterm -T -e"; do
    35         set $gxti
    36         gxtpath="`mywhich $1`"
    37         case "$gxtpath" in ?*)
    38             gxttitle=$2
    39             gxtexec=$3
    40             return
    41             ;;
    42         esac
    43     done
    44 }
    45 
    46 # Quotes its argument by inserting '\' in front of every character save
    47 # for 'A-Za-z0-9/'.  Prints the result to stdout.
    48 quotify() {
    49     echo "$1" | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
    50 }
     21#include sh-utils.sh
    5122
    5223ostype=`uname -s`
  • trunk/src/VBox/Installer/linux/runasroot.sh

    r36626 r36658  
    11#!/bin/sh
     2# $Id$
    23## @file
    34# VirtualBox privileged execution helper script for Linux and Solaris
     
    1617#
    1718
    18 # Deal with differing "which" semantics
    19 mywhich() {
    20     which "$1" 2>/dev/null | grep -v "no $1"
    21 }
    22 
    23 # Get the name and execute switch for a useful terminal emulator
    24 #
    25 # Sets $gxtpath to the emulator path or empty
    26 # Sets $gxttitle to the "title" switch for that emulator
    27 # Sets $gxtexec to the "execute" switch for that emulator
    28 # May clobber $gtx*
    29 # Calls mywhich
    30 getxterm() {
    31     # gnome-terminal uses -e differently to other emulators
    32     for gxti in "gnome-terminal --title -x" "konsole --title -e" "xterm -T -e"; do
    33         set $gxti
    34         gxtpath="`mywhich $1`"
    35         case "$gxtpath" in ?*)
    36             gxttitle=$2
    37             gxtexec=$3
    38             return
    39             ;;
    40         esac
    41     done
    42 }
    43 
    44 # Quotes its argument by inserting '\' in front of every character save
    45 # for 'A-Za-z0-9/'.  Prints the result to stdout.
    46 quotify() {
    47     echo $1 | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
    48 }
     19#include sh-utils.sh
    4920
    5021ostype=`uname -s`
  • trunk/src/VBox/Installer/linux/sh-utils.sh

    r36626 r36658  
    1 #!/bin/sh
     1# $Id$
     2# Shell script include file
    23## @file
    3 # VirtualBox privileged execution helper script for Linux and Solaris
     4# Shell script routines which are likely to be useful for different scripts
    45#
    56
     
    4546# for 'A-Za-z0-9/'.  Prints the result to stdout.
    4647quotify() {
    47     echo $1 | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
     48    echo "$1" | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
    4849}
    49 
    50 ostype=`uname -s`
    51 if test "$ostype" != "Linux" && test "$ostype" != "SunOS" ; then
    52   echo "Linux/Solaris not detected."
    53   exit 1
    54 fi
    55 
    56 case "$#" in "2"|"3")
    57     ;;
    58     *)
    59     echo "Usage: `basename $0` DESCRIPTION COMMAND [ADVICE]" >&2
    60     echo >&2
    61     echo "Attempt to execute COMMAND with root privileges, displaying DESCRIPTION if" >&2
    62     echo "possible and displaying ADVICE if possible if no su(1)-like tool is available." >&2
    63     exit 1
    64     ;;
    65 esac
    66 
    67 DESCRIPTION=$1
    68 COMMAND=$2
    69 ADVICE=$3
    70 PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/X11/bin
    71 
    72 case "$ostype" in SunOS)
    73     PATH=$PATH:/usr/sfw/bin:/usr/gnu/bin:/usr/xpg4/bin:/usr/xpg6/bin:/usr/openwin/bin:/usr/ucb
    74     GKSU_SWITCHES="-au root"
    75     ;;
    76     *)
    77     GKSU_SWITCHES=""
    78     ;;
    79 esac
    80 
    81 case "$DISPLAY" in ?*)
    82     KDESUDO="`mywhich kdesudo`"
    83     case "$KDESUDO" in ?*)
    84         eval "`quotify "$KDESUDO"` --comment `quotify "$DESCRIPTION"` -- $COMMAND"
    85         exit
    86         ;;
    87     esac
    88 
    89     GKSU="`mywhich gksu`"
    90     case "$GKSU" in ?*)
    91         # Older gksu does not grok --description nor '--' and multiple args.
    92         # @todo which versions do?
    93         # "$GKSU" --description "$DESCRIPTION" -- "$@"
    94         # Note that $GKSU_SWITCHES is NOT quoted in the following
    95         "$GKSU" $GKSU_SWITCHES "$COMMAND"
    96         exit
    97         ;;
    98     esac
    99     ;;
    100 esac # $DISPLAY
    101 
    102 # pkexec may work for ssh console sessions as well if the right agents
    103 # are installed.  However it is very generic and does not allow for any
    104 # custom messages.  Thus it comes after gksu.
    105 PKEXEC="`mywhich pkexec`"
    106 case "$PKEXEC" in ?*)
    107     eval "\"$PKEXEC\" $COMMAND"
    108     exit
    109     ;;
    110 esac
    111 
    112 # The ultimate fallback is running 'su -' within an xterm.  We use the
    113 # title of the xterm to tell what is going on.
    114 case "$DISPLAY" in ?*)
    115     SU="`mywhich su`"
    116     case "$SU" in ?*)
    117         getxterm
    118         case "$gxtpath" in ?*)
    119             "$gxtpath" "$gxttitle" "$DESCRIPTION - su" "$gxtexec" su - root -c "$COMMAND"
    120             exit
    121             ;;
    122         esac
    123     esac
    124 esac # $DISPLAY
    125 
    126 # Failure...
    127 case "$DISPLAY" in ?*)
    128     echo "Unable to locate 'pkexec', 'gksu' or 'su+xterm'. $ADVICE" >&2
    129     ;;
    130     *)
    131     echo "Unable to locate 'pkexec'. $ADVICE" >&2
    132     ;;
    133 esac
    134 
    135 exit 1
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette