# This file is part of the src2pkg program: # Copyright 2005-2010 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" != "1" ]] ; then write_src2pkg_script # now set DONT_CLOBBER_SCRIPT to preserve the new script -even if using -W (--cleanup) # this takes care of when an existing script gets updated in 06-configure_source DONT_CLOBBER_SCRIPT=1 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" ]] && [[ "$DOCLIST" != "MINIMAL" ]] ; 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 1 ]] ; then compress_bins fi # check for the directory using the long form of the name for more safety # use the regular version of tar for this --not tar-1.13 if [[ $COMPRESS_DOCS = "YES" ]] && [[ -d "$PKG_DIR"/$GOOD_DOC_PATH/$NAME-$VERSION ]] ; then echo $BLUE"Archiving documents - "$NORMAL"Creating tar/$DOC_COMPRESSOR archive of documents" ( cd "$PKG_DIR"/$GOOD_DOC_PATH/$NAME-$VERSION find -type f -exec chmod 644 {} \; case $DOC_COMPRESSOR in # gzip) tar -czf $NAME-$VERSION-docs.tgz $(find -type f -o -type d) ;; gzip) tar -c --owner=root --group=root --use-compress-program=gzip -f $NAME-$VERSION-docs.tgz . ;; bzip2) tar -c --owner=root --group=root --use-compress-program=bzip2 -f $NAME-$VERSION-docs.tbz . ;; lzma) tar -c --owner=root --group=root --use-compress-program=lzma -f $NAME-$VERSION-docs.tlz . ;; xz) tar -c --owner=root --group=root --use-compress-program=xz -f $NAME-$VERSION-docs.tlz . ;; esac # only compress files and directories, leaving the link to the license if there is one find -type f ! -name "$NAME-$VERSION-docs.*" -exec rm -f {} \; find -type d -exec rm -rf {} &> /dev/null \; ) fi echo $BLUE"Rechecking package correctness - "$NORMAL # take care of empty files handle_empty_files check_dir_locations if [[ $FAILED != "" ]] ; then post_process exit 1 fi check_for_hidden_files # 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 -R root:root "$PKG_DIR"/$dir chmod 755 $PKG_DIR/$dir find "$PKG_DIR"/$dir -type d -exec chmod 755 {} \; find "$PKG_DIR"/$dir -type f -exec chmod 644 {} \; else chown -R $OWNER:$GROUP "$PKG_DIR"/$dir chmod 755 $PKG_DIR/$dir 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 supposed 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 if [[ -d $PKG_DIR/etc/X11/xinit ]] ; then chown root:root $PKG_DIR/etc/X11/xinit/* chmod 755 $PKG_DIR/etc/X11/xinit/* 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 # split the package if necessary segregate_package if [[ $EXTENDED_DATABASE = "YES" ]] ; then # write package meta-data write_meta_data $PKG_DIR fi # Unless we are debugging get rid of these temp files in the sources #if ! [[ $DEBUG ]] ; then # rm -f "$SRC_DIR"/glibc-info.txt # rm -f "$SRC_DIR"/$NAME-config-command.txt # rm -f "$SRC_DIR"/$NAME-compressed-bins #fi } # end do_last_minute_details check_pkg_perms() { OLD_FIS=$IFS IFS=' ' if [[ $(find * -type d -a ! -user $USER -o -type d -a ! -group $GROUP -o -type d -a ! -perm 755 |egrep -v '(tmp|var/tmp|var/lock|var/run)') != "" ]] ; 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 case "$DIR" in tmp|var/tmp|var/lock|var/run|"") true ;; *) perms=$(stat -c %a $DIR) owner=$(stat -c %U $DIR) group=$(stat -c %G $DIR) echo " $perms $owner:$group $DIR" ;; esac done fi # exclude some well-known 'offenders' this list will surely grow... until we need # a more sophisticated routine to separate known exceptions. # *.pod files are usually 666, *.pm files are usually 444, *.wav files are usually 444 PERM_EXCLUDES='(.pod$|.pm$|.wav$|.a$|.pl$)' if [[ $(find * -type f -a ! -user $USER -o -type f -a ! -group $GROUP -o -type f -a ! -perm 755 -a ! -perm 644 -a ! -perm 444 |egrep -v $PERM_EXCLUDES) != "" ]] ; 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 -a ! -perm 444 |egrep -v $PERM_EXCLUDES) ; do perms=$(stat -c %a $FILE) owner=$(stat -c %U $FILE) group=$(stat -c %G $FILE) echo " $perms $owner:$group $FILE" done fi IFS=$OLD_IFS } # compress binaries with upx-ucl, upx or exepak if requested and available compress_bins() { if [[ "$FAILED" = "" ]] ; then if [[ $BIN_COMPRESSOR ]] ; then if [[ $(which $BIN_COMPRESSOR 2> /dev/null) ]] ; then BINCOMPRESSOR=$(which $BIN_COMPRESSOR) else echo "Binary compressor \"$BIN_COMPRESSOR\" not found" fi elif [[ $(which upx-ucl 2> /dev/null) ]] ; then BINCOMPRESSOR=$(which upx-ucl) elif [[ $(which upx 2> /dev/null) ]] ; then BINCOMPRESSOR=$(which upx) elif [[ $(which exepak 2> /dev/null) ]] ; 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 if [[ -f $SRC_DIR/$NAME-ELF-bins ]] ; then cat /dev/null > "$SRC_DIR"/$NAME-compressed-bins for f in $(cat $SRC_DIR/$NAME-ELF-bins) ; 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 if [[ "$DOCLIST" != "MINIMAL" ]] ; then mkdir -p "$DOC_DIR" echo "/$f" >> "$SRC_DIR"/$NAME-compressed-bins fi 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 if [[ "$DOCLIST" != "MINIMAL" ]] ; then mkdir -p "$DOC_DIR" echo "/$f">> "$SRC_DIR"/$NAME-compressed-bins fi 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." elif [[ "$DOCLIST" != "MINIMAL" ]] ; then 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 "$SRC_DIR"/$NAME-compressed-bins >> "$DOC_DIR"/$NAME-$BIN_COMPRESSOR.txt fi fi fi # if no compression succeeded, then remove the file if ! [[ -s "$SRC_DIR"/$NAME-compressed-bins ]] ; then rm -f "$SRC_DIR"/$NAME-compressed-bins fi fi } handle_empty_files() { # first get rid of any zero-length files if [[ $FORCE_ZERO_LENGTH != "YES" ]] ; then cd "$PKG_DIR" ; if [[ $(find $PKG_DIR -name "perllocal.pod" -o -name "*.bs" -o -name ".packlist") != "" ]] ; then echo $CYAN" Notice - "$NORMAL"Removing unneeded perl files: perllocal.pod .packlist or *.bs " ( cd $PKG_DIR ; find \( -name "*perllocal.pod" -o -name "*.bs" -o -name "*.packlist" \) -exec rm -f {} \; ) fi # ignore empty files under /etc, /usr/etc, var or /usr/var and also python '__init__.py' files if [[ $(find * -type f -size 0 |egrep -v '^(etc|var|usr/etc|usr/var)|__init__.py$') ]] ; 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 file in $(find * -type f -size 0 -print |egrep -v '^(etc|var|usr/etc|usr/var)') ; do echo $file rm -f $file done fi find . -type f -name '*.gz' -size 20c | while read file ; do echo "WARNING: Possible empty gzipped file $file" done # Remove empty directories ? Nein, Danke # find . -type d -depth -exec rmdir {} \; 2>/dev/null fi } check_dir_locations() { echo -n $BLUE"Checking for misplaced dirs - "$NORMAL BAD_DIRS=0 # good policy dictates using --sysconfdir=/etc -not /usr/etc if [[ "$FHS_POLICY" = "SLACK" ]] || [[ "$FHS_POLICY" = "LSB" ]] ; then if [[ -d $PKG_DIR/usr/etc ]] ; then echo 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="???")!' BAD_DIRS=1 fi if [[ -d $PKG_DIR/usr/var ]] ; then echo 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="???")!' BAD_DIRS=1 fi fi # if prefix is not /usr/local, then the package shouldn't contain usr/local if [[ -d $PKG_DIR/usr/local ]] && [[ "${PRE_FIX:0:9}" != "usr/local" ]] ; then echo echo $CYAN" Notice - "$NORMAL"Package contains /usr/local directory, but PRE_FIX is: /$PRE_FIX" echo " You may need to patch the Makefile(s) to correct the installation prefix." BAD_DIRS=1 fi # some evil installations create dirs or files in your $HOME dir -bad, bad, bad if [[ -d $PKG_DIR$HOME ]] ; then echo echo $CYAN" Notice - "$NORMAL"Package contains $HOME directory -your HOME directory." echo " You may need to patch the Makefile(s) to correct this." BAD_DIRS=1 fi # some faulty Makefiles create redundant links, dirs or files if [[ -d $PKG_DIR$PKG_DIR ]] ; then echo echo $CYAN" Notice - "$NORMAL"Package contains PKG_DIR directory." echo " This usually happens because of badly written Makefiles." echo " You may need to patch the Makefile(s) to correct this." echo " Or try using INSTALL_TYPE=JAIL to fix this problem." BAD_DIRS=1 fi # some faulty Makefiles create redundant links, dirs or files if [[ -d $PKG_DIR$SRC_DIR ]] ; then echo echo $CYAN" Notice - "$NORMAL"Package contains SRC_DIR directory." echo " This usually happens because of badly written Makefiles." echo " You may need to patch the Makefile(s) to correct this." echo " Or try using INSTALL_TYPE=JAIL to fix this problem." BAD_DIRS=1 fi if [[ -d $PKG_DIR/usr/usr ]] || [[ -d $PKG_DIR/$PRE_FIX/$PRE_FIX ]] ; then if [[ "$PRE_FIX" != "" ]] && [[ "$PRE_FIX" != "/" ]] ; then echo echo $CYAN" Notice - "$NORMAL"Package contains redundant $PRE_FIX directories." echo " This is usually because of bad usage of DESTDIR in Makefiles." echo " Try using INSTALL_TYPE=JAIL (or REAL) to fix this problem." echo " Otherwise, patch the Makefile(s) to correct this problem." BAD_DIRS=1 fi fi # if share contains anything used by the program(besides language files), then # moving them may make them not found if [[ -d "$PKG_DIR"/share ]] ; then echo echo $CYAN" Notice - "$NORMAL"Package contains PKG_DIR/share." echo " This may happen because of using a null prefix or --prefix=/ " echo " $FHS_POLICY filesystem policy places shared data files under usr/share." echo " Add: '--datadir=/usr/share' to the EXTRA_CONFIGS option (-e="???")!" BAD_DIRS=1 fi # if the package contains TRANSL directory then installation went badly wrong if [[ -d "$PKG_DIR"/TRANSL ]] ; then echo echo $CYAN" Notice - "$NORMAL"Package contains PKG_DIR/TRANSL." echo " This indicates a serious failure using the 'JAIL' INSTALL_TYPE." echo " Try using the DESTDIR or other option for content creation." BAD_DIRS=1 fi for LOCATION in bin sbin ; do if [[ -f $PKG_DIR/$LOCATION ]] ; then echo BAD_FILES=1 echo $CYAN" Notice - "$NORMAL"Package contains a file PKG_DIR/$LOCATION" echo " This location is supposed to be a directory!" elif [[ -f $PKG_DIR/$PRE_FIX/$LOCATION ]] ; then echo BAD_FILES=1 echo $CYAN" Notice - "$NORMAL"Package contains a file PKG_DIR/$PRE_FIX/$LOCATION" echo " This location is supposed to be a directory!" fi done if [[ $BAD_FILES = 1 ]] ; then echo " Installing such a package could cause harm your system." echo " This is usually caused by badly-written Makefiles." echo " Patch the Makefile(s) or otherwise correct this problem." fi if [[ $BAD_DIRS != 1 ]] && [[ $BAD_FILES != 1 ]] ; then echo $GREEN"Done"$NORMAL elif [[ $FAIL_ON_BAD_DIRS = "YES" ]] ; then echo $RED" FATAL! "$NORMAL"This build installs faulty directories or files." echo " You must fix the build as suggested above, or override this action with:" echo " FAIL_ON_BAD_DIRS=NO from the command-line or in your src2pkg.conf file." FAILED='BAD_DIRS' fi } check_for_hidden_files() { cd $PKG_DIR ; if [[ "$(find * -name ".*" ! -name ".packlist")" != "" ]] ; then echo $CYAN" Notice - "$NORMAL"Package contains hidden items:" find * -name ".*" ! -name ".packlist" |while read LINE ; do echo " $LINE" done echo " Check and correct if necessary." fi }