Browse Source

update vbuilder.sh.in: added --sign option

git-svn-id: http://trac.vinelinux.org/repos/projects/vbootstrap/trunk@1240 ec354946-7b23-47d6-9f5a-488ba84defc7
munepi 13 years ago
parent
commit
5977fb0d71
2 changed files with 89 additions and 39 deletions
  1. 5 1
      vbootstrap-vl.spec
  2. 84 38
      vbuilder.sh.in

+ 5 - 1
vbootstrap-vl.spec

@@ -1,7 +1,7 @@
 # This package is maintained on trac svn repository. Please do not change on local.
 # If you find a BUG, please report to Vine@vinelinux.org or mailing list or BTS.
 
-%define version 0.0.28
+%define version 0.0.29
 
 Summary: bootstrap scripts to create a basic Vine Linux system
 Summary(ja): Vine Linux の基本システムを作成するためのスクリプト
@@ -75,6 +75,10 @@ vbuilder は vbootstrap を利用して chroot 環境の構築し、
 
 
 %changelog
+* Xxx Yyy Zz 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.0.29-1
+- updated vbuilder.sh.in
+  - added --sign option
+
 * Fri Jun 04 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.0.28-1
 - updated vbuilder.sh.in
   - made /dev/urandom on chroot in Build()

+ 84 - 38
vbuilder.sh.in

@@ -3,7 +3,7 @@
 
 Usage_C(){
     cat<<EOF
-Usage:	$(basename $0) {--version [version]} {--arch [arch]} {--category [categories]} {--dist-upgrade} {--target [target]} {--with-compat32} {--bootstrap-dir [directory]} {--cache-dir [directory]} {--built-rpms-dir [directory]} {clean|build|build-rpm [src.rpm]|install-rpm [arch.rpm|package]|remove-rpm [package]|show-info}
+Usage:	$(basename $0) {--version [version]} {--arch [arch]} {--category [categories]} {--dist-upgrade} {--target [target]} {--with-compat32} {--sign} {--bootstrap-dir [directory]} {--cache-dir [directory]} {--built-rpms-dir [directory]} {clean|build|build-rpm [src.rpm]|install-rpm [arch.rpm|package]|remove-rpm [package]|show-info}
 
 Options:
 	--version:		set [version] (default: ${DEFAULT_VERSION})
@@ -13,6 +13,7 @@ Options:
 	--unionfs:		cover a bootstrap with unionfs
 	--target:		build rpms with [target]
 	--with-compat32:	build rpms with compat32 on boostrap
+	--sign:			sign built rpms
 	--bootstrap-dir:	set a bootstrap directory (default: ${VBOOTSTRAP_DIR})
 	--cache-dir:		set a directory to cache rpms (default: ${CACHE_DIR})
 	--built-rpms-dir:	set a directory to store built rpms in chroot (default: ${BUILT_RPMS_DIR})
@@ -174,6 +175,18 @@ E: $RPM_PKG はソース RPM パッケージでありません
 EOF
 }
 
+Msg_SUDO_USERisEmpty_C(){
+cat<<EOF
+W: \$SUDO_USER is empty
+EOF
+}
+
+Msg_SUDO_USERisEmpty_ja(){
+cat<<EOF
+W: \$SUDO_USER が空です
+EOF
+}
+
 ##############################################################################
 
 check-parameter(){
@@ -191,7 +204,7 @@ check-parameter(){
 		shift
 		check-next-parameter $1 || return 1
 		;;
-	    --dist-upgrade|--unionfs|--with-compat32)
+	    --dist-upgrade|--unionfs|--with-compat32|--sign)
 		[ $with_actions -eq 1 ] && \
 		    Msg_GiveNoMoreOptions_$LOCALE && return 1
 		;;
@@ -231,6 +244,7 @@ setup-vbuilder(){
     VBUILDER_CONF=/etc/vbootstrap/vbuilder.conf
     if [ -r $VBUILDER_CONF ]; then
 	. $VBUILDER_CONF
+	[ $? -eq 1 ] && return 1
     fi
     [ -z "${DEFAULT_VERSION}" ] && \
 	DEFAULT_VERSION=@@VBUILDER_DEFAULT_VERSION@@
@@ -257,8 +271,9 @@ setup-vbuilder(){
 
     ## set boolian
     with_setup_vbootstrap=0
-    with_unionfs=0
     with_dist_upgrade=0
+    with_unionfs=0
+    with_sign=0
     with_actions=0
     with_category_main=0
     with_category_plus=0
@@ -266,6 +281,8 @@ setup-vbuilder(){
     with_category_test=0
     with_category_proposed_updates=0
     with_category_security=0
+
+    return 0
 }
 
 setup-vbootstrap(){
@@ -284,18 +301,18 @@ setup-vbootstrap(){
 	    case "${VARCH}" in
 		i386|i686|x86_64)
 		    [ "$(uname -i)" = "ppc" ] && \
-			Msg_NoSupportVARCH_$LOCALE && exit 1
+			Msg_NoSupportVARCH_$LOCALE && return 1
 		    ;;
 		ppc)
 		    [ "$(uname -i)" = "i386" -o "$(uname -i)" = "i686" -o "$(uname -i)" = "x86_64" ] && \
-			Msg_NoSupportVARCH_$LOCALE && exit 1
+			Msg_NoSupportVARCH_$LOCALE && return 1
 		    ;;
 	    esac
 	fi
 
         ##!! 4.2 is NO support on VARCH=x86_64
 	if [ "${VERSION}" = "4.2" -a "${VARCH}" = "x86_64" ]; then
-	    Msg_NoSupportVERSION_${LOCALE} && exit 1
+	    Msg_NoSupportVERSION_${LOCALE} && return 1
 	fi
 
 	## support i386 chroot on x86_64 below: 
@@ -303,13 +320,13 @@ setup-vbootstrap(){
 
         ## check support ${VERSION}
 	if [ -z "$(/usr/sbin/vbootstrap | sed -e s/^Usage:.*// -e s/^E:.*// | grep -m 1 ${VERSION})" ]; then
-	    Msg_NoSupportVERSION_$LOCALE && exit 1
+	    Msg_NoSupportVERSION_$LOCALE && return 1
 	fi
 
 	## check ${VERSION} equals VineSeed*, when with_dist_upgrade=1
 	if [ $with_dist_upgrade -eq 1 ]; then
 	    if [ "$(echo ${VERSION} | sed -e "s/\(VineSeed\).*/\1/")" != "VineSeed" ]; then 
-		Msg_NoSupportDistUpgradeVERSION_$LOCALE && exit 1
+		Msg_NoSupportDistUpgradeVERSION_$LOCALE && return 1
 	    fi
 	fi
 
@@ -333,24 +350,24 @@ setup-vbootstrap(){
 		test)
                     ## "test" category only exists in VineSeed
 		    [ "${MAJOR_VERSION}" = "VineSeed" ] || \
-			Msg_NoSuchCategoryExists_$LOCALE ${cat} && exit 1
+			Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
 		    with_category_test=1
 		    ;;
 		proposed-updates)
                     ##!! "proposed-updates" category does not exist in 4.2
 		    [ "${MAJOR_VERSION}" = "4.2" ] && \
-			Msg_NoSuchCategoryExists_$LOCALE ${cat} && exit 1
+			Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
 
 		    with_category_proposed_updates=1
 		    ;;
 		security)
                     ## "security" category does not exist in VineSeed
 		    [ "${MAJOR_VERSION}" = "VineSeed" ] && \
-			Msg_NoSuchCategoryExists_$LOCALE ${cat} && exit 1
+			Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
 		    with_category_security=1
 		    ;;
 		*)
-		    Msg_NoSuchCategoryExists_$LOCALE ${cat} && exit 1
+		    Msg_NoSuchCategoryExists_$LOCALE ${cat} && return 1
 		    ;;
 	    esac
 	done
@@ -359,12 +376,18 @@ setup-vbootstrap(){
 	if [ ! -z "${TARGET}" ]; then
 	    RPM_TARGET_LIST="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
 	    if [ -z "$(echo $RPM_TARGET_LIST | grep $TARGET)" ]; then
-		Msg_NoSupportTARGET_$LOCALE && exit 1
+		Msg_NoSupportTARGET_$LOCALE && return 1
 	    fi
 	fi
 
+	## set ${RPM_PKG_ARCH_LIST}
+	RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS"
+	[ -z "${TARGET}" ] || \
+	    RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
+
     fi
 
+    ## set global variables
     BUILD_ROOT=${VBOOTSTRAP_DIR}/${VERSION}
     BUILD_USER=vbuilder
     BUILD_DIR=/home/${BUILD_USER}/rpm
@@ -376,10 +399,12 @@ setup-vbootstrap(){
     __chroot_sh="/usr/sbin/chroot ${BUILD_ROOT} /bin/sh -c"
 
     mkdir -p $VBOOTSTRAP_DIR
+
+    return 0
 }
 
 setup-vbootstrap-rpm(){
-    setup-vbootstrap
+    setup-vbootstrap || return 1
 
     ## check ${BUILD_ROOT}
     [ -d ${BUILD_ROOT} ] || Build
@@ -392,6 +417,8 @@ setup-vbootstrap-rpm(){
     else
 	BASE_RPM_PKG=$RPM_PKG	
     fi
+
+    return 0
 }
 
 ## recover apt-get data on host/chroot
@@ -438,7 +465,6 @@ mount-chroot-umount(){
 	    [ -d ${BUILD_ROOT}${fs} ] || return 1
 	    [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
     		umount ${BUILD_ROOT}${fs}
-	    return 0
 	    ;;
 	vfs)
 	    # for dir in /sys /proc /dev/shm /dev/pts /dev; do
@@ -447,13 +473,11 @@ mount-chroot-umount(){
 	    [ -d ${BUILD_ROOT}/proc ] || return 1
 	    [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \
 		umount ${BUILD_ROOT}/proc
-	    return 0
 	    ;;
 	archives_dir)
 	    [ -d ${ARCHIVES_DIR} ] || return 1
 	    [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
     		umount ${ARCHIVES_DIR}
-	    return 0
 	    ;;
 	unionfs_dir)
 	    [ -d ${BUILD_ROOT} ] || return 1
@@ -464,13 +488,13 @@ mount-chroot-umount(){
 		umount -l ${BUILD_ROOT}
 		echo "done."
 	    fi
-	    return 0
 	    ;;
 	*)
 	    echo mount-chroot-umount: unknown file system $fs
 	    exit 1
 	    ;;
     esac
+    return 0
 }
 
 ## mount-chroot-mount [file system|name]
@@ -492,14 +516,12 @@ mount-chroot-mount(){
 	    [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
 	    [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
 		mount ${mnt_opts} ${fs} ${BUILD_ROOT}${fs}
-	    return 0
 	    ;;
 	vfs)
 	    # for dir in /dev /dev/pts /dev/shm /proc /sys; do
 	    # 	mount-chroot-mount ${dir} || return 1
 	    # done
 	    mount-chroot-mount /proc || return 1
-	    return 0
 	    ;;
 	archives_dir)
 	    [ -d ${EXTERNAL_ARCHIVES_DIR} ] || mkdir -p ${EXTERNAL_ARCHIVES_DIR}
@@ -507,7 +529,6 @@ mount-chroot-mount(){
 	    [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
 		mount ${mnt_opts} ${EXTERNAL_ARCHIVES_DIR} ${ARCHIVES_DIR}
 	    [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
-	    return 0
 	    ;;
 	unionfs_dir)
 	    if [ $with_unionfs -eq 1 ]; then
@@ -516,13 +537,13 @@ mount-chroot-mount(){
 		    mount -t unionfs -o dirs=${UNIONFS_DIR}=rw:${BUILD_ROOT}=ro unionfs ${BUILD_ROOT}
 		unionctl ${BUILD_ROOT} --list
 	    fi
-	    return 0
 	    ;;
 	*)
 	    echo mount-chroot-mount: unknown file system $fs
 	    exit 1
 	    ;;
     esac
+    return 0
 }
 
 write-vbuilder-log(){
@@ -560,12 +581,14 @@ EOF
 $*
 EOF
     fi
+
+    return 0
 }
 
 ##############################################################################
 
 Clean(){
-    setup-vbootstrap
+    setup-vbootstrap || return 1
 
     # # output end-of-line in $VBUILDER_LOG
     # [ -f $VBUILDER_LOG ] && write-vbuilder-log ${HRULE}
@@ -593,10 +616,11 @@ Clean(){
     fi
 
     echo "Cleanup a build farm for ${VERSION} done."
+    return 0
 }
 
 Build(){
-    setup-vbootstrap
+    setup-vbootstrap || return 1
 
     if [ $with_dist_upgrade -eq 1 ]; then
 	## make bootstrap of ${STABLE_VERSION}
@@ -681,22 +705,25 @@ Build(){
     apt-get-update --host
 
     echo "Making a build farm for ${VERSION} done."
+    return 0
 }
 
 Show-Info(){
-    setup-vbootstrap
+    setup-vbootstrap || return 1
 
     [ -f $VBUILDER_LOG ] && cat $VBUILDER_LOG
+
+    return 0
 }
 
 RPM_Remove(){
-    setup-vbootstrap-rpm
+    setup-vbootstrap-rpm || return 1
     mount-chroot unionfs_dir
     mount-chroot archives_dir
     mount-chroot vfs
     apt-get-update --chroot
 
-    [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && exit 1
+    [ -f $RPM_PKG ] && Msg_NotPackageName_$LOCALE $RPM_PKG && return 1
     $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
 
     write-vbuilder-log "remove-rpm $RPM_PKG"
@@ -705,10 +732,12 @@ RPM_Remove(){
     mount-chroot --umount archives_dir
     mount-chroot --umount unionfs_dir
     apt-get-update --host
+
+    return 0
 }
 
 RPM_Install(){
-    setup-vbootstrap-rpm
+    setup-vbootstrap-rpm || return 1
     mount-chroot unionfs_dir
     mount-chroot archives_dir
     mount-chroot vfs
@@ -722,25 +751,24 @@ RPM_Install(){
     mount-chroot --umount archives_dir
     mount-chroot --umount unionfs_dir
     apt-get-update --host
+
+    return 0
 }
 
 RPM_Build(){
-    setup-vbootstrap-rpm
+    setup-vbootstrap-rpm || return 1
     mount-chroot unionfs_dir
     mount-chroot archives_dir
     mount-chroot vfs
     apt-get-update --chroot
 
-    [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && exit 1
+    [ ! -f $RPM_PKG ] && Msg_NotSourceRPM_$LOCALE $RPM_PKG && return 1
     
     RPM_PKG_USER=$(stat -c %U $RPM_PKG)
     RPM_PKG_GROUP=$(stat -c %G $RPM_PKG)
     [ ! -z "${SUDO_UID}" ] && RPM_PKG_USER=${SUDO_UID}
     [ ! -z "${SUDO_GID}" ] && RPM_PKG_GROUP=${SUDO_GID}
     local __install="install -p -v -o ${RPM_PKG_USER} -g ${RPM_PKG_GROUP}"
-    RPM_PKG_ARCH_LIST="RPMS/i386 RPMS/i686 RPMS/x86_64 RPMS/ppc RPMS/noarch SRPMS"
-    [ -z "${TARGET}" ] || \
-	RPM_PKG_ARCH_LIST="RPMS/${TARGET} ${RPM_PKG_ARCH_LIST}"
 
     ## make src.rpm for $VERSION
     $__chroot_sh "cd ${BUILD_DIR} && su ${BUILD_USER} -c 'rpm -ivh $BASE_RPM_PKG'"
@@ -776,12 +804,25 @@ RPM_Build(){
     apt-get-update --host
 
     echo "done."
+    return 0
+}
+
+RPM_Sign(){
+    if [ $with_sign -eq 1 ]; then
+	if [ -z "${SUDO_USER}" ]; then
+	    Msg_SUDO_USERisEmpty_$LOCALE
+	else
+	    su ${SUDO_USER} -c "rpm --addsign $(for i in $RPM_PKG_ARCH_LIST; do find $BUILD_ROOT${BUILD_DIR}/${i} -type f -regex '.*\.rpm'; done | sed -e s,$BUILD_ROOT${BUILD_DIR},${BUILT_RPMS_DIR}/${MAJOR_VERSION},g -e 's/$/ \\/g')"
+	fi
+    fi
+
+    return 0
 }
 
 
 ##############################################################################
 
-setup-vbuilder
+setup-vbuilder || exit 1
 
 check-parameter $* || exit 1
 
@@ -791,7 +832,7 @@ while [ $# -gt 0 ]; do
 	--version|--arch|--category|--target|--bootstrap-dir|--cache-dir|--built-rpms-dir)
 	    shift
 	    ;;
-	--dist-upgrade|--unionfs|--with-compat32)
+	--dist-upgrade|--unionfs|--with-compat32|--sign)
 	    ;;
 	--build-rpm|build-rpm|--install-rpm|install-rpm|--remove-rpm|remove-rpm)
 	    shift
@@ -827,6 +868,9 @@ while [ $# -gt 0 ]; do
 	--with-compat32)
 	    RPM_OPTS="${RPM_OPTS} --with compat32"
 	    ;;
+	--sign)
+	    with_sign=1
+	    ;;
 	--bootstrap-dir)
 	    VBOOTSTRAP_DIR=$1
 	    ;;
@@ -849,16 +893,18 @@ while [ $# -gt 0 ]; do
 	    RPM_Remove || exit 1
 	    ;;
 	--show-info|show-info)
-	    Show-Info
+	    Show-Info || exit 1
 	    ;;
 	--build|build)
-	    Build
+	    Build || exit 1
 	    ;;
 	--clean|clean)
-	    Clean
+	    Clean || exit 1
 	    ;;
     esac
     shift
 done
 
+RPM_Sign
+
 exit