support/package-builder/run-in-chroot.sh
f4d17450
 #!/bin/bash
 #################################################
 #	Title:	run-in-chroot.sh    				#
 #        Date:	2015-02-26          			#
 #     Version:	1.0				                #
 #      Author:	sharathg@vmware.com             #
 #################################################
 set -o errexit
 set -o nounset
 set +h
 source common.inc
 
 LOGFILE="$(date +%Y-%m-%d).log"
 PRGNAME=${0##*/}
 LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"
 if [ $# -lt 1 ]; then
     fail "${PRGNAME}: No build root specified. Usage : ${PRGNAME} <build-root>"
 fi
 
542dc63c
 SOURCES=$1
 shift 
 RPMS=$1
 shift 
f4d17450
 BUILDROOT=$1
 shift 
 
 #
 #	Goto chroot and run the command specified as parameter.
 #
45e37dfb
 
 if [ ${EUID} -eq 0 ] ; then
     CHROOT_CMD=chroot
 else
e8435c63
 #    CHROOT_CMD="contain -b $SOURCES:usr/src/photon/SOURCES,$RPMS:usr/src/photon/RPMS -c"
8f56b626
     CHROOT_CMD="contain -b $RPMS:usr/src/photon/RPMS,$RPMS/../SRPMS:usr/src/photon/SRPMS,$RPMS/../PUBLISHRPMS:publishrpms,$RPMS/../PUBLISHXRPMS:publishxrpms -c -n"
45e37dfb
 fi
 
9a168e5c
 
 # Close all fds except stdin, stdout and stderr
 for fd in $(ls /proc/$$/fd/); do
     [ $fd -gt 2 ] && exec {fd}<&-
 done
 
45e37dfb
 $CHROOT_CMD "${BUILDROOT}" \
 	/usr/bin/env -i \
f4d17450
 	HOME=/root \
 	TERM="$TERM" \
 	PS1='\u:\w\$ ' \
 	PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
80b3670d
 	SHELL=/bin/bash \
45e37dfb
 	/bin/bash --login +h -c "$*"
f4d17450
 
 exit 0