## /usr/libexec/src2pkg/FUNCTIONS ## src2pkg FUNCTIONS Version-1.8 ## src2pkg (formerly PkgBuild) - Copyright 2005-2007 Gilbert Ashley # 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 ! [[ $SRC2PKG_LIBDIR ]] && SRC2PKG_LIBDIR=/usr/libexec/src2pkg . $SRC2PKG_LIBDIR/create_package . $SRC2PKG_LIBDIR/pre_processing . $SRC2PKG_LIBDIR/text_functions ## The DEFINES file sets some very important default variables which are needed for ## the functions below. The code is kept separately because it mostly sets up the basic ## src2pkg behaviour that an advanced user might ever want to tweak. ## They are kept apart to avoid the user editing *this* FUNCTIONS file. ! [[ $DEFINES ]] && DEFINES=$SRC2PKG_LIBDIR/DEFINES if [[ -e $DEFINES ]] ; then source $DEFINES else echo "Warning! DEFINES file not found." FAILED="NO DEFINES" exit 0 fi ## Note that only the above code is executed when this file is 'sourced' by src2pkg, trackinstall ## or a *.src2pkg script. All the code below here is written as functions which are only read-in, ## that is they are saved in RAM and only executed when their name is called by the script or ## program. Each function must be supplied with certain variable values which are given by ## the script or program or as environmental variables. Most of the essential values are finalized ## in the function pre_process, so it should always be called first. ### The function do_all_processes summarizes the default execution order into a single ### command. Showing this here provides an overview of the standard list of commands. ### Most of the functions in this list also call other internal functions. But this list is the ### list used for a standard build and combined with the variables constitutes an API. ### src2pkg scripts which contain no custom code can be abbreviated by using ### this do_all_processes function instead of listing all 16 steps. ### 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. ### This function is not called, but may be used as an abbreviation in a TrackBuild script. 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. ## Most small or distracting internal functions are near the end of this file ## to make for better readability of the code in the most important places. ## The pre_process and post_process functions perform extra operations ## ## the following functions have been moved to /usr/libexec/src2pkg/pre_processing # pre_process # get_my_arch # translate underlines # download_url # find_source # make_dirs # ### unpack_source 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 # The disrpm program script uses 'hexdump' or 'od' to unpack either debian or rpm archives # works even better than rpm2cpio on older rpm archives if [[ $QUIET = "YES" ]] ; then disrpm -x $SOURCE &> /dev/null else echo "" disrpm -x $SOURCE fi elif [[ $QUIET = "YES" ]] ; then case $SOURCE in *.tar.bz2|*.tbz) ${TAR_STATIC} xjvf $SOURCE 1> /dev/null ;; *.tar.gz|*.tgz) ${TAR_STATIC} xzvf $SOURCE 1> /dev/null ;; esac else echo "" case $SOURCE in *.tar.bz2|*.tbz) ${TAR_STATIC} xjvf $SOURCE ;; *.tar.gz|*.tgz) ${TAR_STATIC} xzvf $SOURCE ;; esac 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 fi fi } # local function called by unpack_source. Like the name-guessing code this is # clumsy-looking code using good heuristics to sort out what the content of the archive is # rpm archives get their internal tarred compressed archives unpacked here even with mismatched names examine_source() { cd $SRC_BUILDS_DIR ; 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|*.tar) [[ -f $item ]] && FOUND_SOURCE=1 ;; esac done if [[ $BIN_CONTENT -eq 1 ]] ; then CONFIG_COMMAND="skip" ; INSTALL_COMMAND="skip" MAKE_COMMAND="copyall" else if [[ $(ls |wc -l) -eq 1 ]] ; then UNPACK_NAME=$(ls) if [[ -d $UNPACK_NAME ]] ; then [[ $DEBUG ]] && echo $BLUE"Found sources: "$NORMAL"$UNPACK_NAME"$NORMAL [[ $DEBUG ]] && echo $BLUE"Moving into SRC_DIR: "$NORMAL"$SRC_DIR_NAME" if [[ -e $UNPACK_NAME/$UNPACK_NAME ]] ; then mv $UNPACK_NAME/$UNPACK_NAME $UNPACK_NAME/$UNPACK_NAME.gotcha fi ( cd $UNPACK_NAME && mv ./* ../ ) cd $SRC_BUILDS_DIR/$SRC_DIR_NAME ; rm -rf $UNPACK_NAME # I found this gotcha when packaging the 'rar' program which unpacks to rar/rar if [[ -e $UNPACK_NAME.gotcha ]] ; then mv $UNPACK_NAME.gotcha $UNPACK_NAME fi OPEN_SOURCE=1 fi fi ignoremplease() { ls *.spec &> /dev/null if [[ $? = 0 ]] ; then 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|*.tar) # echo "Found archive: $item" case $item in *.tar.bz2) INT_EXT='tar.bz2' ;; *.tbz) INT_EXT='tbz' ;; *.tar.gz) INT_EXT='tar.gz' ;; *.tgz) INT_EXT='tgz' ;; *.tar) INT_EXT='tar' ;; esac if [[ $(echo $item |grep "patch") ]] || [[ $(echo $item |grep "diff") ]]; then echo -n $BLUE"Ignoring compressed patch: "$NORMAL"$item " else #UNPACK_NAME=$(tar -tf $item |head --n 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) ITEM_NAME=$(basename $item .tar) 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 " case $item in *.tar.gz|.tgz) UNPACK_NAME=$(${TAR_STATIC} -tzf $item |head -n 1 |cut -f1 -d'/') tar xzf $item &> /dev/null ;; *.tar.bz2|*.tbz) UNPACK_NAME=$(${TAR_STATIC} -tjf $item |head -n 1 |cut -f1 -d'/') tar xjf $item &> /dev/null ;; *.tar) UNPACK_NAME=$(${TAR_STATIC} -tf $item |head -n 1 |cut -f1 -d'/') tar xf $item &> /dev/null ;; esac if [[ $? = 0 ]] && [[ -d $UNPACK_NAME ]] ; then echo $GREEN"Done!"$NORMAL if [[ -e $UNPACK_NAME/$UNPACK_NAME ]] ; then mv $UNPACK_NAME/$UNPACK_NAME $UNPACK_NAME/$UNPACK_NAME.gotcha fi ( cd $UNPACK_NAME && mv ./* ../ && cd .. ) rm -rf $UNPACK_NAME if [[ -e $UNPACK_NAME.gotcha ]] ; then mv $UNPACK_NAME.gotcha $UNPACK_NAME fi rm -f $item UNPACK_SUCCESS=1 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 " case $item in *.tar.gz|.tgz) UNPACK_NAME=$(${TAR_STATIC} -tzf $item |head -n 1 |cut -f1 -d'/') ${TAR_STATIC} xzf $item &> /dev/null ;; *.tar.bz2|*.tbz) UNPACK_NAME=$(${TAR_STATIC} -tjf $item |head -n 1 |cut -f1 -d'/') ${TAR_STATIC} xjf $item &> /dev/null ;; *.tar) UNPACK_NAME=$(${TAR_STATIC} -tf $item |head -n 1 |cut -f1 -d'/') tar xf $item &> /dev/null ;; esac if [[ $? = 0 ]] && [[ -d $UNPACK_NAME ]] ; then echo $GREEN"Done!"$NORMAL if [[ -e $UNPACK_NAME/$UNPACK_NAME ]] ; then mv $UNPACK_NAME/$UNPACK_NAME $UNPACK_NAME/$UNPACK_NAME.gotcha fi echo $CYAN"Notice - "$NORMAL"Internal archive name mismatch: $UNPACK_NAME" ( cd $UNPACK_NAME && mv ./* ../ && cd .. ) rm -rf $UNPACK_NAME if [[ -e $UNPACK_NAME.gotcha ]] ; then mv $UNPACK_NAME.gotcha $UNPACK_NAME fi rm -f $item UNPACK_SUCCESS=1 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 } 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() { case $p in *.p0.diff*|*.p0.patch*) PATCH_OPTIONS="-p0" ;; *.p1.diff*|*.p1.patch*) PATCH_OPTIONS="-p1" ;; *.p2.diff*|*.p2.patch*) PATCH_OPTIONS="-p2" ;; *.p3.diff*|*.p3.patch*) PATCH_OPTIONS="-p3" ;; *) PATCH_OPTIONS="-p1" ;; esac 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 # 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 " Files Patched:" 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 |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 } ### 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 CONFIG_DIR=$SRC_DIR/$CONFIG_SUBDIR else for keydir in $SRC_DIR $SRC_DIR/src $SRC_DIR/Src $SRC_DIR/source $SRC_DIR/$NAME-$VERSION $SRC_DIR/$NAME $SRC_DIR/$NAMElib $SRC_DIR/lib$NAME $SRC_DIR/abi ; do 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 setup.py ; do if [[ -e $keydir/$keyfile ]] ; then CONFIG_SUBDIR=$keydir KEYFILE="$keyfile" break ; fi done if [[ $CONFIG_SUBDIR ]] ; then CONFIG_DIR=$keydir break ; fi if [[ $CONFIG_DIR ]] ; then CONFIG_DIR=$keydir break ; fi done fi [[ $DEBUG ]] && echo $BLUE"Using keyfile: "$NORMAL"$KEYFILE" ! [[ "$CONFIG_DIR" ]] && CONFIG_DIR=$SRC_DIR if [[ "$CONFIG_DIR" != "$SRC_DIR" ]] ; then FUNNY_SUBDIR=$(basename $CONFIG_DIR) echo $BLUE"Notice - "$NORMAL"The configuration files are in a subdirectory: $FUNNY_SUBDIR" ! [[ $USE_OBJ_DIR ]] && OBJ_DIR=$CONFIG_DIR fi ! [[ $USE_OBJ_DIR ]] && [[ ! $OBJ_DIR ]] && OBJ_DIR=$CONFIG_DIR # If there are GNUmakefile.in or GNUmakefile.am files *and* a Makefile we have to get # rid of the Makefile as it would take precedence over the generated GNUmakefile 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 ]] || [[ -e $CONFIG_DIR/GNUmakefile.in ]] ; then MAKEFILE="GNUmakefile" elif [[ -e $CONFIG_DIR/Makefile ]] || [[ -e $CONFIG_DIR/Makefile.am ]] || [[ -e $CONFIG_DIR/Makefile.in ]] ; then MAKEFILE="Makefile" fi if [[ $PATCHES_APPLIED ]] && [[ $SHOULD_AUTORECONF ]] && [[ "$AUTORECONF" != "NO" ]] ; then echo $CYAN"NOTICE - "$NORMAL"Patched .am, .ac or .in config files should be regenerated." echo " You can disable this with AUTORECONF=NO if necessary." echo -n $BLUE"Regenerating config files - "$NORMAL"Using: autoreconf -if " cd $CONFIG_DIR ; autoreconf --install --force &> /dev/null autoconf &> /dev/null echo $GREEN"Done!"$NORMAL fi if ! [[ -x $CONFIG_DIR/configure ]] ; then 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 " cd $CONFIG_DIR ; autoreconf -if &> /dev/null autoconf &> /dev/null echo $GREEN"Done!"$NORMAL fi fi fi 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 -a --force --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 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="../$SRC_DIR_NAME/configure" ; else CONFIG_COMMAND="../$SRC_DIR_NAME/$CONFIG_COMMAND" ; fi fi if ! [[ $CONFIG_COMMAND ]] ; then CONFIG_COMMAND="$CONFIG_DIR/configure" else CONFIG_COMMAND="$CONFIG_DIR/$CONFIG_COMMAND" fi # if no EXTRA_CONFIGS were given, look for defaults in an rpm spec file, if one is present if [[ $EXTRA_CONFIGS = "" ]] && [[ $AUTO_SCRIPT ]] ; then if [[ -e $SRC_DIR/$NAME.spec ]] ; then SPECFILE=$SRC_DIR/$NAME.spec elif [[ -e $SRC_DIR/$NAME.spec.in ]] ; then SPECFILE=$SRC_DIR/$NAME.spec.in fi if [[ $SPECFILE != "" ]] ; then FOREIGN_CONFIGS=$(cat $SPECFILE | get_rpm_config) [[ $FOREIGN_CONFIGS = "" ]] && FOREIGN_CONFIGS=$(cat $SPECFILE | get_rpm_config2) [[ $FOREIGN_CONFIGS = "" ]] && FOREIGN_CONFIGS=$(cat $SPECFILE | get_rpm_cflags_config) elif [[ -e $SRC_DIR/debian/rules ]] ; then SPECFILE=$SRC_DIR/debian/rules FOREIGN_CONFIGS=$(cat $SPECFILE | get_deb_config) fi if [[ $FOREIGN_CONFIGS != "" ]] ; then echo"" echo $BLUE"Found default configuration options in: "$NORMAL"$(basename $SPECFILE)" fi EXTRA_CONFIGS=$FOREIGN_CONFIGS fi # if using interactive mode, pause and get config options from the user. Use the FOREIGN_CONFIGS from above if available if [[ "$QUERY_FOR_EXTRA_CONFIGS" = "YES" ]] ; then echo $BLUE"Running interactive configuration - "$NORMAL cd $CONFIG_DIR ; $CONFIG_COMMAND --help # show this prompt again since the --help command throws the first one way off the screen if [[ $FOREIGN_CONFIGS != "" ]] ; then DEFAULT_CONFIGS="$FOREIGN_CONFIGS" echo $BLUE"Default configuration options were found in:"$NORMAL $(basename $SPECFILE) fi echo $BLUE"Interactive mode: "$NORMAL"If you need to pass extra arguments to the configure" echo " script you can do so now. Using SHIFT+PGUP lets you scroll up to see the" echo " available options. Don't pass the '--prefix=??' as it is supplied separately." echo " Just press ENTER to accept the default of: $DEFAULT_CONFIGS" read NEW_CONFIGS if [[ $NEW_CONFIGS != "" ]] ; then EXTRA_CONFIGS=$NEW_CONFIGS fi #echo "" 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 # try this by default -remove stale files -probably should use find for .deps [[ -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 # run the configure script if [[ $QUIET = "YES" ]] ; then cd $OBJ_DIR ; echo $BLUE"Configuring sources using:"$NORMAL echo " CFLAGS=$FLAG_LINE ./$(basename $CONFIG_COMMAND) $CONFIG_ARGS" export CFLAGS=$FLAG_LINE $CONFIG_COMMAND $CONFIG_ARGS &> /dev/null else cd $OBJ_DIR ; echo "Now trying to configure sources using:" echo " CFLAGS=$FLAG_LINE ./$(basename $CONFIG_COMMAND) $CONFIG_ARGS" echo "Messages from configure:" export CFLAGS=$FLAG_LINE $CONFIG_COMMAND $CONFIG_ARGS fi if [[ $? -eq 0 ]] ; then echo $BLUE"Configuration has been - "$GREEN"Successful!"$NORMAL if [[ "$CONFIRM_BUILD" = "YES" ]] ; then echo -n $BLUE"Continue with the build? [ y or n ] > "$NORMAL read ANSWER if [ $ANSWER == "n" ]; then echo $RED"CANCELLED! "$NORMAL"Quitting at users request." FAILED="CANCELLED interactively" exit 0 fi fi 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." 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 autoconf configuration - "$NORMAL"Continuing since we found a "$BLUE"$MAKEFILE"$NORMAL cd $CONFIG_DIR ; if [[ -f $CONFIG_DIR/CMakeLists.txt ]] && [[ "$(grep 'cmake' $MAKEFILE)" != "" ]] ; then if ! [[ $FLAG_LINE ]] ; then FLAG_LINE="$(echo $STD_FLAGS $EXTRA_FLAGS |white_out)" #export CFLAGS=$FLAG_LINE fi export CFLAGS=$FLAG_LINE echo $BLUE"Found 'cmake' configuration - "$NORMAL"Configuring using: cmake . -DCMAKE_INSTALL_PREFIX=/${PRE_FIX}" if ! [[ $(which cmake) ]] ; then echo $RED"FAILED! "$NORMAL"No cmake found in path. "$RED"Exiting..."$NORMAL FAILED="CONFIGURATION - Missing cmake" elif [[ "$PRE_FIX" != "usr/local" ]] ; then if [[ $QUIET = "YES" ]] ; then # this is what you need to change the default PREFIX for cmake non-interactively cmake . -DCMAKE_INSTALL_PREFIX=/${PRE_FIX} &> /dev/null else cmake . -DCMAKE_INSTALL_PREFIX=/${PRE_FIX} fi else if [[ $QUIET = "YES" ]] ; then cmake . &> /dev/null else cmake . fi fi elif [[ $(find . -name "$MAKEFILE" |wc -l) -ge 1 ]] ; then # We have at least one Makfile so we continue echo $BLUE"Skipping autoconf configuration:"$NORMAL echo $BLUE"Continuing - "$NORMAL"We found at least one "$BLUE"$MAKEFILE"$NORMAL fi elif [[ -f $CONFIG_DIR/setup.py ]] ; then #MAKEFILE="setup.py" MAKE_COMMAND="./setup.py build" INSTALL_LINE="./setup.py install" else echo $BLUE"Skipping configure_source - "$NORMAL fi # Some configure routines don't properly set --prefix so we correct the Makefiles here if [[ "$PRE_FIX" != "usr/local" ]] && [[ $(find . -name "$MAKEFILE" |wc -l) -ge 1 ]] ; then if [[ "$(grep 'PREFIX' $MAKEFILE |grep 'usr/local' )" != "" ]] \ || [[ "$(grep 'prefix' $MAKEFILE |grep 'usr/local' )" != "" ]] \ || [[ "$(grep 'DEST' $MAKEFILE |grep 'usr/local' )" != "" ]] \ || [[ "$(grep 'INSTALLROOT' $MAKEFILE |grep 'usr/local' )" != "" ]] ; then echo $CYAN"NOTICE - "$NORMAL"Correcting $MAKEFILE(s) with incorrect hard-coded prefix." find . -name "$MAKEFILE" |xargs sed -i -e s:"/usr/local":"/$PRE_FIX": fi 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() { 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" elif [[ -e $OBJ_DIR/setup.py ]] ; then MAKEFILE="./setup.py" ! [[ $MAKE_COMMAND ]] && MAKE_COMMAND="'./setup.py build'" ! [[ $INSTALL_RULE ]] && INSTALL_LINE="./setup.py install" fi } ### compile_source compile_source() { if [[ "$FAILED" = "" ]] ; then if [[ "$MAKE_COMMAND" = "skip" ]] ; then echo $BLUE"Skipping compile_source - "$NORMAL elif [[ "$MAKE_COMMAND" = "copyall" ]] ; then # examine_source sets MAKE_COMMAND to copyall for sources with binary content. We copy it here directly to PKG_DIR 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 DOCPATH=$(find . -type d -name doc) if [[ -d $DOCPATH ]] ; then cd $DOCPATH ; DOCDIR=$(ls) else mkdir -p $SRC_DIR/usr/doc/$NAME-$VERSION DOCPATH="usr/doc" DOCDIR="$NAME-$VERSION" fi 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 installed for the package." >> $DOCPATH/$DOCDIR/README fi [[ -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 # this is the routine for compiling sources ! [[ $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 clean 1> /dev/null 2> /dev/null $MAKE_COMMAND &> /dev/null else cd $OBJ_DIR ; echo $BLUE"Running 'make clean':"$NORMAL make clean 2> /dev/null echo $BLUE"Compiler Messages:"$NORMAL $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 ; 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 } fake_install() { if [[ "$INSTALL_COMMAND" = "skip" ]] ; then echo $BLUE"Skipping fake_install - "$NORMAL elif [[ "$FAILED" = "" ]] ; then ! [[ $OBJ_DIR ]] && OBJ_DIR=$SRC_DIR find_makefile # install using an install.sh script or other named script # 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 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 [[ "$QUIET" = "YES" ]] && RESTORE_QUIET=1 QUIET="NO" elif [[ ! $MAKEFILE ]] ; then [[ "$QUIET" = "YES" ]] && RESTORE_QUIET=1 QUIET="NO" fi # if the INSTALL_LINE was given to src2pkg, split it into INSTALL_COMMAND # and INSTALL_RULE. This lets us insert the DESTDIR if needed if [[ $INSTALL_LINE ]] ; then INSTALL_LINE=$(echo $INSTALL_LINE |white_out) if [[ $(echo $INSTALL_LINE |grep " ") ]] ; then INSTALL_COMMAND=$(echo $INSTALL_LINE |cut -f1 -d' ') INSTALL_RULE=$(echo $INSTALL_LINE |cut -f2- -d' ') fi elif [[ $INSTALL_COMMAND ]] && [[ $INSTALL_RULE ]] ; then true else FAILED="NO INSTALL_LINE" echo $RED"FAILED!! "$NORMAL"No INSTALL_LINE given." exit fi if [ "$INSTALL_TYPE" = "DESTDIR" ] ; then # make sure the Makefile supports DESTDIR or revert to JAIL method if [[ "$(grep 'DESTDIR' ${OBJ_DIR}/${MAKEFILE} 2> /dev/null)" = "" ]] ; then echo $YELLOW"WARNING! "$NORMAL"DESTDIR is not supported for this package." echo $CYAN"NOTICE - "$NORMAL"Reverting to JAIL installation." INSTALL_TYPE=JAIL fi fi if [ "$INSTALL_TYPE" = "DESTDIR" ] ; then . $SRC2PKG_LIBDIR/destdir_install install_to_destdir elif [ "$INSTALL_TYPE" = "REAL" ] ; then . $SRC2PKG_LIBDIR/real_root_install install_to_real_root elif [ "$INSTALL_TYPE" = "JAIL" ] ; then . $SRC2PKG_LIBDIR/jail_root_install install_to_jail_root fi rm -f $CWD/FILELIST.tmp ## 2 trap safe_user_cancel 2 post_fake_install fi } # end fake_install post_fake_install() { # shortcut switch for deleting all development files [[ $RUNTIME_ONLY = "YES" ]] && { DELETE_STATIC_LIBS="YES" DELETE_HEADERS="YES" } # Remove only static libs [[ $DELETE_STATIC_LIBS = "YES" ]] && { for dir in $LIB_DIRS ; do rm -f $PKG_DIR/$dir/*.a done } # Remove only 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 echo -n $BLUE"Correcting package permissions - "$NORMAL if [ "$(whoami)" = "root" ] ; then chown -R root:root $PKG_DIR else chown -R $OWNER:$GROUP $PKG_DIR fi cd $PKG_DIR ; find . -type d -exec chmod 755 {} \; [[ -d $PKG_DIR/tmp ]] && chmod 1755 $PKG_DIR/tmp [[ -d $PKG_DIR/var/tmp ]] && chmod 1755 $PKG_DIR/var/tmp find . | xargs -r file | grep "executable" | grep ELF | cut -f 1 -d : | xargs -r chmod 755 2> /dev/null echo $GREEN"Done"$NORMAL fi fi } # Strip ELF Binaries and Libraries strip_bins() { if [[ "$FAILED" = "" ]] ; then if [[ $STRIP_BINS = "YES" ]] ; then cd $PKG_DIR ; if [[ $(find . | xargs -r file | grep "executable" | grep ELF) ]] ; then 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 else ! [[ $QUIET = "YES" ]] && echo "No unstripped ELF binaries were found. "$BLUE"Skipping..."$NORMAL fi fi if [[ $STRIP_LIBS = "YES" ]] ; then cd $PKG_DIR ; if [[ $(find . | xargs -r file | grep "current ar archive") ]] ; then echo -n $BLUE"Stripping static archives - "$NORMAL 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 else ! [[ $QUIET = "YES" ]] && echo "No unstripped static archives found. "$BLUE"Skipping..."$NORMAL fi if [[ $(find . | xargs -r file | grep "not stripped" | grep shared | grep ELF ) ]] \ || [[ $(find . | xargs -r file | grep "not stripped" | grep relocatable | grep ELF ) ]] ; then echo -n $BLUE"Stripping shared libraries - "$NORMAL find . | xargs -r file | grep "shared object" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs -r strip $LIB_STRIP_COMMAND 2> /dev/null find . | xargs -r file | grep "relocatable" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs -r strip $LIB_STRIP_COMMAND 2> /dev/null echo $GREEN"Done"$NORMAL else ! [[ $QUIET = "YES" ]] && echo "No unstripped shared libraries found. "$BLUE"Skipping..."$NORMAL fi fi [[ $COMPRESS_BINS = "YES" ]] && compress_bins fi } # compress binaries with upx if requested and available 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 } 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" else # Move docs badly placed by the script writer -note that only stuff under /usr/share gets moved if [[ -d $PKG_DIR/usr/share/doc ]] && [[ "$CORRECT_DOCS" = "YES" ]] ; then [[ -L $PKG_DIR/usr/doc ]] && rm -f $PKG_DIR/usr/doc echo $CYAN"NOTICE! "$NORMAL"Moving docs installed under usr/share/doc to usr/doc." ( cd $PKG_DIR/usr/share && mv doc .. &> /dev/null ) # if nothing else was installed under share then remove it [[ $(ls $PKG_DIR/usr/share 2> /dev/null) = "" ]] && rm -rf $PKG_DIR/usr/share fi # if docs have been installed without a version number correct it 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." mv $PKG_DIR/usr/doc/$DIRME $PKG_DIR/usr/doc/$NAME-$VERSION &> /dev/null 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 LICENCE 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 else if [[ -d $SRC/doc ]] ; then cp -a $SRC/doc/*.txt $SRC/doc/*.doc $SRC/doc/*.ps \ $SRC/doc/*.html $SRC/doc/*.htm $PKG_DIR/usr/doc/$NAME-$VERSION/ 1> /dev/null 2> /dev/null echo $GREEN"Done"$NORMAL elif [[ -d $SRC/docs ]] ; then cp -a $SRC/docs/*.txt $SRC/docs/*.doc $SRC/docs/*.ps \ $SRC/docs/*.html $SRC/docs/*.htm $PKG_DIR/usr/docs/$NAME-$VERSION/ 1> /dev/null 2> /dev/null echo $GREEN"Done"$NORMAL fi fi if [[ "$(find $PKG_DIR/usr/doc -type f)" = "" ]] ; then echo $YELLOW"Warning! "$NORMAL"No documents were found for the package." else 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 fi fi fi } # Internal Routine advanced_docs() { # look for pkgconfig .pc files in sources if [[ $(find $SRC_DIR -maxdepth 1 -name '*.pc' 2> /dev/null) ]] ; then echo $BLUE"Found pkgconfig '*.pc' file - "$NORMAL"Copying into the PKG_DIR" mkdir -p $PKG_DIR/usr/lib/pkgconfig find $SRC_DIR -maxdepth 1 -name '*.pc' -exec cp -a {} $PKG_DIR/usr/lib/pkgconfig \; find $PKG_DIR -maxdepth 1 -name '*uninstalled.pc' -exec rm -f {} \; fi # look for *.desktop file in sources: if [[ $(find $SRC_DIR -maxdepth 1 -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 -maxdepth 1 -name '*.desktop' -exec cp -a {} $PKG_DIR/usr/share/applications \; fi # look for *.desktop file in CWD also if [[ $(find $CWD -maxdepth 1 -name '*.desktop' 2> /dev/null) ]] ; then echo $BLUE"Found '*.desktop' file in CWD - "$NORMAL"Copying into the PKG_DIR" mkdir -p $PKG_DIR/usr/share/applications find $CWD -maxdepth 1 -name '*.desktop' -exec cp -a {} $PKG_DIR/usr/share/applications \; &> /dev/null 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_STATIC} -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 ]] && { rm -f $(find $PKG_DIR/$LOCALE_DIR/$LOCALE -type f) rm -f $(find $PKG_DIR/$LOCALE_DIR/$LOCALE/LC_MESSAGES -type f) rmdir $PKG_DIR/$LOCALE_DIR/$LOCALE/LC_MESSAGES 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 ### compress_man_pages compress_man_pages() { if [[ "$FAILED" = "" ]] ; then # Movebadly placed man-pages if [[ -d $PKG_DIR/usr/share/man ]] && [[ "$CORRECT_MANS" = "YES" ]] ; then [[ -L $PKG_DIR/usr/man ]] && rm -f $PKG_DIR/usr/man ( cd $PKG_DIR/usr/share && mv man .. &> /dev/null ) rm -rf $PKG_DIR/usr/share/man echo $CYAN"NOTICE! "$NORMAL"Moving man pages installed under usr/share/man to usr/man" fi # Move badly placed info pages if [[ -d $PKG_DIR/usr/share/info ]] && [[ "$CORRECT_MANS" = "YES" ]] ; then [[ -L $PKG_DIR/usr/info ]] && rm -f $PKG_DIR/usr/info ( cd $PKG_DIR/usr/share && mv info .. &> /dev/null ) rm -rf $PKG_DIR/usr/share/info echo $CYAN"NOTICE! "$NORMAL"Moving info pages installed under usr/share/info to usr/info" fi # remove the info/dir file if present [[ -e $PKG_DIR/usr/info/dir ]] && rm -f $PKG_DIR/usr/info/dir # remove the usr/share dir if empty [[ $(ls $PKG_DIR/usr/share 2> /dev/null) = "" ]] && rm -rf $PKG_DIR/usr/share # make a more thorough check for man-pages if there still aren't any in the package if ! [[ -d $PKG_DIR/usr/man ]] ; then for mansuffix in 1 3 5 8 ; do if [[ -f ${SRC_DIR}/${NAME}.${mansuffix} ]] ; then mkdir -p $PKG_DIR/usr/man/man$mansuffix cp $SRC_DIR/$NAME.$mansuffix $PKG_DIR/usr/man/man$mansuffix FOUND_MANS=1 fi if [[ -f ${SRC_DIR}/debian/${NAME}.${mansuffix} ]] ; then mkdir -p $PKG_DIR/usr/man/man$mansuffix cp $SRC_DIR/debian/$NAME.$mansuffix $PKG_DIR/usr/man/man$mansuffix FOUND_MANS=1 fi done if [[ -f $SRC_DIR/$NAME.man ]] ; then mkdir -p $PKG_DIR/usr/man/man1 cp $SRC_DIR/$NAME.man $PKG_DIR/usr/man/man1/$NAME.1 FOUND_MANS=1 fi if [[ $FOUND_MANS ]] ; then echo $CYAN"NOTICE - "$NORMAL"No man-pages were installed by the Makefile for $NAME." echo " But, man-pages were found in the sources and copied to the PKG_DIR." fi fi [[ $SAVE_SPACE -gt 0 ]] && MAN_COMPRESS="bzip2" cd $PKG_DIR ; # decompress any existing zipped man-pages, make non-executable and re-compress find . -path './*/man*/*' -name '*.gz' | xargs -r gunzip find . -path './*/man*/*' -name '*.bz2' | xargs -r bunzip2 find . -path './*/man*/*' -name '*.*' | xargs -r chmod 644 # find . -path './*/man*/*' -name '*.[1-9]' | xargs -r $MAN_COMPRESS find . -path './*/man*/*' -name '*.*' | xargs -r $MAN_COMPRESS && MANSCOMPRESSED=1 # do the same for info pages find . -path './usr/info/*' -name '*.gz' | xargs -r gunzip find . -path './usr/info/*' -name '*.bz2' | xargs -r bunzip2 find . -path './usr/info/*' -name '*.*' | xargs -r chmod 644 # 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 && INFOSCOMPRESSED=1 if [[ $(find . -path './*/man*/*' -name '*.*') != "" ]] ; then echo $BLUE"Compressing man pages - "$GREEN"Done"$NORMAL fi if [[ $(find . -path './*/info/*' -name '*.*') != "" ]] ; then echo $BLUE"Compressing info pages - "$GREEN"Done"$NORMAL fi fi } ### These functions have been moved out to /usr/libexec/src2pkg/create_package # make_default_desc # make_description # make_install_script # make_doinst_links # make_doinst # tiny_make_package # make_package # mini_installpkg # really_install # 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_STATIC} -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" DATABASE_FILE=$CWD/$SHORT_NAME.DATABASE make_database 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-$BUILD$SIG/* &> /dev/null if [[ $? -eq 0 ]] ; then rm -rf $BACKUP_DIR/$NAME-$VERSION-backup-$BUILD$SIG/no-backup 2> /dev/null 1> /dev/null if [[ $(ls $BACKUP_DIR/$NAME-$VERSION-backup-$BUILD$SIG/*) != "" ]] ; then cd $BACKUP_DIR/$NAME-$VERSION-backup-$BUILD$SIG echo "Emergency restoration of backup files!" ${TAR_STATIC} -cpf - . | ${TAR_STATIC} -f - -xvpC / # &> /dev/null echo "Backup file restoration complete." fi fi } get_rpm_config() { LINE_COUNT=0 FIRST_LINE=0 LAST_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=$LINE if [[ $FIRST_LINE -ne 0 ]] && [[ $LINE_COUNT -eq $FIRST_LINE ]] ; then echo $CHUNK elif [[ ${CHUNK:0:10} = "%configure" ]] && [[ $FIRST_LINE -eq 0 ]] ; then if [[ ${CHUNK:10} != "" ]] ; then CHUNK=${CHUNK/\%configure/} CHUNK=${CHUNK/--prefix=/} CHUNK=${CHUNK/\%\{_prefix\}/} echo $CHUNK fi FIRST_LINE=$(( $LINE_COUNT )) elif [[ ${CHUNK:0:1} = "%" ]] || [[ ${CHUNK:0:1} != " " ]] && [[ $FIRST_LINE -ne 0 ]] ; then LAST_LINE=$(( $LINE_COUNT -1 )) break elif [[ $FIRST_LINE -ne 0 ]] && [[ $LAST_LINE -eq 0 ]] ; then if [[ "$CHUNK" != "" ]] ; then CHUNK=${CHUNK/\%configure/} CHUNK=${CHUNK/--prefix=/} CHUNK=${CHUNK/\%\{_prefix\}/} echo $CHUNK fi fi done } get_rpm_config2() { FOUND_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=$LINE if [[ ${CHUNK:0:11} = "./configure" ]] && [[ $FOUND_LINE -eq 0 ]] ; then # the configure options are everything to the right of ./configure CHUNK=${CHUNK#*./configure} # remove the --prefix stuff CHUNK=${CHUNK/--prefix=/} CHUNK=${CHUNK/\%\{_prefix\}/} # if --prefix was hard coded above then it still remains (/usr) # so skip to the next '--'option to the right CHUNK=--${CHUNK#*--} # substitute these rpm options with slackware defaults CHUNK=${CHUNK/\%\{_infodir\}/\/usr\/info} CHUNK=${CHUNK/\%\{_mandir\}/\/usr\/man} CHUNK=${CHUNK/\%\{_datadir\}/\/usr\/lib} CHUNK=${CHUNK/\%\{_sysconfdir\}/\/etc} echo $CHUNK FOUND_LINE=1 fi done } get_rpm_cflags_config() { FOUND_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=$LINE if [[ ${CHUNK:0:7} = "CFLAGS=" ]] && [[ $FOUND_LINE -eq 0 ]] ; then if [[ ${CHUNK:8} != "" ]] ; then # get the CFLAGS -everything to the left of ./configure CFLAGS=${CHUNK%./configure*} # remove these variables which we don't use CFLAGS=${CFLAGS/\$RPM_OPT_FLAGS /} CFLAGS=${CFLAGS/\$EXTRACFLAGS/} # the configure options are everything to the right of ./configure CHUNK=${CHUNK#*./configure} # remove the --prefix stuff CHUNK=${CHUNK/--prefix=/} CHUNK=${CHUNK/\%\{_prefix\}/} # if --prefix was hard coded above then it still remains (/usr) # so skip to the next '--'option to the right CHUNK=--${CHUNK#*--} # substitute these rpm options with slackware defaults CHUNK=${CHUNK/\%\{_infodir\}/\/usr\/info} CHUNK=${CHUNK/\%\{_mandir\}/\/usr\/man} CHUNK=${CHUNK/\%\{_datadir\}/\/usr\/lib} CHUNK=${CHUNK/\%\{_sysconfdir\}/\/etc} echo $CHUNK fi FOUND_LINE=1 fi done } get_deb_config() { FOUND_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=$LINE #echo $LINE if [[ $(echo $CHUNK |grep "./configure" ) != "" ]] && [[ $FOUND_LINE -eq 0 ]] ; then # the configure options are everything to the right of ./configure CHUNK=${CHUNK#*./configure} # remove the --host stuff CHUNK=${CHUNK/--host=/} CHUNK=${CHUNK/\$\(DEB_HOST_GNU_TYPE\)/} # remove the --host stuff CHUNK=${CHUNK/--build=/} CHUNK=${CHUNK/\$\(DEB_BUILD_GNU_TYPE\)/} # remove the --prefix stuff CHUNK=${CHUNK/--prefix=\/usr\/} CHUNK=${CHUNK/--prefix=\/usr} CHUNK=${CHUNK/--prefix=/} # if --prefix was hard coded above then it still remains (/usr) # so skip to the next '--'option to the right [[ "$CHUNK" != "" ]] && CHUNK=--${CHUNK#*--} # substitute these debian options with slackware defaults CHUNK=${CHUNK/\$\$\{prefix\}/\/$PRE_FIX} CHUNK=${CHUNK/usr\/share\/info/usr\/info} CHUNK=${CHUNK/usr\/share\/man/usr\/man} CHUNK=${CHUNK/usr\/share\/doc/usr\/doc} [[ "$CHUNK" = "-- " ]] && CHUNK="" [[ "$CHUNK" = "--" ]] && CHUNK="" [[ "$CHUNK" != "" ]] && echo $CHUNK FOUND_LINE=1 fi done } #####-----------------------------------------------------------------------------------------------------------------------