# This file is part of the src2pkg program: # Copyright 2005-2009 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 ### fix_source_perms fix_source_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/05.pre ]] && . "$HOME"/.src2pkg/extensions/05.pre fi if [[ "$FAILED" = "" ]] ; then if [[ "$CORRECT_PERMS" = "YES" ]] ; then echo -n $BLUE"Correcting source permissions - "$NORMAL if [ "$(whoami)" = "root" ] ; then chown -R root:root "$SRC_DIR" else chown -R $OWNER:$GROUP "$SRC_DIR" fi cd "$SRC_DIR" find . -type d -exec chmod 755 {} \; find . -perm 400 -exec chmod 644 {} \; -o -perm 440 -exec chmod 644 {} \; -o -perm 444 -exec chmod 644 {} \; \ -o -perm 600 -exec chmod 644 {} \; -o -perm 664 -exec chmod 644 {} \; -perm 666 -exec chmod 644 {} \; \ -o -perm 511 -exec chmod 755 {} \; -o -perm 555 -exec chmod 755 {} \; \ -o -perm 711 -exec chmod 755 {} \; -o -perm 754 -exec chmod 755 {} \; \ -o -perm 774 -exec chmod 755 {} \; -o -perm 775 -exec chmod 755 {} \; -o -perm 777 -exec chmod 755 {} \; if ! [[ $CORRECT_SUID_PERMS = "NO" ]] ; then find . -perm 2775 -exec chmod 755 {} \; -o -perm 2777 -exec chmod 755 {} \; \ -o -perm 2755 -exec chmod 755 {} \; fi echo $GREEN"Done"$NORMAL fi # Auto-Patching works for most patches, but patch -p option and application order # can be controlled by renaming the files. patches should be in the CWD or CWD/patches directory # we are patching from the toplevel of SRC_DIR which may not work for some patches at all... apply_patches() { echo $BLUE"Applying:$NORMAL $(basename $p)" PATCH_HAS_FAILED=0 for PATCH_OPTIONS in -p1 -p0 -p2 -p3 -p4 -p5 ; do [[ $DEBUG ]] && echo -n $CYAN"Notice - "$NORMAL"Trying patch $p with option $PATCH_OPTIONS " cat /dev/null > "$SRC_DIR"/patchlist.this case $p in *.gz) #echo " Applying: $(basename $p)" ; if [[ $(file "$PATCHES_DIR"/$p |grep compressed) != "" ]] ; then cd "$SRC_DIR" && zcat "$PATCHES_DIR"/$p | patch "$PATCH_OPTIONS" -l >> "$SRC_DIR"/patchlist.this else # Debian patches are plain-text patches named with a .gz suffix to avoid corruption cd "$SRC_DIR" && patch "$PATCH_OPTIONS" -l < "$PATCHES_DIR"/$p >> "$SRC_DIR"/patchlist.this fi ;; *.bz2) #echo " Applying: $(basename $p)" ; cd "$SRC_DIR" && bzcat "$PATCHES_DIR"/$p | patch "$PATCH_OPTIONS" -l >> "$SRC_DIR"/patchlist.this ;; *.dpatch) #echo " Applying: $(basename $p)" ; cd "$SRC_DIR" && patch "$PATCH_OPTIONS" -f -l < "$PATCHES_DIR"/$p >> "$SRC_DIR"/patchlist.this ;; *.patch|*.diff) #echo " Applying: $(basename $p)" ; cd "$SRC_DIR" && patch "$PATCH_OPTIONS" -l < "$PATCHES_DIR"/$p >> "$SRC_DIR"/patchlist.this ;; esac if [ $? -ne 0 ] ; then rm -f "$SRC_DIR"/patchlist.this PATCH_HAS_FAILED=1 [[ $DEBUG ]] && echo "Failed" continue else PATCH_HAS_FAILED=0 [[ $DEBUG ]] && echo "Okay" break fi done if [[ $PATCH_HAS_FAILED = 1 ]] ; then if [[ $EXIT_ON_PATCH_FAILURE = "YES" ]] ; then echo $RED"Failed! "$NORMAL"Application of $p has failed. Exiting..." FAILED="PATCH_FAILURE" post_process else echo $YELLOW"Warning! "$NORMAL"Possible failure in patch $p." fi fi # clean up the list of files patched with this patch if [[ -f "$SRC_DIR"/patchlist.this ]] ; then cat "$SRC_DIR"/patchlist.this| cut -f3 -d' ' | sort | uniq > "$SRC_DIR"/patched-files.this rm -f "$SRC_DIR"/patchlist.this fi if [[ $DEBUG ]] && [[ -f "$SRC_DIR"/patched-files.this ]] ; then echo $BLUE"Files Patched:"$NORMAL cat "$SRC_DIR"/patched-files.this |grep -v succeeded fi # write the entry for this patch to the main patched-files list echo $p >> "$SRC_DIR"/patched-files-$NAME-$VERSION if [[ -f "$SRC_DIR"/patched-files.this ]] ; then cat "$SRC_DIR"/patched-files.this |grep -v succeeded >> "$SRC_DIR"/patched-files-$NAME-$VERSION fi echo "" >> "$SRC_DIR"/patched-files-$NAME-$VERSION rm -f "$SRC_DIR"/patched-files.this } if [[ $PATCHLIST ]] && [[ ! "$AUTO_PATCH" = "NO" ]] ; then echo $BLUE"Applying patches - "$NORMAL"from User-Supplied PATCHLIST" cat /dev/null > "$SRC_DIR"/patched-files-$NAME-$VERSION for p in $PATCHLIST ; do apply_patches ; done PATCHES_APPLIED=1 elif [[ ! "$AUTO_PATCH" = "NO" ]] ; then echo -n $BLUE"Checking for patches - "$NORMAL get_patch_list if [[ "$PATCHLIST" = "" ]] ; then echo "None found" else echo "Found" cat /dev/null > "$SRC_DIR"/patched-files-$NAME-$VERSION for p in $PATCHLIST ; do apply_patches ; done PATCHES_APPLIED=1 fi fi if [[ $PATCHES_APPLIED ]] ; then # check the patchlist for keyfiles to determine whether to run autoreconf #if [[ "$(cat $SRC_DIR/patched-files-$NAME-$VERSION |grep -w configure |egrep -v '(configure.ac|configure.in|Makefile.am|Makefile.in)' | grep -v '#')" != "" ]] ; then if [[ $(cat "$SRC_DIR"/patched-files-$NAME-$VERSION |grep -w configure |egrep -v '(configure.ac|configure.in|Makefile.am)' | grep -v '^#') != "" ]] ; then true # elif [[ "$(cat $SRC_DIR/patched-files-$NAME-$VERSION |egrep '(configure.ac|configure.in|Makefile.am|Makefile.in)' | grep -v '#')" != "" ]] ; then elif [[ $(cat "$SRC_DIR"/patched-files-$NAME-$VERSION |egrep '(configure.ac|configure.in|Makefile.am)' | grep -v '^#') != "" ]] ; then SHOULD_AUTORECONF=1 fi if [[ $DEBUG_FILELISTS ]] ; then cat "$SRC_DIR"/patched-files-$NAME-$VERSION >> "$CWD"/patched-files-$NAME-$VERSION 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/05.post ]] && . "$HOME"/.src2pkg/extensions/05.post fi } # end fix_source_perms get_patch_list() { cd "$CWD" ; if [[ ! -d "$CWD"/patches ]] && [[ ! -d "$CWD"/$NAME-patches ]] && [[ ! -d "$PATCHES_DIR"/$NAME-patches ]] && [[ ! -d "$PATCHES_DIR"/$NAME ]]; then # if there are patches in the CWD use them PATCHLIST=$(find . -maxdepth 1 -type f -name '*.patch*' -o -name '*.diff*' -o -name '*.dpatch' | sort) elif [[ -d "$CWD"/patches ]] ; then # otherwise if there are patches in the CWD/patches use them PATCHLIST=$(find ./patches -maxdepth 1 -type f -name '*.patch*' -o -name '*.diff*' -o -name '*.dpatch' | sort) elif [[ -d "$CWD"/$NAME-patches ]] ; then # otherwise if there are patches in the CWD/patches use them PATCHLIST=$(find ./$NAME-patches -maxdepth 1 -type f -name '*.patch*' -o -name '*.diff*' -o -name '*.dpatch' | sort) elif [[ -d "$PATCHES_DIR"/$NAME-patches ]] ; then cd "$PATCHES_DIR" ; # otherwise if there are patches in the CWD/patches use them PATCHLIST=$(find $NAME-patches -maxdepth 1 -type f -name '*.patch*' -o -name '*.diff*' -o -name '*.dpatch' | sort) elif [[ -d "$PATCHES_DIR/$NAME" ]] ; then cd "$PATCHES_DIR" ; # otherwise if there are patches in the CWD/patches use them PATCHLIST=$(find $NAME -maxdepth 1 -type f -name '*.patch*' -o -name '*.diff*' -o -name '*.dpatch' | sort) fi }