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
37 (c|b) mknod -m$6 "$dst" $3 $4 $5;;
38 (d) mkdir -p -m$4 "$dst";;
42 (*) echo "Unknown dev-entry mode '$3'" >&2
48 function populateDirectory
57 for file in "$i"/*; do
58 isRegularFile "$file" || continue
67 test -z "$ROOTDIR" || return 0
69 for item in "\"$__CONFDIR/.defaults/vdirbase\" 1" "$__DEFAULT_VSERVERDIR"; do
73 test ! -d "$ROOTDIR" || break
76 test -d "$ROOTDIR" || {
77 echo "Root-directory '$ROOTDIR' does not exist or is invalid" >&2
82 function _setVserverDir
84 test -z "$VSERVERDIRNAME" || return 0
85 VSERVERDIRNAME="$VSERVER_NAME"
90 VDIR="$ROOTDIR/$VSERVERDIRNAME"
95 test -z "$OPTION_SILENT" || return 0
99 function _renameVserverCfg
101 local suffix=.~$(date +'%s')~
104 for i in "$VDIR" "$SETUP_CONFDIR"; do
107 say "Renamed '$i' to '$i$suffix'"
113 ## Usage: getDistribution [<default>]
114 function getDistribution
116 test -z "$DISTRIBUTION" || return 0
118 if test -e /etc/fedora-release; then
119 set -- $(cat /etc/fedora-release)
121 elif test -e /etc/redhat-release; then
122 set -- $(cat /etc/redhat-release)
124 elif test -e /etc/debian_version; then
125 set -- $(cat /etc/debian_version)
127 elif test -e /etc/SuSE-release; then
128 set -- $(cat /etc/SuSE-release)
130 elif test -e /etc/gentoo-release; then
131 set -- $(cat /etc/gentoo-release)
132 DISTRIBUTION=gentoo$5
133 elif test -e /etc/slackware-release; then
134 set -- $(cat /etc/slackware-release)
135 DISTRIBUTION=slackware$2
136 elif test -n "$1"; then
140 "Can not determine distribution; please specify it manually
141 with the '-d' option" >&2
146 ## Usage: initFilesystem [force]
147 function base.initFilesystem
149 test -z "$1" || _renameVserverCfg
150 test ! -d "$VDIR" -a ! -d "$SETUP_CONFDIR" || {
152 "vserver-topdirectory '$VDIR' and/or configuration at '$SETUP_CONFDIR'
153 exist already; please try to use '--force', or remove them manually"
158 mkdir -p -m755 "$VDIR"
160 mkdir -p -m755 "$SETUP_CONFDIR"/apps "$VDIR"/{dev/pts,etc}
162 ln -s "$VDIR" "$SETUP_CONFDIR/vdir"
166 makeDevEntry "$VDIR"/dev $spec
169 mkdir -p "$VDIR"/proc
170 findAndCopy "$VDIR"/etc/hosts "$__CONFDIR"/.defaults/files/hosts "$__CONFDIR/.distributions/$DISTRIBUTION"/files/hosts \
171 "$__DISTRIBDIR/$DISTRIBUTION"/files/hosts "$__DISTRIBDIR"/defaults/files/hosts ""
173 for i in nsswitch.conf krb5.conf krb.conf krb.realms ldap.conf localtime resolv.conf; do
174 findAndCopy "$VDIR"/etc/$i "$__CONFDIR/.defaults/files/$i" "$__CONFDIR/.distributions/$DISTRIBUTION/files/$i" ""
178 function base.initVariables
184 findFile _DEV_FILE "$__CONFDIR/.distributions/$DISTRIBUTION/devs" "$__DISTRIBDIR/$DISTRIBUTION/devs" "$__DISTRIBDIR/defaults/devs"
185 findDir _EXECDIR "$__CONFDIR/.distributions/$DISTRIBUTION/execdir" "$__DISTRIBDIR/$DISTRIBUTION/execdir" /
186 findFile BUILD_INITPRE "$__CONFDIR/.distributions/$DISTRIBUTION/initpre" "$__DISTRIBDIR/$DISTRIBUTION/initpre" ""
187 findFile BUILD_INITPOST "$__CONFDIR/.distributions/$DISTRIBUTION/initpost" "$__DISTRIBDIR/$DISTRIBUTION/initpost" ""