#!/bin/bash # /usr/bin/trackinstall # This file is part of the src2pkg program: # Copyright 2005-2009 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 TRACKINSTALL_VERSION="1.9.8" CWD="$(pwd)" cd "$CWD" && CWD="$(pwd)" TRACK_INSTALL=1 show_usage() { echo "" echo " $(basename $0) - Build an installable package from pre-compiled sources" echo " or from other content in the current directory." echo "" echo " $(basename $0) -[ABCHINPSV(VV)W] -[abdinpv]" echo "" echo " The following User Options take no argument:" echo " -A Auto-generate a TrackBuild script if successful." echo " -B Backup any files overwritten by this installation." echo " -I Install the created package when finished." echo " -C Place final package in the current directory." echo " -H Place final package in your home directory." echo " -N New TrackBuild script and slack-desc file only." echo " -P Preserve permissions in the source directory." echo " -Q Query the user interactively during configuration and package creation" echo " -S Run special install commands - 'sh install.sh' by default" echo " -V DEBUG -show detailed prompts for debugging." echo " -VV Be verbose. Show all output from the steps." echo " -W Wipe up -cleanup temporary files when finished." 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 Set the architecture of the package (--arch)[-a=noarch]." echo " -b Set the package build/release number (--build)[-b=4]." echo " -d Specify the included documents (-doclist)[-d='README foo.HOWTO AUTHORS']." echo " -i Set the install command line (--install)[-i='make install']." echo " -n Set alternate name for the package and (--alt-name)[-n=newname]" echo " -p (--pre_fix,--prefix) Set the package installation prefix. [-p=/usr/local]" echo " -v Set alternate version for the package (--alt-version)[-v=0.0.0a]." echo " Special Options:" echo " -h (--help) Show this help page and exit." echo " -hh (--more-help) Show extended options and examples, then exit." echo " --version Show the trackinstall version number and exit." echo " --list Show a list of the trackinstall instruction functions." echo "" echo " Examples:" echo " trackinstall -C -W" echo " Place final package in the current directory and delete temporary files." echo " trackinstall -b=2" echo " Set the BUILD number to '2'." echo " trackinstall -i='make install install_data'" echo " install with 'make install install_data (same as running 'make install' and 'make install_data')" echo " trackinstall -P -S -i='bash ./install.script'" echo " Preserve permissions and use 'bash ./install.script' instead of 'make install'" echo "" echo " For more usage help, run 'trackinstall -hh', 'man trackinstall' or see the documentation." } show_more_help() { echo "" echo " Advanced options for creating small non-standard packages :-)" echo " -JAIL Run installation in a 'jailed' root directory." echo " -REAL Run installation in the real root filesystem using backup." echo " -DEST Run installation using the DESTDIR variable, when available." echo " -UNION Run installation using a unionfs/chroot, if available." echo " --pause=?? (before|after) Pause before or after running each function." echo " --resume=?? Resume a build starting at the named instrcution function." echo " -E Use extended database files (slack-required and slack-supplies)" echo " -L Delete extra language files (man-pages, locale and i18n) files." echo " Be sure to configure /etc/src2pkg/DONT_PURGE.locales file first." 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 " -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 or upx-ucl if present" echo " -Z4 Z4 Link to a common copy of the GPL in /usr/share/licences." } FUNCTION_LIST=" 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." echo "* And, trackinstall only uses some of the available src2pkg functions." exit 0 } NAMVERS=$(basename "$CWD") VERSION=$(echo "$NAMVERS" | rev | cut -f1 -d"-" | rev) NAME=$(echo "$NAMVERS" | rev | cut -f2,3,4 -d"-" | rev) # . /usr/libexec/src2pkg/FUNCTIONS if ! [[ -z $1 ]] ; then if [ "$1" = "-h" -o "$1" = "--help" ] ; then show_usage exit 0 fi if [[ "$1" = "--version" ]] ; then echo "trackinstall version-$TRACKINSTALL_VERSION" exit 0 fi if [[ $1 = "--more-help" ]] | [[ $1 = "-hh" ]] ; then show_more_help exit 0 fi for word in "$@" ; do case $word in -A) AUTO_SCRIPT=1 ; shift ;; -B) KEEP_BACKUPS="YES" ; shift ;; -I) REALLY_INSTALL="YES" ;; -C) PKG_DEST_DIR="$CWD" ; shift ;; -DESTDIR) INSTALL_TYPE="DESTDIR" ; shift ;; -E) EXTENDED_DATABASE="YES" ; shift ;; -EPX) COMPRESS_BINS="YES" ; BIN_COMPRESSOR="exepak" ; shift ;; -H) PKG_DEST_DIR="$HOME" ; shift ;; -JAIL) INSTALL_TYPE="JAIL" ; shift ;; -L) PURGE_LOCALES="YES" ; shift ;; -N) NEW_BUILD=1 ; shift ;; -P) CORRECT_PERMS="NO" ; shift ;; -Q) INTERACTIVE_MODE="ALL" ; shift ;; -REAL) INSTALL_TYPE="REAL" ; shift ;; -S) SHELL_INSTALL=1 ; shift ;; -TBZ) PKG_FORMAT="tbz" ; shift ;; -TGZ) PKG_FORMAT="tgz" ; shift ;; -TLZ) PKG_FORMAT="tlz" ; shift ;; -TXZ) PKG_FORMAT="txz" ; shift ;; -UNION) INSTALL_TYPE=UNION ; shift ;; -UPX) COMPRESS_BINS="YES" ; shift ;; -V) DEBUG=1 ; shift ;; -VV) QUIET="NO" ; shift ;; -W|--cleanup) CLEANUP="PKG" ; shift ;; -Z1) SAVE_SPACE=1 ; shift ;; -Z2) SAVE_SPACE=2 ; shift ;; -Z3) SAVE_SPACE=3 ; shift ;; -Z4) SAVE_SPACE=4 ; 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 $word |cut -f2 -d'=') ; shift ;; -b=*|--build=*) BUILD=$(echo $word |cut -f2 -d'=') ; shift ;; -d=*|--doclist=*) DOCLIST=$(echo $word |cut -f2 -d'=') ; shift ;; -i=*|--install_line=*) INSTALL_LINE=$(echo $word |cut -f2- -d'=') ; shift ;; -n=*|--alt_name=*) ALT_NAME=$(echo $word |cut -f2 -d'=') ; shift ;; -p=*|--pre_fix=*|--prefix=*) PRE_FIX=$(echo $option |cut -f2 -d'=') ; shift ;; -v=*|--alt_version=*) ALT_VERSION=$(echo $word |cut -f2 -d'=') ; shift ;; *) echo "Ignoring unrecognized option: $word" ; sleep 2 ;; esac done fi . /usr/libexec/src2pkg/FUNCTIONS pre_process if ! [[ $NEW_BUILD ]] ; then make_dirs fake_install fix_pkg_perms strip_bins create_docs compress_man_pages make_description make_doinst make_package post_process if [[ $FAILED = "" ]] ; then true else echo $RED"FAILED!! "$NORMAL"Creation of package $PKG_NAME has failed." fi if [[ $FAILED = "CANCELLED" ]] ; then echo "Operation cancelled by user. "$RED"Exiting!"$NORMAL exit elif [[ $FAILED != "" ]] ; then echo $(basename "$0") $RED"ERROR "$NORMAL"in $FAILED" exit fi fi # 3 write the script if [[ $AUTO_SCRIPT ]] || [[ $NEW_BUILD ]]; then echo -n $CYAN"NOTICE- "$NORMAL"Writing build script: $NAME.TrackBuild for you... " # TrackBuild echo "#!/bin/bash" > "$CWD"/$NAME.TrackBuild echo "## TrackBuild script for: $NAME" >> "$CWD"/$NAME.TrackBuild echo "## Auto-generated by 'trackinstall-$TRACKINSTALL_VERSION'" >> "$CWD"/$NAME.TrackBuild echo "## trackinstall Copyright 2005-2008 Gilbert Ashley " >> "$CWD"/$NAME.TrackBuild echo "## Full package name: $SHORT_NAME.tgz" >> "$CWD"/$NAME.TrackBuild echo "" >> "$CWD"/$NAME.TrackBuild echo "NAME='$NAME'" >> "$CWD"/$NAME.TrackBuild echo "VERSION='$VERSION'" >> "$CWD"/$NAME.TrackBuild echo "ARCH='$ARCH'" >> "$CWD"/$NAME.TrackBuild echo "BUILD='$BUILD'" >> "$CWD"/$NAME.TrackBuild echo "TRACK_INSTALL='YES'" >> "$CWD"/$NAME.TrackBuild [[ $SHELL_INSTALL ]] && echo "SHELL_INSTALL='YES'" >> "$CWD"/$NAME.TrackBuild echo "PRE_FIX='$PRE_FIX'" >> "$CWD"/$NAME.TrackBuild echo "" >> "$CWD"/$NAME.TrackBuild echo "# Any extra options go here:" >> "$CWD"/$NAME.TrackBuild ! [[ "$INSTALL_LINE" = "" ]] && echo "INSTALL_LINE='$INSTALL_LINE'" >> "$CWD"/$NAME.TrackBuild ! [[ "$DOCLIST" = "" ]] && echo "DOCLIST='$DOCLIST'" >> "$CWD"/$NAME.TrackBuild [[ "$CORRECT_PERMS" = "NO" ]] && echo "CORRECT_PERMS='NO'" >> "$CWD"/$NAME.TrackBuild echo "" >> "$CWD"/$NAME.TrackBuild echo "# Read in the config file and functions:" >> "$CWD"/$NAME.TrackBuild echo ". /usr/libexec/src2pkg/FUNCTIONS ;" >> "$CWD"/$NAME.TrackBuild echo "" >> "$CWD"/$NAME.TrackBuild echo "# do_track_install can substitute the following functions:" >> "$CWD"/$NAME.TrackBuild echo "" >> "$CWD"/$NAME.TrackBuild cat >> "$CWD"/$NAME.TrackBuild << EOF pre_process make_dirs fake_install fix_pkg_perms strip_bins create_docs compress_man_pages make_description make_doinst make_package post_process EOF echo "" >> "$CWD"/$NAME.TrackBuild echo "# src2pkg and trackinstall - Copyright 2005-2009 Gilbert Ashley " >> "$CWD"/$NAME.TrackBuild echo "# See /usr/doc/src2pkg-x.x.x, run 'man trackinstall' or 'trackinstall --help' for help. Below" >> "$CWD"/$NAME.TrackBuild echo "# are some common trackinstall options for easy cut-and-paste use if you need them." >> "$CWD"/$NAME.TrackBuild echo "# INSTALL_LINE ='' PRE_FIX='' DOCLIST=''" >> "$CWD"/$NAME.TrackBuild echo "# SHELL_INSTALL='YES' CORRECT_PERMS='NO'" >> "$CWD"/$NAME.TrackBuild echo "# When editing this script to add custom code, use these variables" >> "$CWD"/$NAME.TrackBuild echo "# to refer to the current directory, the sources or the package tree:" >> "$CWD"/$NAME.TrackBuild echo "# \$CWD (current directory), \$SRC_DIR (sources), \$PKG_DIR (package tree)" >> "$CWD"/$NAME.TrackBuild echo $GREEN"DONE!"$NORMAL fi #3 if [[ $NEW_BUILD ]] ; then echo $BLUE"Creating new.slack-desc file. "$NORMAL"Edit, if needed and rename to slack-desc for use." cat > "$CWD"/new.slack-desc << END $NAME: $NAME $NAME: $NAME: No description was given for this package. $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: $NAME: $BLURB_11 END fi exit 0