# This file is part of the src2pkg program: # Copyright 2005-2008 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 ### fix_source_perms fix_source_perms() { 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 666 -perm 664 -perm 600 -exec chmod 644 {} \; find . -perm 444 -perm 440 -perm 400 -exec chmod 644 {} \; find . -perm 555 -perm 511 -exec chmod 755 {} \; find . -perm 777 -perm 775 -perm 754 -perm 711 -exec chmod 755 {} \; ! [[ $CORRECT_SUID_PERMS = "NO" ]] && find . -perm 2775 -perm 2755 -exec chmod 755 {} \; 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 " Applying: $(basename $p)" ; for PATCH_OPTIONS in -p0 -p1 -p2 -p3 -p4 -p5 ; do cat /dev/null > $SRC_DIR/patchlist.this case $p in *.gz) #echo " Applying: $(basename $p)" ; if [[ $(file $CWD/$p |grep compressed) != "" ]] ; then cd $SRC_DIR && zcat $CWD/$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 < $CWD/$p >> $SRC_DIR/patchlist.this fi ;; *.bz2) #echo " Applying: $(basename $p)" ; cd $SRC_DIR && bzcat $CWD/$p | patch "$PATCH_OPTIONS" -l >> $SRC_DIR/patchlist.this ;; *.patch|*.diff) #echo " Applying: $(basename $p)" ; cd $SRC_DIR && patch "$PATCH_OPTIONS" -l < $CWD/$p >> $SRC_DIR/patchlist.this ;; esac if [ $? -ne 0 ] ; then rm -f $SRC_DIR/patchlist.this continue else break fi done # clean up the list of files patched with this patch cat $SRC_DIR/patchlist.this| cut -f3 -d' ' | sort | uniq > $SRC_DIR/patched-files.this rm -f $SRC_DIR/patchlist.this if [[ $DEBUG ]] ; then echo $BLUE"Files Patched:"$NORMAL cat $SRC_DIR/patched-files.this fi # write the entry for this patch to the main patched-files list echo $p >> $SRC_DIR/patched-files-$NAME-$VERSION cat $SRC_DIR/patched-files.this >> $SRC_DIR/patched-files-$NAME-$VERSION echo "" >> $SRC_DIR/patched-files-$NAME-$VERSION rm -f $SRC_DIR/patched-files.this } if [[ $PATCHLIST ]] ; 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 true elif [[ "$(cat $SRC_DIR/patched-files-$NAME-$VERSION |egrep '(configure.ac|configure.in|Makefile.am|Makefile.in)' | 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 } get_patch_list() { cd $CWD ; if [[ ! -d $CWD/patches ]] ; then # if there are patches in the CWD use them PATCHLIST=$(find . -maxdepth 1 -type f -name '*.patch*' -o -name '*.diff*' | sort) else # otherwise if there are patches in the CWD/patches use them PATCHLIST=$(find ./patches -maxdepth 1 -type f -name '*.patch*' -o -name '*.diff*' | sort) fi }