#!/bin/bash # /usr/bin/src2pkg # This file is part of the src2pkg program: # Copyright 2005-2009 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 ! [[ "$CWD" ]] && CWD="$(pwd)" # && export CWD SRC2PKG_VERSION="1.9.8" # 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="" show_usage() { echo "" echo " $(basename $0) - Build an installable package from a source tarball or other content." echo " $(basename $0) [-h,--help,--more-help(-hh) --version, --setup]" echo " $(basename $0) [User Options] [Build Options] FILENAME" echo " $(basename $0) -[ABCDHINOPQRTUV(VV)WX] -[abcdefimnpsuv] FILENAME" echo " FILENAME should be the name of an archive or *.src2pkg build script." echo " FILENAME can be a relative or absolute path or a valid URL address." echo "" echo " The following User Options take no argument:" echo " -A Autogenerate a src2pkg script if the build succeeds." echo " -B Keep backups of overwritten files (implies the SAFE method)." echo " -C Place finished package in Current directory." echo " -D Don't apply diff or patch files automatically." echo " -H Place finished package in your HOME directory." echo " -I Install the created package when finished." echo " -N Generate a starting src2pkg script and description file only." echo " -O Compile sources in a separate 'clean' directory." echo " -P Preserve permissions in the source directory" echo " -Q Query the user interactively during configuration and package creation." echo " -R Replay errors if configuration or compilation fail." echo " -T Test-build the source code without installing or making a package." echo " -U Update the build script for compatibility if needed." echo " -V Show detailed prompts for debugging." echo " -VV Be verbose. Show all output from the steps." echo " -W (--cleanup) Delete (wipe out) temporary build files." echo " -X Find and execute a build script in the current working directory." echo "" echo " The following Build Options require an argument separated by the '=' sign." echo " Use single quotes '' around the arguments if they contain spaces." echo " -a (--arch) Set the architecture of the package. [-a=noarch]" echo " -b (--build) Set the build or release number. [-b=2]" echo " -c (--config_command) Set CONFIG_COMMAND option. [-c='./configure Linux']" echo " -d (--doclist) List of documents to include. [-d='README AUTHORS']" echo " -e (--extra_configs) Extra arguments to configure. [-e='--with-gnu-ld']" echo " -f (--std_flags) Set the CFLAGS variable. [-f='-Wall -O3']" echo " -i (--install_line) Set the install command line.[-i='make install']" echo " -m (--make_command) Set the 'make' command. [-m='make dep all']" echo " -n (--alt_name) Set the package name [-n='newname']." echo " -p (--pre_fix,--prefix) Set the package installation prefix. [-p=/usr]" echo " -s (--config_subdir) Set the configuration subdir. [-s=src]" echo " -u (--source_url) URL location of the source tarball [-u=http://xxx]" echo " -v (--alt_version) Set the version of the package. [-v=0.0.0a]" echo "" echo " Special Options:" echo " -h (--help) Show this help page and exit." echo " -hh (--more-help) Show extended options and examples." echo " --version Show the src2pkg version number and exit." echo " --list Show a list of the src2pkg instruction functions." echo " --setup Compile the binaries and libraries needed by src2pkg." echo " Usually only needed when you first install src2pkg." echo "" echo " Examples:" echo " src2pkg myprogram-0.1.tar.bz2" echo " src2pkg -N myprogram-0.1.tar.bz2" echo " src2pkg -i='make install install-data' -A myprogram-0.1.tar.bz2" echo " src2pkg -e='--disable-nls' -A myprogram-0.1.tar.bz2" echo " src2pkg URL (URL can be the URL of a tarball or of a src2pkg script)" echo "" if ! [[ -x /usr/libexec/src2pkg/bin/tar-1.13 ]] ; then echo $RED" Notice!"$NORMAL" src2pkg has not been set up for use yet. You must run" echo " 'src2pkg --setup' as user 'root' before src2pkg can be used." else echo " Please give the path or URL to an archive, or give other valid argument." echo " Extra help options can be seen by running the command 'src2pkg -hh'." fi } show_more_help() { echo "" echo " -LOG Log output of 'configure', 'make' and 'make install' to a file." echo " -JAIL Run installation in a 'jailed root' or sandbox directory." echo " -REAL Run installation in the real root filesystem using backup." echo " -SAFE Backup and restore files which are overwritten by the installation." echo " -DEST Run installation using the DESTDIR (or similar) variable, if available." echo " -UNION Run installation using a unionfs/chroot, if available." echo " -ACF Use configure options from rpm *.spec or debian rules files, if found." echo " -ACN Use configure options found from the configure script in the sources." echo " --pause=?? (before|after) Pause before or after running each function." echo " --resume=?? Resume a build starting at the named instruction function." echo "" echo " Advanced options for special non-standard packages:" echo " -E Use extended database files (slack-required and slack-supplies)" echo " -L Delete extra language files (man-pages, locale and i18n) files." echo " -TGZ Use gzip to compress the final package (this is the default)." echo " -TBZ Use bzip2 instead of gzip to compress the final package." echo " -TLZ Use lzma instead of gzip to compress the final package." echo " -TXZ Use xz (lzma-2) instead of gzip to compress the final package." echo " -UPX Use upx-ucl or upx to compress binaries inside the package." echo " -EPX Use exepak to compress binaries inside the package." #echo " -UPXL Use upx-ucl or upx to compress libraries inside the package." echo " -Z? SAVE_SPACE=? Squeeze packages by using more compression:" echo " The 'Z' options are cumulative - Z4 does all of Z1, Z2 and Z3." echo " -Z1 Z1 uses bzip2 instead of gzip for man-pages." echo " -Z2 Z2 creates a bzipped tar archive of the package doc directory." echo " -Z3 Z3 compresses ELF binaries using upx-ucl or upx if present" echo " -Z4 Z4 Link to a common copy of the GPL in /usr/share/licences." } FUNCTION_LIST=" 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 " list_functions() { for FUNCTION in $FUNCTION_LIST ; do echo $FUNCTION done echo "* Note that pre_process and post_process are left out of the list." exit 0 } if [[ -z $1 ]] ; then show_usage exit 0 else if [[ $1 = "-h" ]] || [[ $1 = "--help" ]] ; then show_usage exit 0 fi if [[ $1 = "--version" ]] ; then echo "src2pkg version-$SRC2PKG_VERSION" exit 0 fi if [[ $1 = "--more-help" ]] | [[ $1 = "-hh" ]] ; then show_more_help exit 0 fi if [[ $1 = "--setup" ]] ; then if [[ $EUID -eq 0 ]] ; then #cd /usr/src/src2pkg/src2pkg ; # check to make sure we have been setup. If not run setup if the user is root # otherwise warn the user if [[ -f /var/log/packages/src2pkg-helpers* ]] ; then INSTALLED_HELPERS_VERSION=$(ls /var/log/packages/src2pkg-helpers* |cut -f3 -d'-') fi if [[ -f /usr/src/src2pkg/src2pkg-helpers/src2pkg-helpers.src2pkg ]] ; then CURRENT_HELPERS_VERSION=$(grep '^VERSION=' /usr/src/src2pkg/src2pkg-helpers/src2pkg-helpers.src2pkg |cut -f 2 -d'=') fi if [[ $INSTALLED_HELPERS_VERSION = "" ]] ; then . /usr/src/src2pkg/src2pkg/src2pkg.setup ; elif [[ $INSTALLED_HELPERS_VERSION != $CURRENT_HELPERS_VERSION ]] ; then UPDATE=1 . /usr/src/src2pkg/src2pkg/src2pkg.setup fi exit 0 else echo $RED"FAILED! "$NORMAL" You must be logged in as user 'root' to setup src2pkg." exit 0 fi fi for option in "$@" ; do case $option in -A) AUTO_SCRIPT=1 ; shift ;; -ACF) AUTO_CONFIG=FOREIGN ; shift ;; -ACN) AUTO_CONFIG=NATIVE ; shift ;; -B) KEEP_BACKUPS="YES" ; SAFE_METHOD=YES ; INSTALL_TYPE=REAL ; shift ;; -C) PKG_DEST_DIR="$CWD" ; shift ;; -D) AUTO_PATCH="NO" ; shift ;; -DESTDIR|-DEST) INSTALL_TYPE="DESTDIR" WRITE_INSTALL_TYPE=1 ; shift ;; -E) EXTENDED_DATABASE="YES" ; shift ;; -EPX) COMPRESS_BINS="YES" ; BIN_COMPRESSOR="exepak" ; shift ;; -H) PKG_DEST_DIR="$HOME" ; shift ;; -I) REALLY_INSTALL="YES" ; shift ;; -JAIL) INSTALL_TYPE="JAIL" WRITE_INSTALL_TYPE=1 ; shift ;; -L) PURGE_LOCALES="YES" ; shift ;; -LOG) LOG_COMMANDS="YES" ; shift ;; -N) NEW_BUILD=1 ; shift ;; -O) USE_OBJ_DIR="YES" ; shift ;; -P) CORRECT_PERMS="NO" ; shift ;; -Q) INTERACTIVE_MODE="ALL" ; shift ;; -R) REPLAY_ERRORS="YES" ; shift ;; -REAL) INSTALL_TYPE="REAL" WRITE_INSTALL_TYPE=1 ; shift ;; -S) SHELL_INSTALL=1 ; shift ;; -SAFE) SAFE_METHOD=YES ; INSTALL_TYPE=REAL ; shift ;; -T) TEST_BUILD=1 ; shift ;; -TBZ) PKG_FORMAT="tbz" ; shift ;; -TGZ) PKG_FORMAT="tgz" ; shift ;; -TLZ) PKG_FORMAT="tlz" ; shift ;; -TXZ) PKG_FORMAT="txz" ; shift ;; -U) UPDATE_SCRIPT=1 ; shift ;; -UNION) INSTALL_TYPE=UNION ; shift ;; -UPX) COMPRESS_BINS="YES" ; shift ;; #-UPXL) COMPRESS_LIBS="YES" ; shift ;; -V) DEBUG=1 SHOW_DEPS=1 ; shift ;; -VV) QUIET="NO" ; shift ;; -W|--cleanup) CLEANUP="ALL" ; shift ;; -Z1) SAVE_SPACE=1 ; shift ;; -Z2) SAVE_SPACE=2 ; shift ;; -Z3) SAVE_SPACE=3 ; COMPRESS_BINS="YES" ; shift ;; -Z4) SAVE_SPACE=4 ; shift ;; -X) RUN_SCRIPT=1 ; shift ;; --list) list_functions ;; --resume=*) RESUME=$(echo $option |cut -f2 -d'=') ; if ! [[ $(echo $FUNCTION_LIST |grep $RESUME) ]] ; then echo "'$RESUME' is not a valid function name." echo "Run 'src2pkg --list' to see the list of functions." exit 0 else shift fi ;; --pause=*) PAUSE=$(echo $option |cut -f2 -d'=') ; if [[ $PAUSE = "before" ]] ; then PAUSE=BEFORE ; shift elif [[ $PAUSE = "after" ]] ; then PAUSE=AFTER ; shift else echo "Invalid use of '--pause=??' option." echo "Usage: '--pause=before', or: '--pause=after'" exit 0 fi ;; -a=*|--arch=*) ARCH=$(echo $option |cut -f2 -d'=') ; shift ;; -b=*|--build=*) BUILD=$(echo $option |cut -f2 -d'=') ; shift ;; -c=*|--config_command=*) CONFIG_COMMAND=$(echo $option |cut -f2 -d'=') ; WRITE_CONFIG_COMMAND=1 ; shift ;; -d=*|--doclist=*) DOCLIST=$(echo $option |cut -f2 -d'=') ; shift ;; -e=*|--extra_configs=*) EXTRA_CONFIGS=$(echo $option |cut -f2- -d'=') ; shift ;; -f=*|--std_flags=*) STD_FLAGS=$(echo $option |cut -f2- -d'=') ; WRITE_FLAGS=1 ; shift ;; -i=*|--install_line=*) INSTALL_LINE=$(echo $option |cut -f2- -d'=') ; shift ;; -m=*|--make_command=*) MAKE_COMMAND=$(echo $option |cut -f2- -d'=') ; shift ;; -n=*|--alt_name=*) ALT_NAME=$(echo $option |cut -f2 -d'=') ; shift ;; -p=*|--pre_fix=*|--prefix=*) PRE_FIX=$(echo $option |cut -f2 -d'=') ; shift ;; -s=*|--config_subdir=*) CONFIG_SUBDIR=$(echo $option |cut -f2 -d '=') ; shift ;; -u=*|--source_url=*) SOURCE_URL=$(echo $option |cut -f2 -d '=') ; shift ;; -v=*|--alt_version=*) ALT_VERSION=$(echo $option |cut -f2 -d'=') ; shift ;; *.tbz) EXT=tbz ;; *.tar.bz2) EXT=tar.bz2 ;; *.tgz) EXT=tgz ;; *.tar.gz) EXT=tar.gz ;; *.tlz) EXT=tlz ;; *.tar.lzma) EXT=tar.lzma ;; *.txz) EXT=txz ;; *.tar.xz) EXT=tar.xz ;; *.deb) EXT=deb ;; *.src.rpm) EXT=src.rpm ;; *.rpm) EXT=rpm ;; *.zip) EXT=zip ;; *.src2pkg) EXT=.src2pkg ;; *.src2pkg.auto) EXT=.src2pkg.auto ;; *.PkgBuild) EXT=.PkgBuild ;; *.PkgBuild.auto) EXT=.PkgBuild.auto ;; # *.torrent) EXT=.torrent ;; *) echo "Unrecognized option: $option" ; exit ;; esac done if [[ "$1" != "" ]] ; then case $1 in *.src2pkg|*.src2pkg.auto|*.PkgBuild|*.PkgBuild.auto) SCRIPT="$1" ;; #*.torrent) SOURCE_URL="$1" ; SOURCE_NAME=${SOURCE_URL%.torrent*} ;; *) SOURCE="$1" ;; esac fi ! [[ $SRC2PKG_LIBDIR ]] && SRC2PKG_LIBDIR=/usr/libexec/src2pkg . $SRC2PKG_LIBDIR/FUNCTIONS # Since we have already read the conf files set HAVE_CONF so that they don't # get read again if we later source a SCRIPT HAVE_CONF=1 if [[ "$SOURCE" != "" ]] || [[ "$SOURCE_URL" != "" ]] ; then ! [[ $SRC2PKG_LIBDIR ]] && SRC2PKG_LIBDIR=/usr/libexec/src2pkg . $SRC2PKG_LIBDIR/FUNCTIONS if [[ $NEW_BUILD ]] ; then pre_process elif [[ $TEST_BUILD ]] ; then pre_process find_source make_dirs unpack_source fix_source_perms configure_source compile_source if [[ $FAILED = "" ]] ; then echo $BLUE"Test Compile - "$GREEN"Successful! "$NORMAL"for $NAME-$VERSION" echo $CYAN"NOTICE- "$NORMAL"This doesn't necessarily mean a package can be made." else echo $RED"FAILED!! "$NORMAL"Test build of $NAME-$VERSION has failed." exit fi else do_all_processes if [[ $FAILED != "" ]] ; then exit fi fi # create a default description file -the function is located in FUNCTIONS if [ "$TEST_BUILD" -a "$AUTO_SCRIPT" ] \ && [[ ! -e "$CWD"/$PKG_DESC ]] ; then make_simple_desc fi # write the script -the function is located in FUNCTIONS if [[ $NEW_BUILD ]] ; then if [[ "$INTERACTIVE_MODE" = "ALL" ]] ; then echo $BLUE" Note: "$NORMAL"src2pkg has guessed the NAME and VERSION" echo " based on the name of the archive. Check to see if these are" echo " correct and accept them or enter a new NAME and VERSION." # prompt the user to accept or change the NAME guessed by pre_process echo $BLUE"Guessed NAME: "$NORMAL"$NAME" echo -n "Press ENTER to use the guessed NAME or enter a new NAME:" read -e NEWNAME if [[ $NEWNAME != "" ]] ; then # BLURB_1 needs to be reset if NAME changes if [[ $BLURB_1 = $NAME ]] ; then BLURB_1=$NEWNAME fi ALT_NAME=$NEWNAME NAME=$ALT_NAME echo $BLUE"Using NAME: "$NORMAL"$ALT_NAME" else echo $BLUE"Using NAME: "$NORMAL"$NAME" fi # prompt the user to accept or change the VERSIONguessed by pre_process echo echo $BLUE"Guessed VERSION: "$NORMAL"$VERSION" echo -n "Press ENTER to use the guessed VERSION or enter a new VERSION:" read -e NEWVERSION if [[ $NEWVERSION != "" ]] ; then ALT_VERSION=$NEWVERSION VERSION=$ALT_VERSION echo $BLUE"Using VERSION: "$NORMAL"$ALT_VERSION" else echo $BLUE"Using VERSION: "$NORMAL"$VERSION" fi fi [[ ! -e "$CWD"/$PKG_DESC ]] && make_simple_desc write_src2pkg_script fi exit 0 fi if [[ $UPDATE_SCRIPT ]] ; then if [[ $RUN_SCRIPT ]] ; then SCRIPT=$(ls -1 *.src2pkg *.src2pkg.auto |head -n 1 2> /dev/null) &> /dev/null fi if ! [[ "$SCRIPT" ]] ; then if [ -f "$CWD"/*.PkgBuild ] ; then SCRIPT=$(ls *.PkgBuild -1 |head -n 1) EXT=.PkgBuild elif [ -f $PWD/*.PkgBuild.auto ] ; then [[ SCRIPT = "" ]] && SCRIPT=$(ls *.PkgBuild.auto -1 |head -n 1) EXT=.PkgBuild.auto fi if [[ $SCRIPT = "" ]] ; then echo SCRIPT=$SCRIPT echo "No PkgBuild script found!" exit 0 fi fi if [[ "$SCRIPT" ]] ; then echo -n $BLUE"Updating $SCRIPT - "$NORMAL if [[ $(grep '^BUILD=' $SCRIPT) ]] ; then OLD_BUILD=$(grep '^BUILD=' $SCRIPT |cut -f2- -d '=') if [[ $INCREMENT_BUILD = "YES" ]] ; then BUILD=$(( "$OLD_BUILD" + 1 )) fi fi sed -e "s'Amigo PkgBuild'\src2pkg'" \ -e "s/2005-2006/2005-2009/" \ -e "s/2006-2007/2005-2009/" \ -e "s'PkgBuild'\src2pkg'" \ -e "s'pkgbuild'\src2pkg'" "$SCRIPT" > "$SCRIPT".new if [[ $INCREMENT_BUILD = "YES" ]] ; then sed -i "s,^BUILD=.*,BUILD=$BUILD," "$SCRIPT".new fi rm -f "$SCRIPT" SCRIPT_NAME=$(basename "$SCRIPT" $EXT) if [[ $EXT = ".PkgBuild" ]] ; then mv -f "$SCRIPT".new "$SCRIPT_NAME".src2pkg SCRIPT="$SCRIPT_NAME".src2pkg elif [[ $EXT = ".PkgBuild.auto" ]] ; then mv -f "$SCRIPT".new "$SCRIPT_NAME".src2pkg.auto SCRIPT="$SCRIPT_NAME".src2pkg.auto else mv -f "$SCRIPT".new "$SCRIPT" fi chmod 644 "$SCRIPT" echo $GREEN"DONE!"$NORMAL fi fi if [[ "$SCRIPT" != "" ]] && [[ -e $CWD/$(basename "$SCRIPT") ]] ; then echo $BLUE"Running build script:"$NORMAL $(basename "$SCRIPT") . "$CWD"/$(basename "$SCRIPT") elif [[ $RUN_SCRIPT ]] ; then if [[ $(ls -1 *.src2pkg 2> /dev/null) != "" ]] ; then SCRIPT=$(ls -1 *.src2pkg |head -n 1) &> /dev/null elif [[ $(ls -1 *.src2pkg.auto 2> /dev/null) != "" ]] ; then SCRIPT=$(ls -1 *.src2pkg.auto |head -n 1) &> /dev/null else echo "No src2pkg script found!" exit 0 fi echo $BLUE"Running build script:"$NORMAL $(basename "$SCRIPT") # run the script by sourcing it . "$SCRIPT" elif [[ $(echo "$SCRIPT" |grep '://') != "" ]] ; then if [ ! -w "$CWD" ] ; then echo $RED"FAILED! "$NORMAL"CWD is not writable... exiting." FAILED="READONLY CWD" else URL_ADDRESS="${SCRIPT}" URL_DEST="${CWD}"/$(basename "$URL_ADDRESS") URL_TYPE="build script" download_url if [ $? -ne 0 ]; then mv -f "${URL_DEST}" "${URL_DEST}".FAIL echo $RED"FAILED! "$NORMAL"Downloading '$(basename ${URL_DEST})' failed or cancelled." FAILED="SCRIPT DOWNLOAD" else if [ "$DOWNLOAD_ONLY" ]; then echo $BLUE"Download completed to: "$NORMAL"$URL_DEST" exit 0 else echo $BLUE"Script downloaded to: "$NORMAL"$URL_DEST" fi fi # run the script by sourcing it . "$(basename $SCRIPT)" fi else echo "File $@ not found!" fi fi