Browse Source

updated libvbuilder.sh.in

git-svn-id: http://trac.vinelinux.org/repos/projects/vbootstrap/trunk@5370 ec354946-7b23-47d6-9f5a-488ba84defc7
munepi 11 years ago
parent
commit
3c3a282f82
1 changed files with 125 additions and 34 deletions
  1. 125 34
      libvbuilder.sh.in

+ 125 - 34
libvbuilder.sh.in

@@ -1,14 +1,103 @@
 #!/bin/bash
 
+initialize-variables(){
+    ## set boolian variables
+    with_profile=0
+    with_setup_vbootstrap=0
+    with_dist_upgrade=0
+    with_unionfs=0
+    with_sign=0
+    with_no_install=0
+    with_login=0
+    with_debug=0
+    with_actions=0
+    with_ix86_on_x86_64=0
+    with_category_main=0
+    with_category_plus=0
+    with_category_nonfree=0
+    with_category_test=0
+    with_category_proposed_updates=0
+    with_category_security=0
+
+    return 0
+}
+
+check-parameter(){
+    [ -z "$*" ] && Usage && return 1
+
+    while [ ! -z "$*" ]; do
+	case $1 in
+	    --help|help)
+		setup-vbuilder ||:
+		Usage
+		return 1
+		;;
+	    --profile)
+		shift
+		with_profile=1
+		PROFILE=$1
+		check-next-parameter $1 || return 1
+		;;
+	    --version|--arch|--category|--fetch-url|--target|--rpmbuild-define|--rpmbuild-with|--rpmbuild-without|--bootstrap-dir|--unionfs-dir|--cache-dir|--built-rpms-dir)
+		[ $with_actions -eq 1 ] && \
+		    echo $"E: You can give no more options after actions" && \
+		    return 1
+		shift
+		check-next-parameter $1 || return 1
+		;;
+	    --dist-upgrade|--unionfs|--with-compat32|--sign|--no-install|--login|--debug)
+		[ $with_actions -eq 1 ] && \
+		    echo $"E: You can give no more options after actions" && \
+		    return 1
+		;;
+	    --build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
+		with_actions=1
+		shift
+		check-next-parameter $1 || return 1
+		;;
+	    --build|build|--clean|clean)
+		with_actions=1
+		;;
+	    *)
+		echo $"E: Missing some parameters after $1"
+		return 1
+		;;
+	esac
+	shift
+    done
+
+    [ $with_actions -eq 0 ] && \
+	echo $"E: You must give at least one action" && return 1
+
+    return 0
+}
+
+check-next-parameter(){
+    [ -z "$1" ] && echo $"E: Missing some parameters after $1" && return 1
+
+    [ $(echo $1 | grep '^-') ] && \
+	echo $"E: Missing some parameters after $1" && return 1
+
+    return 0
+}
+
+## NOTE: setup-vbuilder() loads
+##  - system wide configurations (from /etc/vbootstrap/vbuilder.conf)
+##  - given profile (from /etc/vbootstrap/profile.d/*.conf)
+##  - given command-line parameters 
+## where given command-line parameters override the settings given profile, 
+## and the settings given profile override system wide settings. 
+## If you use a profile of vbuilder, you may not override the settings 
+## given profile. 
 setup-vbuilder(){
     ## check $SUDO_USER and $USERHELPER_UID
     RPM_SIGN_USER=$SUDO_USER
     if [ -z "${RPM_SIGN_USER}" ]; then
-	RPM_SIGN_USER=$(getent passwd $USERHELPER_UID | cut -d":" -f1)
-	if [ -z "${RPM_SIGN_USER}" ]; then
-	    echo $"W: \$SUDO_USER and \$USERHELPER_UID are empty"
+	[ -z "${USERHELPER_UID}" ] && \
+	    echo $"W: \$SUDO_USER and \$USERHELPER_UID are empty" && \
 	    return 1
-	fi
+	    
+	RPM_SIGN_USER=$(getent passwd $USERHELPER_UID | cut -d":" -f1)
     fi
     ## get $RPM_SIGN_USER's home directory
     HOME=$(getent passwd $RPM_SIGN_USER |  cut -d":" -f6)
@@ -19,10 +108,10 @@ setup-vbuilder(){
 	. $VBUILDER_CONF
 	[ $? -eq 1 ] && return 1
     fi
-    [ -z "${DEFAULT_VERSION}" ] && \
-	DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
     [ -z "${CATEGORIES}" ] && \
 	CATEGORIES=@@VBUILDER_CATEGORIES@@
+    [ -z "${VBOOTSTRAP_FETCH_URL}" ] && \
+	VBOOTSTRAP_FETCH_URL=@@VBUILDER_VBOOTSTRAP_FETCH_URL@@
     [ -z "${VBOOTSTRAP_DIR}" ] && \
 	VBOOTSTRAP_DIR=@@VBUILDER_VBOOTSTRAP_DIR@@
     [ -z "${UNIONFS_DIR}" ] && \
@@ -33,7 +122,16 @@ setup-vbuilder(){
 	BUILT_RPMS_DIR=@@VBUILDER_BUILT_RPMS_DIR@@
 
     ## set default version for vbootstrap
-    VERSION=$DEFAULT_VERSION
+    VERSION=@@VBUILDER_DEFAULT_VERSION@@
+
+    ## load profile
+    if [ ${with_profile} -eq 1 ]; then
+	[ ! -r /etc/vbootstrap/profile.d/${PROFILE}.conf ] && \
+	    echo $"E: No such profile found: ${PROFILE}" && return 1
+
+	. /etc/vbootstrap/profile.d/${PROFILE}.conf
+	[ $? -eq 1 ] && return 1
+    fi
 
     ## set current stable relase version
     STABLE_VERSION=@@VBUILDER_STABLE_VERSION@@
@@ -46,23 +144,6 @@ setup-vbuilder(){
 	    ;;
     esac
 
-    ## set boolian variables
-    with_setup_vbootstrap=0
-    with_dist_upgrade=0
-    with_unionfs=0
-    with_sign=0
-    with_no_install=0
-    with_login=0
-    with_debug=0
-    with_actions=0
-    with_ix86_on_x86_64=0
-    with_category_main=0
-    with_category_plus=0
-    with_category_nonfree=0
-    with_category_test=0
-    with_category_proposed_updates=0
-    with_category_security=0
-
     return 0
 }
 
@@ -82,7 +163,7 @@ setup-vbootstrap(){
 
 	## check chroot version
 	case ${VERSION} in
-	    4.2|5.2|VineSeed)
+	    4.2|5.2|6.0|VineSeed)
 		;;
 	    *)
 		echo $"E: ${VERSION} is NOT supported"
@@ -124,12 +205,12 @@ setup-vbootstrap(){
 	    fi
 	fi
 
-	## set the profile <version>_<arch>
-	PROFILE=${VERSION}_${VARCH}
+	## set base profile <version>_<arch>
+	BASE_PROFILE=${VERSION}_${VARCH}
 
-        ## check support ${PROFILE}
-	if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${PROFILE})" ]; then
-	    echo $"E: ${PROFILE} is NOT supported"
+        ## check support ${BASE_PROFILE}
+	if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${BASE_PROFILE})" ]; then
+	    echo $"E: ${BASE_PROFILE} is NOT supported"
 	    return 1
 	fi
 
@@ -195,19 +276,29 @@ setup-vbootstrap(){
 	fi
 
 	## set ${RPM_PKG_ARCH_LIST}
-	RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch RPMS/armv3l RPMS/armv4l RPMS/armv4tl RPMS/armv5tejl RPMS/armv5tel RPMS/armv6l RPMS/armv7l SRPMS"
+	RPM_PKG_ARCH_LIST=" \
+            RPMS/i386 RPMS/i486 RPMS/i586 RPMS/i686 RPMS/x86_64 RPMS/ppc \
+            RPMS/noarch \
+            RPMS/armv3l RPMS/armv4l RPMS/armv4tl \
+            RPMS/armv5tejl RPMS/armv5tel RPMS/armv6l RPMS/armv7l \
+            SRPMS"
 	[ -z "${TARGET}" ] || \
 	    RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
 
     fi
 
     ## set global variables
-    BUILD_ROOT=${VBOOTSTRAP_DIR}/${PROFILE}
     BUILD_USER=vbuilder
     BUILD_DIR=/home/${BUILD_USER}/rpm
-    UNIONFS_ROOT=${UNIONFS_DIR}/${PROFILE}
+    if [ ${with_profile} -eq 1 ]; then
+	BUILD_ROOT=${VBOOTSTRAP_DIR}/${PROFILE}
+	UNIONFS_ROOT=${UNIONFS_DIR}/${PROFILE}
+    else
+	BUILD_ROOT=${VBOOTSTRAP_DIR}/${BASE_PROFILE}
+	UNIONFS_ROOT=${UNIONFS_DIR}/${BASE_PROFILE}
+    fi
     ARCHIVES_DIR=${BUILD_ROOT}/var/cache/apt/archives
-    EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${PROFILE}/apt/archives
+    EXTERNAL_ARCHIVES_DIR=${CACHE_DIR}/${BASE_PROFILE}/apt/archives
 
     __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c -l"