From f5c5a277e2df14650ae441f32950aa6d4deee50f Mon Sep 17 00:00:00 2001 From: Xavier Chantry <shiningxc@gmail.com> Date: Wed, 28 May 2008 21:57:28 +0200 Subject: [PATCH] makepkg : switch from getopt to getopts builtin
getopt is an external script for parsing and is less portable than getopts which is a bash builtin. The main problem is that it only supports short opts, so long opts had to be dropped. The benefits are a much better portability and a simpler code for the arguments parsing. TODO: better testing, fix man page. Signed-off-by: Xavier Chantry <shiningxc@gmail.com> --- scripts/makepkg.sh.in | 143 +++++++++++++++++++++--------------------------- 1 files changed, 63 insertions(+), 80 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index cc44c68..f880091 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -27,7 +27,7 @@ # makepkg uses quite a few external programs during its execution. You # need to have at least the following installed for makepkg to function: # awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, find (findutils), -# getopt (util-linux), gettext, grep, gzip, sed +# gettext, grep, gzip, sed # gettext initialization export TEXTDOMAIN='pacman' @@ -1056,31 +1056,31 @@ usage() { printf "$(gettext "Usage: %s [options]")\n" "$0" echo echo "$(gettext "Options:")" - printf "$(gettext " -A, --ignorearch Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT" - echo "$(gettext " -c, --clean Clean up work files after build")" - echo "$(gettext " -C, --cleancache Clean up source files from the cache")" - echo "$(gettext " -d, --nodeps Skip all dependency checks")" - echo "$(gettext " -e, --noextract Do not extract source files (use existing src/ dir)")" - echo "$(gettext " -f, --force Overwrite existing package")" - echo "$(gettext " -g, --geninteg Generate integrity checks for source files")" - echo "$(gettext " -h, --help This help")" - echo "$(gettext " -i, --install Install package after successful build")" - echo "$(gettext " -L, --log Log package build process")" - echo "$(gettext " -m, --nocolor Disable colorized output messages")" - echo "$(gettext " -o, --nobuild Download and extract files only")" + printf "$(gettext " -A Ignore incomplete arch field in %s")\n" "$BUILDSCRIPT" + echo "$(gettext " -c Clean up work files after build")" + echo "$(gettext " -C Clean up source files from the cache")" + echo "$(gettext " -d Skip all dependency checks")" + echo "$(gettext " -e Do not extract source files (use existing src/ dir)")" + echo "$(gettext " -f Overwrite existing package")" + echo "$(gettext " -g Generate integrity checks for source files")" + echo "$(gettext " -h This help")" + echo "$(gettext " -i Install package after successful build")" + echo "$(gettext " -L Log package build process")" + echo "$(gettext " -m Disable colorized output messages")" + echo "$(gettext " -o Download and extract files only")" printf "$(gettext " -p <buildscript> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT" - echo "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")" + echo "$(gettext " -r Remove installed dependencies after a successful build")" # fix flyspray feature request #2978 - echo "$(gettext " -R, --repackage Repackage contents of pkg/ without building")" - echo "$(gettext " -s, --syncdeps Install missing dependencies with pacman")" - echo "$(gettext " --asroot Allow makepkg to run as root user")" - echo "$(gettext " --holdver Prevent automatic version bumping for development PKGBUILDs")" - echo "$(gettext " --source Do not build package; generate a source-only tarball")" + echo "$(gettext " -R Repackage contents of pkg/ without building")" + echo "$(gettext " -s Install missing dependencies with pacman")" + echo "$(gettext " -O Allow makepkg to run as root user")" + echo "$(gettext " -H Prevent automatic version bumping for development PKGBUILDs")" + echo "$(gettext " -S Do not build package; generate a source-only tarball")" echo echo "$(gettext "These options can be passed to pacman:")" echo - echo "$(gettext " --noconfirm Do not ask for confirmation when resolving dependencies")" - echo "$(gettext " --noprogressbar Do not show a progress bar when downloading files")" + echo "$(gettext " -n Do not ask for confirmation when resolving dependencies")" + echo "$(gettext " -N Do not show a progress bar when downloading files")" echo printf "$(gettext "If -p is not specified, makepkg will look for '%s'")\n" "$BUILDSCRIPT" echo @@ -1130,66 +1130,49 @@ SRCDEST=${_SRCDEST:-$SRCDEST} SRCDEST=${SRCDEST:-$startdir} #default to $startdir if undefined # Parse Command Line Options. -OPT_SHORT="AbcCdefFghiLmop:rRsSV" -OPT_LONG="ignorearch,asroot,builddeps,clean,cleancache,nodeps,noextract,force,forcever:,geninteg,help,holdver" -OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source,syncdeps,usesudo,version" -# Pacman Options -OPT_LONG="$OPT_LONG,noconfirm,noprogressbar" -OPT_TEMP="$(getopt -o "$OPT_SHORT" -l "$OPT_LONG" -n "$(basename "$0")" -- "$@" || echo 'GETOPT GO BANG!')" -if echo "$OPT_TEMP" | grep -q 'GETOPT GO BANG!'; then - # This is a small hack to stop the script bailing with 'set -e' - echo; usage; exit 1 # E_INVALID_OPTION; -fi -eval set -- "$OPT_TEMP" -unset OPT_SHORT OPT_LONG OPT_TEMP +OPT_SHORT="AcCdefF:ghHiLmnNoOp:rRsSVX" -while true; do - case "$1" in +while getopts "$OPT_SHORT" name; do + case $name in # Pacman Options - --noconfirm) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;; - --noprogressbar) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;; + n) PACMAN_OPTS="$PACMAN_OPTS --noconfirm" ;; + N) PACMAN_OPTS="$PACMAN_OPTS --noprogressbar" ;; # Makepkg Options - --asroot) ASROOT=1 ;; - -A|--ignorearch) IGNOREARCH=1 ;; - -c|--clean) CLEANUP=1 ;; - -C|--cleancache) CLEANCACHE=1 ;; - -d|--nodeps) NODEPS=1 ;; - -e|--noextract) NOEXTRACT=1 ;; - -f|--force) FORCE=1 ;; - #hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver - --forcever) shift; FORCE_VER=$1;; - -F) INFAKEROOT=1 ;; - -g|--geninteg) GENINTEG=1 ;; - --holdver) HOLDVER=1 ;; - -i|--install) INSTALL=1 ;; - -L|--log) LOGGING=1 ;; - -m|--nocolor) USE_COLOR='n' ;; - -o|--nobuild) NOBUILD=1 ;; - -p) shift; BUILDSCRIPT=$1 ;; - -r|--rmdeps) RMDEPS=1 ;; - -R|--repackage) REPKG=1 ;; - --source) SOURCEONLY=1 ;; - -s|--syncdeps) DEP_BIN=1 ;; - - # BEGIN DEPRECATED - -S|--usesudo) - warning "$(gettext "Sudo is used by default now. The --usesudo option is deprecated!")" ;; - # END DEPRECATED - - -h|--help) usage; exit 0 ;; # E_OK - -V|--version) version; exit 0 ;; # E_OK - - --) OPT_IND=0; shift; break;; - *) usage; exit 1 ;; # E_INVALID_OPTION + A) IGNOREARCH=1 ;; + c) CLEANUP=1 ;; + C) CLEANCACHE=1 ;; + d) NODEPS=1 ;; + e) NOEXTRACT=1 ;; + f) FORCE=1 ;; + # hidden opt used by fakeroot call for svn/cvs/etc PKGBUILDs to set pkgver + F) FORCE_VER="$OPTARG";; + g) GENINTEG=1 ;; + H) HOLDVER=1 ;; + i) INSTALL=1 ;; + L) LOGGING=1 ;; + m) USE_COLOR='n' ;; + o) NOBUILD=1 ;; + O) ASROOT=1 ;; + p) BUILDSCRIPT="$OPTARG" ;; + r) RMDEPS=1 ;; + R) REPKG=1 ;; + s) DEP_BIN=1 ;; + S) SOURCEONLY=1 ;; + # hidden opt to indicate fakeroot call + X) INFAKEROOT=1 ;; + + h) usage; exit 0 ;; # E_OK + V) version; exit 0 ;; # E_OK + + ?) usage; exit 1 ;; # E_INVALID_OPTION esac - shift done if [ "$HOLDVER" = "1" -a "$FORCE_VER" != "" ]; then - # The extra '--' is here to prevent gettext from thinking --holdver is + # The extra '--' is here to prevent gettext from thinking -H is # an option - error "$(gettext "\\0--holdver and --forcever cannot both be specified" )" + error "$(gettext "\\0-H and -F cannot both be specified" )" exit 1 fi @@ -1233,12 +1216,12 @@ if [ "$INFAKEROOT" = "0" ]; then # Warn those who like to live dangerously. error "$(gettext "Running makepkg as root is a BAD idea and can cause")" plain "$(gettext "permanent, catastrophic damage to your system. If you")" - plain "$(gettext "wish to run as root, please use the --asroot option.")" + plain "$(gettext "wish to run as root, please use the -O option.")" exit 1 # $E_USER_ABORT elif [ $EUID -gt 0 -a "$ASROOT" = "1" ]; then - # Warn those who try to use the --asroot option when they are not root - error "$(gettext "The --asroot option is meant for the root user only.")" - plain "$(gettext "Please rerun makepkg without the --asroot flag.")" + # Warn those who try to use the -O option when they are not root + error "$(gettext "The -O option is meant for the root user only.")" + plain "$(gettext "Please rerun makepkg without the -O flag.")" exit 1 # $E_USER_ABORT elif [ "$(check_buildenv fakeroot)" = "y" -a $EUID -gt 0 ]; then if [ ! $(type -p fakeroot) ]; then @@ -1254,7 +1237,7 @@ if [ "$INFAKEROOT" = "0" ]; then fi else if [ "$FAKEROOTKEY" = "" ]; then - error "$(gettext "Do not use the '-F' option. This option is only for use by makepkg.")" + error "$(gettext "Do not use the '-X' option. This option is only for use by makepkg.")" exit 1 # TODO: error code fi fi @@ -1333,7 +1316,7 @@ if [ "$install" -a ! -f "$install" ]; then fi # We need to run devel_update regardless of whether we are in the fakeroot -# build process so that if the user runs makepkg --forcever manually, we +# build process so that if the user runs makepkg -F (forcever) manually, we # 1) output the correct pkgver, and 2) use the correct filename when # checking if the package file already exists - fixes FS #9194 devel_check @@ -1469,9 +1452,9 @@ else msg "$(gettext "Entering fakeroot environment...")" if [ "$newpkgver" != "" ]; then - fakeroot -- $0 --forcever $newpkgver -F $ARGLIST || exit $? + fakeroot -- $0 -F $newpkgver -X $ARGLIST || exit $? else - fakeroot -- $0 -F $ARGLIST || exit $? + fakeroot -- $0 -X $ARGLIST || exit $? fi fi -- 1.5.5.1