VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/run-inst.sh@ 44080

Last change on this file since 44080 was 44080, checked in by vboxsync, 12 years ago

lightdm-greeter: Implemented Guest Additions installation.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1#!/bin/sh
2#
3# Oracle VM VirtualBox
4# VirtualBox Makeself installation starter script
5# for Linux Guest Additions
6
7#
8# Copyright (C) 2006-2012 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
19# This is a stub installation script to be included in VirtualBox Makeself
20# installers which removes any previous installations of the package, unpacks
21# the package into the filesystem (by default under /opt) and starts the real
22# installation script.
23#
24PATH=$PATH:/bin:/sbin:/usr/sbin
25
26# Note: These variable names must *not* clash with variables in $CONFIG_DIR/$CONFIG!
27PACKAGE="_PACKAGE_"
28PACKAGE_NAME="_PACKAGE_NAME_"
29UNINSTALL="uninstall.sh"
30ROUTINES="routines.sh"
31ARCH="_ARCH_"
32INSTALLATION_VER="_VERSION_"
33INSTALLATION_REV="_SVNREV_"
34BUILD_TYPE="_BUILDTYPE_"
35USERNAME="_USERNAME_"
36UNINSTALL_SCRIPTS="_UNINSTALL_SCRIPTS_"
37
38INSTALLATION_DIR="/opt/$PACKAGE-$INSTALLATION_VER"
39CONFIG_DIR="/var/lib/$PACKAGE"
40CONFIG="config"
41CONFIG_FILES="filelist"
42SELF=$1
43LOGFILE="/var/log/$PACKAGE.log"
44
45INSTALLATION_LIGHTDM_CONFIG="/etc/lightdm/lightdm.conf"
46INSTALLATION_LIGHTDM_GREETER_DIR="/usr/share/xgreeters"
47
48. "./$ROUTINES"
49
50check_root
51
52create_log "$LOGFILE"
53
54## @todo r=andy: Explain options like "force" and "no_setup" -- not self-explanatory
55# to the user.
56usage()
57{
58 info ""
59 info "Usage: $SELF install [<installation directory>] [--with-autologon] |"
60 info " uninstall"
61 info " [--force] [--no-setup]"
62 info ""
63 info "Example:"
64 info "$SELF install"
65 exit 1
66}
67
68# Create a symlink in the filesystem and add it to the list of package files
69add_symlink()
70{
71 self=add_symlink
72 ## Parameters:
73 # The file the link should point to
74 target="$1"
75 # The name of the actual symlink file. Must be an absolute path to a
76 # non-existing file in an existing directory.
77 link="$2"
78 link_dir="`dirname "$link"`"
79 test -n "$target" ||
80 { echo 1>&2 "$self: no target specified"; return 1; }
81 test -d "$link_dir" ||
82 { echo 1>&2 "$self: link directory $link_dir does not exist"; return 1; }
83 test ! -e "$link" ||
84 { echo 1>&2 "$self: link file "$link" already exists"; return 1; }
85 expr "$link" : "/.*" > /dev/null ||
86 { echo 1>&2 "$self: link file name is not absolute"; return 1; }
87 rm -f "$link"
88 ln -s "$target" "$link"
89 echo "$link" >> "$CONFIG_DIR/$CONFIG_FILES"
90}
91
92# Create symbolic links targeting all files in a directory in another
93# directory in the filesystem
94link_into_fs()
95{
96 ## Parameters:
97 # Directory containing the link target files
98 target_branch="$1"
99 # Directory to create the link files in
100 directory="$2"
101 for i in "$INSTALLATION_DIR/$target_branch"/*; do
102 test -e "$i" &&
103 add_symlink "$i" "$directory/`basename $i`"
104 done
105}
106
107# Look for broken installations or installations without a known uninstaller
108# and try to clean them up, asking the user first.
109def_uninstall()
110{
111 ## Parameters:
112 # Whether to force cleanup without asking the user
113 force="$1"
114
115 . ./deffiles
116 found=0
117 for i in $DEFAULT_FILE_NAMES; do
118 test "$found" = 0 -a -e "$i" && found=1
119 done
120 test "$found" = 0 &&
121 for i in $DEFAULT_VERSIONED_FILE_NAMES-*; do
122 test "$found" = 0 -a -e "$i" && found=1
123 done
124 test "$found" = 0 && return 0
125 if ! test "$1" = "force" ; then
126 cat 1>&2 << EOF
127You appear to have a version of the _PACKAGE_ software
128on your system which was installed from a different source or using a
129different type of installer. If you installed it from a package from your
130Linux distribution or if it is a default part of the system then we strongly
131recommend that you cancel this installation and remove it properly before
132installing this version. If this is simply an older or a damaged
133installation you may safely proceed.
134
135Do you wish to continue anyway? [yes or no]
136EOF
137 read reply dummy
138 if ! expr "$reply" : [yY] > /dev/null &&
139 ! expr "$reply" : [yY][eE][sS] > /dev/null
140 then
141 info
142 info "Cancelling installation."
143 return 1
144 fi
145 fi
146 # Stop what we can in the way of services and remove them from the
147 # system
148 for i in $UNINSTALL_SCRIPTS; do
149 stop_init_script "$i"
150 cleanup_init "$i" 1>&2 2>> "$LOGFILE"
151 test -x "./$i" && "./$i" cleanup 1>&2 2>> "$LOGFILE"
152 remove_init_script "$i"
153 done
154
155 remove_autologon
156
157 # Get rid of any remaining files
158 for i in $DEFAULT_FILE_NAMES; do
159 rm -f "$i" 2> /dev/null
160 done
161 for i in $DEFAULT_VERSIONED_FILE_NAMES; do
162 rm -f "$i-"* 2> /dev/null
163 done
164 rm -f "/usr/lib/$PACKAGE" "/usr/lib64/$PACKAGE" "/usr/share/$PACKAGE"
165
166 # And any packages left under /opt
167 for i in "/opt/$PACKAGE-"*; do
168 test -d "$i" && rm -rf "$i"
169 done
170 return 0
171}
172
173info "$PACKAGE_NAME installer"
174
175check_bzip2
176
177# Check architecture
178cpu=`uname -m`;
179case "$cpu" in
180 i[3456789]86|x86)
181 cpu="x86"
182 lib_path="/usr/lib"
183 ;;
184 x86_64|amd64)
185 cpu="amd64"
186 if test -d "/usr/lib64"; then
187 lib_path="/usr/lib64"
188 else
189 lib_path="/usr/lib"
190 fi
191 ;;
192 *)
193 cpu="unknown"
194esac
195ARCH_PACKAGE="$PACKAGE-$cpu.tar.bz2"
196if [ ! -r "$ARCH_PACKAGE" ]; then
197 info "Detected unsupported $cpu machine type."
198 exit 1
199fi
200
201# Sensible default actions
202ACTION="install"
203WITH_AUTOLOGON=""
204DO_SETUP="true"
205NO_CLEANUP=""
206FORCE_UPGRADE=""
207while true
208do
209 if [ "$2" = "" ]; then
210 break
211 fi
212 shift
213 case "$1" in
214 install)
215 ACTION="install"
216 ;;
217
218 uninstall)
219 ACTION="uninstall"
220 ;;
221
222 --lightdm-config)
223 INSTALLATION_LIGHTDM_CONFIG="$2"
224 shift
225 ;;
226
227 --lightdm-greeter-dir)
228 INSTALLATION_LIGHTDM_GREETER_DIR="$2"
229 shift
230 ;;
231
232 --with-autologon)
233 WITH_AUTOLOGON="true"
234 ;;
235
236 --force)
237 force) # Keep for backwards compatibility.
238 FORCE_UPGRADE="force"
239 ;;
240
241 --no-setup)
242 no_setup) # Keep for backwards compatibility.
243 DO_SETUP=""
244 ;;
245
246 --no-cleanup)
247 no_cleanup) # Keep for backwards compatibility.
248 # Do not do cleanup of old modules when removing them. For
249 # testing purposes only.
250 DO_SETUP=""
251 NO_CLEANUP="no_cleanup"
252 ;;
253
254 *)
255 if [ "`echo $1|cut -c1`" != "/" ]; then
256 info "Please specify an absolute path"
257 usage
258 fi
259 INSTALLATION_DIR="$1"
260 ;;
261 esac
262done
263
264# uninstall any previous installation
265INSTALL_DIR=""
266uninstalled=0
267test -r "$CONFIG_DIR/$CONFIG" && . "$CONFIG_DIR/$CONFIG"
268if test -n "$INSTALL_DIR" -a -x "$INSTALL_DIR/$UNINSTALLER"; then
269 "$INSTALL_DIR/$UNINSTALLER" $NO_CLEANUP 1>&2 ||
270 abort "Failed to remove existing installation. Aborting..."
271 uninstalled=1
272fi
273test "$uninstalled" = 0 && def_uninstall "$FORCE_UPGRADE" && uninstalled=1
274test "$uninstalled" = 0 && exit 1
275rm -f "$CONFIG_DIR/$CONFIG"
276rm -f "$CONFIG_DIR/$CONFIG_FILES"
277rmdir "$CONFIG_DIR" 2>/dev/null
278test "$ACTION" = "install" || exit 0
279
280# install the new version
281mkdir -p -m 755 "$CONFIG_DIR"
282test ! -d "$INSTALLATION_DIR" && REMOVE_INSTALLATION_DIR=1
283mkdir -p -m 755 "$INSTALLATION_DIR"
284# Create a list of the files in the archive, skipping any directories which
285# already exist in the filesystem.
286bzip2 -d -c "$ARCH_PACKAGE" | tar -tf - |
287 while read name; do
288 fullname="$INSTALLATION_DIR/$name"
289 case "$fullname" in
290 */)
291 test ! -d "$fullname" &&
292 echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
293 ;;
294 *)
295 echo "$fullname" >> "$CONFIG_DIR/$CONFIG_FILES"
296 ;;
297 esac
298 done
299bzip2 -d -c "$ARCH_PACKAGE" | tar -xf - -C "$INSTALLATION_DIR" || exit 1
300
301# Set symlinks into /usr and /sbin
302link_into_fs "bin" "/usr/bin"
303link_into_fs "sbin" "/usr/sbin"
304link_into_fs "lib" "$lib_path"
305link_into_fs "share" "/usr/share"
306link_into_fs "src" "/usr/src"
307
308# Remember our installation configuration before we call any init scripts
309cat > "$CONFIG_DIR/$CONFIG" << EOF
310# $PACKAGE installation record.
311# Package installation directory
312INSTALL_DIR='$INSTALLATION_DIR'
313# Package uninstaller. If you repackage this software, please make sure
314# that this prints a message and returns an error so that the default
315# uninstaller does not attempt to delete the files installed by your
316# package.
317UNINSTALLER='$UNINSTALL'
318# Package version
319INSTALL_VER='$INSTALLATION_VER'
320INSTALL_REV='$INSTALLATION_REV'
321# Build type and user name for logging purposes
322BUILD_TYPE='$BUILD_TYPE'
323USERNAME='$USERNAME'
324# LightDM greeter configuration
325LIGHTDM_CONFIG='$INSTALLATION_LIGHTDM_CONFIG'
326LIGHTDM_GREETER_DIR='$INSTALLATION_LIGHTDM_GREETER_DIR'
327EOF
328
329# Install, set up and start init scripts
330for i in "$INSTALLATION_DIR/init/"*; do
331 if test -r "$i"; then
332 install_init_script "$i" "`basename "$i"`"
333 test -n "$DO_SETUP" && setup_init_script "`basename "$i"`" 1>&2
334 start_init_script "`basename "$i"`"
335 fi
336done
337
338cp $ROUTINES $INSTALLATION_DIR
339echo $INSTALLATION_DIR/$ROUTINES >> "$CONFIG_DIR/$CONFIG_FILES"
340cat > $INSTALLATION_DIR/$UNINSTALL << EOF
341#!/bin/sh
342# Auto-generated uninstallation file
343
344PATH=\$PATH:/bin:/sbin:/usr/sbin
345LOGFILE="/var/log/$PACKAGE-uninstall.log"
346
347# Read routines.sh
348if ! test -r "$INSTALLATION_DIR/$ROUTINES"; then
349 echo 1>&2 "Required file $ROUTINES not found. Aborting..."
350 return 1
351fi
352. "$INSTALLATION_DIR/$ROUTINES"
353
354# We need to be run as root
355check_root
356
357create_log "\$LOGFILE"
358
359echo 1>&2 "Removing installed version $INSTALLATION_VER of $PACKAGE_NAME..."
360
361NO_CLEANUP=""
362if test "\$1" = "no_cleanup"; then
363 shift
364 NO_CLEANUP="no_cleanup"
365fi
366
367test -r "$CONFIG_DIR/$CONFIG_FILES" || abort "Required file $CONFIG_FILES not found. Aborting..."
368
369# Stop and clean up all services
370for i in "$INSTALLATION_DIR/init/"*; do
371 if test -r "\$i"; then
372 stop_init_script "\`basename "\$i"\`"
373 test -z "\$NO_CLEANUP" && cleanup_init "\`basename "\$i"\`" 2>> "\$LOGFILE"
374 remove_init_script "\`basename "\$i"\`"
375 fi
376done
377
378# And remove all files and empty installation directories
379# Remove any non-directory entries
380cat "$CONFIG_DIR/$CONFIG_FILES" | xargs rm 2>/dev/null
381# Remove any empty (of files) directories in the file list
382cat "$CONFIG_DIR/$CONFIG_FILES" |
383 while read file; do
384 case "\$file" in
385 */)
386 test -d "\$file" &&
387 find "\$file" -depth -type d -exec rmdir '{}' ';' 2>/dev/null
388 ;;
389 esac
390 done
391
392# Load configuration values
393test -r "$CONFIG_DIR/$CONFIG" && . "$CONFIG_DIR/$CONFIG"
394
395# Remove auto-logon support
396remove_autologon
397
398# Remove configuration files
399rm "$CONFIG_DIR/$CONFIG_FILES" 2>/dev/null
400rm "$CONFIG_DIR/$CONFIG" 2>/dev/null
401rmdir "$CONFIG_DIR" 2>/dev/null
402exit 0
403EOF
404chmod 0755 $INSTALLATION_DIR/$UNINSTALL
405echo $INSTALLATION_DIR/$UNINSTALL >> "$CONFIG_DIR/$CONFIG_FILES"
406test -n "$REMOVE_INSTALLATION_DIR" &&
407 echo "$INSTALLATION_DIR/" >> "$CONFIG_DIR/$CONFIG_FILES"
408
409# Install auto-logon support.
410if test -n "$WITH_AUTOLOGON"; then
411 ## @todo Make parameters configurable thru command line.
412 install_autologon "$INSTALLATION_LIGHTDM_GREETER_DIR" "$INSTALLATION_LIGHTDM_CONFIG" "$FORCE_UPGRADE"
413fi
414
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