buildpkg.sh enhancements

Tim Rice tim at multitalents.net
Sat May 1 06:12:35 EST 2004


I've made some changes to buildpkg.sh to make it easier for package
builders to add their local changes.

I'd like people that use buildpkg.sh to test and comment on these
changes before I commit them to CVS.

None of the defaults have changed.

Some of the patch is is just moving chunks of code to a different
location to make some of the enhancements work.

Some things you may find usefull:

New variables you can put in your config.local
REMOVE_FAKE_ROOT_WHEN_DONE	Remove fake root dir when done.
SYSVINITSTART			System V init start level
SYSVINITSTOPT			System V init start level
POST_MAKE_INSTALL_FIXES		Name of script to run after "make install"
POST_PROTOTYPE_EDITS		Name of script to run after prototype is made
PKG_PREINSTALL_LOCAL		Local preinstall additions
PKG_POSTINSTALL_LOCAL		Local postinstall additions
PKG_PREREMOVE_LOCAL		Local preremove additions
PKG_POSTREMOVE_LOCAL		Local postremove additions
PKG_REQUEST_LOCAL		Local request additions

I've moved OPENSSHD_IN up so it can be overriden by your config.local

$srcdir is now available to scripts

Start to add support for OpenSerever. (not done yet)
I've always intended for this script to work on any system that
has the pkgadd/pkgrm tools.

We now build an empty depend file that you can add to.
We now build a postremove file.

If you link buildpkg.sh to justpkg.sh you can use justpkg.sh to do a
pkgmk, pkgtrans from the bits already installed instead of
removing $FAKE_ROOT and starting from scratch.

Enjoy.

-- 
Tim Rice				Multitalents	(707) 887-1469
tim at multitalents.net
-------------- next part --------------
--- buildpkg.sh	2004-01-22 16:10:03.000000000 -0800
+++ /usr/local/src/networking/openssh-3.8/buildpkg.sh	2004-04-30 11:09:40.232352018 -0700
@@ -11,6 +11,8 @@
 # Options for building the package
 # You can create a config.local with your customized options
 #
+REMOVE_FAKE_ROOT_WHEN_DONE=yes
+#
 # uncommenting TEST_DIR and using
 # configure --prefix=/var/tmp --with-privsep-path=/var/tmp/empty
 # and
@@ -27,6 +29,22 @@
 #PERMIT_ROOT_LOGIN=no
 #X11_FORWARDING=yes
 #USR_LOCAL_IS_SYMLINK=yes
+# System V init run levels
+SYSVINITSTART=S98
+SYSVINITSTOPT=K30
+# We will source these if they exist
+POST_MAKE_INSTALL_FIXES=./pkg_post_make_install_fixes.sh
+POST_PROTOTYPE_EDITS=./pkg_post_prototype_edit.sh
+# We'll be one level deeper looking for these
+PKG_PREINSTALL_LOCAL=../pkg-preinstall.local
+PKG_POSTINSTALL_LOCAL=../pkg-postinstall.local
+PKG_PREREMOVE_LOCAL=../pkg-preremove.local
+PKG_POSTREMOVE_LOCAL=../pkg-postremove.local
+PKG_REQUEST_LOCAL=../pkg-request.local
+# end of sourced files
+#
+OPENSSHD_IN=`dirname $0`/opensshd.in
+#
 # list of system directories we do NOT want to change owner/group/perms
 # when installing our package
 SYSTEM_DIR="/etc	\
@@ -63,6 +81,10 @@
 
 # We may need to build as root so we make sure PATH is set up
 # only set the path if it's not set already
+[ -d /opt/bin ]  &&  {
+	echo $PATH | grep ":/opt/bin"  > /dev/null 2>&1
+	[ $? -ne 0 ] && PATH=$PATH:/opt/bin
+}
 [ -d /usr/local/bin ]  &&  {
 	echo $PATH | grep ":/usr/local/bin"  > /dev/null 2>&1
 	[ $? -ne 0 ] && PATH=$PATH:/usr/local/bin
@@ -82,22 +104,11 @@
 # we will look for config.local to override the above options
 [ -s ./config.local ]  &&  . ./config.local
 
-## Start by faking root install
-echo "Faking root install..."
 START=`pwd`
-OPENSSHD_IN=`dirname $0`/opensshd.in
 FAKE_ROOT=$START/package
-[ -d $FAKE_ROOT ]  &&  rm -fr $FAKE_ROOT
-mkdir $FAKE_ROOT
-${MAKE} install-nokeys DESTDIR=$FAKE_ROOT
-if [ $? -gt 0 ]
-then
-	echo "Fake root install failed, stopping."
-	exit 1
-fi
 
 ## Fill in some details, like prefix and sysconfdir
-for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir
+for confvar in prefix exec_prefix bindir sbindir libexecdir datadir mandir sysconfdir piddir srcdir
 do
 	eval $confvar=`grep "^$confvar=" Makefile | cut -d = -f 2`
 done
@@ -118,6 +129,10 @@
 ## Extract common info requires for the 'info' part of the package.
 VERSION=`./ssh -V 2>&1 | sed -e 's/,.*//'`
 
+ARCH=`uname -m`
+DEF_MSG="\n"
+OS_VER=`uname -v`
+SCRIPT_SHELL=/sbin/sh
 UNAME_S=`uname -s`
 case ${UNAME_S} in
 	SunOS)	UNAME_S=Solaris
@@ -125,10 +140,25 @@
 		RCS_D=yes
 		DEF_MSG="(default: n)"
 		;;
-	*)	ARCH=`uname -m`
-		DEF_MSG="\n" ;;
+	SCO_SV)	UNAME_S=OpenServer
+		OS_VER=`uname -X | grep Release | sed -e 's/^Rel.*3.2v//'`
+		SCRIPT_SHELL=/bin/sh
+		;;
 esac
 
+case `basename $0` in
+	buildpkg.sh)
+## Start by faking root install
+echo "Faking root install..."
+[ -d $FAKE_ROOT ]  &&  rm -fr $FAKE_ROOT
+mkdir $FAKE_ROOT
+${MAKE} install-nokeys DESTDIR=$FAKE_ROOT
+if [ $? -gt 0 ]
+then
+	echo "Fake root install failed, stopping."
+	exit 1
+fi
+
 ## Setup our run level stuff while we are at it.
 mkdir -p $FAKE_ROOT${TEST_DIR}/etc/init.d
 
@@ -155,6 +185,9 @@
 [ -f $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds ]  &&  \
 mv $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds $FAKE_ROOT/${sysconfdir}/ssh_prng_cmds.default
 
+# local tweeks here
+[ -s "${POST_MAKE_INSTALL_FIXES}" ]  &&  . ${POST_MAKE_INSTALL_FIXES}
+
 cd $FAKE_ROOT
 
 ## Ok, this is outright wrong, but it will work.  I'm tired of pkgmk
@@ -175,12 +208,35 @@
 CATEGORY="Security,application"
 BASEDIR=/
 CLASSES="none"
+PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`"
+_EOF
+
+## Build empty depend file that may get updated by $POST_PROTOTYPE_EDITS
+echo "Building depend file..."
+touch depend
+
+## Build space file
+echo "Building space file..."
+cat > space << _EOF
+# extra space required by start/stop links added by installf in postinstall
+$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1
+$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1
+$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME} 0 1
 _EOF
+[ "$RCS_D" = yes ]  &&  \
+echo "$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME} 0 1" >> space
 
 ## Build preinstall file
 echo "Building preinstall file..."
 cat > preinstall << _EOF
-#! /sbin/sh
+#! ${SCRIPT_SHELL}
+#
+_EOF
+
+# local preinstall changes here
+[ -s "${PKG_PREINSTALL_LOCAL}" ]  &&  . ${PKG_PREINSTALL_LOCAL}
+
+cat >> preinstall << _EOF
 #
 [ "\${PRE_INS_STOP}" = "yes" ]  &&  ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
 exit 0
@@ -189,7 +245,7 @@
 ## Build postinstall file
 echo "Building postinstall file..."
 cat > postinstall << _EOF
-#! /sbin/sh
+#! ${SCRIPT_SHELL}
 #
 [ -f \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config ]  ||  \\
 	cp -p \${PKG_INSTALL_ROOT}${sysconfdir}/ssh_config.default \\
@@ -214,21 +270,27 @@
 if [ "\${USE_SYM_LINKS}" = yes ]
 then
 	[ "$RCS_D" = yes ]  &&  \
-installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
-	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
-	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
-	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
+installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
+	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
+	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
+	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=../init.d/${SYSVINIT_NAME} s
 else
 	[ "$RCS_D" = yes ]  &&  \
-installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
-	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
-	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
-	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
+installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rcS.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
+	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc0.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
+	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc1.d/${SYSVINITSTOPT}${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
+	installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR/etc/rc2.d/${SYSVINITSTART}${SYSVINIT_NAME}=$TEST_DIR/etc/init.d/${SYSVINIT_NAME} l
 fi
 
 # If piddir doesn't exist we add it. (Ie. --with-pid-dir=/var/opt/ssh)
 [ -d $piddir ]  ||  installf ${PKGNAME} \${PKG_INSTALL_ROOT}$TEST_DIR$piddir d 755 root sys
 
+_EOF
+
+# local postinstall changes here
+[ -s "${PKG_POSTINSTALL_LOCAL}" ]  &&  . ${PKG_POSTINSTALL_LOCAL}
+
+cat >> postinstall << _EOF
 installf -f ${PKGNAME}
 
 # Use chroot to handle PKG_INSTALL_ROOT
@@ -290,9 +352,29 @@
 ## Build preremove file
 echo "Building preremove file..."
 cat > preremove << _EOF
-#! /sbin/sh
+#! ${SCRIPT_SHELL}
 #
 ${TEST_DIR}/etc/init.d/${SYSVINIT_NAME} stop
+_EOF
+
+# local preremove changes here
+[ -s "${PKG_PREREMOVE_LOCAL}" ]  &&  . ${PKG_PREREMOVE_LOCAL}
+
+cat >> preremove << _EOF
+exit 0
+_EOF
+
+## Build postremove file
+echo "Building postremove file..."
+cat > postremove << _EOF
+#! ${SCRIPT_SHELL}
+#
+_EOF
+
+# local postremove changes here
+[ -s "${PKG_POSTREMOVE_LOCAL}" ]  &&  . ${PKG_POSTREMOVE_LOCAL}
+
+cat >> postremove << _EOF
 exit 0
 _EOF
 
@@ -300,6 +382,59 @@
 echo "Building request file..."
 cat > request << _EOF
 trap 'exit 3' 15
+
+_EOF
+
+[ -x /usr/bin/ckyorn ]  ||  cat >> request << _EOF
+
+ckyorn() {
+# for some strange reason OpenServer has no ckyorn
+# We build a striped down version here
+
+DEFAULT=n
+PROMPT="Yes or No [yes,no,?,quit]"
+HELP_PROMPT="        Enter y or yes if your answer is yes; n or no if your answer is no."
+USAGE="usage: ckyorn [options]
+where options may include:
+        -d default
+        -h help
+        -p prompt
+"
+
+if [ \$# != 0 ]
+then
+	while getopts d:p:h: c
+	do
+		case \$c in
+			h)	HELP_PROMPT="\$OPTARG" ;;
+			d)	DEFAULT=\$OPTARG ;;
+			p)	PROMPT=\$OPTARG ;;
+			\\?)	echo "\$USAGE" 1>&2
+				exit 1 ;;
+		esac
+	done
+	shift \`expr \$OPTIND - 1\`
+fi
+
+while true
+do
+	echo "\${PROMPT}\\c " 1>&2
+	read key
+	[ -z "\$key" ]  &&  key=\$DEFAULT
+	case \$key in
+		[n,N]|[n,N][o,O]|[y,Y]|[y,Y][e,E][s,S])	echo "\${key}\\c"
+			exit 0 ;;
+		\\?)	echo \$HELP_PROMPT 1>&2 ;;
+		q|quit)	echo "q\\c" 1>&2
+			exit 3 ;;
+	esac
+done
+
+}
+
+_EOF
+
+cat >> request << _EOF
 USE_SYM_LINKS=no
 PRE_INS_STOP=no
 POST_INS_START=no
@@ -338,26 +473,23 @@
 PRE_INS_STOP='\$PRE_INS_STOP'
 POST_INS_START='\$POST_INS_START'
 !
-exit 0
 
 _EOF
 
-## Build space file
-echo "Building space file..."
-cat > space << _EOF
-# extra space required by start/stop links added by installf in postinstall
-$TEST_DIR/etc/rc0.d/K30${SYSVINIT_NAME} 0 1
-$TEST_DIR/etc/rc1.d/K30${SYSVINIT_NAME} 0 1
-$TEST_DIR/etc/rc2.d/S98${SYSVINIT_NAME} 0 1
+# local request changes here
+[ -s "${PKG_REQUEST_LOCAL}" ]  &&  . ${PKG_REQUEST_LOCAL}
+
+cat >> request << _EOF
+exit 0
+
 _EOF
-[ "$RCS_D" = yes ]  &&  \
-echo "$TEST_DIR/etc/rcS.d/K30${SYSVINIT_NAME} 0 1" >> space
 
 ## Next Build our prototype
 echo "Building prototype file..."
 cat >mk-proto.awk << _EOF
-	    BEGIN { print "i pkginfo"; print "i preinstall"; \\
-		    print "i postinstall"; print "i preremove"; \\
+	    BEGIN { print "i pkginfo"; print "i depend"; \\
+		    print "i preinstall"; print "i postinstall"; \\
+ 		    print "i preremove"; print "i postremove"; \\
 		    print "i request"; print "i space"; \\
 		    split("$SYSTEM_DIR",sys_files); }
 	    {
@@ -378,9 +510,27 @@
 }
 
 ## Step back a directory and now build the package.
-echo "Building package.."
 cd ..
+# local prototype tweeks here
+[ -s "${POST_PROTOTYPE_EDITS}" ]  &&  . ${POST_PROTOTYPE_EDITS}
+
+echo "Building package.."
 pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
-echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$UNAME_S-$ARCH-$VERSION.pkg
-rm -rf $FAKE_ROOT
+echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION-$UNAME_S-$ARCH.pkg
+	;;
+
+	justpkg.sh)
+rm -fr ${FAKE_ROOT}/${PKGNAME}
+grep -v "^PSTAMP=" $FAKE_ROOT/pkginfo > $$tmp
+mv $$tmp $FAKE_ROOT/pkginfo
+cat >> $FAKE_ROOT/pkginfo << _EOF
+PSTAMP="${UNAME_S} ${OS_VER} ${ARCH} `date '+%d%b%Y %H:%M'`"
+_EOF
+pkgmk -d ${FAKE_ROOT} -f $FAKE_ROOT/prototype -o
+echo | pkgtrans -os ${FAKE_ROOT} ${START}/$PKGNAME-$VERSION-$UNAME_S-$ARCH.pkg
+	;;
+
+esac
+
+[ "${REMOVE_FAKE_ROOT_WHEN_DONE}" = yes ]  &&  rm -rf $FAKE_ROOT
 


More information about the openssh-unix-dev mailing list