VirtualBox

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

Last change on this file since 36314 was 33034, checked in by vboxsync, 14 years ago

Installer/linux: set directory permissions explicitly in the Linux installers

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