X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Fvserver-build.functions;h=4d78cddedfc2aac5995c5580e660b239715e0bd5;hb=dfa40e043f50b3ed0f89cdec01d0655c94c1e12e;hp=8a85849f9c60a3b10e1ccaa6c76d6b9dcf8f674e;hpb=16eafb4fda7a2946dbcc9ca52f4cf7f68383e873;p=util-vserver.git diff --git a/util-vserver/scripts/vserver-build.functions b/util-vserver/scripts/vserver-build.functions index 8a85849..4d78cdd 100644 --- a/util-vserver/scripts/vserver-build.functions +++ b/util-vserver/scripts/vserver-build.functions @@ -30,16 +30,19 @@ _EXEC_DIR= BUILD_INITPRE= BUILD_INITPOST= +__BASE_GENERATED_FILES=() +__BASE_SUCCESS= + function makeDevEntry { local dst=$1/$2 case "$3" in - c|b) mknod -m$6 "$dst" $3 $4 $5;; - d) mkdir -p -m$4 "$dst";; - f) touch "$dst" + (c|b) mknod -m$6 "$dst" $3 $4 $5;; + (d) mkdir -p -m$4 "$dst";; + (f) touch "$dst" chmod $4 "$dst" ;; - *) echo "Unknown dev-entry mode '$3'" >&2 + (*) echo "Unknown dev-entry mode '$3'" >&2 false ;; esac @@ -55,12 +58,7 @@ function populateDirectory local file= for file in "$i"/*; do - test -e "$file" || continue - case "$file" in - */CVS) test ! -d "$file" || continue;; - *.rpmsave|*.rpmnew|*.rpmorig) - continue;; - esac + isRegularFile "$file" || continue cp -a "$file" "$dst/" done @@ -71,7 +69,7 @@ function _setRootDir { test -z "$ROOTDIR" || return 0 - for item in "\"$CONFDIR/.defaults/vdirbase\" 1" "$DEFAULT_VSERVERDIR"; do + for item in "\"$__CONFDIR/.defaults/vdirbase\" 1" "$__DEFAULT_VSERVERDIR"; do eval set -- "$item" ROOTDIR=$1 ROOTDIR_REL=$2 @@ -79,7 +77,7 @@ function _setRootDir done test -d "$ROOTDIR" || { - echo "Root-directory '$ROOTDIR' does not exist or is invalid" + echo "Root-directory '$ROOTDIR' does not exist or is invalid" >&2 exit 1 } } @@ -107,44 +105,75 @@ function _renameVserverCfg local i for i in "$VDIR" "$SETUP_CONFDIR"; do - test ! -e "$i" || { + test ! -e "$i" || isDirectoryEmpty "$i" || { mv "$i" "$i$suffix" say "Renamed '$i' to '$i$suffix'" } done } + +## Usage: getDistribution [] [] function getDistribution { - test -z "$DISTRIBUTION" || return 0 - - if test -e /etc/fedora-release; then - set -- $(cat /etc/fedora-release) - DISTRIBUTION=fdr$4 - elif test -e /etc/redhat-release; then - set -- $(cat /etc/redhat-release) - DISTRIBUTION=rh$5 - elif test -e /etc/debian_version; then - set -- $(cat /etc/debian_version) - DISTRIBUTION=deb$1 - else - echo "Can not determine distribution; please specify it manually" - echo "with the '-d' option" - exit 1 - fi >&2 + local ignore_config=$2 + + if test -z "$DISTRIBUTION"; then + if test -e /etc/fedora-release; then + set -- $(cat /etc/fedora-release) + DISTRIBUTION=fdr$4 + elif test -e /etc/redhat-release; then + set -- $(cat /etc/redhat-release) + DISTRIBUTION=rh$5 + elif test -e /etc/debian_version; then + set -- $(cat /etc/debian_version) + DISTRIBUTION=deb$1 + elif test -e /etc/SuSE-release; then + set -- $(cat /etc/SuSE-release) + DISTRIBUTION=suse$3 + elif test -e /etc/gentoo-release; then + set -- $(cat /etc/gentoo-release) + DISTRIBUTION=gentoo$5 + elif test -e /etc/slackware-release; then + set -- $(cat /etc/slackware-release) + DISTRIBUTION=slackware$2 + elif test -n "$1"; then + DISTRIBUTION=$1 + else + colpanic $"\ +ERROR: Can not determine distribution; please specify it manually with + the '-d' option." + fi + fi + + test -n "$ignore_config" -o \ + -d "$__CONFDIR/.distributions/$DISTRIBUTION" -o \ + -d "$__DISTRIBDIR/$DISTRIBUTION" || + colpanic $"\ +ERROR: Can not find configuration for the distribution '$DISTRIBUTION'; + please read http://linux-vserver.org/HowToRegisterNewDistributions + for information how to add support for your own distribution." +} + +function base._addGeneratedFile +{ + __BASE_GENERATED_FILES=( "${__BASE_GENERATED_FILES[@]}" "$@" ) } ## Usage: initFilesystem [force] -function initFilesystem +function base.initFilesystem { test -z "$1" || _renameVserverCfg - test ! -d "$VDIR" -a ! -d "$SETUP_CONFDIR" || { - echo "vserver-topdirectory and/or configuration exist already; " - echo "please try to use '--force', or remove them manually" - exit 1 - } >&2 + { isDirectoryEmpty "$VDIR" && test ! -e "$SETUP_CONFDIR"; } || colpanic $"\ +vserver-topdirectory '$VDIR' and/or configuration at '$SETUP_CONFDIR' +exist already; please try to use '--force', or remove them manually." - mkdir -p "$SETUP_CONFDIR"/apps "$VDIR"/{dev/pts,etc} "$SETUP_LOCKREVDIR" + mkdir -p -m755 "$VDIR" + chattr -t "$VDIR" + base._addGeneratedFile "$VDIR" + + mkdir -p -m755 "$SETUP_CONFDIR"/apps "$VDIR"/{dev/pts,etc} + base._addGeneratedFile "$SETUP_CONFDIR" ln -s "$VDIR" "$SETUP_CONFDIR/vdir" @@ -153,22 +182,46 @@ function initFilesystem makeDevEntry "$VDIR"/dev $spec done <$_DEV_FILE - findAndCopy "$VDIR"/etc/hosts "$CONFDIR"/.defaults/files/hosts "$CONFDIR/.distributions/$DISTRIBUTION"/files/hosts \ - "$DISTRIBDIR/$DISTRIBUTION"/files/hosts "$DISTRIBDIR"/defaults/files/hosts "" + mkdir -p "$VDIR"/proc + findAndCopy "$VDIR"/etc/hosts "$__CONFDIR"/.defaults/files/hosts "$__CONFDIR/.distributions/$DISTRIBUTION"/files/hosts \ + "$__DISTRIBDIR/$DISTRIBUTION"/files/hosts "$__DISTRIBDIR"/defaults/files/hosts "" for i in nsswitch.conf krb5.conf krb.conf krb.realms ldap.conf localtime resolv.conf; do - findAndCopy "$VDIR"/etc/$i "$CONFDIR/.defaults/files/$i" "$CONFDIR/.distributions/$DISTRIBUTION/files/$i" "" + findAndCopy "$VDIR"/etc/$i "$__CONFDIR/.defaults/files/$i" "$__CONFDIR/.distributions/$DISTRIBUTION/files/$i" "" done } -function initVariables +function base._initVariables { _setRootDir _setVserverDir _setVdir - findFile _DEV_FILE "$CONFDIR/.distributions/$DISTRIBUTION/devs" "$DISTRIBDIR/$DISTRIBUTION/devs" "$DISTRIBDIR/defaults/devs" - findDir _EXECDIR "$CONFDIR/.distributions/$DISTRIBUTION/execdir" "$DISTRIBDIR/$DISTRIBUTION/execdir" / - findFile BUILD_INITPRE "$CONFDIR/.distributions/$DISTRIBUTION/initpre" "$DISTRIBDIR/$DISTRIBUTION/initpre" "" - findFile BUILD_INITPOST "$CONFDIR/.distributions/$DISTRIBUTION/initpost" "$DISTRIBDIR/$DISTRIBUTION/initpost" "" + findFile _DEV_FILE "$__CONFDIR/.distributions/$DISTRIBUTION/devs" "$__DISTRIBDIR/$DISTRIBUTION/devs" "$__DISTRIBDIR/defaults/devs" + findDir _EXECDIR "$__CONFDIR/.distributions/$DISTRIBUTION/execdir" "$__DISTRIBDIR/$DISTRIBUTION/execdir" / + findFile BUILD_INITPRE "$__CONFDIR/.distributions/$DISTRIBUTION/initpre" "$__DISTRIBDIR/$DISTRIBUTION/initpre" "" + findFile BUILD_INITPOST "$__CONFDIR/.distributions/$DISTRIBUTION/initpost" "$__DISTRIBDIR/$DISTRIBUTION/initpost" "" +} + +function base.__cleanup +{ + test -z "$OPTION_KEEP" || return 0 + test -z "$__BASE_SUCCESS" || return 0 + + rm -rf "${__BASE_GENERATED_FILES[@]}" +} + +function base.init +{ + test -z "$SETUP_CONTEXT" || ! $_VSERVER_INFO -q "$SETUP_CONTEXT" RUNNING || \ + panic $"\ +Context '$SETUP_CONTEXT' is already in use. Please select another one." + + trap "base.__cleanup" EXIT + base._initVariables +} + +function base.setSuccess +{ + __BASE_SUCCESS=1 }