1 # $Id: vserver-build.functions,v 1.18 2005/07/04 22:38:42 ensc Exp $ --*- sh -*--
3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Expected environment:
19 # $VSERVER_NAME ... name of vserver
33 __BASE_GENERATED_FILES=()
40 (c|b) mknod -m$6 "$dst" $3 $4 $5;;
41 (d) mkdir -p -m$4 "$dst";;
45 (*) echo "Unknown dev-entry mode '$3'" >&2
51 function populateDirectory
60 for file in "$i"/*; do
61 isRegularFile "$file" || continue
70 test -z "$ROOTDIR" || return 0
72 for item in "\"$__CONFDIR/.defaults/vdirbase\" 1" "$__DEFAULT_VSERVERDIR"; do
76 test ! -d "$ROOTDIR" || break
79 test -d "$ROOTDIR" || {
80 echo "Root-directory '$ROOTDIR' does not exist or is invalid" >&2
85 function _setVserverDir
87 test -z "$VSERVERDIRNAME" || return 0
88 VSERVERDIRNAME="$VSERVER_NAME"
93 VDIR="$ROOTDIR/$VSERVERDIRNAME"
98 test -z "$OPTION_SILENT" || return 0
102 function _renameVserverCfg
104 local suffix=.~$(date +'%s')~
107 for i in "$VDIR" "$SETUP_CONFDIR"; do
110 say "Renamed '$i' to '$i$suffix'"
116 ## Usage: getDistribution [<default>]
117 function getDistribution
119 test -z "$DISTRIBUTION" || return 0
121 if test -e /etc/fedora-release; then
122 set -- $(cat /etc/fedora-release)
124 elif test -e /etc/redhat-release; then
125 set -- $(cat /etc/redhat-release)
127 elif test -e /etc/debian_version; then
128 set -- $(cat /etc/debian_version)
130 elif test -e /etc/SuSE-release; then
131 set -- $(cat /etc/SuSE-release)
133 elif test -e /etc/gentoo-release; then
134 set -- $(cat /etc/gentoo-release)
135 DISTRIBUTION=gentoo$5
136 elif test -e /etc/slackware-release; then
137 set -- $(cat /etc/slackware-release)
138 DISTRIBUTION=slackware$2
139 elif test -n "$1"; then
143 "Can not determine distribution; please specify it manually
144 with the '-d' option" >&2
149 function base._addGeneratedFile
151 __BASE_GENERATED_FILES=( "${__BASE_GENERATED_FILES[@]}" "$@" )
154 ## Usage: initFilesystem [force]
155 function base.initFilesystem
157 test -z "$1" || _renameVserverCfg
158 test ! -d "$VDIR" -a ! -d "$SETUP_CONFDIR" || {
160 "vserver-topdirectory '$VDIR' and/or configuration at '$SETUP_CONFDIR'
161 exist already; please try to use '--force', or remove them manually"
166 mkdir -p -m755 "$VDIR"
168 base._addGeneratedFile "$VDIR"
170 mkdir -p -m755 "$SETUP_CONFDIR"/apps "$VDIR"/{dev/pts,etc}
171 base._addGeneratedFile "$SETUP_CONFDIR"
173 ln -s "$VDIR" "$SETUP_CONFDIR/vdir"
177 makeDevEntry "$VDIR"/dev $spec
180 mkdir -p "$VDIR"/proc
181 findAndCopy "$VDIR"/etc/hosts "$__CONFDIR"/.defaults/files/hosts "$__CONFDIR/.distributions/$DISTRIBUTION"/files/hosts \
182 "$__DISTRIBDIR/$DISTRIBUTION"/files/hosts "$__DISTRIBDIR"/defaults/files/hosts ""
184 for i in nsswitch.conf krb5.conf krb.conf krb.realms ldap.conf localtime resolv.conf; do
185 findAndCopy "$VDIR"/etc/$i "$__CONFDIR/.defaults/files/$i" "$__CONFDIR/.distributions/$DISTRIBUTION/files/$i" ""
189 function base._initVariables
195 findFile _DEV_FILE "$__CONFDIR/.distributions/$DISTRIBUTION/devs" "$__DISTRIBDIR/$DISTRIBUTION/devs" "$__DISTRIBDIR/defaults/devs"
196 findDir _EXECDIR "$__CONFDIR/.distributions/$DISTRIBUTION/execdir" "$__DISTRIBDIR/$DISTRIBUTION/execdir" /
197 findFile BUILD_INITPRE "$__CONFDIR/.distributions/$DISTRIBUTION/initpre" "$__DISTRIBDIR/$DISTRIBUTION/initpre" ""
198 findFile BUILD_INITPOST "$__CONFDIR/.distributions/$DISTRIBUTION/initpost" "$__DISTRIBDIR/$DISTRIBUTION/initpost" ""
201 function base.__cleanup
203 test -z "$OPTION_KEEP" || return 0
204 test -z "$__BASE_SUCCESS" || return 0
206 echo rm -rf "${__BASE_GENERATED_FILES[@]}"
211 test -z "$SETUP_CONTEXT" || ! $_VSERVER_INFO -q "$SETUP_CONTEXT" RUNNING || \
213 Context '$SETUP_CONTEXT' is already in use. Please select another one."
215 trap "base.__cleanup" EXIT
219 function base.setSuccess