VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/autorun.sh@ 79666

Last change on this file since 79666 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1#!/bin/sh
2# $Id: autorun.sh 76553 2019-01-01 01:45:53Z vboxsync $
3## @file
4# VirtualBox Guest Additions installation script for *nix guests
5#
6
7#
8# Copyright (C) 2009-2019 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18
19PATH=$PATH:/bin:/sbin:/usr/sbin
20
21# Deal with differing "which" semantics
22mywhich() {
23 which "$1" 2>/dev/null | grep -v "no $1"
24}
25
26# Get the name and execute switch for a useful terminal emulator
27#
28# Sets $gxtpath to the emulator path or empty
29# Sets $gxttitle to the "title" switch for that emulator
30# Sets $gxtexec to the "execute" switch for that emulator
31# May clobber $gtx*
32# Calls mywhich
33getxterm() {
34 # gnome-terminal and mate-terminal use -e differently to other emulators
35 for gxti in "konsole --title -e" "gnome-terminal --title -x" "mate-terminal --title -x" "xterm -T -e"; do
36 set $gxti
37 gxtpath="`mywhich $1`"
38 case "$gxtpath" in ?*)
39 gxttitle=$2
40 gxtexec=$3
41 return
42 ;;
43 esac
44 done
45}
46
47# Quotes its argument by inserting '\' in front of every character save
48# for 'A-Za-z0-9/'. Prints the result to stdout.
49quotify() {
50 echo "$1" | sed -e 's/\([^a-zA-Z0-9/]\)/\\\1/g'
51}
52
53ostype=`uname -s`
54if test "$ostype" != "Linux" && test "$ostype" != "SunOS" ; then
55 echo "Linux/Solaris not detected."
56 exit 1
57fi
58
59# The below is GNU-specific. See VBox.sh for the longer Solaris/OS X version.
60TARGET=`readlink -e -- "${0}"` || exit 1
61path="${TARGET%/[!/]*}"
62# 32-bit or 64-bit?
63case `uname -m` in
64 i[3456789]86|x86|i86pc)
65 arch='x86'
66 ;;
67 x86_64|amd64|AMD64)
68 arch='amd64'
69 ;;
70 *)
71 echo "Unknown architecture `uname -m`."
72 exit 1
73 ;;
74esac
75
76# execute the installer
77if test "$ostype" = "Linux"; then
78 for i in "$path/VBoxLinuxAdditions.run" \
79 "$path/VBoxLinuxAdditions-$arch.run"; do
80 if test -f "$i"; then
81 getxterm
82 case "$gxtpath" in ?*)
83 TITLE="VirtualBox Guest Additions installation"
84 BINARY="`quotify "$i"`"
85 exec "$gxtpath" "$gxttitle" "$TITLE" "$gxtexec" /bin/sh "$path/runasroot.sh" --has-terminal "$TITLE" "/bin/sh $BINARY --xwin" "Please try running "\""$i"\"" manually."
86 exit
87 ;;
88 esac
89 fi
90 done
91
92 # else: unknown failure
93 echo "Linux guest additions installer not found -- try to start them manually."
94 exit 1
95
96elif test "$ostype" = "SunOS"; then
97
98 # check for combined package
99 installfile="$path/VBoxSolarisAdditions.pkg"
100 if test -f "$installfile"; then
101
102 # check for pkgadd bin
103 pkgaddbin=pkgadd
104 found=`which pkgadd | grep "no pkgadd"`
105 if test ! -z "$found"; then
106 if test -f "/usr/sbin/pkgadd"; then
107 pkgaddbin=/usr/sbin/pkgadd
108 else
109 echo "Could not find pkgadd."
110 exit 1
111 fi
112 fi
113
114 # check for pfexec
115 pfexecbin=pfexec
116 found=`which pfexec | grep "no pfexec"`
117 if test ! -z "$found"; then
118 # Use su and prompt for password
119 echo "Could not find pfexec."
120 subin=`which su`
121 else
122 idbin=/usr/xpg4/bin/id
123 if test ! -x "$idbin"; then
124 found=`which id 2> /dev/null`
125 if test ! -x "$found"; then
126 echo "Failed to find a suitable user id executable."
127 exit 1
128 else
129 idbin=$found
130 fi
131 fi
132
133 # check if pfexec can get the job done
134 if test "$idbin" = "/usr/xpg4/bin/id"; then
135 userid=`$pfexecbin $idbin -u`
136 else
137 userid=`$pfexecbin $idbin | cut -f1 -d'(' | cut -f2 -d'='`
138 fi
139 if test $userid != "0"; then
140 # pfexec exists but user has no pfexec privileges, switch to using su and prompting password
141 subin=`which su`
142 fi
143 fi
144
145 # create temporary admin file for autoinstall
146 TMPFILE=`mktemp -q /tmp/vbox.XXXXXX`
147 if [ -z $TMPFILE ]; then
148 echo "Unable to create a temporary file"
149 exit 1
150 fi
151 echo "basedir=default
152runlevel=nocheck
153conflict=quit
154setuid=nocheck
155action=nocheck
156partial=quit
157instance=unique
158idepend=quit
159rdepend=quit
160space=quit
161mail=
162" > $TMPFILE
163
164 # check gnome-terminal, use it if it exists.
165 if test -f "/usr/bin/gnome-terminal"; then
166 # use su/pfexec
167 if test -z "$subin"; then
168 /usr/bin/gnome-terminal --title "Installing VirtualBox Additions" --command "/bin/sh -c '$pfexecbin $pkgaddbin -G -d $installfile -n -a $TMPFILE SUNWvboxguest; /bin/echo press ENTER to close this window; /bin/read'"
169 else
170 /usr/bin/gnome-terminal --title "Installing VirtualBox Additions: Root password required." --command "/bin/sh -c '$subin - root -c \"$pkgaddbin -G -d $installfile -n -a $TMPFILE SUNWvboxguest\"; /bin/echo press ENTER to close this window; /bin/read'"
171 fi
172 elif test -f "/usr/X11/bin/xterm"; then
173 # use xterm
174 if test -z "$subin"; then
175 /usr/X11/bin/xterm -title "Installing VirtualBox Additions" -e "$pfexecbin $pkgaddbin -G -d $installfile -n -a $TMPFILE SUNWvboxguest; /bin/echo press ENTER to close this window; /bin/read"
176 else
177 /usr/X11/bin/xterm -title "Installing VirtualBox Additions: Root password required." -e "$subin - root -c \"$pkgaddbin -G -d $installfile -n -a $TMPFILE SUNWvboxguest\"; /bin/echo press ENTER to close this window; /bin/read"
178 fi
179 else
180 echo "No suitable terminal not found. -- install additions using pkgadd -d."
181 fi
182 rm -r $TMPFILE
183
184 exit 0
185 fi
186
187 echo "Solaris guest additions installer not found -- try to start them manually."
188 exit 1
189fi
190
Note: See TracBrowser for help on using the repository browser.

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