# This file is part of the src2pkg program: # Copyright 2005-2010 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 ### fix_pkg_perms fix_pkg_perms() { if [[ $ALLOW_USER_EXTENSIONS = "YES" ]] ; then # check if the user has any pre-execution extensions to this file and run them, if so. [[ -f "$HOME"/.src2pkg/extensions/09.pre ]] && . "$HOME"/.src2pkg/extensions/09.pre fi if [[ "$FAILED" = "" ]] && [[ ! $USER_CANCELLED ]] ; then if [[ ! $RESUME ]] || [[ $RESUME = $FUNCNAME ]] || [[ $HAVE_RESUMED ]] ; then [[ $RESUME = $FUNCNAME ]] && HAVE_RESUMED=1 && echo $CYAN"Notice - "$BLUE"Resuming build at: "$NORMAL "$FUNCNAME" if [[ $PAUSE = "BEFORE" ]] || [[ $PAUSE = $FUNCNAME ]] ; then echo $MAGENTA"Notice - "$BLUE"Pausing before: "$NORMAL" '$FUNCNAME' Press ENTER to continue" read fi echo $BLUE"Processing package content:"$NORMAL # this is redundant, but won't hurt if [[ "$EUID" = "0" ]] ; then chown root:root "$PKG_DIR" else chown $OWNER:$GROUP "$PKG_DIR" fi ( cd "$PKG_DIR" && chmod 755 . ) cd "$PKG_DIR" ; # replace hardlinks with softlinks for DIR in $BIN_DIRS ; do if [[ -d $DIR ]] ; then replace_hardlinks $DIR fi done if [[ -d "$PKG_DIR"/lib$LIBDIRSUFFIX ]] \ && [[ $(find "$PKG_DIR"/lib$LIBDIRSUFFIX -name "*.a" -o -name "*.la" -o -name pkgconfig -o -name aclocal) != "" ]] ; then [[ $DEBUG ]] && echo -n $CYAN" Notice - "$NORMAL"Moving static items in PKG_DIR/lib$LIBDIRSUFFIX " if [[ $PRE_FIX != "" ]] && [[ $PRE_FIX != "/" ]] ; then [[ $DEBUG ]] && echo "to PKG_DIR/$PRE_FIX/lib$LIBDIRSUFFIX" mkdir -p "$PKG_DIR"/$PRE_FIX/lib$LIBDIRSUFFIX (cd "$PKG_DIR"/lib$LIBDIRSUFFIX mv *.a *.la pkgconfig aclocal "$PKG_DIR"/$PRE_FIX/lib$LIBDIRSUFFIX/ &> /dev/null ) else [[ $DEBUG ]] && echo "to PKG_DIR/usr/lib$LIBDIRSUFFIX" mkdir -p "$PKG_DIR"/usr/lib$LIBDIRSUFFIX (cd "$PKG_DIR"/lib$LIBDIRSUFFIX mv *.a *.la pkgconfig aclocal "$PKG_DIR"/usr/lib$LIBDIRSUFFIX/ &> /dev/null ) fi fi if [[ -d "$PKG_DIR"/include ]] ; then if [[ $PRE_FIX != "" ]] && [[ $PRE_FIX != "/" ]] ; then [[ $DEBUG ]] && echo $CYAN" Notice - "$NORMAL"Moving PKG_DIR/include to PKG_DIR/$PRE_FIX/include" mkdir -p "$PKG_DIR"/$PRE_FIX mv "$PKG_DIR"/include "$PKG_DIR"/$PRE_FIX else [[ $DEBUG ]] && echo $CYAN" Notice - "$NORMAL"Moving PKG_DIR/include to PKG_DIR/usr/include" mkdir -p "$PKG_DIR"/usr mv "$PKG_DIR"/include "$PKG_DIR"/usr fi fi #segregate_package # create lists of the ELF-bin, ELF-libs, libtool-files and ar-archives ##[[ $DEBUG ]] && echo -n $BLUE"Building file lists: "$NORMAL # intialize files # : > "$SRC_DIR"/$NAME-la-files #: > "$SRC_DIR"/$NAME-a-files : > "$SRC_DIR"/$NAME-libtool-files : > "$SRC_DIR"/$NAME-header-files : > "$SRC_DIR"/$NAME-static-libs : > "$SRC_DIR"/$NAME-ELF-libs : > "$SRC_DIR"/$NAME-ELF-bins : > "$SRC_DIR"/$NAME-ELF-compressed-bins # much faster than find with multiple tests and '-exec file |grep' # this also lets us avoid using file so much find * -type f |while read FILE ; do case "$FILE" in *.la) echo "$FILE" >> $SRC_DIR/$NAME-libtool-files ;; *.h|*.hh) echo "$FILE" >> "$SRC_DIR"/$NAME-header-files ;; *.txt) true ;; *.o|*.o.gz|*.ko|*.ko.gz) true ;; */plugins/*) true ;; *.a) if is_ar_archive $FILE ; then echo "$FILE" >> $SRC_DIR/$NAME-static-libs fi ;; *) if is_elf $FILE ; then # using is_elf is way faster than 'file |grep' if is_upxed $FILE ; then echo $FILE >> "$SRC_DIR"/$NAME-ELF-compressed-bins elif [[ $(file $FILE |grep executable) ]] ; then echo $FILE >> "$SRC_DIR"/$NAME-ELF-bins elif [[ $(file $FILE |egrep '(shared object|relocatable object)') ]] ; then echo $FILE >> "$SRC_DIR"/$NAME-ELF-libs fi fi ;; esac done # get rid of this right away if empty ! [[ -s "$SRC_DIR"/$NAME-ELF-compressed-bins ]] && rm -f "$SRC_DIR"/$NAME-ELF-compressed-bins # get rid of libtool *.la files, if --disable-static or enable-static=no # was in the configure options, or if no static libs are present if [[ "$CORRECT_LIBTOOL_FILES" != "NO" ]] ; then if [[ -s $SRC_DIR/$NAME-libtool-files ]] ; then if [[ ! -s $SRC_DIR/$NAME-static-libs ]] ; then DO_REMOVE_LIBTOOL_FILES=1 else case $EXTRA_CONFIGS in *disable-static*|*enable-static=no*) DO_REMOVE_LIBTOOL_FILES=1 ;; esac fi if [[ $DO_REMOVE_LIBTOOL_FILES = 1 ]] ; then ( cd $PKG_DIR echo -n $BLUE"Removing libtool files - "$NORMAL find -name "*.la" -exec rm -f {} \; echo $GREEN"Done"$NORMAL [[ $DEBUG ]] && echo $CYAN" Notice - "$NORMAL"Can be disabled with: CORRECT_LIBTOOL_FILES=NO" ) fi rm -f $SRC_DIR/$NAME-libtool-files fi fi if [[ "$CORRECT_PKG_PERMS" != "NO" ]] ; then echo -n $BLUE"Correcting package permissions - "$NORMAL ## Fix exceptions which are set to 1777 : drwxrwxrwt [[ -d "$PKG_DIR"/tmp ]] && chmod 1777 "$PKG_DIR"/tmp [[ -d "$PKG_DIR"/var/tmp ]] && chmod 1777 "$PKG_DIR"/var/tmp [[ -d "$PKG_DIR"/var/lock ]] && chmod 1777 "$PKG_DIR"/var/lock ## Fix exceptions which are set to 775 : drwxrwxr-x [[ -d "$PKG_DIR"/var/run ]] && chmod 775 "$PKG_DIR"/var/run ## make sure /var itself is chmod 755 [[ -d "$PKG_DIR"/var ]] && chmod 755 "$PKG_DIR"/var # Fix common bin and sbin dirs for dir in $BIN_DIRS ; do if [[ -d "$PKG_DIR"/$dir ]] ; then if [[ "$EUID" = "0" ]] ; then chown -R root:root "$PKG_DIR"/$dir else chown -R $OWNER:$GROUP "$PKG_DIR"/$dir fi chmod -R 755 "$PKG_DIR"/$dir fi done for dir in $LIB_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 chown root:root {} \; find "$PKG_DIR"/$dir -type d -exec chmod 755 {} \; else chown -R $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 {} \; fi fi done # chmod all ELF files 755 for FILE in $NAME-ELF-libs $NAME-ELF-bins $NAME-ELF-compressed-bins ; do if [[ -s "$SRC_DIR"/$FILE ]] ; then while read line ; do chmod 755 "$PKG_DIR"/${line} 2> /dev/null done < "$SRC_DIR"/$FILE fi done # chmod all libtool files 644 if [[ -s "$SRC_DIR"/$NAME-libtool-files ]] ; then while read line ; do chmod 644 "$PKG_DIR"/$line 2> /dev/null done < "$SRC_DIR"/$NAME-libtool-files fi # chmod all static libs 644 if [[ -s "$SRC_DIR"/$NAME-static-libs ]] ; then while read line ; do chmod 644 "$PKG_DIR"/$line 2> /dev/null done < "$SRC_DIR"/$NAME-static-libs fi # if [[ -d "$PKG_DIR"/etc/X11/app-defaults ]] ; then chmod 644 "$PKG_DIR"/etc/X11/app-defaults/* fi echo $GREEN"Done"$NORMAL fi if [[ $PAUSE = "AFTER" ]] || [[ $PAUSE = $FUNCNAME ]] ; then echo $MAGENTA"Notice - "$BLUE"Pausing after: "$NORMAL" '$FUNCNAME' Press ENTER to continue" read fi fi fi if [[ $ALLOW_USER_EXTENSIONS = "YES" ]] ; then # check if the user has any post-execution extensions to this file and run them, if so. [[ -f "$HOME"/.src2pkg/extensions/09.post ]] && . "$HOME"/.src2pkg/extensions/09.post fi } # end fix_source_perms # used by replace_hardlinks list_inodes() { for FILE in * ; do #echo $(stat -c %i $FILE) $FILE # ha! echo $(ls -i $FILE 2> /dev/null) done } # replace hardlinks with symlinks replace_hardlinks() { HAVE_HARD_LINKS= THIS_DIR=$1 ( cd $THIS_DIR list_inodes |sort > inode.list LAST_INODE= THIS_INODE= LAST_FILE= THIS_FILE= if [[ -s inode.list ]] ; then while read THIS_INODE THIS_FILE ; do if [[ -n $THIS_INODE ]] && [[ $THIS_INODE = $LAST_INODE ]] ; then [[ $DEBUG ]] && echo $CYAN" Notice - "$NORMAL"Symlinking hardlink: $THIS_DIR/$THIS_FILE" rm -f $THIS_FILE ; ln -sf $LAST_FILE $THIS_FILE HAVE_HARD_LINKS=1 else LAST_INODE=$THIS_INODE LAST_FILE=$THIS_FILE fi done < inode.list fi rm -f inode.list if [[ $HAVE_HARD_LINKS ]] && [[ ! $DEBUG ]] ; then echo $CYAN" Notice - "$NORMAL"Replacing hardlinks in: $THIS_DIR" fi ) } # Check for ELF file is_elf() { [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] } # Check for ELF file compressed with UPX is_upxed(){ [ "$(dd if=$1 bs=1 skip=120 count=3 2> /dev/null)" = "UPX" ] # default.sfx skip=121 } # Check for ara archive is_ar_archive() { [ "$(dd if=$1 bs=1 skip=1 count=6 2> /dev/null)" = '' ] # count=6= } # Check for ELF executable file # this is not dependable enough to use is_dyn_exe() { if [ "$(dd if=$1 bs=1 skip=307 count=17 2> /dev/null)" = "/lib/ld-linux.so" ] ; then return 0 elif [ "$(dd if=$1 bs=1 skip=276 count=17 2> /dev/null)" = "/lib/ld-linux.so" ] ; then return 0 fi # skip=276 (cat, link, ln, mkdir, readlink, rm, rmdir, touch }