##### pre_process ##### This is the only function which is really required as it is where all ##### the main variables get setup and crunched into usable form pre_process() { # color is on only if COLOR_PROMPT=YES get_color_options ; # you must be root to run src2pkg if [[ "$(id -u)" != "0" ]] && [[ "$INSTALL_TYPE" = "REAL" ]] ; then echo $RED"FATAL!!! "$NORMAL"You have chosen to use the -REAL installation option for src2pkg." echo "Normal users don't have the write priviledges needed for doing this." echo "You must be logged in as root or su to root to run src2pkg in this mode." echo "Or choose to use one of the other installation methods -JAIL or -DESTDIR." exit 1 fi OWNER="$(id -un)" GROUP="$(id -gn)" # 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. # Among the first goals of src2pkg was to *not* install packages by default ! [[ $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="" # A BUILD number is required, so supply a default if none was given. ! [[ $BUILD ]] && BUILD="1" if [[ "$INTERACTIVE_MODE" = "ALL" ]] ; then QUERY_FOR_EXTRA_CONFIGS="YES" CONFIRM_BUILD="YES" QUERY_FOR_PKG_DESC="YES" fi DESC_WRAP_LENGTH=70 # this variable tells the text wrapper how many lines to pad the PKG_DESC file. # the PKG_DESC file should be at least 11 lines -the first, second and 11th line # are supplied separately (8+3=11) and lines 12 and 13 are optionally added DESC_MAX_LINES=8 # get the ARCH and compiler tuning flags for CFLAGS (function is near end of file) get_flags ; # Use our own statically-linked binaries at least for the most critical stuff ! [[ $STATIC_DIR ]] && STATIC_DIR=/usr/libexec/src2pkg/static # These are the programs needed during restoration of overwritten files # and removal of any left over new files, before running ldconfig in fake_install # we use a version of tar from the full sources instead of the busybox version # The static tar program is used in all cases for consistency and to allow # re-building the 'tar' or pkgtools packages. This version of tar is identical # to the one that Slackware uses, except that the '-j' option is used for bzip2 # archives for syntax consistency with versions of tar>=1.15 TAR_STATIC=$STATIC_DIR/tar # these all come from busybox and are only used in fake_install from *after* # running INSTALL_LINE ('make install') until installation restoration is complete CAT_STATIC=$STATIC_DIR/cat cp_STATIC=$STATIC_DIR/cp CUT_STATIC=$STATIC_DIR/cut EGREP_STATIC=$STATIC_DIR/egrep GREP_STATIC=$STATIC_DIR/grep MKDIR_STATIC=$STATIC_DIR/mkdir RM_STATIC=$STATIC_DIR/rm SORT_STATIC=$STATIC_DIR/sort UNIQ_STATIC=$STATIC_DIR/uniq LS_STATIC=$STATIC_DIR/ls # Get the name, version and source suffix(SOURCE_NAME) # early PkgBuild versions supplied NAME VERSION and SRC_SUFFIX separately if [ "$NAME" -a "$VERSION" -a "$SRC_SUFFIX" ] ; then SOURCE_NAME="$NAME-$VERSION$SRC_SUFFIX" fi # newer versions of src2pkg derive NAME & VERSION from SOURCE_URL, SOURCE or SOURCE_NAME if [[ "$SOURCE_URL" != "" ]] ; then # SOURCE_URL was given explicitly SOURCE_NAME="$(basename $SOURCE_URL)" SOURCE=$SOURCES_DIR/$SOURCE_NAME elif [[ "$SOURCE" != "" ]] ; then SOURCE_NAME=$(basename $SOURCE) case $SOURCE in # SOURCE is a URL *://*) SOURCE_URL="$SOURCE" ; SOURCE=$SOURCES_DIR/$SOURCE_NAME ; shift ;; # Double slashes get corrected if this is not a URL //*) SOURCE=${SOURCE#*/} ; shift ;; # Relative path(./) ./*) SOURCE=$CWD/${SOURCE#*/} ; shift ;; # Absoulte path" /*) SOURCE=$SOURCE ;; # Extended relative path [a-z,A-Z,0-9]*/*) SOURCE=$CWD/$SOURCE ; shift ;; # No path given -assume it's in SOURCES_DIR *) SOURCE=$SOURCES_DIR/$SOURCE ; shift ;; esac elif [[ "$SOURCE_NAME" != "" ]] ; then case $SOURCE_NAME in # use the same rules as above for SOURCE_NAME *://*) SOURCE_URL="$SOURCE" ; SOURCE=$SOURCES_DIR/$SOURCE_NAME SOURCE_NAME=$(basename $SOURCE_NAME) ; shift ;; //*) SOURCE=${SOURCE_NAME#*/} ;; ./*) SOURCE=$CWD/${SOURCE_NAME#*/} ;; /*) SOURCE=$SOURCE_NAME ;; [a-z,A-Z,0-9]*/*) SOURCE=$CWD/$SOURCE_NAME ;; *) SOURCE=$SOURCES_DIR/$SOURCE_NAME ;; esac fi # local function used to retrieve the given architecture when converting binary package names 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 ;; *x86_64*) MYARCH=x86_64 ;; *s390*) MYARCH=s390 ;; *s390x*) MYARCH=s390x ;; *noarch*) MYARCH=noarch ;; esac } # local function 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 } # The next +-200 lines analyze the SOURCE_NAME and try to figure out the correct NAME and VERSION # Handling of debian and especially rpm archives make this pretty complex. Of course it still won't always # get them both right. you can always override them easily with '-n=?' (ALT_NAME) and '-v=?' (ALT_VERSION). # The logic is based on heuristic rules built up from thousands of real archive names and error scenarios # if [[ "$SOURCE_NAME" != "" ]] ; then [[ $DEBUG ]] && echo -n $BLUE"Guessing content type based on file suffix: "$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 # this is where the user gave just a suffix and no package name if [[ $NAMVERS = ".$EXT" ]] || [[ $NAMVERS = $EXT ]] ; then echo $RED"Error! "$NORMAL"Invalid package name -probably null name or suffix-only. Exiting..." exec $0 exit 0 else RAW_SOURCE_NAME=$(basename $NAMVERS ."$EXT") fi NAMVERS=$RAW_SOURCE_NAME case $EXT in src.rpm|src.tgz|src.tar.gz) if [[ $DEBUG ]] ; then [[ "$EXT" = "src.rpm" ]] && echo -n "RPM source archive" #\ # || 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 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" true fi 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 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") 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") translate_underlines else [[ $DEBUG ]] && echo -n "Generic source archive" fi #translate_underlines if [[ $(echo $NAMVERS |grep '_') != "" ]] ; then # debian #[[ $DEBUG ]] && echo -n " Rule 1" VERSION=$(echo $NAMVERS |rev |cut -f1 -d'_' |rev) NAME=$(basename $NAMVERS _$VERSION) VERSION=$(echo $VERSION |tr '-' '.') elif [[ $(echo $NAMVERS |grep '-') != "" ]] ; then #[[ $DEBUG ]] && echo && echo " Rule 2" VERSION=$(echo $NAMVERS |rev |cut -f1 -d'-' |rev) NAME=$(basename $NAMVERS -$VERSION) else #[[ $DEBUG ]] && echo && echo " Rule 3" NAME=$(echo $NAMVERS |cut -f1 -d'.') VERSION=$(echo $NAMVERS |cut -f2- -d'.') [[ "$VERSION" = "$NAME" ]] && VERSION=0.0.0 fi ;; esac fi ;; esac [[ $DEBUG ]] && echo "" # Whew!! The derived name and version can always be overridden. else # trackinstall and src2pkg are 'clients' of these FUNCTIONS 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? We'll name it: unknown-0.unknown.0 " NAME=unknown VERSION=0.unknown.0 fi VERSION=$(echo $VERSION |tr '-' '_') fi # ORIG_NAME & ORIG_VERSION are the 'best guess' from above. We save the values before # correcting or overriding them. They are used later to help second-guess tarball names, if needed. ORIG_NAME="$NAME" ORIG_VERSION="$VERSION" # [[ $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 and corrections are not turned off or overridden 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') 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 might 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 # exit if no NAME or VERSION are found 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 if [[ $TRACK_INSTALL ]] ; then SRC_DIR=$CWD OBJ_DIR=$SRC_DIR elif [[ $USE_OBJ_DIR ]] ; 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 # make script writing easier by using DOC_DIR and MAN_DIR DOC_DIR=usr/doc/$NAME-$VERSION MAN_DIR=usr/man # This should help make 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 # remove the leading / from PRE_FIX. This obsoletes some of my own old scripts that used # $PKG_DIR$PREFIX, but that just doesn't look or feel right like writing: $PKG_DIR/$PREFIX if [[ $(echo $PRE_FIX |cut -f1 -d'/') = "" ]] ; then PRE_FIX="$(echo ${PRE_FIX} |cut -f2- -d'/')" fi # set default text for the description file if not given ! [[ $BLURB_1 ]] && BLURB_1=$NAME ! [[ $BLURB_3 ]] && BLURB_3="No description was given for this package." # ! [[ $BLURB_11 ]] && BLURB_11="Packaged by src2pkg" # check the validity of the directories (function near end of file). This important check # insures that the user isn't trying to unpack sources or build packages inside some # system directory or / root directory. check_dirs1 # now check to make sure the user has permission to write in all the needed places check_write_permissions if [ "FAILED" != "" ] ; then post_process fi } # end pre_process # this function gets used for downloading build scripts, sources and extra sources # by passing a URL to either an archive or *src2pkg script or as a member of EXTRA_SOURCES download_url() { if ! [[ $DOWNLOADER ]] ; then if [[ $(which wget) ]] ; then DOWNLOADER=wget elif [[ $(which rsync) ]] ; then DOWNLOADER=rsync elif [[ $(which curl) ]] ; then DOWNLOADER=curl elif [[ $(which lynx) ]] ; then DOWNLOADER=lynx else DOWNLOADER="" fi fi case $DOWNLOADER in wget) echo $BLUE"Downloading ${URL_TYPE} with wget from: "$NORMAL"$URL_ADDRESS" ; wget -nv -O "${URL_DEST}" "${URL_ADDRESS}" &> /dev/null ;; rsync) echo $BLUE"Downloading ${URL_TYPE} with rsync from: "$NORMAL"$URL_ADDRESS" rsync "${URL_ADDRESS}" >"${URL_DEST}" &> /dev/null ;; curl) echo $BLUE"Downloading ${URL_TYPE} with curl from: "$NORMAL"$URL_ADDRESS" ; curl -s "${URL_ADDRESS}" >"${URL_DEST}" &> /dev/null ;; lynx) echo $BLUE"Downloading ${URL_TYPE} with lynx from: "$NORMAL"$URL_ADDRESS" ; lynx -source "${URL_ADDRESS}" >"${URL_DEST}" &> /dev/null ;; *) echo "No downloader available." ; exit ;; esac } ### find_source find_source() { if [[ "$EXTRA_SOURCES" != "" ]] ; then for URL in $EXTRA_SOURCES ; do if ! [[ -e $CWD/$(basename ${URL}) ]] ; then if [ ! -w "$CWD" ] ; then echo $RED"FAILED! "$NORMAL"CWD is not writable... exiting." FAILED="READONLY CWD" else if [[ "$BASE_URL" != "" ]] ; then URL_ADDRESS=${BASE_URL}/${URL} else URL_ADDRESS=${URL} fi URL_DEST=${CWD}/$(basename $URL) URL_TYPE="extra sources" download_url if [ $? -ne 0 ] ; then mv -f "${CWD}/$(basename $URL)" ${CWD}/$(basename $URL).FAIL echo $RED"FAILED! "$NORMAL"Downloading '$(basename ${URL})' failed or cancelled." FAILED="EXTRA_SOURCES DOWNLOAD" else if [ "$DOWNLOAD_ONLY" ]; then echo $BLUE"Download completed to: "$NORMAL"${CWD}/$(basename $URL)" exit 0 else echo $BLUE"Extra sources downloaded to: "$NORMAL"${CWD}/$(basename $URL)" fi fi fi fi done fi if [[ "$SOURCE" != "" ]] || [[ "$SOURCE_NAME" != "" ]] ; then if [[ -L $SOURCE ]] ; then echo $BLUE"Found source archive: "$NORMAL"$(basename $SOURCE)" echo "It's really a symlink to: $(readlink -f $SOURCE)" SOURCE=$(readlink -f $SOURCE) elif [[ -f $SOURCE ]] ; then echo $BLUE"Found source archive: "$NORMAL"$(basename $SOURCE)" SOURCE=$SOURCE elif [[ -f $SOURCES_DIR/$SOURCE_NAME ]] ; then echo $BLUE"Found source archive in SOURCES_DIR: "$NORMAL"$(basename $SOURCE_NAME)" SOURCE=$SOURCES_DIR/$SOURCE_NAME elif [[ -f $CWD/$SOURCE ]] ; then echo $BLUE"Found source archive in CWD: "$NORMAL"$(basename $SOURCE)" SOURCE=$CWD/$SOURCE elif [ "${SOURCE_URL}" != "" ]; then if [ ! -w "$SOURCES_DIR" ] ; then echo $RED"FAILED! "$NORMAL"SOURCES_DIR is not writable... exiting." FAILED="READONLY SOURCES_DIR" else if [[ "$BASE_URL" != "" ]] ; then URL_ADDRESS=${BASE_URL}/${SOURCE_URL} else URL_ADDRESS=${SOURCE_URL} fi URL_DEST=${SOURCE} URL_TYPE="sources" download_url if [ $? -ne 0 ]; then mv -f "${SOURCE}" "${SOURCE}".FAIL echo $RED"FAILED! "$NORMAL"Downloading '$(basename ${SOURCE})' failed or cancelled." FAILED="SOURCE DOWNLOAD" else if [ "$DOWNLOAD_ONLY" ]; then echo $BLUE"Download completed to: "$NORMAL"$SOURCE" exit 0 else echo $BLUE"Sources downloaded to: "$NORMAL"$SOURCE" fi fi fi 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 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 validity of directories again -even harder cause we're going to use 'rm -rf' here to cleanup check_dirs2 # clean up any leftover directories, packages and logs. Use rm -rf as safely as possible 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 [[ -e $CWD/patched-files-$NAME-$VERSION ]] && rm -f $CWD/patched-files-$NAME-$VERSION 2> /dev/null 1> /dev/null [[ -e $CWD/deps_list ]] && rm -f $CWD/deps_list [[ -e $CWD/deps_list.tmp ]] && rm -f $CWD/deps_list.tmp [[ -e $CWD/installwatch.debug ]] && rm -f $CWD/installwatch.debug # 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/FILELIST.orig 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 really went wrong last time -remove it if [[ -d $BACKUP_DIR/$NAME-$VERSION-backup-$BUILD$SIG ]] ; then cd $BACKUP_DIR rm -rf $NAME-$VERSION-backup-$BUILD$SIG 2> /dev/null 1> /dev/null fi [[ "$QUIET" = "YES" ]] && echo $GREEN"Done"$NORMAL fi # create new working directories echo $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. That way an empty PKG_DIR can serve as a test later. if [[ ! -d $PKG_DIR ]] ; then cd $PKG_BUILDS_DIR && mkdir -p $PKG_DIR_NAME && echo " PKG_DIR=$PKG_DIR" fi # Create a separate OBJ_DIR if asked for. This must be in the same directory as the sources # so that we can call 'configure' using a relative path name which we know: ../$SRC_DIR_NAME/configure if [[ $USE_OBJ_DIR ]] ; then cd $SRC_BUILDS_DIR && mkdir -p $OBJ_DIR_NAME && echo " OBJ_DIR=$OBJ_DIR" fi # be sure and not recreate the directory you are in (running src2pkg like trackinstall where SRC_DIR=$CWD) if [[ $SOURCE_NAME ]] && [[ "$SRC_DIR" != "$CWD" ]] ; then cd $SRC_BUILDS_DIR [[ ! -d $SRC_DIR_NAME ]] && mkdir -p $SRC_DIR_NAME && echo " SRC_DIR=$SRC_DIR" fi fi } # end make_dirs # this function figures out the architecture and CFLAGS 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 -m)" = "ppc" ]] ; then ! [[ $ARCH ]] && ARCH="powerpc" TUNE_FLAGS="" elif [[ "$(uname -m)" = "s390" ]] ; then ! [[ $ARCH ]] && ARCH="s390" TUNE_FLAGS="" elif [[ "$(uname -m)" = "s390x" ]] ; then ! [[ $ARCH ]] && ARCH="s390x" TUNE_FLAGS="" elif [[ "$(uname -m)" = "x86_64" ]] ; then ! [[ $ARCH ]] && ARCH="x86_64" TUNE_FLAGS="-fPIC" elif [[ "$(uname -m |grep 86)" != "" ]] ; 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" else ! [[ $ARCH ]] && ARCH="unknown" TUNE_FLAGS="" fi ! [[ $STD_FLAGS ]] && STD_FLAGS="$OPTIM_FLAGS $TUNE_FLAGS" ! [[ $EXTRA_FLAGS ]] && EXTRA_FLAGS="" } 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() { 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 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 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 } check_write_permissions() { touch $CWD/perms-test.txt &> /dev/null if [ $? -eq 0 ] ; then rm -f $CWD/perms-test.txt else echo $RED"FAILED! "$NORMAL"You don't have permission to create files in" echo "the current directory: $CWD" FAILED=WRITE_PERMISSION fi touch $SRC_BUILDS_DIR/perms-test.txt &> /dev/null if [ $? -eq 0 ] ; then rm -f $SRC_BUILDS_DIR/perms-test.txt else echo $RED"FAILED! "$NORMAL"You don't have permission to create files in" echo "the SRC_BUILDS_DIR directory: $SRC_BUILDS_DIR" FAILED=WRITE_PERMISSION fi touch $PKG_BUILDS_DIR/perms-test.txt &> /dev/null if [ $? -eq 0 ] ; then rm -f $PKG_BUILDS_DIR/perms-test.txt else echo $RED"FAILED! "$NORMAL"You don't have permission to create files in" echo "the PKG_BUILDS_DIR directory: $PKG_BUILDS_DIR" FAILED=WRITE_PERMISSION fi touch $PKG_DEST_DIR/perms-test.txt &> /dev/null if [ $? -eq 0 ] ; then rm -f $PKG_DEST_DIR/perms-test.txt else echo $RED"FAILED! "$NORMAL"You don't have permission to create files in" echo "the PKG_DEST_DIR directory: $PKG_DEST_DIR" FAILED=WRITE_PERMISSION fi } # 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 }