VirtualBox

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

Last change on this file since 93115 was 93115, checked in by vboxsync, 3 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.4 KB
Line 
1#!/bin/sh
2# $Id: autorun.sh 93115 2022-01-01 11:31:46Z vboxsync $
3## @file
4# VirtualBox Guest Additions installation script for *nix guests
5#
6
7#
8# Copyright (C) 2009-2022 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 *)
89 echo "Unable to start installation process with elevated privileges automatically. Please try running "\""$i"\"" manually."
90 exit
91 ;;
92 esac
93 fi
94 done
95
96 # else: unknown failure
97 echo "Linux guest additions installer not found -- try to start it manually."
98 exit 1
99
100elif test "$ostype" = "SunOS"; then
101
102 # check for combined package
103 installfile="$path/VBoxSolarisAdditions.pkg"
104 if test -f "$installfile"; then
105
106 # check for pkgadd bin
107 pkgaddbin=pkgadd
108 found=`which pkgadd | grep "no pkgadd"`
109 if test ! -z "$found"; then
110 if test -f "/usr/sbin/pkgadd"; then
111 pkgaddbin=/usr/sbin/pkgadd
112 else
113 echo "Could not find pkgadd."
114 exit 1
115 fi
116 fi
117
118 # check for pfexec
119 pfexecbin=pfexec
120 found=`which pfexec | grep "no pfexec"`
121 if test ! -z "$found"; then
122 # Use su and prompt for password
123 echo "Could not find pfexec."
124 subin=`which su`
125 else
126 idbin=/usr/xpg4/bin/id
127 if test ! -x "$idbin"; then
128 found=`which id 2> /dev/null`
129 if test ! -x "$found"; then
130 echo "Failed to find a suitable user id executable."
131 exit 1
132 else
133 idbin=$found
134 fi
135 fi
136
137 # check if pfexec can get the job done
138 if test "$idbin" = "/usr/xpg4/bin/id"; then
139 userid=`$pfexecbin $idbin -u`
140 else
141 userid=`$pfexecbin $idbin | cut -f1 -d'(' | cut -f2 -d'='`
142 fi
143 if test $userid != "0"; then
144 # pfexec exists but user has no pfexec privileges, switch to using su and prompting password
145 subin=`which su`
146 fi
147 fi
148
149 # create temporary admin file for autoinstall
150 TMPFILE=`mktemp -q /tmp/vbox.XXXXXX`
151 if [ -z $TMPFILE ]; then
152 echo "Unable to create a temporary file"
153 exit 1
154 fi
155 echo "basedir=default
156runlevel=nocheck
157conflict=quit
158setuid=nocheck
159action=nocheck
160partial=quit
161instance=unique
162idepend=quit
163rdepend=quit
164space=quit
165mail=
166" > $TMPFILE
167
168 # check gnome-terminal, use it if it exists.
169 if test -f "/usr/bin/gnome-terminal"; then
170 # use su/pfexec
171 if test -z "$subin"; then
172 /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'"
173 else
174 /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'"
175 fi
176 elif test -f "/usr/X11/bin/xterm"; then
177 # use xterm
178 if test -z "$subin"; then
179 /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"
180 else
181 /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"
182 fi
183 else
184 echo "No suitable terminal not found. -- install additions using pkgadd -d."
185 fi
186 rm -r $TMPFILE
187
188 exit 0
189 fi
190
191 echo "Solaris guest additions installer not found -- try to start them manually."
192 exit 1
193fi
194
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