#!/bin/bash # src2pkg Copyright 2006 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` -[ANOTV(VV)W] [bdefilmnprsz] file-name" echo "" echo " The following options take no argument:" echo " -A Autogenerate a src2pkg script if the build succeeds." echo " -B Backup any files overwritten by this installation." echo " -C Place finished package in Current directory." echo " -D DEBUG -show detailed prompts for debugging." 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." echo " -T Test-build the source code without installing or making a package." echo " -V Replay errors if configuration or compilation fail." echo " -VV Be verbose. Show all output from the steps." echo " -W Wipe out temporary files." echo " The following options require an argument separated by the '=' sign:" echo " Use quotes '' or \"\" around the arguments if they contain spaces." echo " -a Set the architecture of the package (--arch)[-a=noarch] (ARCH='')." echo " -b Set the build or release number (--build)[-b=2] (BUILD='')." echo " -c Set the CONFIG_COMMAND option" echo " -d Set the list of douments to include [-d='README AUTHORS'] (DOCLIST='')." echo " -e Pass extra arguments to configure [-e='--with-gnu-ld'] (EXTRA_CONFIGS='')." echo " -f Set the CFLAGS variable [-f='-Wall -O3'] (STD_FLAGS='')." echo " -i Set the install command line (--install)(-i='make install')." echo " -m Set the 'make' command [-m='make dep all']." echo " -n Set the package name (--alt-name)[-n='newname'] (ALT_NAME='')." echo " -p Set the package installation prefix [-p=/usr/local] (PRE_FIX='')." echo " -s Set the configuration subdir [-s=src] (CONFIG_SUBDIR='')." echo " -v Set the version of the package (--alt-version)[-v=0.0.0a]." echo " Note: Variables shown above in parenthesis are the src2pkg script equivalents." 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" } # 1 if ! [[ -z $1 ]] ; then 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) DEBUG=1 ; 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 ;; -V) REPLAY_ERRORS="YES" ; shift ;; -VV) QUIET="NO" ; shift ;; -W) CLEANUP="ALL" ; shift ;; -a=*|--arch=*) ARCH=`echo $option |cut -f2 -d'='` ; shift ;; -b=*|--build=*) BUILD=`echo $option |cut -f2 -d'='` ; shift ;; -c=*|--configure=*) CONFIG_COMMAND=`echo $option |cut -f2 -d'='` ; shift ;; -d=*|--doclist=*) DOCLIST=`echo $option |cut -f2 -d'='` ; shift ;; -e=*) EXTRA_CONFIGS=`echo $option |cut -f2- -d'='` ; shift ;; -f=*) STD_FLAGS=`echo $option |cut -f2- -d'='` ; shift ;; -i=*|--install=*) INSTALL_LINE=`echo $option |cut -f2- -d'='` ; shift ;; -m=*|--make=*) MAKE_COMMAND=`echo $option |cut -f2 -d'='` ; shift ;; -n=*|--name=*) ALT_NAME=`echo $option |cut -f2 -d'='` ; shift ;; -p=*|--prefix=*) PRE_FIX=`echo $option |cut -f2 -d'='` ; [[ `echo $PRE_FIX |cut -f1 -d'/'` != "" ]] && PRE_FIX="/$PRE_FIX" ; shift ;; -s=*) CONFIG_SUBDIR=`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 ;; *) echo "Unrecognized option: $option" ; exit ;; esac done if [[ "$1" != "" ]] ; then SOURCE="$1" fi if [[ $SOURCE ]] ; then #SOURCE="$@" #[[ ! $SOURCE_NAME ]] && SOURCE_NAME="`basename $@`" #echo $SOURCE $NAME $VERSION $EXT # source /usr/libexec/src2pkg/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 # 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 2006-2007 Gilbert Ashley " >> $CWD/$NAME.src2pkg.auto echo "" >> $CWD/$NAME.src2pkg.auto if [[ $SOURCE_NAME ]] ; then echo "SOURCE_NAME='$SOURCE_NAME'" >> $CWD/$NAME.src2pkg.auto 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 else echo "NAME='$NAME'" >> $CWD/$NAME.src2pkg.auto echo "VERSION='$VERSION'" >> $CWD/$NAME.src2pkg.auto echo "SRC_SUFFIX='$SRC_SUFFIX'" >> $CWD/$NAME.src2pkg.auto fi 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 [ "$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 [[ $FUNNY_SUBDIR ]] || [[ $CONFIG_SUBDIR ]] && echo "CONFIG_SUBDIR='$FUNNY_SUBDIR'" >> $CWD/$NAME.src2pkg.auto [[ "$DOCLIST" ]] && echo "DOCLIST='$DOCLIST'" >> $CWD/$NAME.src2pkg.auto [[ "$USE_OBJ_DIR" = "YES" ]] && echo "USE_OBJ_DIR='YES'" >> $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 # echo $GREEN"DONE!"$NORMAL fi #3 else echo "File $@ not found!" fi #2 else show_usage echo "Please give the path to a tar archive." fi exit 0