#!/bin/sh # # Functions taken from protopkg by David Cantrell # # stripeverything() # Goes through the package tree and strips all ELF stuff (binaries, # libraries, and so on). # # Parameters: $1 The package tree. # stripeverything() { cd $1 STATIC_DONE=n # strip shared libraries and binaries if [ ! "$STRIPLIB" = "n" -o ! "$STRIPBIN" = "n" ] then msgOut=n for testname in `find . -type f` do islib="`file $testname | grep ELF | \ grep 'shared object' | \ grep 'not stripped'`" isprog="`file $testname | grep ELF | \ grep executable | \ grep 'not stripped'`" isstatic="`file $testname | grep 'current ar archive'`" # strip binaries if the user so desires if [ ! "$isprog" = "" -a "$STRIPBIN" = "y" ] then if [ "$msgOut" = "n" ] then echo echo "Stripping ELF objects, generating static library indexes..." msgOut=y fi echo " --> strip $testname" strip -p --strip-unneeded $testname 2>/dev/null 1>/dev/null fi # strip libraries if the user so desires if [ ! "$islib" = "" -a "$STRIPLIB" = "y" ] then if [ "$msgOut" = "n" ] then echo echo "Stripping ELF objects, generating static library indexes..." msgOut=y fi echo " --> strip $testname" strip -p --strip-unneeded $testname 2>/dev/null 1>/dev/null fi # run ranlib on static libraries if [ ! "$isstatic" = "" ] then STATIC_DONE=y echo " --> ranlib $testname" ranlib $testname 2>/dev/null 1>/dev/null fi done if [ "$msgOut" = "y" ] then echo fi fi if [ "$STATIC_DONE" = "n" ] then # ranlib static libraries msgOut=n for libname in `find . -name *.a -type f` do if [ ! "`file $libname | grep 'current ar archive'`" = "" ] then if [ "$msgOut" = "n" ] then echo echo "Generating static library indexes..." msgOut=y fi echo " --> $libname" ranlib $libname 2>/dev/null 1>/dev/null fi done fi } # # make_install_script() # Runs through the temporary package directory and searches for symlinks. # These are put into a script to create those symlinks at installation # time. # make_install_script() { COUNT=1 LINE="`sed -n "$COUNT p" $1`" while [ ! "$LINE" = "" ] do LINKGOESIN="`echo "$LINE" | cut -f 1 -d " "`" LINKGOESIN1="`dirname $LINKGOESIN`" LINKGOESIN=`trim_slash $LINKGOESIN1` LINKNAMEIS="`echo "$LINE" | cut -f 1 -d ' '`" LINKNAMEIS="`basename "$LINKNAMEIS"`" LINKPOINTSTO="`echo "$LINE" | cut -f 3 -d ' '`" echo "( cd $LINKGOESIN ; rm -rf $LINKNAMEIS )" echo "( cd $LINKGOESIN ; ln -sf $LINKPOINTSTO $LINKNAMEIS )" COUNT=`expr $COUNT + 1` LINE="`sed -n "$COUNT p" $1`" done } # # permissionize() # Called by protopkg() to fix permissions on the temporary package build # directory. It sets all bin and sbin stuff to root.bin, chmod'ed 755. # After that it runs the ownerships and permissions functions from the # package prototype file (to set any special permissions the package # maintainer wants). # # Parameters: $1 The package tree. # permissionize() { cd $1 # default system-wide permissions find . -exec chown root.root {} \; 1>/dev/null 2>/dev/null find . -type d -exec chmod 755 {} \; 1>/dev/null 2>/dev/null find . -type d -exec chown root.root {} \; 1>/dev/null 2>/dev/null # default bin and sbin permissions (root.bin, 755) for d in usr/bin usr/sbin usr/X11R6/bin bin sbin usr/local/bin usr/local/sbin do chown -R root.bin $1/$d 2>/dev/null chmod -R 755 $1/$d 2>/dev/null done # default include permissions find usr/include -name *.h -exec chmod 644 {} \; 1>/dev/null 2>/dev/null find usr/X11R6/include -name *.h -exec chmod 644 {} \; 1>/dev/null 2>/dev/null # default man and info page permissions find usr/man -type f -exec chmod 644 {} \; 1>/dev/null 2>/dev/null find usr/X11R6/man -type f -exec chmod 644 {} \; 1>/dev/null 2>/dev/null find usr/info -type f -exec chmod 644 {} \; 1>/dev/null 2>/dev/null # default /usr/doc permissions and ownerships find . | grep "usr/doc" | xargs chown root.root 1>/dev/null 2>/dev/null find . -type f | grep "usr/doc" | xargs chmod 644 1>/dev/null 2>/dev/null find . -type d | grep "usr/doc" | xargs chmod 755 1>/dev/null 2>/dev/null } # # compressdocs() # Compresses all man pages and info files in a package tree. # # Parameters: $1 The package tree. # compressdocs() { dir1=`pwd` cd $1 for dn in usr \ usr/local \ 'opt/*' \ usr/X11R6 \ usr/openwin do # adapted by Jasper Huijsmans to repair broken links # and to also gzip the originally installed file for dn2 in man share/man info share/info do for file in `find $dn/$dn2 -type f 2>/dev/null` do gzip -9f $1/$file /$file 2>/dev/null done for link in `find $dn/$dn2 -type l 2>/dev/null` do relink_docs $1/$link 2>/dev/null relink_docs /$link 2>/dev/null done done done cd $dir1 } # # relink_docs() # repair broken links to docs cause by gzipping # added by Jasper Huijsmans # # Parameters: $1 The symbolic link file # relink_docs() { LINKGOESIN=`dirname $1` LINKNAMEIS=`basename $1` LINKPOINTSTO=`ls -l $1 | cut -b58- | cut -f 3 -d ' '` rm $1 # Here comes the trick: just add .gz to every name ( cd $LINKGOESIN; ln -s $LINKPOINTSTO.gz $LINKNAMEIS.gz ) } # # symlinks() # Called by protopkg() to remove any symlinks found in the temporary # package build directory. Also makes the doinst.sh file for recreating # those at install time. # # Parameters: $1 The package tree. # $2 The embedded package control directory. # symlinks() { # Get rid of possible pre-existing trouble: rm -rf /tmp/iNsT-a.$$ cd $1 echo find . -type l -exec ls -l {} \; | cut -b58- | tee /tmp/iNsT-a.$$ cd /tmp # create the install directory if we need it if [ ! -d $2 ] then mkdir -p $2 chown root.root $2 chmod 755 $2 fi if [ ! "`file_size /tmp/iNsT-a.$$`" = "0" ] then echo make_install_script /tmp/iNsT-a.$$ | tee /tmp/doinst.sh # write out the doinst script cat /tmp/doinst.sh >> $2/doinst.sh chown root.root $2/doinst.sh chmod 644 $2/doinst.sh # remove symlinks and clean up temp files cd $1 echo find . -type l -exec rm -v {} \; cd /tmp ; rm -f doinst.sh iNsT-a.$$ fi rm -rf /tmp/iNsT-a.$$ } # # trim_slash() # Removes the first character of the passed in string if it's a slash. # trim_slash() { if [ "`echo $1 | cut -c1`" = "/" ] then expr substr $1 2 `expr length $1` fi } # # filesize() # This function duplicates what the "filesize" program in Slackware does. # We may not have this on the particular filesystem we're on. It's # simple enough to just be a function. # # The argument it accepts is a filename to take the size of. # file_size() { SIZE=`ls -l -d -G "$1" | cut -b23-33` echo -n $SIZE } stripeverything $1 permissionize $1 compressdocs $1 symlinks $1 $1/install