# This file is part of the src2pkg program: # Copyright 2005-2009 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 do_last_minute_details () { # Last minute inclusions before creating the package. These are put here instead of at the top # of make_package so that changes can still be made manually in a src2pkg script between # make_doinst and make_package cd "$CWD" # this has been moved here from /usr/bin/src2pkg so that scripts can be included in the package # but if we are running $NAME.src2pkg using -A, a new script is not written # The function write_src2pkg_script is located in the FUNCTIONS file if [[ $AUTO_SCRIPT ]] && [[ ! $DONT_CLOBBER_SCRIPT ]] ; then write_src2pkg_script SCRIPT=$NAME.src2pkg.auto fi # now see if the user wants the src2pkg script included in the package # if the script was just created above, we get the name $SCRIPT from there # if the script was run using 'src2pkg -X', the name $SCRIPT was set in /usr/bin/src2pkg # if the script was executed with something like: 'sh $NAME.src2pkg' then SCRIPT=$EXEC_NAME if [[ $ADD_SRC2PKG_SCRIPT = "YES" ]] && [[ "$EXEC_NAME" != "trackinstall" ]] ; then # strip leading slash from SRC2PKG_SCRIPT_DIR if necessary if [[ ${SRC2PKG_SCRIPT_DIR:0:1} = "/" ]] ; then SRC2PKG_SCRIPT_DIR=${SRC2PKG_SCRIPT_DIR:1} fi # if SCRIPT is still NULL, that means that the script was run directly # and corresponds to $EXEC_NAME, except if [[ $SCRIPT = "" ]] && [[ "$EXEC_NAME" != "src2pkg" ]] ; then SCRIPT="$EXEC_NAME" fi # if SCRIPT is still null, that means src2pkg was run directly on the target without any script at all if [[ "$SCRIPT" != "" ]] ; then if [[ $SRC2PKG_SCRIPT_DIR = "DOC_DIR" ]] ; then echo $BLUE"Adding src2pkg script to package in: "$NORMAL"${DOC_DIR#$PKG_DIR/*}" mkdir -p "$DOC_DIR" cp "$SCRIPT" "$DOC_DIR" else if [[ $USE_VERSION_NUMBERS = "YES" ]] ; then SCRIPT_DIR=$SRC2PKG_SCRIPT_DIR/$NAME-$VERSION else SCRIPT_DIR=$SRC2PKG_SCRIPT_DIR/$NAME fi echo $BLUE"Adding src2pkg script to package in: "$NORMAL"PKG_DIR/$SCRIPT_DIR" mkdir -p "$PKG_DIR"/$SCRIPT_DIR cp $SCRIPT "$PKG_DIR"/$SCRIPT_DIR if [[ $LINK_SCRIPT_TO_DOC_DIR = "YES" ]] ; then ( cd "$DOC_DIR" ; ln -sf /$SCRIPT_DIR/$SCRIPT $SCRIPT ) fi fi fi fi # moved here from 10-strip_bins -Compression of binaries must be done after # generating dependency information if [[ $COMPRESS_BINS = "YES" ]] || [[ $SAVE_SPACE -gt 2 ]] ; then compress_bins fi # I thought this was working... but no. #if [[ $COMPRESS_LIBS = "YES" ]] || [[ $SAVE_SPACE -gt 3 ]] ; then # compress_libs #fi # this has been moved here from fix_pkg_perms as this should # be done at the very last moment to catch any last-minute errors echo -n $BLUE"Rechecking package permissions - "$NORMAL # BIN_DIRS and LIB_DIRS are done in 09-fix_pkg_perms # fix other common dirs here # all files in these dirs are also chmod'ed 644 for dir in $INC_DIRS $LOCALE_DIRS $MAN_DIRS $DOC_DIRS ; do if [[ -d "$PKG_DIR"/$dir ]] ; then if [[ "$EUID" = "0" ]] ; then chown root:root "$PKG_DIR"/$dir chmod 755 $PKG_DIR/$dir find "$PKG_DIR"/$dir -type d -exec chown root:root {} \; find "$PKG_DIR"/$dir -type d -exec chmod 755 {} \; find "$PKG_DIR"/$dir -type f -exec chmod 644 {} \; else chown $OWNER:$GROUP "$PKG_DIR"/$dir chmod 755 $PKG_DIR/$dir find "$PKG_DIR"/$dir -type d -exec chown $OWNER:$GROUP {} \; find "$PKG_DIR"/$dir -type d -exec chmod 755 {} \; find "$PKG_DIR"/$dir -type f -exec chmod 644 {} \; fi fi done # seems the best we can do here, we have no way of reliably knowing whether a conf file # should be executable or not. xnitrc.* and some rc.* and even others may rightly # be executable. But any file in the toplevel of /etc should not be -not that I've seen, anyway. # And we can't use chmod 644, because the thing might really suppsoed to be 600 # so use chmod ogu-x to just make sure the executable bit is not set. if [[ -d $PKG_DIR/etc ]] ; then cd $PKG_DIR/etc #find -type f ! -name "rc.*" -a ! -name "xinitrc.*" -exec chmod 644 {} \; find -maxdepth 1 -type f -exec chmod ogu-x {} \; fi cd $PKG_DIR check_pkg_perms if [[ ! $UNUSUAL_DIRS ]] && [[ ! $UNUSUAL_FILES ]] ; then echo $GREEN"Done"$NORMAL else #echo "Check files and/or dirs manually." echo $CYAN" Notice - "$NORMAL"These files and/or directories are listed for information only." echo " Corrections may not be needed, but you should check them to be sure." fi # take care of empty files handle_empty_files check_dir_locations } # end do_last_minute_details check_pkg_perms() { if [[ $(find * -type d -a ! -user $USER -o -type d -a ! -group $GROUP -o -type d -a ! -perm 755) != "" ]] ; then echo "" #"Hmmm..." echo $CYAN" Notice - "$NORMAL"Found directories with unusual owner, group or permissions:" UNUSUAL_DIRS=1 for DIR in $(find * -type d -a ! -user $USER -o \ -type d -a ! -group $GROUP -o \ -type d -a ! -perm 755) ; do if [[ $DIR != "tmp" ]] && [[ $DIR != "var/tmp" ]] && [[ $DIR != "var/lock" ]] && [[ $DIR != "var/run" ]] ; then child=$(basename $DIR) parent=$(dirname $DIR) perms=$(stat $DIR |grep Access: |head -n 1|cut -f 1 -d/) perms=${perms#*(} STATS=$(ls -l $parent |grep "$child$" |white_out) owner=$(echo $STATS |cut -f 3 -d ' ') group=$(echo $STATS |cut -f 4 -d ' ') echo " $perms $owner:$group $DIR" fi done fi if [[ $(find * -type f -a ! -user $USER -o -type f -a ! -group $GROUP -o -type f -a ! -perm 755 -a ! -perm 644) != "" ]] ; then echo "" #"Hmmm..." echo $CYAN" Notice - "$NORMAL"Found files with unusual owner, group or permissions:" UNUSUAL_FILES=1 for FILE in $(find * -type f -a ! -user $USER -o -type f -a ! -group $GROUP -o -type f -a ! -perm 755 -a ! -perm 644) ; do perms=$(stat $FILE |grep Access: |head -n 1|cut -f 1 -d/) perms=${perms#*(} STATS=$(ls -l $FILE |white_out) owner=$(echo $STATS |cut -f 3 -d ' ') group=$(echo $STATS |cut -f 4 -d ' ') echo " $perms $owner:$group $FILE" done fi } # compress binaries with upx if requested and available compress_bins() { if [[ "$FAILED" = "" ]] ; then if [[ $BIN_COMPRESSOR ]] ; then if [[ $(which $BIN_COMPRESSOR) ]] ; then BINCOMPRESSOR=$(which $BIN_COMPRESSOR) else echo "Binary compressor \"$BIN_COMPRESSOR\" not found" fi elif [[ $(which upx-ucl) ]] ; then BINCOMPRESSOR=$(which upx-ucl) elif [[ $(which upx) ]]; then BINCOMPRESSOR=$(which upx) else echo $CYAN"Notice! "$NORMAL"Compression of binaries was requested, but no compressor found." BINCOMPRESSOR="" fi cd "$PKG_DIR" ; if [[ $BINCOMPRESSOR != "" ]] ; then echo $BLUE"Searching for binaries >$COMPRESSION_SIZE_LIMIT KB to compress: "$NORMAL # use find instead of hard-coded directory list: for f in $(find * -type f |xargs -r file |grep ELF |grep 'executable' |cut -f1 -d :) ; do FILE_SIZE=$(du $f |cut -f1 -d' ') if [[ $FILE_SIZE -gt $COMPRESSION_SIZE_LIMIT ]] ; then echo -n $BLUE" Compressing: "$NORMAL"$(basename $f) " if [[ $QUIET != "YES" ]] ; then $BINCOMPRESSOR $BIN_COMPRESOR_OPTIONS $f if [[ $? = 0 ]] ; then NEW_FILE_SIZE=$(du $f |cut -f1 -d' ') echo $GREEN"Done!"$NORMAL" Saved: $(( $FILE_SIZE - $NEW_FILE_SIZE ))KB ($FILE_SIZE/$NEW_FILE_SIZE)" COMPRESSION_OKAY=1 mkdir -p "$DOC_DIR" echo "$f" >> "$DOC_DIR"/compressed-bins.tmp else echo $YELLOW"Failed! "$NORMAL COMPRESSION_FAILED=1 fi else $BINCOMPRESSOR $BIN_COMPRESOR_OPTIONS $f &> /dev/null if [[ $? = 0 ]] ; then NEW_FILE_SIZE=$(du $f |cut -f1 -d' ') echo $GREEN"Done!"$NORMAL" Saved: $(( $FILE_SIZE - $NEW_FILE_SIZE ))KB ($FILE_SIZE/$NEW_FILE_SIZE)" COMPRESSION_OKAY=1 mkdir -p "$DOC_DIR" #echo "$(basename $f)"$'\t'"$FILE_SIZE"$'\t'"$NEW_FILE_SIZE " >> $DOC_DIR/compressed-bins.tmp echo "$f">> "$DOC_DIR"/compressed-bins.tmp else echo $YELLOW"Failed! "$NORMAL COMPRESSION_FAILED=1 fi fi else continue fi done [[ $COMPRESSION_FAILED = 1 ]] && echo $CYAN" Notice: "$NORMAL"Failures may mean COMPRESSION_SIZE_LIMIT is too low." if [[ $COMPRESSION_OKAY != 1 ]] ; then echo $BLUE"Skipping - "$NORMAL"No binaries were compressed." else echo "Some files in this package were compressed using '$BIN_COMPRESSOR'." > "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt echo "If you have trouble running any of the programs listed here, try" >> "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt echo "uncompressing the binary using the command '$BIN_COMPRESSOR -d prog-name'." >> "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt echo "If the program then runs normally, report the problem to the" >> "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt echo "person who created the program package." >> "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt echo "Programs compressed:" >> "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt #echo "NAME"$'\t'"Orig Size"$'\t'"Compressed size" >> "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt cat "$DOC_DIR"/compressed-bins.tmp >> "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt fi rm -f "$DOC_DIR"/compressed-bins.tmp fi fi } # I thought this worked but doesn't after all. Maybe I find another solution, so leave code here for now # compress libraries with upx if requested and available # compressing libs can cause them to be unusable... compress_libs() { if [[ "$FAILED" = "" ]] ; then if [[ $BIN_COMPRESOR ]] ; then if [[ $(which $BIN_COMPRESOR) ]] ; then BINCOMPRESSOR=$(which $BIN_COMPRESOR) else echo "Binary compressor \"$BIN_COMPRESOR\" not found" fi elif [[ $(which upx-ucl) ]] ; then BINCOMPRESSOR=$(which upx-ucl) elif [[ $(which upx) ]]; then BINCOMPRESSOR=$(which upx) else echo $CYAN"Notice! "$NORMAL"Compression of libraries was requested, but no compressor found." BINCOMPRESSOR="" fi cd $PKG_DIR ; if [[ $BINCOMPRESSOR != "" ]] ; then echo $BLUE"Searching for libraries to compress: "$NORMAL for f in $(find * -type f |xargs -r file |grep ELF |cut -f1 -d :) ; do if [[ $(file $f |grep "shared object") ]] || [[ $(file $f |grep "relocatable") ]]; then if [[ $(du $f |cut -f1 -d' ') -gt $COMPRESSION_SIZE_LIMIT ]] ; then echo -n $BLUE" Compressing: $(basename $f) - "$NORMAL if [[ $QUIET != "YES" ]] ; then $BINCOMPRESSOR $BIN_COMPRESOR_OPTIONS -f $f if [[ $? = 0 ]] ; then echo $GREEN"Okay!"$NORMAL COMPRESSION_OKAY=1 else echo $YELLOW"Failed! "$NORMAL COMPRESSION_FAILED=1 fi else $BINCOMPRESSOR $BIN_COMPRESOR_OPTIONS -f $f &> /dev/null if [[ $? = 0 ]] ; then echo $GREEN"Okay!"$NORMAL COMPRESSION_OKAY=1 else echo $YELLOW"Failed! "$NORMAL COMPRESSION_FAILED=1 fi fi else continue fi fi done [[ $COMPRESSION_FAILED = 1 ]] && echo $CYAN" Notice: "$NORMAL"Failures may mean COMPRESSION_SIZE_LIMIT is too low." [[ $COMPRESSION_OKAY != 1 ]] && echo $BLUE"Skipping - "$NORMAL"No libraries were compressed." fi fi } handle_empty_files() { # first get rid of any zero-length files if [[ $FORCE_ZERO_LENGTH != "YES" ]] ; then cd "$PKG_DIR" ; if [[ $(find * -type f -size 0 |egrep -v '^(etc|var|usr/etc|usr/var)') ]] ; then echo $CYAN"NOTICE! "$NORMAL" Empty files were found in the package tree. These may" echo "or may not be needed by the program. By default, src2pkg allows" echo "empty files under /etc or /var but removes any others. Use the" echo "option ALLOW_EMPTY_FILES=YES to allow all zero-length files." echo $BLUE"List of removed files:"$NORMAL # for dir in $(ls |grep -v '^etc' |grep -v '^var') ; do for dir in $(find * -type d |egrep -v '^(etc|var|usr/etc|usr/var)') ; do #( cd $dir find $dir -type f -size 0 -exec echo $dir/$(basename {}) \; find $dir -type f -size 0 -exec rm -f {} \; #cd ../ #) done fi find . -type f -name '*.gz' -size 20c | while read file ; do echo "WARNING: Possible empty gzipped file $file" done fi } check_dir_locations() { if [[ "$FHS_POLICY" = "SLACK" ]] ; then if [[ -d $PKG_DIR/usr/etc ]] ; then echo $CYAN" Notice - "$NORMAL"Package contains /usr/etc directory. Normal $FHS_POLICY" echo " filesystem policy places config files under /etc. You should add" echo ' --sysconfdir=/etc to the EXTRA_CONFIGS option (-e="???")!' fi if [[ -d $PKG_DIR/usr/var ]] ; then echo $CYAN" Notice - "$NORMAL"Package contains /usr/var directory. Normal $FHS_POLICY" echo " filesystem policy places log files under /var. You should add" echo ' -localstatedir=/var to the EXTRA_CONFIGS option (-e="???")!' fi fi }