#!/bin/bash # src2pkg Copyright 2006-2007 Gilbert Ashley SRC2PKG_VERSION=1.1 source /usr/libexec/src2pkg/FUNCTIONS show_usage() { echo "" echo " $(basename $0) - Build an installable package from a source tarball." echo " $(basename $0) [User Options] [Build Options] file-name" echo " $(basename $0) [-h,--help,--version]" echo " $(basename $0) -[ABCDHINOPTUV(VV)(VVV)WX] [abcdefimnpsuv] file-name" echo "" echo " The following User Options take no argument:" echo " -A Autogenerate a src2pkg script if the build succeeds." echo " -B Keep backups of any files overwritten by this installation." echo " -C Place finished package in Current directory." echo " -D Don't apply diff or patch files automatically (AUTO_PATCH='NO')" 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 Use an OBJECT directory for compiling apart from the sources." echo " -P Preserve permissions in the source directory (CORRECT_PERMS='NO')." 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 Replay errors if configuration or compilation fail." echo " -VV Be verbose. Show all output from the steps." echo " -VVV (--debug) DEBUG -show detailed prompts for debugging." echo " -W (--cleanup) Delete (wipe out) temporary build files." echo " -X 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 the 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'] (ALT_NAME)." echo " -p (--pre_fix,--prefix) Set the package installation prefix. [-p=/usr/local]" 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 " 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' -i='make install install-data' -A myprogram-0.1.tar.bz2" echo "" } get_color_options ; # 1 if [[ -z $1 ]] ; then show_usage echo "Please give the path or URL to an archive, or give other valid argument." 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 for option in "$@" ; do case $option in -A) AUTO_SCRIPT=1 ; shift ;; -B) KEEP_BACKUPS="YES" ; shift ;; -C) PKG_DEST_DIR=$CWD ; shift ;; -D) AUTO_PATCH="NO" ; shift ;; -H) PKG_DEST_DIR=$HOME ; shift ;; -I) REALLY_INSTALL="YES" ; shift ;; -N) NEW_BUILD=1 ; shift ;; -O) USE_OBJ_DIR="YES" ; shift ;; -P) CORRECT_PERMS="NO" ; shift ;; -S) SHELL_INSTALL=1 ; shift ;; -T) TEST_BUILD=1 ; shift ;; -U) UPDATE_SCRIPT=1 ; shift ;; -V) REPLAY_ERRORS="YES" ; shift ;; -VV) QUIET="NO" ; shift ;; -VVV) DEBUG=1 ; shift ;; -W|--cleanup) CLEANUP="ALL" ; shift ;; -X) RUN_SCRIPT=1 ; shift ;; -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'=') ; 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'=') ; 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'=') ; [[ $(echo $PRE_FIX |cut -f1 -d'/') != "" ]] && PRE_FIX="/$PRE_FIX" ; 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 ;; *.deb) EXT=deb ;; *.rpm) EXT=rpm ;; *.src2pkg) EXT=.src2pkg ;; *.src2pkg.auto) EXT=.src2pkg.auto ;; *.PkgBuild) EXT=.PkgBuild ;; *.PkgBuild.auto) EXT=.PkgBuild.auto ;; *) echo "Unrecognized option: $option" ; exit ;; esac done if [[ "$1" != "" ]] ; then case $1 in *.src2pkg|*.src2pkg.auto|*.PkgBuild|*.PkgBuild.auto) SCRIPT="$1" ;; *) SOURCE="$1" ;; esac fi if [[ $SOURCE ]] || [[ $SOURCE_URL ]] ; then 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 # echo $(basename $0) $RED"ERROR "$NORMAL"in $FAILED" #FAILED="TEST COMPILE" exit fi fi if [[ $NEW_BUILD ]] || [ "$TEST_BUILD" -a "$AUTO_SCRIPT" ] && [[ ! -e $CWD/$PKG_DESC ]] ; then echo $BLUE"Creating new.$PKG_DESC file. "$NORMAL"Edit, if needed and rename to $PKG_DESC for use." cat > $CWD/new.$PKG_DESC << END $NAME: $NAME $NAME: $NAME: No description was given for this package. $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: Packaged by: ${CREATOR} END fi # 3 write the script if [[ $AUTO_SCRIPT ]] || [[ $NEW_BUILD ]] ; then echo $BLUE"Writing build script - "$NORMAL"$NAME.src2pkg.auto in the current directory." # src2pkg.auto echo "#!/bin/bash" > $CWD/$NAME.src2pkg.auto echo "## src2pkg script for: $NAME" >> $CWD/$NAME.src2pkg.auto echo "## Auto-generated by src2pkg-$SRC2PKG_VERSION" >> $CWD/$NAME.src2pkg.auto echo "## src2pkg Copyright 2005-2007 Gilbert Ashley " >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto if [[ $SOURCE_URL ]] ; then echo "SOURCE_URL='$SOURCE_URL'" >> $CWD/$NAME.src2pkg.auto elif [[ $SOURCE_NAME ]] ; then echo "SOURCE_NAME='$SOURCE_NAME'" >> $CWD/$NAME.src2pkg.auto fi if [[ "$ALT_NAME" != "" ]] ;then echo "ALT_NAME='$ALT_NAME'" >> $CWD/$NAME.src2pkg.auto else echo "NAME='$NAME'" >> $CWD/$NAME.src2pkg.auto fi if [[ "$ALT_VERSION" != "" ]] ;then echo "ALT_VERSION='$ALT_VERSION'" >> $CWD/$NAME.src2pkg.auto else echo "VERSION='$VERSION'" >> $CWD/$NAME.src2pkg.auto fi [[ $SRC_SUFFIX ]] && echo "SRC_SUFFIX='$SRC_SUFFIX'" >> $CWD/$NAME.src2pkg.auto echo "ARCH='$ARCH'" >> $CWD/$NAME.src2pkg.auto echo "BUILD='$BUILD'" >> $CWD/$NAME.src2pkg.auto echo "PRE_FIX='$PRE_FIX'" >> $CWD/$NAME.src2pkg.auto echo "# Any extra options go here" >> $CWD/$NAME.src2pkg.auto [[ "$STD_CONFIGS" != "" ]] && echo "STD_CONFIGS='$STD_CONFIGS'" >> $CWD/$NAME.src2pkg.auto if [[ "$EXTRA_CONFIGS" != "" ]] ; then echo "EXTRA_CONFIGS='${EXTRA_CONFIGS}'" >> $CWD/$NAME.src2pkg.auto else echo "# EXTRA_CONFIGS='${EXTRA_CONFIGS}'" >> $CWD/$NAME.src2pkg.auto fi [[ "$STD_FLAGS" != "" ]] && echo "# STD_FLAGS='$STD_FLAGS'" >> $CWD/$NAME.src2pkg.auto [[ "$PATCHLIST" != "" ]] && echo "PATCHLIST='${PATCHLIST}'" >> $CWD/$NAME.src2pkg.auto [ "$MAKEFILE" != "" -a "$MAKEFILE" != "Makefile" ] && echo "MAKEFILE='$MAKEFILE'" >> $CWD/$NAME.src2pkg.auto [ "$MAKE_COMMAND" != "" -a "$MAKE_COMMAND" != "make" ] && echo "MAKE_COMMAND='$MAKE_COMMAND'" >> $CWD/$NAME.src2pkg.auto [ "$INSTALL_LINE" != "" -a "$INSTALL_LINE" != "make install" ] && echo "INSTALL_LINE='$INSTALL_LINE'" >> $CWD/$NAME.src2pkg.auto if [[ $FUNNY_SUBDIR ]] ; then echo "CONFIG_SUBDIR='$FUNNY_SUBDIR'" >> $CWD/$NAME.src2pkg.auto elif [[ $CONFIG_SUBDIR ]] && [[ $NEW_BUILD ]] ; then echo "CONFIG_SUBDIR='$CONFIG_SUBDIR'" >> $CWD/$NAME.src2pkg.auto fi [[ "$DOCLIST" ]] && echo "DOCLIST='$DOCLIST'" >> $CWD/$NAME.src2pkg.auto [[ "$USE_OBJ_DIR" = "YES" ]] && echo "USE_OBJ_DIR='YES'" >> $CWD/$NAME.src2pkg.auto [[ $AUTO_PATCH = "NO" ]] && echo "AUTO_PATCH='NO'" >> $CWD/$NAME.src2pkg.auto [[ $CORRECT_PERMS = "NO" ]] && echo "CORRECT_PERMS='NO'" >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto echo "# Get the functions and configs" >> $CWD/$NAME.src2pkg.auto echo "source /usr/libexec/src2pkg/FUNCTIONS ;" >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto echo "# do_all_processes can substitute these 16 steps:" >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto cat >> $CWD/$NAME.src2pkg.auto << EOF 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 EOF # fi echo "" >> $CWD/$NAME.src2pkg.auto echo "# src2pkg - Copyright 2005-2007 Gilbert Ashley " >> $CWD/$NAME.src2pkg.auto echo "## See the documentation for more help and examples. Below are some of" >> $CWD/$NAME.src2pkg.auto echo "# the most common Extras and Options for easy cut-and-paste use." >> $CWD/$NAME.src2pkg.auto echo "# EXTRA_CONFIGS='' PRE_FIX='' DOCLIST=''" >> $CWD/$NAME.src2pkg.auto echo "# MAKE_COMMAND='' INSTALL_LINE='' " >> $CWD/$NAME.src2pkg.auto echo "# SHELL_INSTALL='YES' CORRECT_PERMS='NO'" >> $CWD/$NAME.src2pkg.auto fi #3 exit 0 # end of SOURCE handling fi if [[ $UPDATE_SCRIPT ]] ; then if ! [[ $SCRIPT ]] ; then if [ -f $PWD/*.PkgBuild ] ; then SCRIPT=$(ls *.PkgBuild) elif [ -f $PWD/*.PkgBuild.auto ] ; then [[ SCRIPT = "" ]] && SCRIPT=$(ls *.PkgBuild.auto) fi # [[ SCRIPT = "" ]] && SCRIPT=$(ls *.src2pkg) #[[ SCRIPT = "" ]] && SCRIPT=$(ls *.src2pkg.auto) if [[ SCRIPT = "" ]] ; then echo "No src2pkg script found!" exit 0 fi fi if [[ $SCRIPT ]] ; then echo -n $BLUE"Updating $SCRIPT - "$NORMAL sed -e "s'Amigo PkgBuild'\src2pkg'" \ -e "s/2005-2006/2005-2007/" \ -e "s/2006-2007/2005-2007/" \ -e "s'PkgBuild'\src2pkg'" \ -e "s'pkgbuild'\src2pkg'" $SCRIPT > $SCRIPT.new mv $SCRIPT $SCRIPT.old SCRIPT_NAME=$(basename $SCRIPT $EXT) if [[ $EXT = ".PkgBuild" ]] ; then mv $SCRIPT.new $SCRIPT_NAME.src2pkg SCRIPT=$SCRIPT_NAME.src2pkg elif [[ $EXT = ".PkgBuild.auto" ]] ; then mv $SCRIPT.new $SCRIPT_NAME.src2pkg.auto SCRIPT=$SCRIPT_NAME.src2pkg.auto else mv $SCRIPT.new $SCRIPT fi echo $GREEN"DONE!"$NORMAL fi fi if [[ $SCRIPT ]] ; then export KEEP_BACKUPS PKG_DEST_DIR DEBUG REALLY_INSTALL REPLAY_ERRORS QUIET CLEANUP AUTO_PATCH CORRECT_PERMS /bin/bash $SCRIPT elif [[ $RUN_SCRIPT ]] ; then if [ -f $PWD/*.src2pkg.auto ] ; then SCRIPT=$(ls $PWD/*.src2pkg.auto) 2> /dev/null elif [ -f $PWD/*.src2pkg ] ; then SCRIPT=$(ls *.src2pkg) &> /dev/null else echo "No src2pkg script found!" exit 0 fi echo $BLUE"Running build script:"$NORMAL $(basename $SCRIPT) export KEEP_BACKUPS PKG_DEST_DIR DEBUG REALLY_INSTALL REPLAY_ERRORS QUIET CLEANUP AUTO_PATCH CORRECT_PERMS /bin/bash $SCRIPT else echo "File $@ not found!" fi #2 fi