## /usr/libexec/src2pkg/src2pkg.FUNCTIONS ## src2pkg FUNCTIONS Version-1.1rc1 # How were we called? EXEC_NAME="${0##*/}" # Where were we called from? CWD ! [[ $CWD ]] && CWD=`pwd` && cd $CWD && CWD=`pwd` ; # If GLOBAL_CONF is not specified, look for the default GLOBAL.conf file ! [[ $GLOBAL_CONF ]] && GLOBAL_CONF="/etc/src2pkg/src2pkg.conf" # Read in the global configuration if it's there, though you can run without one. [[ -e $GLOBAL_CONF ]] && source $GLOBAL_CONF # Some basic defaults are set in the DEFINES file which a user might possibly edit. # They are kept apart to avoid the user editing *this* file and to save space here. ! [[ $DEFINES ]] && DEFINES=/usr/libexec/src2pkg/DEFINES if [[ -e $DEFINES ]] ; then source $DEFINES else echo "Warning! DEFINES file not found." FAILED="NO DEFINES" exit 0 fi ### The function do_all_processes summarizes the default execution order into a single ### command. Showing this here provides an overview of the 'long' list of commands. ### Function do_all_processes ######################################## do_all_processes() { pre_process find_source make_dirs unpack_source fix_source_perms configure_source compile_source fake_install fix_pkg_perms strip_bins create_docs compress_man_pages make_description make_doinst make_package post_process } ### End Function do_all_processes ############################### ### The function do_track_install summarizes the execution order for trackinstall ### find_source, unpack_source, configure_source and compile_source are not used do_track_install() { pre_process make_dirs fake_install fix_pkg_perms strip_bins create_docs compress_man_pages make_description make_doinst make_package post_process } ### ############### Process Functions ######################## ## The individual processing functions -mostly in their order of execution. ## Functions marked as Internal Routines or not in the list of do_all_processes shouldn't be ## called directly from a src2pkg script, unless you really know what you are doing. ### pre_process pre_process() { # color is on only if COLOR_PROMPT=YES get_color_options ; # you must be root to run src2pkg if ! [[ "`whoami`" = "root" ]] ; then echo $RED"FATAL!!! "$NORMAL"You must be logged in as root or use su to run src2pkg." exit 1 fi # These are important defaults that need to be set ! [[ $STD_MASK ]] && STD_MASK="000" umask $STD_MASK ! [[ $MAKE_LINKS ]] && MAKE_LINKS="YES" # REALLY_INSTALL=YES is similar to what checkinstall does. ! [[ $REALLY_INSTALL = "YES" ]] && REALLY_INSTALL="NO" # This is the most-used option of all. But if not specified it should be nulled. ! [[ $EXTRA_CONFIGS ]] && EXTRA_CONFIGS="" ! [[ $BUILD ]] && BUILD="1" # get the ARCH and compiler tuning flags get_flags ; # try to get a name and version if [ "$NAME" -a "$VERSION" -a "$SRC_SUFFIX" ] ; then SOURCE_NAME="$NAME-$VERSION$SRC_SUFFIX" fi if [[ "$SOURCE" != "" ]] ; then case $SOURCE in //*) SOURCE=${SOURCE#*/} ; shift ;; ./*) SOURCE=$CWD/${SOURCE#*/} ; shift ;; /*) SOURCE=$SOURCE ;; [a-z,A-Z,0-9]*/*) SOURCE=$CWD/$SOURCE ; shift ;; *) SOURCE=$SOURCES_DIR/$SOURCE ; shift ;; esac SOURCE_NAME=`basename $SOURCE` elif [[ "$SOURCE_NAME" != "" ]] ; then case $SOURCE_NAME in # Double slashes! //*) SOURCE=${SOURCE_NAME#*/} ;; # Relative path(./) ./*) SOURCE=$CWD/${SOURCE_NAME#*/} ;; # Absoulte path" /*) SOURCE=$SOURCE_NAME ;; # Extended relative path [a-z,A-Z,0-9]*/*) SOURCE=$CWD/$SOURCE_NAME ;; # No path given *) SOURCE=$SOURCES_DIR/$SOURCE_NAME ;; esac fi get_my_arch() { ARCH_CHUNK=`echo $NAMVERS |rev |cut -f1,2 -d'-' |rev` case $ARCH_CHUNK in *i386*) MYARCH=i386 ;; *i486*) MYARCH=i486 ;; *i586*) MYARCH=i586 ;; *i686*) MYARCH=i686 ;; *ppc*) MYARCH=ppc ;; *powerpc*) MYARCH=powerpc ;; *noarch*) MYARCH=noarch ;; esac } translate_underlines() { if [[ `echo $NAMVERS |grep -v "_"` = "" ]] ; then if [[ `echo $NAMVERS |grep -v "."` = "" ]] ; then #echo "Translating underlines to periods" NAMVERS=`echo $NAMVERS |tr '_' '.'` fi fi } if [[ "$SOURCE_NAME" != "" ]] ; then [[ $DEBUG ]] && echo -n $BLUE"Guessing NAME, VERSION and content type: "$NORMAL NAMVERS=`basename $SOURCE_NAME` case $NAMVERS in *src.rpm) EXT='src.rpm' ;; *src.tgz) EXT='src.tgz' ;; *src.tar.gz) EXT='src.tar.gz' ;; *rpm) EXT='rpm' ;; *deb) EXT='deb' ;; *orig.tar.gz) EXT='orig.tar.gz' ;; *orig.tar.bz2) EXT='orig.tar.bz2' ;; *tgz) EXT='tgz' ;; *tbz) EXT='tbz' ;; *tar.gz) EXT='tar.gz' ;; *tar.bz2) EXT='tar.bz2' ;; esac if [[ $NAMVERS = ".$EXT" ]] || [[ $NAMVERS = $EXT ]] ; then echo "We're crapping out" exit else RAW_SOURCE_NAME=`basename $NAMVERS ."$EXT"` fi NAMVERS=$RAW_SOURCE_NAME # this does a pretty good job crunching the name into NAME and VERSION case $EXT in src.rpm|src.tgz|src.tar.gz) # [[ $DEBUG ]] && if [[ $DEBUG ]] ; then [[ "$EXT" = "src.rpm" ]] && echo -n "RPM source package" \ || echo -n "rpm2tgz-converted RPM source" fi translate_underlines if [[ `echo $NAMVERS |grep '-'` ]] ; then if [[ `echo $NAMVERS |rev |cut -f2 -d'-'` != `echo $NAMVERS |rev |cut -f3 -d'-'` ]] ; then # this means we have more than one dash if [[ `echo $NAMVERS |rev |cut -f1 -d'.' |grep "-"` ]] ; then [[ $DEBUG ]] && echo " Rule 1" CHUNK=`echo $NAMVERS |rev |cut -f1 -d'.' |rev` CARRY=`echo $CHUNK |cut -f1 -d'-'` REV_CHUNK=`echo $CHUNK |cut -f2- -d'-'` NAMVERS=`basename $NAMVERS .$CHUNK`.$CARRY else [[ $DEBUG ]] && echo " Rule 2" REV_CHUNK=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAMVERS=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` fi fi VERSION=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAME=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` else [[ $DEBUG ]] && echo "Name contains no dashes" fi # if src was in the name but the name was not RPM-type NAME=VERSION, so redo it. if [[ $NAME = $VERSION ]] ; then [[ $DEBUG ]] && echo "Reconverting! This is not an RPM-type name" VERSION=`echo $RAW_SOURCE_NAME |rev |cut -f1 -d'-' |rev` NAME=`basename $RAW_SOURCE_NAME -$VERSION` fi [[ "$VERSION" = "$NAME" ]] && VERSION=0.0.0 ;; rpm) translate_underlines get_my_arch if [[ `echo $NAMVERS |grep "$MYARCH"` != "" ]] ; then [[ $DEBUG ]] && echo -n "RPM binary package" ARCH=`echo $NAMVERS |rev |cut -f1 -d'.' |rev` NAMVERS=`basename $NAMVERS .$ARCH` if [[ `echo $ARCH |grep "-"` ]] ; then ARCH=`echo $ARCH |rev |cut -f2- -d'-' |rev` fi else [[ $DEBUG ]] && echo -n "Generic RPM archive" fi if [[ `echo $NAMVERS |rev |cut -f2 -d'-'` != `echo $NAMVERS |rev |cut -f3 -d'-'` ]] ; then if [[ `echo $NAMVERS |rev |cut -f1 -d'.' |grep "-"` ]] ; then [[ $DEBUG ]] && echo -n " Rule 1" CHUNK=`echo $NAMVERS |rev |cut -f1 -d'.' |rev` REV_CHUNK=`echo $CHUNK |cut -f2- -d'-'` CARRY=`echo $CHUNK |cut -f1 -d'-'` NAMVERS=`basename $NAMVERS .$CHUNK`.$CARRY else [[ $DEBUG ]] && echo -n " Rule 2" REV_CHUNK=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAMVERS=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` fi fi if [[ `echo $NAMVERS |rev |cut -f1 -d'-' |rev |grep "_"` ]] ; then [[ $DEBUG ]] && echo -n " Rule 3" VERSION=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` VERSION=`echo $NAMVERS |tr '_' '.'` NAME=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` else [[ $DEBUG ]] && echo -n " Rule 4" VERSION=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAME=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` fi ;; deb) [[ $DEBUG ]] && echo "Debian binary package" ARCH=`echo $NAMVERS |rev |cut -f1 -d'_' |rev` NAMVERS=`echo $NAMVERS |rev |cut -f2- -d'_' |rev` if [[ `echo $NAMVERS |rev |cut -f1 -d'.' |grep '-'` ]] ; then NAMVERS=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` fi VERSION=`echo $NAMVERS |cut -f2- -d'_'` NAME=`echo $NAMVERS |cut -f1 -d'_'` ;; *) get_my_arch if [[ "$MYARCH" != "" ]] ; then if [[ `echo $ARCH_CHUNK |cut -f1 -d '-'` = $ARCH ]] ; then [[ $DEBUG ]] && echo "Slackware binary package" ARCH=`echo $NAMVERS |rev |cut -f2 -d'-' |rev` NAMVERS=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` VERSION=`echo $NAMVERS |rev |cut -f2 -d'-' |rev` NAME=`basename $NAMVERS -$VERSION-$ARCH` elif [[ `echo $NAMVERS |rev |cut -f1 -d'.' |rev |grep $MYARCH` != "" ]] ; then translate_underlines ARCH_CHUNK=`echo $NAMVERS |rev |cut -f1 -d'.' |rev` [[ $DEBUG ]] && echo "Binary rpm2$EXT archive" NAMVERS=`basename $NAMVERS .$ARCH_CHUNK` if [[ `echo $ARCH_CHUNK |grep '-'` ]] ; then ARCH=`echo $ARCH_CHUNK |rev |cut -f2- -d'-' |rev` else ARCH="$ARCH_CHUNK" fi if [[ `echo $NAMVERS |rev |cut -f1 -d'.' |grep "-"` ]] ; then CHUNK=`echo $NAMVERS |rev |cut -f1 -d'.' |rev` REV_CHUNK=`echo $CHUNK |cut -f2- -d'-'` CARRY=`echo $CHUNK |cut -f1 -d'-'` NAMVERS=`basename $NAMVERS .$CHUNK`.$CARRY else REV_CHUNK=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAMVERS=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` fi VERSION=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAME=`echo $NAMVERS |rev |cut -f2- -d'-' |rev` else translate_underlines [[ $DEBUG ]] && echo "Generic binary $EXT archive" if [[ `echo $NAMVERS |grep '-'` ]] ; then VERSION=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAME=`basename $NAMVERS -$VERSION` elif [[ `echo $NAMVERS |grep '.'` ]] ; then NAME=`echo $NAMVERS |cut -f1 -d'.'` NAME=`echo $NAMVERS |cut -f2- -d'.'` else echo "What is this?" NAME=unknown VERSION=0.0 fi fi else #echo hello $EXT case $EXT in tgz|tar.gz|tbz|tar.bz2|orig.tar.gz|orig.tar.bz2) if [[ `basename $SOURCE_NAME |grep ".orig."` ]] ; then [[ $DEBUG ]] && echo -n "Debian source archive" NAMVERS=`basename $NAMVERS ".orig"` # NAMVERS=`echo $NAMVERS |tr '_' '.'` elif [[ `basename $SOURCE_NAME |grep "_"` ]] ; then [[ $DEBUG ]] && echo -n "Possible Debian source archive" elif [[ `basename $SOURCE_NAME |grep ".source."` ]] ; then [[ $DEBUG ]] && echo -n "Converted RPM source archive" NAMVERS=`basename $NAMVERS ".source"` else [[ $DEBUG ]] && echo -n "Generic source archive" fi translate_underlines ignore() { if [[ `echo $NAMVERS |rev |cut -f1 -d'.' |grep '-'` != "" ]] ; then if [[ `echo $NAMVERS |grep "[0-9]"` ]] ; then [[ $DEBUG ]] && echo " -Rule 3" CHUNK=`echo $NAMVERS |rev |cut -f1 -d'.' |tr '-' '.' |rev` NAMVERS=`echo $NAMVERS |rev |cut -f2- -d'.' |rev`.$CHUNK fi fi } if [[ `echo $NAMVERS |grep '-'` != "" ]] ; then [[ $DEBUG ]] && echo " Rule 1" VERSION=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAME=`basename $NAMVERS -$VERSION` elif [[ `echo $NAMVERS |grep '_'` != "" ]] ; then # redundant because of translate_underlines, but leave as a marker since it worked VERSION=`echo $NAMVERS |rev |cut -f1 -d'_' |rev` NAME=`basename $NAMVERS _$VERSION` else [[ $DEBUG ]] && echo " Rule 2" NAME=`echo $NAMVERS |cut -f1 -d'.'` VERSION=`echo $NAMVERS |cut -f2- -d'.'` [[ "$VERSION" = "$NAME" ]] && VERSION=0.0.0 fi ;; esac fi ;; esac # Whew!! The derived name and can always be overridden else if [[ $NAME ]] && [[ $VERSION ]] ; then NAMVERS="$NAME-$VERSION" echo $BLUE"Client or user supplied NAME and VERSION: "$NORMAL"$NAMVERS" else NAMVERS=`basename $CWD` echo $BLUE"Using NAME and VERSION from CWD: "$NORMAL"$NAMVERS" fi if [[ `echo $NAMVERS |grep '-'` != "" ]] ; then VERSION=`echo $NAMVERS |rev |cut -f1 -d'-' |rev` NAME=`basename $NAMVERS -$VERSION` elif [[ `echo $NAMVERS |grep '_'` != "" ]] ; then VERSION=`echo $NAMVERS |rev |cut -f1 -d'_' |rev` NAME=`basename $NAMVERS _$VERSION` elif [[ `echo $NAMVERS |grep '.'` ]] ; then NAME=`echo $NAMVERS |cut -f1 -d'.'` VERSION=`echo $NAMVERS |cut -f2- -d'.'` [[ "$VERSION" = "$NAME" ]] && VERSION=0.0.0 else echo "What in the world is this?" NAME=unknown VERSION=0.unknown.0 fi VERSION=`echo $VERSION |tr '-' '_'` fi ORIG_NAME="$NAME" ORIG_VERSION="$VERSION" [[ $DEBUG ]] && echo $BLUE"RAW_SOURCE_NAME="$NORMAL"$RAW_SOURCE_NAME" [[ $DEBUG ]] && [[ $ARCH_CHUNK ]] && echo $BLUE"ARCH_CHUNK="$NORMAL"$ARCH_CHUNK" [[ $DEBUG ]] && [[ $MYARCH ]] && echo $BLUE"MYARCH="$NORMAL"$MYARCH" [[ $DEBUG ]] && [[ $REV_CHUNK ]] && echo $BLUE"REV_CHUNK="$NORMAL"$REV_CHUNK" [[ $DEBUG ]] && echo $BLUE"ORIG_NAME="$NORMAL"$ORIG_NAME" [[ $DEBUG ]] && echo $BLUE"ORIG_VERSION="$NORMAL"$ORIG_VERSION" # Now correct the name for capital letters if needed if [[ `echo $NAME | grep -e "[A-Z]"` ]] ; then echo $BLUE"Notice - "$NORMAL"Source name contains capital letters." if [[ "$CORRECT_NAMES" = "YES" ]] && [[ ! $ALT_NAME ]] ; then ALT_NAME=`echo $NAME | tr 'A-Z' 'a-z'` # echo $BLUE"Correcting $NAME to $ALT_NAME"$NORMAL elif [[ $ALT_NAME ]] ; then if echo $ALT_NAME | grep -e "[A-Z]" &> /dev/null ; then echo $BLUE"Notice - "$NORMAL"Alternate Name contains capital letters." echo -n "A better name for $ALT_NAME would be: " echo $ALT_NAME | tr 'A-Z' 'a-z' fi fi fi if [[ "$ALT_VERSION" != "" ]] ; then if echo $ALT_VERSION | grep -e "-" &> /dev/null ; then echo $YELLOW"ERROR - "$NORMAL"Version numbers with a '-' character are not allowed." ALT_VERSION=`echo $ALT_VERSION |tr '-' '.'` fi echo $BLUE"Resetting version number - "$NORMAL"Using: "$BLUE"$ALT_VERSION"$NORMAL VERSION="$ALT_VERSION" fi if [[ "$ALT_NAME" != "" ]] ; then echo $BLUE"Resetting package name - "$NORMAL"Using: "$BLUE"$ALT_NAME"$NORMAL NAME="$ALT_NAME" fi if [[ ! $NAME ]] ; then echo $RED"ERROR - "$NORMAL"Unable to find a NAME. Please give one!" exit elif [[ ! $VERSION ]] ; then echo $RED"ERROR - "$NORMAL"Unable to find a VERSION. Please give one!" exit fi #debug #exit if [[ $TRACK_INSTALL ]] ; then SRC_DIR=$CWD OBJ_DIR=$SRC_DIR elif [[ $USE_OBJ_DIR = "YES" ]] ; then SRC_DIR_NAME=$NAME-$VERSION-src-$BUILD$SIG SRC_DIR=$SRC_BUILDS_DIR/$SRC_DIR_NAME OBJ_DIR_NAME=$NAME-$VERSION-obj-$BUILD$SIG OBJ_DIR=$SRC_BUILDS_DIR/$OBJ_DIR_NAME elif [[ $SOURCE_NAME ]] ; then # let configure_source sort our CONFIG_DIR and OBJ_DIR SRC_DIR_NAME=$NAME-$VERSION-src-$BUILD$SIG SRC_DIR=$SRC_BUILDS_DIR/$SRC_DIR_NAME elif [[ $NAME ]] && [[ $VERSION ]] ; then # try assuming this, which should allow using a src2pkg script inside sources SRC_DIR=$CWD OBJ_DIR=$SRC_DIR fi PKG_DIR_NAME=$NAME-$VERSION-pkg-$BUILD$SIG PKG_DIR=$PKG_BUILDS_DIR/$PKG_DIR_NAME # This should make most code from SlackBuild scripts compatible PKG=$PKG_DIR # these are internal abbreviations to shorten code lines SHORT_NAME="$NAME-$VERSION-$ARCH-$BUILD$SIG" PKG_NAME=$SHORT_NAME.tgz PACKAGE=$PKG_DEST_DIR/$PKG_NAME check_dirs1 } # end pre_process # find_source() { if [[ "$SOURCE" != "" ]] || [[ "$SOURCE_NAME" != "" ]] ; then #echo -n $BLUE"Searching source archive: "$NORMAL"$SOURCE - " if [[ -L $SOURCE ]] ; then echo $BLUE"Found source archive: "$NORMAL"`basename $SOURCE`" echo "It's really a symlink to:" echo "`readlink -f $SOURCE`" SOURCE=`readlink -f $SOURCE` elif [[ -f $SOURCE ]] ; then echo $BLUE"Found source archive: "$NORMAL"`basename $SOURCE`" #echo $GREEN"Okay"$NORMAL SOURCE=$SOURCE elif [[ -f $SOURCES_DIR/$SOURCE ]] ; then echo $BLUE"Found source archive in SOURCES_DIR: "$NORMAL"`basename $SOURCE`" SOURCE=$SOURCES_DIR/$SOURCE_NAME elif [[ -f $CWD/$SOURCE ]] ; then echo $BLUE"Found source archive in CWD: "$NORMAL"`basename $SOURCE`" SOURCE=$CWD/$SOURCE else echo $RED"FAILED! "$NORMAL"File: `basename $SOURCE` not found!" echo "Check for errors in the NAME, VERSION or SRC_SUFFIX. " FAILED="SOURCE LOCATION" fi fi } make_dirs() { if [[ "$PACKAGE" = "$SOURCE" ]] ; then echo $RED"FAILED! "$NORMAL"You appear to be trying to repackage" echo "a package with the same name from inside your PKG_DEST_DIR." FAILED=" SOURCE_EQUALS_PACKAGE" fi if [[ "$FAILED" = "" ]] ; then check_dirs2 # clean up any directories, packages and logs that fit if [[ -f $PACKAGE ]] || [[ -d $PKG_DIR ]] ; then [[ "$QUIET" = "YES" ]] && echo -n $BLUE"Deleting old build files - "$NORMAL if [[ -f $PKG_DEST_DIR/$PKG_NAME ]] && [[ "$PACKAGE" != "$SOURCE" ]] ; then [[ "$QUIET" = "NO" ]] && echo $BLUE"Removing existing package from previous build - "$NORMAL ( cd $PKG_DEST_DIR && rm -f $PKG_NAME 2> /dev/null 1> /dev/null ) fi if [[ -d $PKG_BUILDS_DIR/$PKG_DIR_NAME ]] ; then [[ "$QUIET" = "NO" ]] && echo $BLUE"Removing existing package build directory from previous build - "$NORMAL ( cd $PKG_BUILDS_DIR && rm -rf $PKG_DIR_NAME 2> /dev/null 1> /dev/null ) fi if [[ $OBJ_DIR_NAME != "" ]] && [[ -d $SRC_BUILDS_DIR/$OBJ_DIR_NAME ]] ; then [[ "$QUIET" = "NO" ]] && echo $BLUE"Removing existing object build directory from previous build - "$NORMAL ( cd $SRC_BUILDS_DIR && rm -rf $OBJ_DIR_NAME 2> /dev/null 1> /dev/null ) fi if [[ -d $SRC_BUILDS_DIR/$SRC_DIR_NAME ]] ; then if [[ $SRC_DIR = $CWD ]] || [[ $SRC_BUILDS_DIR/$SRC_DIR_NAME = $CWD ]] ; then [[ "$QUIET" = "NO" ]] && echo $BLUE"Skipping source build directory - "$NORMAL # be sure to skip this if SRC_DIR=CWD or we remove ourselves true else [[ "$QUIET" = "NO" ]] && echo $BLUE"Removing existing source build directory from previous build - "$NORMAL ( cd $SRC_BUILDS_DIR && rm -rf $SRC_DIR_NAME 2> /dev/null 1> /dev/null ) fi fi # remove any logfiles leftover from fake_install. They should only exist if the build # was interrupted or if we were asked to save them [[ -e $CWD/FILELIST ]] && rm -f $CWD/FILELIST 2> /dev/null 1> /dev/null [[ -e $CWD/FILELIST.tmp ]] && rm -f $CWD/FILELIST.tmp 2> /dev/null 1> /dev/null [[ -e $CWD/DIRLIST ]] && rm -f $CWD/DIRLIST 2> /dev/null 1> /dev/null # clean up any debugging list or logs [[ -e $CWD/LINKLIST ]] && rm -f $CWD/LINKLIST 2> /dev/null 1> /dev/null [[ -e $CWD/FILELIST.orig ]] && rm -f $CWD/LINKLIST 2> /dev/null 1> /dev/null # cleanup any reports left from post_process [[ -e $DATABASE_FILE ]] && rm -f $DATABASE_FILE [[ -e $REPORT_FILE ]] && rm -f $REPORT_FILE # if the -backup dir still exists something went wrong last time -remove it anyway if [[ -d $BACKUP_DIR/$NAME-$VERSION-backup ]] ; then cd $BACKUP_DIR rm -rf $NAME-$VERSION-backup 2> /dev/null 1> /dev/null fi [[ "$QUIET" = "YES" ]] && echo $GREEN"Done"$NORMAL fi # create new working directories echo -n $BLUE"Creating working directories - "$NORMAL # these general directories are usually already present -we don't ever remove these # since by default all these are equal to /tmp. [[ ! -d $SRC_BUILDS_DIR ]] && mkdir -p $SRC_BUILDS_DIR [[ ! -d $PKG_BUILDS_DIR ]] && mkdir -p $PKG_BUILDS_DIR [[ ! -d $PKG_DEST_DIR ]] && mkdir -p $PKG_DEST_DIR # create the PKG_DIR where package content is prepared. PRE_FIX is only created later # in fake_install if installation is successful. Empty PKG_DIR serves as a test later. if [[ ! -d $PKG_DIR ]] ; then cd $PKG_BUILDS_DIR && mkdir -p $PKG_DIR_NAME && echo -n "PKG_DIR " fi # create a separate OBJ_DIR if asked for if [[ $USE_OBJ_DIR = "YES" ]] ; then cd $SRC_BUILDS_DIR && mkdir -p $OBJ_DIR_NAME && echo -n "OBJ_DIR" fi # be extra careful with this if [[ $SOURCE_NAME ]] && [[ "$SRC_DIR" != "$CWD" ]] ; then cd $SRC_BUILDS_DIR [[ ! -d $SRC_DIR_NAME ]] && mkdir -p $SRC_DIR_NAME && echo -n "SRC_DIR " fi echo $GREEN"Okay"$NORMAL fi } # end make_dirs examine_source() { # do this first #fix_source_perms #CORRECT_PERMS="NO" cd $SRC_BUILDS_DIR ; # hold2 if [[ `ls $SRC_DIR_NAME/*` != "" ]] ; then cd $SRC_DIR_NAME ; CONTENT=`ls` for item in $CONTENT ; do case $item in usr|etc|var|lib|bin|opt|sbin|boot|dev|tmp) [[ -d $item ]] && BIN_CONTENT=1 ;; control) [[ -f control ]] && SRC_TYPE="DEB" ;; install) [[ -d install ]] && SRC_TYPE="SLK" ; BIN_CONTENT=1 ;; *.spec) SRC_TYPE="RPM" ;; *.tar.bz2|*.tar.gz|*.tgz|*.tbz) [[ -f $item ]] && FOUND_SOURCE=1 ;; esac done if [[ $BIN_CONTENT -eq 1 ]] ; then #skip out CONFIG_COMMAND="skip" ; INSTALL_COMMAND="skip" MAKE_COMMAND="copyall" #debug #echo "BIN_CONTENT handling disabled..." #exit else if [[ `ls |wc -l` -eq 1 ]] ; then UNPACK_NAME=`ls` if [[ -d $UNPACK_NAME ]] ; then echo $BLUE"Found sources: "$NORMAL"$UNPACK_NAME"$NORMAL echo $BLUE"Moving into SRC_DIR: "$NORMAL"$SRC_DIR_NAME" cd $UNPACK_NAME ; mv ./* ../ ; cd $SRC_BUILDS_DIR/$SRC_DIR_NAME ; rm -rf $UNPACK_NAME #OPEN_SOURCE=1 fi fi ls *.spec &> /dev/null if [[ $? = 0 ]] ; then #rm -f ./*.spec #UNPACK_NAME="`ls`" if [[ "$EXT" = "tgz" ]] || [[ "$EXT" = "tar.gz" ]] ; then echo $BLUE"Found 'rpm2tgz' format:"$NORMAL elif [[ "$EXT" = "rpm" ]] || [[ "$EXT" = "src.rpm" ]] ; then echo $BLUE"Found RPM format:"$NORMAL fi fi if ! [[ $OPEN_SOURCE ]] ; then for item in `ls` ; do case $item in *.tar.bz2|*.tar.gz|*.tgz|*.tbz) # echo "Found archive: $item" case $item in *.tar.bz2) INT_EXT='tar.bz2' ;; *.tbz) INT_EXT='tbz' ;; *.tar.gz) INT_EXT='tar.bgz' ;; *.tgz) INT_EXT='tgz' ;; esac if [[ `echo $item |grep "patch"` ]] || [[ `echo $item |grep "diff"` ]]; then #true echo -n $BLUE"Ignoring compressed patch: "$NORMAL"$item " else UNPACK_NAME=`tar -tf $item |head -1 |cut -f1 -d'/'` ITEM_NAME=`basename $item .tar.bz2` ; ITEM_NAME=`basename $item .tbz` ITEM_NAME=`basename $item .tar.gz` ; ITEM_NAME=`basename $item .tgz` GUESSED_NAME=`basename $RAW_SOURCE_NAME |rev |cut -f2- -d'-' |rev` case $item in $NAME-$VERSION.*|$GUESSED_NAME.*|$ORIG_NAME-$ORIG_VERSION.*|$NAME-cvs*) echo -n $BLUE"Decompressing matching archive: "$NORMAL"$item " UNPACK_NAME=`tar -tf $item |head -1 |cut -f1 -d'/'` tar xf $item &> /dev/null if [[ $? = 0 ]] && [[ -d $UNPACK_NAME ]] ; then echo $GREEN"Done!"$NORMAL ( cd $UNPACK_NAME && mv ./* ../ && cd .. ) rm -rf $UNPACK_NAME rm -f $item UNPACK_SUCCESS=1 #CORRECT_PERMS="YES" # fix_source_perms else echo $RED"FAILED!"$NORMAL echo "Unable to unpack archive: $item "$RED"Exiting..."$NORMAL FAILED="UNPACK_RENAME" fi ;; *) if ! [[ $UNPACK_SUCCESS ]] ; then echo -n $BLUE"Decompressing (unknown) archive: "$NORMAL"$item " UNPACK_NAME=`tar -tf $item |head -1 |cut -f1 -d'/'` tar xf $item &> /dev/null if [[ $? = 0 ]] && [[ -d $UNPACK_NAME ]] ; then echo $GREEN"Done!"$NORMAL echo $CYAN"Notice - "$NORMAL"Internal archive name mismatch: $UNPACK_NAME" ( cd $UNPACK_NAME && mv ./* ../ && cd .. ) rm -rf $UNPACK_NAME rm -f $item UNPACK_SUCCESS=1 #CORRECT_PERMS="YES" #fix_source_perms else echo $RED"FAILED!"$NORMAL echo "Unable to unpack $item. "$RED"Exiting..."$NORMAL FAILED="UNPACK_RENAME" fi else echo $BLUE"Ignoring archive: "$NORMAL"$item" fi ;; esac fi ;; esac done fi fi else echo $RED"FAILED!"$NORMAL echo "Source directory is empty. "$RED"Exiting..."$NORMAL FAILED="EMPTY_SOURCE" fi # hold2 } unpack_source() { if [[ ! $SOURCE_NAME ]] || [[ $SRC_DIR = $CWD ]] ; then true elif [[ "$FAILED" = "" ]] ; then echo -n $BLUE"Unpacking source archive - "$NORMAL cd $SRC_BUILDS_DIR/$SRC_DIR_NAME ; if [[ "$EXT" = "deb" ]] || [[ "$EXT" = "rpm" ]] || [[ "$EXT" = "src.rpm" ]] ; then if [[ $QUIET = "YES" ]] ; then disrpm -x $SOURCE &> /dev/null else echo "" disrpm -x $SOURCE fi elif [[ $QUIET = "YES" ]] ; then tar xvf $SOURCE 1> /dev/null else echo "" tar xvf $SOURCE fi if [[ $? -ne 0 ]] ; then echo $RED"FAILED!"$NORMAL echo "This may be caused by a defective or non-tar archive. "$RED"Exiting..."$NORMAL FAILED="UNPACK" else [[ $QUIET = "YES" ]] && echo $GREEN"Done"$NORMAL || echo "" UNPACK_NAME=`ls $SRC_BUILDS_DIR/$SRC_DIR_NAME` examine_source # exit fi fi } fix_source_perms() { if [[ "$FAILED" = "" ]] ; then if [[ "$CORRECT_PERMS" = "YES" ]] ; then echo -n $BLUE"Correcting file permissions - "$NORMAL cd $SRC_DIR chown -R root.root . # now we do the directories too, for handling installable directory structures 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 if [[ "$AUTO_PATCH" = "YES" ]] ; then echo -n $BLUE"Checking for patches - "$NORMAL [[ `find $CWD -name '*patch*' -o -name '*.diff*' |grep -v unused |grep -v disabled |grep -v pasture` = "" ]] && echo "None found" || echo for p in `find $CWD -name '*patch*' -o -name '*.diff*' |grep -v unused |grep -v disabled |grep -v pasture | sort` ; do case $p in *.gz) echo " Applying: `basename $p`" ; cd $SRC_DIR && zcat $p | patch -p1 -l ;; *.bz2) echo " Applying: `basename $p`" ; cd $SRC_DIR && bzcat $p | patch -p1 -l ;; *.patch|*.diff) echo " Applying: `basename $p`" ; cd $SRC_DIR && patch -p1 -l < $p ;; esac done fi fi } # configure_source configure_source() { if [[ "$FAILED" = "" ]] ; then if [[ "$CONFIG_COMMAND" = "skip" ]] ; then echo $BLUE"Skipped configure_source - "$NORMAL CONFIG_DIR=$SRC_DIR else # find the main configuration directory if [[ $CONFIG_SUBDIR ]] ; then # if what's below doesn't find the main dir, use like this: CONFIG_SUBDIR=abi (see below) CONFIG_DIR=$SRC_DIR/$CONFIG_SUBDIR else # abi is for AbiWord. this would find $SRC_DIR/abiword -more possibles? Order makes a difference. # SRC_DIR/$NAME ?? what about using ls ? # for keydir in $SRC_DIR `ls $SRC_DIR/*` ; do for keydir in $SRC_DIR $SRC_DIR/src $SRC_DIR/Src $SRC_DIR/$NAME-$VERSION $SRC_DIR/$NAME $SRC_DIR/$NAMElib $SRC_DIR/lib$NAME $SRC_DIR/abi ; do #if [[ -x $keydir/configure ]] || [[ -r $keydir/Makefile ]] ; then # CONFIG_DIR=$keydir # break ; #else for keyfile in configure Makefile configure.in configure.ac Makefile.in Makefile.am autogen.sh GNUmakefile GNUmakefile.in GNUmakefile.am Imakefile SConstruct makefile Jamfile install.sh ; do if [[ -e $keydir/$keyfile ]] ; then CONFIG_SUBDIR=$keydir KEYFILE="$keyfile" break ; fi done if [[ $CONFIG_SUBDIR ]] ; then CONFIG_DIR=$keydir break ; fi #fi if [[ $CONFIG_DIR ]] ; then CONFIG_DIR=$keydir break ; fi done fi ! [[ "$CONFIG_DIR" ]] && CONFIG_DIR=$SRC_DIR # this should finish setting OBJ_DIR if [[ "$CONFIG_DIR" != "$SRC_DIR" ]] ; then FUNNY_SUBDIR=`basename $CONFIG_DIR` echo $BLUE"Notice - "$NORMAL"The main files are in a subdirectory: $FUNNY_SUBDIR" ! [[ $USE_OBJ_DIR ]] && OBJ_DIR=$CONFIG_DIR fi [[ $DEBUG ]] && echo $CYAN"Notice- "$NORMAL"Using keyfile: $KEYFILE" ! [[ $USE_OBJ_DIR ]] && [[ ! $OBJ_DIR ]] && OBJ_DIR=$CONFIG_DIR if [[ -e $CONFIG_DIR/GNUmakefile.in ]] ; then echo $BLUE"Notice - "$NORMAL"This packages uses GNUmakefiles, instead of Makefiles." if ! [[ $USE_DEFAULT_MAKEFILES = "YES" ]] ; then MAKEFILE="GNUmakefile" if [[ -e $CONFIG_DIR/Makefile ]] ; then echo "But, we found a default Makefile. We rename to Makefile.found and start fresh." echo "If not, the Makefile would be used instead of the new GNUmakefile." mv $CONFIG_DIR/Makefile $CONFIG_DIR/Makefile.found fi fi fi if [[ -e $CONFIG_DIR/makefile ]] ; then MAKEFILE="makefile" elif [[ -e $CONFIG_DIR/GNUmakefile ]] || [[ -e $CONFIG_DIR/GNUmakefile.am ]] ; then MAKEFILE="GNUmakefile" elif [[ -e $CONFIG_DIR/Makefile ]] || [[ -e $CONFIG_DIR/Makefile.am ]] ; then MAKEFILE="Makefile" fi # if [[ -e $CONFIG_DIR/acconfig.h ]] ; then # echo $CYAN"Notice- "$NORMAL"This package contains deprecated autoconf/automake files." # fi if ! [[ -x $CONFIG_DIR/configure ]] ; then # echo $YELLOW"NOTICE! "$NORMAL"No executable configure script was found in the sources. Hmmmm..." if [[ -e $CONFIG_DIR/configure.in ]] || [[ -e $CONFIG_DIR/configure.ac ]] ; then if [[ -e $CONFIG_DIR/$MAKEFILE.in ]] && [[ -e $CONFIG_DIR/$MAKEFILE.am ]] ; then echo -n $BLUE"Found autoconf files. "$NORMAL"We'll try running autoconf - " cd $CONFIG_DIR ; autoconf 1> /dev/null && echo $GREEN"Done"$NORMAL || echo $YELLOW"FAILED!"$NORMAL elif [[ -e $CONFIG_DIR/$MAKEFILE.am ]] ; then echo -n $BLUE"Found incomplete autoconf sources - "$NORMAL"Running autoreconf -if " autoreconf --install --force &> /dev/null echo $GREEN"Done!"$NORMAL fi fi fi # if there's an autogen.sh, try that before using our generic, but don't run it if you already have an executable configure if ! [[ -x $CONFIG_DIR/configure ]] && [[ -e $CONFIG_DIR/autogen.sh ]] ; then echo "Found an autogen.sh script. We'll try running that - " cd $CONFIG_DIR ; sh ./autogen.sh 2> /dev/null && echo $GREEN"Done"$NORMAL || echo $YELLOW"FAILED!"$NORMAL echo -n "Now we'll try running autoconf - " autoconf 2> /dev/null && echo $GREEN"Done"$NORMAL || echo $YELLOW"FAILED!"$NORMAL fi # # if all else fails try this generic routine. if ! [[ -x $CONFIG_DIR/configure ]] && [[ -e $CONFIG_DIR/$MAKEFILE.am ]] && [[ -e $CONFIG_DIR/$MAKEFILE.in ]] ; then if [[ -e $CONFIG_DIR/configure.ac ]] || [[ -e $CONFIG_DIR/configure.in ]] ; then echo $BLUE"Found Makefile.am and configure.in. "$NORMAL"We'll try with these generic commands:" echo "aclocal -I. ; autoheader ; automake --add-missing --copy --foreign ; autoconf" [[ -d $CONFIG_DIR/autom4te.cache ]] && rm -rf $CONFIG_DIR/autom4te.cache [[ -d $CONFIG_DIR/.deps ]] && rm -rf $CONFIG_DIR/.deps [[ -f $CONFIG_DIR/.deps ]] && rm -f $CONFIG_DIR/.deps [[ -f $CONFIG_DIR/config.status ]] && rm -f $CONFIG_DIR/config.status [[ -f $CONFIG_DIR/config.cache ]] && rm -f $CONFIG_DIR/config.cache cd $CONFIG_DIR ; # automake aclocal -I . 2> /dev/null 1> /dev/null autoheader 2> /dev/null 1> /dev/null # automake --add-missing --copy --foreign 2> /dev/null 1> /dev/null automake -a --force --copy --foreign 2> /dev/null 1> /dev/null autoconf 2> /dev/null fi if ! [[ -x $CONFIG_DIR/configure ]] ; then echo $YELLOW"WARNING! "$NORMAL"This looks like a non-working autoconf package or maybe needs automake-1.4." if [[ -e $CONFIG_DIR/$MAKEFILE ]] ; then echo "But we have a Makefile, so we'll proceed anyway. Maybe it's your lucky day." else echo $YELLOW"WARNING! "$NORMAL"No Makefile and no configure script found. "$BLUE"Skipping..."$NORMAL fi fi fi if [[ -x $CONFIG_DIR/configure ]] ; then trap safe_user_cancel 2 echo -n $BLUE"Found configure script - "$NORMAL if [[ $USE_OBJ_DIR = "YES" ]] ; then REL_CONFIG_PATH=`basename $CONFIG_DIR` echo "" echo $BLUE"Using OBJ_DIR: "$NORMAL "`basename ${OBJ_DIR}`" if [[ -e $CONFIG_DIR/$MAKEFILE ]] ; then echo $BLUE"NOTICE - "$NORMAL"Stale Makefile found. Running 'make distclean' - " cd $CONFIG_DIR && make distclean &> /dev/null && echo $GREEN"Okay"$NORMAL fi if ! [[ $CONFIG_COMMAND ]] ; then CONFIG_COMMAND="../$REL_CONFIG_PATH/configure" ; CONFIG_ARGS="--prefix=$PRE_FIX $STD_CONFIGS $EXTRA_CONFIGS" ; fi fi if ! [[ $CONFIG_COMMAND ]] ; then CONFIG_COMMAND="$CONFIG_DIR/configure" else CONFIG_COMMAND="$CONFIG_DIR/$CONFIG_COMMAND" fi CONFIG_ARGS="`echo --prefix=$PRE_FIX $STD_CONFIGS $EXTRA_CONFIGS| white_out`" if ! [[ $FLAG_LINE ]] ; then FLAG_LINE="`echo $STD_FLAGS $EXTRA_FLAGS |white_out`" CFLAGS=$FLAG_LINE fi if [[ $QUIET = "YES" ]] ; then cd $OBJ_DIR ; echo "Configuring sources using:" # echo $FLAG_LINE $CONFIG_LINE echo " CFLAGS=$CFLAGS ./`basename $CONFIG_COMMAND` $CONFIG_ARGS" #export CFLAGS=$STD_FLAGS$EXTRA_FLAGS ; export CFLAGS=$FLAG_LINE $CONFIG_COMMAND $CONFIG_ARGS &> /dev/null else cd $OBJ_DIR ; echo "Now trying to configure sources using:" echo " CFLAGS=$CFLAGS ./$CONFIG_COMMAND $CONFIG_ARGS" echo "Messages from configure:" export CFLAGS=$STD_FLAGS$EXTRA_FLAGS $CONFIG_COMMAND $CONFIG_ARGS fi if [[ $? -eq 0 ]] ; then echo $BLUE"Configuration has been - "$GREEN"Successful!"$NORMAL elif [[ $USER_CANCELLED ]] ; then echo $RED"STOPPED! "$NORMAL"Operation cancelled during configuration!" FAILED="CANCELLED" else FAILED="configure_source" echo $RED"ERROR! "$NORMAL"Configuring sources has failed!"$NORMAL echo "This usually happens because of missing libraries, or you" echo "may need to pass extra options to configure using EXTRA_CONFIGS." # show_requires if [[ $REPLAY_ERRORS = "YES" ]] && [[ $QUIET = "YES" ]] ; then if [[ $DISPLAY ]] ; then cd $CONFIG_DIR ; echo $CYAN"NOTICE-"$NORMAL"Replaying failed configuration in a separate xterm:" export CFLAGS=$STD_FLAGS$EXTRA_FLAGS ( xterm -hold -e "$CONFIG_COMMAND" "$CONFIG_ARGS" & ) else cd $CONFIG_DIR ; echo $CYAN"NOTICE-"$NORMAL"Replaying failed configuration:" export CFLAGS=$STD_FLAGS$EXTRA_FLAGS $CONFIG_COMMAND $CONFIG_ARGS fi fi show_requires fi elif [[ -f $CONFIG_DIR/Imakefile ]] ; then if ! [[ $USE_DEFAULT_MAKEFILES = "YES" ]] ; then echo -n $BLUE"Found Imakefile - "$NORMAL"Configuring using: 'xmkmf -a' - " cd $CONFIG_DIR ; xmkmf -a 2> /dev/null 1> /dev/null MAKEFILE="Makefile" echo $GREEN"Done"$NORMAL fi elif [[ -f $CONFIG_DIR/SConstruct ]] ; then echo -n $BLUE"Found SConstruct file - "$NORMAL"Configuring using: 'scons configure' - " cd $CONFIG_DIR ; if [[ $QUIET = "YES" ]] ; then scons configure 2> /dev/null 1> /dev/null else scons configure fi MAKEFILE="SConstruct" echo $GREEN"Done"$NORMAL elif [[ -f $CONFIG_DIR/$MAKEFILE ]] ; then echo $BLUE"Skipping configure_source - "$NORMAL"Continuing since we found a "$BLUE"$MAKEFILE"$NORMAL cd $CONFIG_DIR ; if [[ ! "$PRE_FIX" = "/usr/local" ]] && [[ `find . -name "$MAKEFILE" |wc -l` -eq 1 ]] ; then if [[ `grep 'PREFIX=/usr/local' $MAKEFILE` ]] ; then mv $MAKEFILE $MAKEFILE.ours echo $BLUE"Correcting $MAKEFILE - "$NORMAL"Fixed mismatching arbitrary PREFIX" sed -e s:"PREFIX=/usr/local":"PREFIX=$PRE_FIX": $MAKEFILE.ours > $MAKEFILE elif [[ `grep 'PREFIX = /usr/local' $MAKEFILE` ]] ; then mv $MAKEFILE $MAKEFILE.ours echo $BLUE"Correcting $MAKEFILE - "$NORMAL"Fixed mismatching arbitrary PREFIX" sed -e s:"PREFIX[\t, ]=[\t, ]/usr/local":"PREFIX = ${PRE_FIX}": $MAKEFILE.ours > $MAKEFILE elif [[ `grep 'prefix=/usr/local' $MAKEFILE` ]] ; then mv $MAKEFILE $MAKEFILE.ours echo $BLUE"Correcting $MAKEFILE - "$NORMAL"Fixed mismatching arbitrary PREFIX" sed -e s:"prefix=/usr/local":"prefix=${PRE_FIX}": $MAKEFILE.ours > $MAKEFILE elif [[ `grep 'prefix = /usr/local' $MAKEFILE` ]] ; then mv $MAKEFILE $MAKEFILE.ours echo $BLUE"Correcting $MAKEFILE - "$NORMAL"Fixed mismatching arbitrary PREFIX" sed -e s:"prefix[\t, ]=[\t, ]/usr/local":"prefix = ${PRE_FIX}": $MAKEFILE.ours > $MAKEFILE fi fi else echo $BLUE"Skipping configure_source - "$NORMAL fi fi fi } show_requires() { if [[ -e $CONFIG_DIR/$NAME.spec ]] ; then if grep "Requires:" $CONFIG_DIR/$NAME.spec 1> /dev/null ; then echo $BLUE"Found an RPM .spec file which shows this:"$NORMAL grep "Requires:" $CONFIG_DIR/$NAME.spec |uniq else echo "No Requires information found in $NAME.spec." fi elif [[ -e $CONFIG_DIR/$NAME.spec.in ]] ; then if grep "Requires:" $CONFIG_DIR/$NAME.spec.in 1> /dev/null ; then echo $BLUE"Searching the RPM .spec.in file turns up this:"$NORMAL grep "Requires:" $CONFIG_DIR/$NAME.spec.in |uniq else echo "No Requires information found in $NAME.spec.in." fi elif [[ -e $CONFIG_DIR/debian/control ]] ; then if grep "Depends:" $CONFIG_DIR/debian/control 1> /dev/null ; then echo $BLUE"Searching the Debian control file turns up this:"$NORMAL grep "Depends:" $CONFIG_DIR/debian/control |uniq else echo $BLUE"Sorry! "$NORMAL"No Depends: information found in Debian control file.." fi else echo $BLUE"Sorry! ""$NORMAL""No Dependency or Requirements information found." fi echo "" } # find Makefile find_makefile() { if [[ -e $OBJ_DIR/GNUmakefile ]] ;then MAKEFILE="GNUmakefile" ! [[ $MAKE_COMMAND ]] && MAKE_COMMAND="make" ! [[ $INSTALL_COMMAND ]] && INSTALL_COMMAND="make" ! [[ $INSTALL_RULE ]] && INSTALL_RULE="install" elif [[ -e $OBJ_DIR/Makefile ]] ; then MAKEFILE="Makefile" ! [[ $MAKE_COMMAND ]] && MAKE_COMMAND="make" ! [[ $INSTALL_COMMAND ]] && INSTALL_COMMAND="make" ! [[ $INSTALL_RULE ]] && INSTALL_RULE="install" elif [[ -e $OBJ_DIR/makefile ]] ; then MAKEFILE="makefile" ! [[ $MAKE_COMMAND ]] && MAKE_COMMAND="make" ! [[ $INSTALL_COMMAND ]] && INSTALL_COMMAND="make" ! [[ $INSTALL_RULE ]] && INSTALL_RULE="install" elif [[ -e $OBJ_DIR/SConstruct ]] ; then MAKEFILE="SConstruct" ! [[ $MAKE_COMMAND ]] && MAKE_COMMAND="scons" ! [[ $INSTALL_COMMAND ]] && INSTALL_COMMAND="scons" ! [[ $INSTALL_RULE ]] && INSTALL_RULE="install" elif [[ -e $OBJ_DIR/Jamfile ]] ; then MAKEFILE="Jamfile" ! [[ $MAKE_COMMAND ]] && MAKE_COMMAND="jam" ! [[ $INSTALL_COMMAND ]] && INSTALL_COMMAND="jam" ! [[ $INSTALL_RULE ]] && INSTALL_RULE="install" fi } compile_source() { if [[ "$FAILED" = "" ]] ; then if [[ "$MAKE_COMMAND" = "skip" ]] ; then echo $BLUE"Skipping compile_source - "$NORMAL elif [[ "$MAKE_COMMAND" = "copyall" ]] ; then SHOW_DEPS=1 cd $SRC_DIR ; if [[ -f control ]] ; then echo $BLUE"Found Debian binary content - "$NORMAL elif [[ -d install ]] ; then echo $BLUE"Found Slackware package content - "$NORMAL"Contents of the install directory are" echo "copied into the CWD. Be sure to correct if needed and rebuild package." elif [[ $EXT = "rpm" ]] ; then echo $BLUE"Found RPM binary content - "$NORMAL else echo $BLUE"Found generic binary package content - "$NORMAL fi #cd $SRC_DIR DOCPATH=`find . -type d -name doc` # echo DOCPATH=$DOCPATH if [[ -d $DOCPATH ]] ; then cd $DOCPATH ; DOCDIR=`ls` #echo DOCDIR=$DOCDIR else mkdir -p $SRC_DIR/usr/doc/$NAME-$VERSION DOCPATH="usr/doc" DOCDIR="$NAME-$VERSION" fi # echo $DOCPATH $DOCDIR echo -n $BLUE"Checking contents - "$NORMAL ; [[ $DEBUG ]] && echo "" cd $SRC_DIR for item in `ls` ; do if [[ -d $item ]] ; then case $item in # looks like some kind of installable directory structure. usr|etc|var|lib|bin|opt|sbin|boot|dev|tmp) [[ $DEBUG ]] && echo "Found directory: $item" ; shift ;; var) echo ; echo $YELLOW"Warning! "$NORMAL"Directory 'var' may need special permissons" ; shift ;; install) cp -a $SRC_DIR/install/* $CWD; shift ;; esac elif [[ -f $item ]] ; then case $item in preinst|prerm|postinst|md5sums|control) [[ $DEBUG ]] && echo "Moving file: $item into docs" ; cp -a $item $DOCPATH/$DOCDIR/ ; rm -f $item ; ;; # What's this? maybe some sort of installer or other debian file? *) [[ $DEBUG ]] && echo "Removing unrecognized file: $item " ; rm -f $item ;; esac else [[ $DEBUG ]] && echo "Removing unrecognized item: $item " ; rm -f $item fi done ! [[ $DEBUG ]] && echo $GREEN"Done!"$NORMAL if [[ `ls $DOCPATH/$DOCDIR` = "" ]] ; then echo $CYAN"Notice - "$NORMAL"No documents were found in the content. Creating default README" echo "Notice - This package was created by src2pkg from:" > $DOCPATH/$DOCDIR/README echo "$SOURCE_NAME" >> $DOCPATH/$DOCDIR/README echo "No documents were found for the package." >> $DOCPATH/$DOCDIR/README fi # echo $GREEN"Done!"$NORMAL [[ -d $PKG_DIR ]] && mkdir -p $PKG_DIR echo -n $BLUE"Copying contents to PKG_DIR - "$NORMAL cp -a * $PKG_DIR &> /dev/null echo $GREEN"Done!"$NORMAL else ! [[ $OBJ_DIR ]] && OBJ_DIR="$CONFIG_DIR" find_makefile if [[ $MAKEFILE ]] && [[ $MAKE_COMMAND ]] ; then trap safe_user_cancel 2 CFLAGS="`echo $STD_FLAGS $EXTRA_FLAGS |white_out`" echo $BLUE"Compiling sources - "$NORMAL"Using: '$MAKE_COMMAND'" export CFLAGS if [[ $QUIET = "YES" ]] ; then cd $OBJ_DIR ; # $MAKE_COMMAND 2> /dev/null 1> /dev/null # let's try this make clean 1> /dev/null 2> /dev/null $MAKE_COMMAND &> /dev/null else cd $OBJ_DIR ; echo $BLUE"Compiler Messages:"$NORMAL # let's try this make clean 1> /dev/null 2> /dev/null $MAKE_COMMAND fi if [[ $? -eq 0 ]] ; then echo $BLUE"Compiling has been - "$GREEN"Successful!"$NORMAL elif [[ $USER_CANCELLED ]] ; then echo $RED"STOPPED! "$NORMAL"Operation cancelled during compilation! "$NORMAL FAILED="CANCELLED" else FAILED="compile_source" echo "$RED""ERROR! "$NORMAL"Compiling source code has failed." echo "This usually happens because of missing libraries, or" echo "badly written Makefiles or configure scripts." show_requires if [[ $REPLAY_ERRORS = "YES" ]] && [[ $QUIET = "YES" ]] ; then cd $OBJ_DIR ; # echo $CYAN"NOTICE-"$NORMAL"Replaying failed compilation:" export CFLAGS=$STD_FLAGS$EXTRA_FLAGS if [[ $DISPLAY ]] ; then echo $CYAN"NOTICE-"$NORMAL"Replaying failed compilation in a separate xterm." ( xterm -hold -e $MAKE_COMMAND & ) else echo $CYAN"NOTICE-"$NORMAL"Replaying failed compilation:" $MAKE_COMMAND fi fi fi else echo $BLUE"Skipping compile_source - "$NORMAL fi fi fi } check_makefile() { if [[ -f $OBJ_DIR/$MAKEFILE ]] && [ "$INSTALL_RULE" = "install" -o "$INSTALL_LINE" = "make install" ] ; then if ! [[ `grep "DESTDIR" $OBJ_DIR/$MAKEFILE 2> /dev/null` ]] ; then echo $CYAN"NOTICE! "$NORMAL"DESTDIR not supported. We don't use it anyway, since it's unreliable." fi if ! [[ `grep "install:" $OBJ_DIR/$MAKEFILE 2> /dev/null` ]] ; then echo $RED"FATAL ERROR! "$NORMAL"No 'install' rule was found in the Makefile! You'll have to" echo "write a manual install rule for this one. We could guess, but better not! "$RED"Exiting..."$NORMAL FAILED="NO INSTALL RULE" exit 0 fi fi } fake_install() { if [[ "$INSTALL_COMMAND" = "skip" ]] ; then echo $BLUE"Skipping fake_install - "$NORMAL elif [[ "$FAILED" = "" ]] ; then #if [[ $TRACK_INSTALL ]] ; then # SRC_DIR=$CWD # OBJ_DIR=$SRC_DIR #fi ! [[ $OBJ_DIR ]] && OBJ_DIR=$SRC_DIR # if we have MAKEFILE, check it for DESTDIR and 'install:' rule find_makefile # check_makefile if [[ $SHELL_INSTALL ]] ; then if ! [[ $INSTALL_LINE ]] ; then INSTALL_LINE="sh install.sh" if [[ -e $OBJ_DIR/install.sh ]] ; then echo $BLUE"Found install.sh script - "$NORMAL"Interactive input may be required." sleep 2 else echo $CYAN"NOTICE! "$NORMAL"No install.sh script found!" fi fi # The -S option turns off redirection of stdout and stderr -allowing tracking of interactive install scripts. # But if we are running QUIET it will be reset just after critical install install operations [[ "$QUIET" = "YES" ]] && RESTORE_QUIET=1 QUIET="NO" elif [[ ! $MAKEFILE ]] ; then [[ "$QUIET" = "YES" ]] && RESTORE_QUIET=1 QUIET="NO" fi #BLURB='i=cp -aL \* /' ; $(echo ${BLURB##*=} |sed 's/\\//') if [[ $INSTALL_LINE ]] ; then INSTALL_LINE=$(echo $INSTALL_LINE |sed 's/\\//') elif [[ $INSTALL_COMMAND ]] && [[ $INSTALL_RULE ]] ; then INSTALL_LINE=$(echo $INSTALL_COMMAND $INSTALL_RULE |sed 's/\\//') else FAILED="NO INSTALL_LINE" echo $RED"FAILED!! "$NORMAL"No INSTALL_LINE given." exit fi echo $BLUE"Tracking Installation - "$NORMAL"Logging: '$INSTALL_LINE'"$NORMAL ! [[ $BACKUP_DIR ]] && BACKUP_DIR=/tmp ! [[ $BACKUP_DIRECTORY ]] && BACKUP_DIRECTORY=$BACKUP_DIR/$NAME-$VERSION-backup unset INSTALLWATCH_BACKUP_PATH INSTALLWATCH_BACKUP_PATH=$BACKUP_DIRECTORY export INSTALLWATCH_BACKUP_PATH INSTALLWATCHFILE=$CWD/FILELIST.tmp export INSTALLWATCHFILE if cat /dev/null > $INSTALLWATCHFILE ; then true else echo $RED"FAILED! - "$NORMAL "Unable to prepare $INSTALLWATCHFILE" exit 1 fi # get this ready, but exporting it below is what turns it on LD_PRELOAD=/usr/libexec/src2pkg/installwatch.so cd $OBJ_DIR; if [[ $QUIET = "YES" ]] ; then trap trap_int 2 export LD_PRELOAD $INSTALL_LINE &> /dev/null else trap trap_int 2 export LD_PRELOAD $INSTALL_LINE fi ## 2 this routine ends at the end of the function if [[ $? -gt 0 ]] ; then # make install itself returned an error if [[ -x $OBJ_DIR/$NAME ]] || [[ -x $OBJ_DIR/$ORIG_NAME ]]; then echo $CYAN"Notice - "$NORMAL"Running '$INSTALL_COMMAND $INSTALL_RULE' has failed." echo "But, there seems to be an executable called $NAME in the SRC_DIR." echo $BLUE"Doing generic install - "$NORMAL mkdir -p $PKG_DIR/$PRE_FIX/bin [[ -x $OBJ_DIR/$NAME ]] && cp -a $OBJ_DIR/$NAME $PKG_DIR/$PRE_FIX/bin [[ -x $OBJ_DIR/$ORIG_NAME ]] && cp -a $OBJ_DIR/$ORIG_NAME $PKG_DIR/$PRE_FIX/bin if [[ -e $OBJ_DIR/$NAME.1 ]] || [[ -e $OBJ_DIR/$NAME.man ]] ; then echo $BLUE"Found man-page - "$NORMAL"Copying into PKG_DIR" mkdir -p $PKG_DIR/usr/man/man1 [[ -e $OBJ_DIR/$NAME.1 ]] && cp -a $OBJ_DIR/$NAME.1 $PKG_DIR/usr/man/man1 [[ -e $OBJ_DIR/$NAME.man ]] && cp -a $OBJ_DIR/$NAME.man $PKG_DIR/usr/man/man1 fi else echo $RED"FATAL! "$NORMAL"Running '$INSTALL_COMMAND $INSTALL_RULE' has failed with error: $? " echo "Try using 'make -i install' if this is a false error. "$RED"Exiting..."$NORMAL [[ "$INSTALLWATCH_BACKUP_PATH" ]] && rm -rf "${INSTALLWATCH_BACKUP_PATH}/no-backup" FAILED="make_install" fi unset INSTALLWATCH_BACKUP_PATH unset LD_PRELOAD rm -rf $BACKUP_DIR/$NAME-$VERSION-backup rm -f $CWD/FILELIST.tmp # FAILED="make_install" elif [[ `cat $CWD/FILELIST.tmp |grep -v FILELIST.tmp 2> /dev/null` = "" ]] ; then # 'make install' produced no errors but also produced no output [[ "$INSTALLWATCH_BACKUP_PATH" ]] && rm -rf "${INSTALLWATCH_BACKUP_PATH}/no-backup" unset INSTALLWATCH_BACKUP_PATH unset LD_PRELOAD echo $RED"FATAL! "$NORMAL"Running '$INSTALL_COMMAND $INSTALL_RULE' with installwatch produced no files list. " echo "This may be the result of an empty or faulty install rule. "$RED"Exiting..."$NORMAL rm -rf $BACKUP_DIR/$NAME-$VERSION-backup rm -f $CWD/FILELIST.tmp FAILED="make_install NO FILES" elif [[ $FAILED = "CANCELLED" ]] ; then [[ "$INSTALLWATCH_BACKUP_PATH" ]] && rm -rf "${INSTALLWATCH_BACKUP_PATH}/no-backup" unset INSTALLWATCH_BACKUP_PATH unset LD_PRELOAD /sbin/ldconfig exit #true else # Commands have succeeded and we have files. # remove the no-backup directory [[ "$INSTALLWATCH_BACKUP_PATH" ]] && rm -rf "${INSTALLWATCH_BACKUP_PATH}/no-backup" # unset these INSTALLWATCH_BACKUP_PATH is unwritable otherwise unset INSTALLWATCH_BACKUP_PATH unset LD_PRELOAD # used by SHELL_INSTALL [[ $RESTORE_QUIET ]] && QUIET="YES" echo $BLUE"Installation Tracking - "$GREEN"Successful!"$NORMAL echo -n $BLUE"Processing FILELIST - "$NORMAL # Parse the full original installwatch log FILELIST.tmp # extract a list of the regular files cat $CWD/FILELIST.tmp | cut -f 3 | egrep -v "^(/dev|$CWD|/tmp)" | sort -u > $CWD/FILELIST # extract a list of symlinks cat $CWD/FILELIST.tmp | cut -f 4 | egrep -v "^(/dev|$CWD|/tmp)" | grep -v "#success" | sort -u >> $CWD/FILELIST # DIRLIST extract the directories to a separate DIRLIST so they can be handled apart cat $CWD/FILELIST.tmp | grep 'mkdir' | grep -v '#File exists' | grep '#success' | cut -f3 | sort -r -u >> $CWD/DIRLIST # DEBUG_FILELISTS if [[ $DEBUG_FILELISTS ]] ; then # get a list of the links created cat $CWD/FILELIST.tmp | grep 'symlink' | grep "#success" | cut -f4 | sort -u >> $CWD/LINKLIST # copy the full installwatch log cp $CWD/FILELIST.tmp $CWD/FILELIST.orig KEEP_FILELIST="YES" KEEP_DIRLIST="YES" fi # Delete the original list so we can recycle the name rm -f $CWD/FILELIST.tmp # sort and remove duplicates sort -u < $CWD/FILELIST | uniq | while read file; do ! [[ -d "$file" ]] && [[ -e "$file" ]] && echo $file >> $CWD/FILELIST.tmp done # remove more cruft cat $CWD/FILELIST.tmp | grep -v "$CWD" | grep -v "#success"> $CWD/FILELIST rm -f $CWD/FILELIST.tmp echo $GREEN"Done"$NORMAL # End parsed FILELIST creation # Now create the initial content in the PKG_DIR from the installed files echo -n $BLUE"Copying files "$NORMAL"into the PKG_DIR - " # Create $PKG_DIR$PRE_FIX is only created if make install succeeds mkdir -p $PKG_DIR$PRE_FIX cd / ; cat $CWD/FILELIST | while read i; do if ! [[ -d "$i" ]] && [[ -e "$i" ]] ; then (tar -cpf - "$i"| tar -f - -xvpC $PKG_DIR) 2> /dev/null 1> /dev/null fi done echo $GREEN"Done"$NORMAL # echo $BLUE"Backup Cleanup and Restore - "$NORMAL"" # Once we have the file list and have copied the installed files into PKG_DIR # immediately restore any files which were overwritten by the installation ls $BACKUP_DIR/$NAME-$VERSION-backup/* &> /dev/null if [[ $? -eq 0 ]] ; then # if [[ `ls $BACKUP_DIR/$NAME-$VERSION-backup/*` != "" ]] ; then if [[ `find $BACKUP_DIR/$NAME-$VERSION-backup -type f` != "" ]] ; then cd $BACKUP_DIR/$NAME-$VERSION-backup [[ "$QUIET" = "NO" ]] && echo -n $BLUE"Restoring backup files - "$NORMAL tar -cpf - . | tar -f - -xvpC / &> /dev/null [[ "$QUIET" = "NO" ]] && echo $GREEN"Done"$NORMAL fi fi # Now remove the files and links installed from the system, unless they were just backed up above. # Compare the list of installed file and links with the contents of the backup directory [[ "$QUIET" = "NO" ]] && echo -n $BLUE"Removing files installed "$NORMAL"by '$INSTALL_LINE' - " cd / ; cat $CWD/FILELIST | while read i; do if [ -e "$i" -o -L "$i" ] && ! [ -d "$i" ] ; then if [[ $QUIET = "YES" ]] ; then if ! [[ -e "$BACKUP_DIR/$NAME-$VERSION-backup/$i" ]] ; then ( rm -f $i ) 1> /dev/null fi else if ! [[ -e "$BACKUP_DIR/$NAME-$VERSION-backup/$i" ]] ; then ( rm -f $i ) fi fi fi done [[ "$QUIET" = "NO" ]] && echo $GREEN"Done "$NORMAL"" # Now remove any new directories from the system that were created by the INSTALL_LINE . # Our DIRLIST only includes directories which didn't exist before. cd / ; if [[ "`cat $CWD/DIRLIST`" != "" ]] ; then [[ "$QUIET" = "NO" ]] && echo -n $BLUE"Removing empty directories installed "$NORMAL"by '$INSTALL_LINE' - " cat $CWD/DIRLIST | while read i; do if [[ -d "$i" ]] ; then ( rm -rf $i ) fi done [[ "$QUIET" = "NO" ]] && echo $GREEN"Done "$NORMAL"" fi if [[ $KEEP_BACKUPS = "YES" ]] ; then ! [[ $BACKUPS_SAVE_DIR ]] && BACKUPS_SAVE_DIR="$CWD" #ls $BACKUP_DIR/$NAME-$VERSION-backup/* &> /dev/null #if [[ $? -eq 0 ]] ; then if [[ "`find $BACKUP_DIR/$NAME-$VERSION-backup -type f`" != "" ]] ; then cd $BACKUP_DIR/$NAME-$VERSION-backup echo -n $BLUE"Creating backup package - "$NORMAL tar -cpf - . | gzip -9 > "${BACKUPS_SAVE_DIR}/backup-`date +%m%d%Y%H%M`-pre-${SHORT_NAME}.tar.gz" rm -f $CWD/BACKUP.list echo $GREEN"Done"$NORMAL fi fi if [[ -d $BACKUP_DIR/$NAME-$VERSION-backup ]] ; then ls $BACKUP_DIR/$NAME-$VERSION-backup/* &> /dev/null if [[ $? -eq 0 ]] ; then cd $BACKUP_DIR ; if [[ "`find $BACKUP_DIR/$NAME-$VERSION-backup -type f`" != "" ]] ; then [[ "$QUIET" = "NO" ]] && echo -n $BLUE"Removing backup files - "$NORMAL rm -rf $NAME-$VERSION-backup 2> /dev/null 1> /dev/null else [[ "$QUIET" = "NO" ]] && echo -n $BLUE"Removing empty backup directories - "$NORMAL rm -rf $NAME-$VERSION-backup 2> /dev/null 1> /dev/null fi # rm -rf $BACKUP_DIR/$NAME-$VERSION-backup 2> /dev/null 1> /dev/null [[ "$QUIET" = "NO" ]] && echo $GREEN"Done"$NORMAL else cd $BACKUP_DIR ; [[ "$QUIET" = "NO" ]] && echo $BLUE"Removing unused backup directory - "$NORMAL rm -rf $NAME-$VERSION-backup 2> /dev/null 1> /dev/null fi fi ! [[ $KEEP_FILELIST = "YES" ]] && rm -f $CWD/FILELIST ! [[ $KEEP_DIRLIST = "YES" ]] && rm -f $CWD/DIRLIST [[ "$QUIET" = "NO" ]] && echo $BLUE"Running ldconfig - "$NORMAL"Updating shared library links" /sbin/ldconfig echo $BLUE"Safe installation - "$GREEN"Successful! "$NORMAL"Processing package content:" # echo $BLUE"Processing PKG_DIR content:"$NORMAL # this fi comes from the top... fi trap safe_user_cancel 2 fi } # end fake_install post_fake_install() { # Move any man-pages installed to usr/share/man by 'make install' if [[ -d $PKG_DIR/usr/share/man ]] && [[ "$CORRECT_MANS" = "YES" ]] ; then mkdir -p $PKG_DIR/usr/man cp -a $PKG_DIR/usr/share/man/* $PKG_DIR/usr/man/ rm -rf $PKG_DIR/usr/share/man echo $YELLOW"NOTICE! "$NORMAL"Makefile installed man-pages to /usr/share/man!" echo "Better 'policy' places them under /usr/man so they'll be moved there." echo "You can safely ignore this warning or try EXTRA_CONFIGS='--mandir=/usr/man'." MOVEMANS=1 fi # Move any info pages installed to usr/share/info by 'make install' if [[ -d $PKG_DIR/usr/share/info ]] && [[ "$CORRECT_MANS" = "YES" ]] ; then mkdir -p $PKG_DIR/usr/info cp -a $PKG_DIR/usr/share/info/* $PKG_DIR/usr/info/ rm -rf $PKG_DIR/usr/share/info echo $YELLOW"NOTICE! "$NORMAL"Makefile installed info pages to /usr/share/info!" echo "Better 'policy' places them under /usr/info so they'll be moved there." echo "You can safely ignore this warning or try EXTRA_CONFIGS='--infodir=/usr/info'." MOVEINFO=1 fi # Move any docs installed to usr/share/doc by 'make install' if [[ -d $PKG_DIR/usr/share/doc ]] && [[ "$CORRECT_DOCS" = "YES" ]] ; then mkdir -p $PKG_DIR/usr/doc cp -a $PKG_DIR/usr/share/doc/* $PKG_DIR/usr/doc/ rm -rf $PKG_DIR/usr/share/doc echo $YELLOW"NOTICE! "$NORMAL"Makefile installed docs to /usr/share/doc!" echo "Better 'policy' places them under /usr/doc so they'll be moved there." MOVEDOCS=1 fi # Below are advanced routines # shortcut switch for deleting all development files [[ $RUNTIME_ONLY = "YES" ]] && { DELETE_STATIC_LIBS="YES" DELETE_HEADERS="YES" } # Remove static libs? [[ $DELETE_STATIC_LIBS = "YES" ]] && { for dir in $LIB_DIRS ; do rm -f $PKG_DIR/$dir/*.a done } # Remove include header files and directories? [[ $DELETE_HEADERS = "YES" ]] && { for dir in $INC_DIRS ; do rm -rf $PKG_DIR/$dir done } } fix_pkg_perms() { if [[ "$FAILED" = "" ]] ; then if [[ "$CORRECT_PKG_PERMS" != "NO" ]] ; then chown -R root.root $PKG_DIR cd $PKG_DIR ; find . -type d -exec chmod 755 {} \; find . -type d -exec chown root.root {} \; for dir in $BIN_DIRS ; do [[ -d $dir ]] && chmod 755 $dir/* done fi fi } # Strip ELF Binaries and Libraries strip_bins() { if [[ "$FAILED" = "" ]] ; then if [[ $STRIP_BINS = "YES" ]] ; then cd $PKG_DIR ; find . | xargs -r file | grep "executable" | grep ELF 2> /dev/null 1> /dev/null && { echo -n $BLUE"Stripping ELF binaries - "$NORMAL ( cd $PKG_DIR find . | xargs -r file | grep "executable" | grep ELF | cut -f 1 -d : | xargs -r strip $BIN_STRIP_COMMAND 2> /dev/null ) echo $GREEN"Done"$NORMAL } || { ! [[ $QUIET = "YES" ]] && echo "No unstripped ELF binaries were found. "$BLUE"Skipping..."$NORMAL } fi if [[ $STRIP_LIBS = "YES" ]] ; then cd $PKG_DIR ; find . | xargs -r file | grep "not stripped" | grep shared | grep ELF 2> /dev/null 1> /dev/null && { echo -n $BLUE"Stripping shared libraries - "$NORMAL ( cd $PKG_DIR find . | xargs -r file | grep "not stripped" | grep shared | grep ELF | cut -f 1 -d : | xargs -r strip $LIB_STRIP_COMMAND 2> /dev/null ) echo $GREEN"Done"$NORMAL } || { ! [[ $QUIET = "YES" ]] && echo "No unstripped shared libraries found. "$BLUE"Skipping..."$NORMAL } find . | xargs -r file | grep "current ar archive" > /dev/null 1> /dev/null && { echo -n $BLUE"Stripping static archives - "$NORMAL ( cd $PKG_DIR find . | xargs -r file | grep "current ar archive" | cut -f 1 -d : | xargs -r strip $LIB_STRIP_COMMAND 2> /dev/null ) echo $GREEN"Done"$NORMAL } || { ! [[ $QUIET = "YES" ]] && echo "No unstripped static archives found. "$BLUE"Skipping..."$NORMAL } fi [[ $COMPRESS_BINS = "YES" ]] && compress_bins fi } # Internal routine -Do not call directly # compress_bins() { if [[ "$FAILED" = "" ]] ; then [[ $COMPRESS_BINS = "YES" ]] && [[ `which upx` ]] && { cd $PKG_DIR ; for d in $BIN_DIRS ; do [[ -d $d ]] && { for f in `ls $d` ; do [[ "`file $f |grep 'ELF'`" ]] && continue || { echo $CYAN"NOTE- "$NORMAL"Attempting to compress binary file ""$BLUE""$d/$f""$NORMAL" echo "upx won't compress files smaller than about 50K." echo "Be aware that files compressed with UPX normally show a corrupt header." [[ $QUIET != "YES" ]] && upx $d/$f \ || upx $d/$f 2> /dev/null 1> /dev/null } done } done } fi } # End compress_bins ## gzip man and info pages: compress_man_pages() { if [[ "$FAILED" = "" ]] ; then # Move man-pages badly placed by the 'operator' if [[ -d $PKG_DIR/usr/share/man ]] && [[ "$CORRECT_MANS" = "YES" ]] ; then mkdir -p $PKG_DIR$PRE_FIX/man cp -a $PKG_DIR$PRE_FIX/share/man $PKG_DIR$PRE_FIX rm -rf $PKG_DIR/usr/share/man [[ `ls $PKG_DIR/usr/share` = "" ]] && rm -rf $PKG_DIR/usr/share echo $CYAN"NOTICE! "$NORMAL"Moving man pages installed under usr/share/man to usr/man" #echo "For better directory conformance they'll be moved to usr/man." MOVEMANS=1 fi # Move info pages badly placed by the 'operator' if [[ -d $PKG_DIR/usr/share/info ]] && [[ "$CORRECT_MANS" = "YES" ]] ; then mkdir -p $PKG_DIR$PRE_FIX/info cp -a $PKG_DIR$PRE_FIX/share/info $PKG_DIR$PRE_FIX rm -rf $PKG_DIR/usr/share/info [[ `ls $PKG_DIR/usr/share` = "" ]] && rm -rf $PKG_DIR/usr/share echo $CYAN"NOTICE! "$NORMAL"Moving info pages installed under usr/share/info to usr/info" #echo "For better directory conformance they'll be moved to usr/info." MOVEINFO=1 fi [[ $SAVE_SPACE -gt 0 ]] && MAN_COMPRESS="bzip2" cd $PKG_DIR ; # decompress any existing zipped man-pages find . -path './*/man*/*' -name '*.gz' | xargs -r gunzip find . -path './*/man*/*' -name '*.bz2' | xargs -r bunzip2 # make sure the execute bit is not set find . -path './*/man*/*' -name '*.*' | xargs -r chmod 644 ## compress man pages: # find . -path './*/man*/*' -name '*.[1-9]' | xargs -r $MAN_COMPRESS find . -path './*/man*/*' -name '*.*' | xargs -r $MAN_COMPRESS find . -path './usr/info/*' -name '*.gz' | xargs -r gunzip find . -path './usr/info/*' -name '*.bz2' | xargs -r bunzip2 ## gzip info pages: # find . -path './usr/info/*' -name '*.info' -o -name '*.info-[0-9]' \ # -o -name '*.info-[0-9][0-9]' | xargs -r $MAN_COMPRESS find . -path './*/info/*' -name '*.*' | xargs -r $MAN_COMPRESS fi } create_docs() { if [[ "$FAILED" = "" ]] ; then cd $PKG_DIR ; if [[ `find . -type f` = "" ]] ; then echo $RED"ERROR! "$NORMAL"The package tree has no content!" echo "For now, we bail out from the top of create_docs." FAILED="EMPTY PKG_DIR" # exit else # Move docs badly placed by the script writer # note that only stuff under /usr gets moved. Other PRE_FIX's are not affected if [[ -e $PKG_DIR/usr/share/doc ]] && [[ "$CORRECT_DOCS" = "YES" ]] ; then mkdir -p $PKG_DIR/usr/doc cp -a $PKG_DIR/usr/share/doc/* $PKG_DIR/usr/doc/ rm -rf $PKG_DIR/usr/share/doc # if nothing else was installed under share then remove it [[ `ls $PKG_DIR/usr/share` = "" ]] && rm -rf $PKG_DIR/usr/share echo $CYAN"NOTICE! "$NORMAL"Moving docs installed under usr/share/doc to usr/doc." # echo "For better directory conformance they'll be moved to /usr/doc" MOVEDOCS=1 fi # if docs have been installed under if [[ -d $PKG_DIR/usr/doc ]] && [ `ls $PKG_DIR/usr/doc |wc -l` -eq 1 ] ; then if [[ ! -d $PKG_DIR/usr/doc/$NAME-$VERSION ]] && [[ "$CORRECT_DOCS" = "YES" ]] ; then DIRME=`ls $PKG_DIR/usr/doc` echo $CYAN"NOTICE! "$NORMAL"Renaming doc directory installed without a version number." # echo $BLUE"Renaming doc directory to: "$NORMAL"/usr/doc/$NAME-$VERSION for conformity. " mv $PKG_DIR/usr/doc/$DIRME $PKG_DIR/usr/doc/$NAME-$VERSION rm -rf $PKG_DIR/usr/doc/$DIRME MOVEDOCSVERSION=1 fi fi ! [[ -d $PKG_DIR/usr/doc/$NAME-$VERSION ]] && mkdir -p $PKG_DIR/usr/doc/$NAME-$VERSION if ! [[ $DOCLIST = "" ]] ; then echo -n $BLUE"Copying documents - "$NORMAL"Using user-supplied DOCLIST - " for doc in $DOCLIST ; do if [[ -f $CONFIG_DIR/$doc ]] ; then cp $CONFIG_DIR/$doc $PKG_DIR/usr/doc/$NAME-$VERSION/ 2> /dev/null 1> /dev/null elif [[ -f $SRC_DIR/$doc ]] ; then cp $SRC_DIR/$doc $PKG_DIR/usr/doc/$NAME-$VERSION/ 2> /dev/null 1> /dev/null fi done else echo -n $BLUE"Checking for standard documents - "$NORMAL for doc in ABOUT ANNOUNCE AUTHORS BUGS CHANGELOG CHANGES ChangeLog Changelog CONTRIBUTORS COPYING COPYRIGHT CREDITS FAQ FEATURES History HISTORY INSTALL LICENSE LSM MANIFEST NEWS README README.txt README.TXT README.* *.README Readme readme readme.txt THANKS TIPS TODO VERSION CONFIGURATION GPL LGPL License ; do if [[ -f $CONFIG_DIR/$doc ]] ; then cp -a $CONFIG_DIR/$doc $PKG_DIR/usr/doc/$NAME-$VERSION/ 2> /dev/null 1> /dev/null elif [[ -f $SRC_DIR/$doc ]] ; then cp -a $SRC_DIR/$doc $PKG_DIR/usr/doc/$NAME-$VERSION/ 2> /dev/null 1> /dev/null fi done fi if [[ "`find $PKG_DIR/usr/doc -type f`" != "" ]] ; then echo $GREEN"Done"$NORMAL cd $PKG_DIR/usr/doc ; if [[ `find . -type f -size 0` ]] && ! [[ "$CORRECT_DOCS" = "NO" ]] ; then echo $BLUE"Found empty documents - "$NORMAL"Removing zero-length files in /usr/doc." find . -type f -size 0 -exec rm -f {} \; fi cd $PKG_DIR ; find $PKG_DIR/usr/doc -type f -exec chmod 644 {} \; # be more thorough... for really weird installations find $PKG_DIR$PRE_FIX -path './*/doc/*' -type f -exec chmod 644 {} \; find $PKG_DIR$PRE_FIX -path './*/share/doc/*' -type f -exec chmod 644 {} \; find $PKG_DIR$PRE_FIX -path './*/share/$NAME/doc/*' -type f -exec chmod 644 {} \; advanced_docs else echo $YELLOW"Warning! "$NORMAL echo "No documents were found for the package." ! [[ $ALLOW_NO_DOCS ]] && FAILED="create_docs" # setting FAILED should bail us out alright fi fi fi } # Internal Routine advanced_docs() { # look for pkgconfig .pc files in sources if [[ `find $SRC_DIR -name '*.pc' 2> /dev/null` ]] ; then echo $BLUE"Found pkgconfig '*.pc' file - "$NORMAL"Copying into the PKG_DIR" mkdir -p $PKG_DIR/usr/share/pkgconfig find $SRC_DIR -name '*.pc' -exec cp -a {} $PKG_DIR/usr/share/pkgconfig \; find $PKG_DIR -name '*uninstalled.pc' -exec rm -f {} \; #echo $GREEN"Okay"$NORMAL fi # look for *.desktop file in sources: if [[ `find $SRC_DIR -name '*.desktop' 2> /dev/null` ]] ; then echo $BLUE"Found '*.desktop' file - "$NORMAL"Copying into the PKG_DIR" mkdir -p $PKG_DIR/usr/share/applications find $SRC_DIR -name '*.desktop' -exec cp -a {} $PKG_DIR/usr/share/applications \; #echo $GREEN"Okay"$NORMAL fi # look for *.desktop file in CWD also if [[ -e $CWD/*.desktop ]] ; then echo $BLUE"Found '*.desktop' file in CWD - "$NORMAL"Copying into the PKG_DIR" mkdir -p $PKG_DIR/usr/share/applications cat $CWD/*.desktop > $PKG_DIR/usr/share/applications/$NAME.desktop fi # Below are Advanced package handling routines [[ $SAVE_SPACE -gt 2 ]] && \ [[ -f $PKG_DIR/usr/doc/$NAME-$VERSION/COPYING ]] && \ { mkdir -p $PKG_DIR/usr/share/licenses mv $PKG_DIR/usr/doc/$NAME-$VERSION/COPYING $PKG_DIR/usr/share/licenses/COPYING cd $PKG_DIR/usr/doc/$NAME-$VERSION ln -sf ../../share/licenses/COPYING $COPYING } [[ $SAVE_SPACE -gt 1 ]] && \ { cd $PKG_DIR/usr/doc tar -cjf $NAME-$VERSION-doc.tbz $NAME-$VERSION cd $PKG_DIR rm -rf $PKG_DIR/usr/doc/$NAME-$VERSION } # purge_locales if [[ "$PURGE_LOCALES" = "YES" ]] ; then ! [[ $DONT_PURGE_LIST ]] && DONT_PURGE_LIST="/etc/src2pkg/DONT_PURGE.locales" ! [[ $LOCALE_LIST ]] && LOCALE_LIST="/etc/src2pkg/all-locales.txt" if [[ -e $DONT_PURGE_LIST ]] && [[ -e $LOCALE_LIST ]] ; then $BLUE"Purging locale files- "$NORMAL"Removing extra language files if found" for LOCALE_DIR in $LOCALE_DIRS ; do if [[ -d $PKG_DIR/$LOCALE_DIR ]] ; then for LOCALE in `/bin/ls $PKG_DIR/$LOCALE_DIR` ; do [[ "`grep -x ^$LOCALE $LOCALE_LIST`" ]] && \ [[ ! "`grep -x ^$LOCALE $DONT_PURGE_LIST`" ]] && \ [[ -d $PKG_DIR/$LOCALE_DIR/$LOCALE/LC_MESSAGES ]] && { /bin/rm -f `find $PKG_DIR/$LOCALE_DIR/$LOCALE -type f` /bin/rm -f `find $PKG_DIR/$LOCALE_DIR/$LOCALE/LC_MESSAGES -type f` /usr/bin/rmdir $PKG_DIR/$LOCALE_DIR/$LOCALE/LC_MESSAGES /usr/bin/rmdir $PKG_DIR/$LOCALE_DIR/$LOCALE } done fi done else echo $YELLOW"Notice! "$NORMAL"LOCALE_PURGE configuration files were not found." echo "See the documentation for how to set up locale purging. "$BLUE"Skipping..."$NORMAL fi fi } # End advanced_docs # Internal function called by make_description make_default_desc() { if [[ "$FAILED" = "" ]] ; then [[ ! $CREATOR ]] && CREATOR="src2pkg" touch $PKG_DIR/install/$PKG_DESC echo "# This file should have 11 lines with NAME:" >> $PKG_DIR/install/$PKG_DESC echo "# NAME must match exactly with the package name." >> $PKG_DIR/install/$PKG_DESC echo "# Lines beginning with '#' are okay above the description." >> $PKG_DIR/install/$PKG_DESC echo "# Finally, this file should end with a final blank line." >> $PKG_DIR/install/$PKG_DESC # use awk to align the guide starting at ':' (plus one space) echo -n "# " >> $PKG_DIR/install/$PKG_DESC HR_SPACES=`echo $NAME | wc -c| awk '{ for (i=1;substr ($0,i,1) ~ /[[:blank:]]/ ;i++); print substr ($0,i);}'` awk -v S=$HR_SPACES 'BEGIN {ORS=""; for (i=1; i < S; i++) print " ";}' >> $PKG_DIR/install/$PKG_DESC echo "|-----Use this guide to format your text with------------------|" >> $PKG_DIR/install/$PKG_DESC cat >> $PKG_DIR/install/$PKG_DESC << END $NAME: $NAME $NAME: $NAME: No description was given for this package. $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: Packaged by: ${CREATOR} END if [ "$EXEC_NAME" = "trackinstall" -o "$EXEC_NAME" = "src2pkg" ] && [[ ! $AUTO_SCRIPT ]] ; then # skip this if we are using trackinstall or src2pkg without AUTO_SCRIPT true else echo "A copy of it named new.$PKG_DESC will be placed in the current directory." echo "Edit, if needed, and copy or rename to $PKG_DESC for permanent use." cp $PKG_DIR/install/$PKG_DESC $CWD/new.$PKG_DESC fi fi } make_description() { if [[ "$FAILED" = "" ]] ; then cd $CWD; mkdir -p $PKG_DIR/install ! [[ $CREATOR ]] && CREATOR="src2pkg" if [[ -e $CWD/$PKG_DESC ]] ; then nol=`cat $CWD/$PKG_DESC | sed -e '/^$/d' -e '/^[ #]/d' | grep $NAME: | wc -l` if [[ $nol -ne 11 ]] ; then echo $YELLOW"WARNING! "$NORMAL"The supplied $PKG_DESC file is not valid." echo "You need 11 lines that begin with '$NAME:' for this package." REMAKE_DESC=1 fi if [[ $REMAKE_DESC ]] ; then if ! [[ -e $CWD/rej.$PKG_DESC ]] ; then echo "It will be renamed to rej.$PKG_DESC and a new one created." mv $CWD/$PKG_DESC $CWD/rej.$PKG_DESC else rm $CWD/$PKG_DESC fi echo $BLUE"Creating $PKG_DESC - "$NORMAL"Inserting new $PKG_DESC file in the package tree" make_default_desc else cat $CWD/$PKG_DESC > $PKG_DIR/install/$PKG_DESC && \ chmod 644 $PKG_DIR/install/$PKG_DESC && \ echo $BLUE"Verified $PKG_DESC found - "$NORMAL"Inserting in the package tree " fi else echo $BLUE"Creating $PKG_DESC - "$NORMAL"Inserting new $PKG_DESC file in the package tree" # echo $CYAN"NOTICE! "$NORMAL"No $PKG_DESC file was found for $NAME." # echo $BLUE"Creating $PKG_DESC - "$NORMAL"Inserting new $PKG_DESC file in the package tree" make_default_desc fi fi } # make_link_script make_install_script() { COUNT=1 LINE="`sed -n "$COUNT p" $1`" while [ ! "$LINE" = "" ]; do LINKGOESIN="`echo "$LINE" | cut -f 1 -d " "`" LINKGOESIN="`dirname $LINKGOESIN`" LINKNAMEIS="`echo "$LINE" | cut -f 1 -d ' '`" LINKNAMEIS="`basename "$LINKNAMEIS"`" LINKPOINTSTO="`echo "$LINE" | cut -f 3 -d ' '`" echo "( cd $LINKGOESIN ; rm -rf $LINKNAMEIS )" echo "( cd $LINKGOESIN ; ln -sf $LINKPOINTSTO $LINKNAMEIS )" COUNT=`expr $COUNT + 1` LINE="`sed -n "$COUNT p" $1`" done } #search for links and make link creation script if necessary make_doinst_links() { cd $PKG_DIR ; TMP=/tmp echo -n $BLUE"Searching for links in the PKG_DIR - "$NORMAL INST=`mktemp $TMP/src2pkg.XXXXXX` # This requires the ls from coreutils-5.0 (or newer): find . -type l -exec ls -l --time-style=long-iso {} \; | white_out | cut -f 8- -d ' ' | cut -b3- | tee $INST 1> /dev/null if [ ! "`cat $INST`" = "" ]; then echo $GREEN"Done"$NORMAL # echo -n $BLUE"Making link creation script - "$NORMAL make_install_script $INST | tee $CWD/doinst.links 1> /dev/null # echo $GREEN"Done"$NORMAL else echo "None found" fi rm -f $INST } # make_doinst() { if [[ "$FAILED" = "" ]] ; then # If a doinst.sh is present, assume that it is final and don't do anything if [[ -e $CWD/doinst.sh ]] ; then echo $BLUE"Found doinst.sh - "$NORMAL"Inserting in the package directory" cat $CWD/doinst.sh > $PKG_DIR/install/doinst.sh else if ! [[ $MAKE_LINKS = "NO" ]] ; then make_doinst_links fi if [[ -e $CWD/doinst.prepend ]] ; then echo $BLUE"Found doinst.prepend - "$NORMAL"Starting a new doinst.sh with its' contents" cat $CWD/doinst.prepend > $PKG_DIR/install/doinst.sh echo "" >> $PKG_DIR/install/doinst.sh fi if [[ -e $CWD/doinst.links ]] ; then echo $BLUE"Adding links to doinst.sh - "$NORMAL"Adding links-creation to the doinst.sh" cat $CWD/doinst.links >> $PKG_DIR/install/doinst.sh rm -f $CWD/doinst.links fi if [ -e $CWD/doinst.append ] ; then echo $BLUE"Found doinst.append - "$NORMAL"Adding its' contents to doinst.sh" cat $CWD/doinst.append >> $PKG_DIR/install/doinst.sh echo "" >> $PKG_DIR/install/doinst.sh fi if [ "$EXEC_NAME" = "trackinstall" -o "$EXEC_NAME" = "src2pkg" ] && [[ ! $AUTO_SCRIPT ]] ; then # skip this if we are using trackinstall or src2pkg without AUTO_SCRIPT true elif [ -e $PKG_DIR/install/doinst.sh ] ; then echo $BLUE"Copying new doinst.sh - "$NORMAL"Copying as new.doinst.sh into the current directory" echo "Be sure to check it. For permanent use, edit and/or rename to doinst.sh" cat $PKG_DIR/install/doinst.sh > $CWD/new.doinst.sh fi fi # Remove symbolic links if ! [[ $REMOVE_LINKS = "NO" ]] ; then cd $PKG_DIR ; if [[ `find . -type l` != "" ]] ; then echo $BLUE"Deleting symbolic links - "$NORMAL"Removing links from the package directory" find . -type l -exec rm -f {} \; fi fi # I dont't even know if this is right. if [[ -f $CWD/slack-requires ]] ; then cat $CWD/slack-requires > $PKG_DIR/install/slack-requires fi if [[ $SHOW_DEPS ]] ; then cd $PKG_DIR ; if [[ "`find . | xargs file | grep ELF | cut -f 1 -d : | xargs ldd | white_out | cut -f1 -d' '`" != "" ]] ; then echo $CYAN"Notice- "$NORMAL"The package depends on the following libraries:" find . | xargs file | grep ELF | cut -f 1 -d : | xargs ldd | white_out | cut -f1 -d' ' |grep -v "./" |sort -u fi fi fi } # tiny_make_package tiny_make_package() { # this straight out of makepkg TAR=tar-1.13 umask 022 $TAR --help 1> /dev/null 2> /dev/null if [ ! $? = 0 ]; then TAR=tar fi PACKAGE_NAME=$1 TARGET_NAME="`dirname $PACKAGE_NAME`" PACKAGE_NAME="`basename $PACKAGE_NAME`" TAR_NAME="`basename $PACKAGE_NAME .tgz`" echo $TAR cvf $TAR_NAME.tar . echo echo "Gzipping $TAR_NAME.tar to $TAR_NAME.tar.gz" gzip -9 $TAR_NAME.tar echo "Renaming $TAR_NAME.tar.gz to $PACKAGE_NAME" mv $TAR_NAME.tar.gz $PACKAGE_NAME if [ ! "$TARGET_NAME" = "." ]; then echo "Moving $PACKAGE_NAME to $TARGET_NAME" mv $PACKAGE_NAME $TARGET_NAME fi } # Create package make_package() { if [[ "$FAILED" = "" ]] ; then # first get rid of any zero-length files if ! [[ $FORCE_ZERO_LENGTH = "YES" ]] ; then cd $PKG_DIR ; if [[ `find . -type f -size 0` ]] ; then echo $CYAN"NOTICE! "$NORMAL" Zero-length files were found in the package tree These are" echo "usually blank documents, so we remove them by default. You can always force" echo "installation with: FORCE_ZERO_LENGTH=YES if any of them are really needed." echo "Zero-length files installed under /etc are allowed (some conf files are blank)." echo $BLUE"List of removed files:"$NORMAL for dir in `ls |grep -v etc` ; do ( cd $dir find . -type f -size 0 -exec echo `basename {}` \; find . -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 echo -n $BLUE"Making installable package - "$NORMAL # Build the package: if [[ $QUIET = "YES" ]] ; then cd $PKG_DIR ; tiny_make_package $PACKAGE &> /dev/null else cd $PKG_DIR ; echo "" tiny_make_package $PACKAGE fi if [[ $? -ne 0 ]] ; then echo "" echo $RED"FAILED! "$NORMAL"Creation of package has failed." FAILED="PACKAGE CREATION" else [[ $QUIET = "YES" ]] && echo $GREEN"Done"$NORMAL || echo "" echo $BLUE"Package Creation - "$GREEN"Successful!"$NORMAL" $PKG_NAME "$BLUE"Location:"$NORMAL echo $PACKAGE fi [[ $REALLY_INSTALL = "YES" ]] && really_install fi } # Internal Routine # really install the package only if REALLY_INSTALL="YES" really_install() { if [[ "$FAILED" = "" ]] && [[ $REALLY_INSTALL = "YES" ]] ; then echo $BLUE"Installing package $PKG_NAME"$NORMAL if [[ $QUIET="YES" ]] ; then $INSTALLPKG $PACKAGE 2> /dev/null 1> /dev/null else $INSTALLPKG $PACKAGE fi fi } post_process() { if [[ "$FAILED" = "" ]] ; then # The following produces if [[ $MAKE_REPORT = "YES" ]] ; then echo $BLUE"Creating REPORT: "$NORMAL"$SHORT_NAME.REPORT" REPORT_FILE="$CWD/$SHORT_NAME.REPORT" echo "Build Log for ""$SHORT_NAME" > $REPORT_FILE echo "" >> $REPORT_FILE echo -n "Uncompressed Package Size:" >> $REPORT_FILE echo "`du $PKG_DIR -ch |grep total |cut -f1`"" bytes" >> $REPORT_FILE echo "TGZ Package Contents:" >> $REPORT_FILE tar -tzf $PKG_DEST_DIR/$PKG_NAME >> $REPORT_FILE echo "" >> $REPORT_FILE echo "Permissions from PKG_DIR:" >> $REPORT_FILE cd $PKG_DIR && ls -lR |grep -v total >> $REPORT_FILE echo "" >> $REPORT_FILE echo "src2pkg script:" >> $REPORT_FILE cat $CWD/$EXEC_NAME >> $REPORT_FILE echo "" >> $REPORT_FILE if [[ -e $PKG_DIR/install/doinst.sh ]] ; then echo "doinst.sh contents:" >> $REPORT_FILE cat $PKG_DIR/install/doinst.sh >> $REPORT_FILE echo "" >> $REPORT_FILE fi # chk_pkg_deps() { echo "Package dependencies:" >> $REPORT_FILE cd $PKG_DIR ; if [[ "`find . | xargs file | grep ELF | cut -f 1 -d : | xargs ldd | white_out | cut -f1 -d' '`" != "" ]] ; then echo $CYAN"Notice- "$NORMAL"The package depends on the following installed libraries:" >> $REPORT_FILE find . | xargs file | grep ELF | cut -f 1 -d : | xargs ldd | white_out | cut -f1 -d' ' >> $REPORT_FILE fi fi #Create a DATABASE file. This is a replica of what installpkg puts in /var/log/packages when the package is installed if [[ $MAKE_DATABASE = "YES" ]] ; then echo $BLUE"Creating DATABASE: "$NORMAL"$SHORT_NAME.DATABASE" COMPRESSED=`gzip -l $PACKAGE | grep -v uncompressed_name | white_out | cut -f 1 -d ' '` COMPRESSED="`expr $COMPRESSED / 1024` K" UNCOMPRESSED=`gzip -l $PACKAGE | grep -v uncompressed_name | white_out | cut -f 2 -d ' '` UNCOMPRESSED="`expr $UNCOMPRESSED / 1024` K" DATABASE_FILE=$CWD/$SHORT_NAME.DATABASE echo "PACKAGE NAME: $NAME-$VERSION" > $DATABASE_FILE echo "COMPRESSED PACKAGE SIZE: $COMPRESSED" >> $DATABASE_FILE echo "UNCOMPRESSED PACKAGE SIZE: $UNCOMPRESSED" >> $DATABASE_FILE echo "PACKAGE LOCATION: $PKG_NAME" >> $DATABASE_FILE echo "PACKAGE DESCRIPTION:" >> $DATABASE_FILE cat $PKG_DIR/install/$PKG_DESC | grep -v '#' >> $DATABASE_FILE echo "FILE LIST:" >> $DATABASE_FILE tar -tzf $PACKAGE >> $DATABASE_FILE fi # cleanup build files if asked for -trackinstall sets this to PKG but lets be redundant if [[ $CLEANUP ]] ; then [[ $TRACK_INSTALL ]] && CLEANUP="PKG" echo -n $BLUE"Deleting build directories - "$NORMAL if [[ $CLEANUP = "SRC" ]] || [[ $CLEANUP = "ALL" ]] ; then if [[ -d $SRC_DIR ]] ; then echo -n "SRC_DIR " cd $SRC_BUILDS_DIR ; rm -rf $SRC_DIR_NAME fi if [[ -d $OBJ_DIR ]] ; then echo -n "OBJ_DIR " cd $SRC_BUILDS_DIR ; rm -rf $OBJ_DIR_NAME fi fi if [[ $CLEANUP = "PKG" ]] || [[ $CLEANUP = "ALL" ]] ; then if [[ -d $PKG_DIR ]] ; then echo -n "PKG_DIR " cd $PKG_BUILDS_DIR ; rm -rf $PKG_DIR_NAME fi fi echo $GREEN"Done"$NORMAL fi elif [[ $USER_CANCELLED ]] ; then echo $RED"Exiting! "$NORMAL"User cancelled operation." elif [[ $FAILED = "CANCELLED" ]] ; then echo $RED"Exiting! "$NORMAL exit 0 else echo `basename $0` $RED"FAILURE "$NORMAL"in $FAILED" exit 0 fi } # End post_process ## General Functions used internally # Eliminate whitespace function: white_out() { while read GAGA ; do echo $GAGA done } safe_user_cancel() { USER_CANCELLED=1 } trap_int() { echo echo $RED"*** OUCH!!! ***"$NORMAL emergency_restore FAILED="CANCELLED" exit } emergency_restore() { echo "Please don't interrupt during installation!" ls $BACKUP_DIR/$NAME-$VERSION-backup/* &> /dev/null if [[ $? -eq 0 ]] ; then # rm -rf $BACKUP_DIR/$NAME-$VERSION-backup/no-backup 2> /dev/null 1> /dev/null if [[ `ls $BACKUP_DIR/$NAME-$VERSION-backup/*` != "" ]] ; then cd $BACKUP_DIR/$NAME-$VERSION-backup echo "Emergency restoration of backup files!" tar -cpf - . | tar -f - -xvpC / # &> /dev/null echo "Backup file restoration complete." fi fi # echo $RED"Exiting!"$NORMAL # exit 1 } check_dirs1 () { for VAR_NAME in PKG_BUILDS_DIR PKG_DEST_DIR SRC_DIR PKG_DIR CWD; do if [[ "${VAR_NAME}" = "" ]] ; then echo $RED"FATAL! "$NORMAL"Null value given for critical src2pkg variable." echo "Please read the src2pkg documentation for help." exit 1 fi if [[ "${VAR_NAME}" = "/" ]] ; then echo $RED"FATAL! "$NORMAL"Root directory was given as a critical src2pkg variable," echo "or is the current directory. Please read the src2pkg documentation for help." exit 1 fi if [[ "${VAR_NAME}" = "${HOME}" ]] ; then if [[ "${VAR_NAME}" = "PKG_DEST_DIR" ]] ; then true else echo $RED"FATAL! "$NORMAL"Home directory was given as a critical src2pkg variable," echo "or is the current directory. Please read the src2pkg documentation for help." exit 1 fi fi # MISC_DIRS="boot etc dev home mnt opt proc root sys usr var usr/share usr/local" CRITICAL_DIRS="$BIN_DIRS $LIB_DIRS $INC_DIRS $LOCALE_DIRS $MAN_DIRS $MISC_DIRS" for SYSTEM_DIR in `echo $CRITICAL_DIRS 2> /dev/null` ; do SYSTEM_DIR="/""$SYSTEM_DIR" if [[ "${VAR_NAME}" = "$SYSTEM_DIR" ]] ; then echo $RED"FATAL! "$NORMAL"$SYSTEM_DIR was given as a critical src2pkg variable," echo "or is the current directory. Please read the src2pkg documentation for help." exit 1 fi done done } check_dirs2() { # Check for valid dirs first -could be done before, but here's where danger is if [[ "${SRC_BUILDS_DIR}" = "" ]] || [[ "${SRC_BUILDS_DIR}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid SRC_BUILDS_DIR." exit 1 fi if [[ "${PKG_BUILDS_DIR}" = "" ]] || [[ "${PKG_BUILDS_DIR}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid PKG_BUILDS_DIR." echo "Don't give a null PKG_BUILDS_DIR or use / !" exit 1 fi # this could be rechecked before fake_install for extra safety. if [[ "${PRE_FIX}" = "" ]] || [[ "${PRE_FIX}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid PRE_FIX." echo "Don't give a null PRE_FIX or use / !" exit 1 fi # Pretty hard to get here, but maybe I change the parsing later and this is really needed. if [[ "${SRC_DIR}" = "" ]] || [[ "${SRC_DIR}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid SRC_DIR." exit 1 fi if [[ "${PKG_DIR}" = "" ]] || [[ "${PKG_DIR}" = "/" ]] ; then echo $RED"FATAL ERROR "$NORMAL"Please give a valid PKG_DIR." exit 1 fi # This shouldn't happen either [[ "${PACKAGE}" = "" ]] || [[ "${PACKAGE}" = "/" ]] && echo $RED"ERROR "$NORMAL"Bad PACKAGE name!" && exit 1 } get_flags() { # # Compiler options # Using -O3 gives results similar to -Os. ! [[ $OPTIM_FLAGS ]] && OPTIM_FLAGS="-O2" # Optimize for smaller binaries [[ $OPTIMIZE_4_SIZE = "YES" ]] && OPTIM_FLAGS="-Os" # Machine architecture tuning flags and package ARCH if [[ "`uname -i`" = "i386" ]] ; then GCCVERSION=`gcc --version|grep 'GCC' |cut -f3 -d' '` if [[ `expr $GCCVERSION` > 3.4 ]] ; then CPU_TAG="-mtune" else CPU_TAG="-mcpu" fi # MARCH_FLAG="i486" CPU_FLAG="i686" # Could set dynamically : MARCH_FLAG= or CPU_FLAG="`uname -m`" # This ARCH is for the package name. ! [[ $ARCH ]] && ARCH="$MARCH_FLAG" TUNE_FLAGS="-march=$MARCH_FLAG $CPU_TAG=$CPU_FLAG" elif [[ "`uname -m`" = "ppc" ]] ; then ! [[ $ARCH ]] && ARCH="powerpc" TUNE_FLAGS="" else ! [[ $ARCH ]] && ARCH="unknown" TUNE_FLAGS="" fi ! [[ $STD_FLAGS ]] && STD_FLAGS="$OPTIM_FLAGS $TUNE_FLAGS" ! [[ $EXTRA_FLAGS ]] && EXTRA_FLAGS="" } # color get_color_options() { # Check for color prompting if [[ $COLOR_PROMPT = "YES" ]] ; then # ANSI COLORS CRE="" NORMAL="" # RED: Failure or error message RED="" # GREEN: Success message GREEN="" # YELLOW: Warnings YELLOW="" # BLUE: Summary messages BLUE="" # CYAN: Current Process CYAN="" fi } #####-----------------------------------------------------------------------------------------------------------------------