From 08980fb4bcf4078b4b22b2c1f6f36cbbdee89ec4 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Mon, 22 Dec 2008 21:28:35 +1000 Subject: makepkg: Replace getopt with internal function This will allow makepkg to work on systems like Mac OS X where the default getopt is too old to properly handle long options. The new parse_options function should replicate getopt's behaviour completely. Original work: Yun Zheng Hu [Allan: Rewrite and bug fixes] Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 91 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index ef2ede1f..8a6dcb2f 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1101,6 +1101,93 @@ devel_update() { fi } +# getopt like parser +parse_options() { + local short_options=$1; shift; + local long_options=$1; shift; + local ret=0; + local unused_options="" + + while [ -n "$1" ]; do + if [ ${1:0:2} = '--' ]; then + if [ -n "${1:2}" ]; then + local match="" + for i in ${long_options//,/ }; do + if [ ${1:2} = ${i//:} ]; then + match=$i + break + fi + done + if [ -n "$match" ]; then + if [ ${1:2} = $match ]; then + printf ' %s' "$1" + else + if [ -n "$2" ]; then + printf ' %s' "$1" + shift + printf " '%s'" "$1" + else + echo "makepkg: option '$1' $(gettext "requires an argument")" >&2 + ret=1 + fi + fi + else + echo "makepkg: $(gettext "unrecognized option") '$1'" >&2 + ret=1 + fi + else + shift + break + fi + elif [ ${1:0:1} = '-' ]; then + for ((i=1; i<${#1}; i++)); do + if [[ "$short_options" =~ "${1:i:1}" ]]; then + if [[ "$short_options" =~ "${1:i:1}:" ]]; then + if [ -n "${1:$i+1}" ]; then + printf ' -%s' "${1:i:1}" + printf " '%s'" "${1:$i+1}" + else + if [ -n "$2" ]; then + printf ' -%s' "${1:i:1}" + shift + printf " '%s'" "${1}" + else + echo "makepkg: option $(gettext "requires an argument") -- '${1:i:1}'" >&2 + ret=1 + fi + fi + break + else + printf ' -%s' "${1:i:1}" + fi + else + echo "makepkg: $(gettext "invalid option") -- '${1:i:1}'" >&2 + ret=1 + fi + done + else + unused_options="${unused_options} '$1'" + fi + shift + done + + printf " --" + if [ -n "$unused_options" ]; then + for i in ${unused_options[@]}; do + printf ' %s' "$i" + done + fi + if [ -n "$1" ]; then + while [ -n "$1" ]; do + printf " '%s'" "${1}" + shift + done + fi + printf "\n" + + return $ret +} + usage() { printf "makepkg (pacman) %s\n" "$myver" echo @@ -1189,8 +1276,8 @@ OPT_LONG="$OPT_LONG,install,log,nocolor,nobuild,rmdeps,repackage,source" OPT_LONG="$OPT_LONG,syncdeps,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 +OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@" || echo 'PARSE_OPTIONS FAILED')" +if echo "$OPT_TEMP" | grep -q 'PARSE_OPTIONS FAILED'; then # This is a small hack to stop the script bailing with 'set -e' echo; usage; exit 1 # E_INVALID_OPTION; fi -- cgit v1.2.3-24-g4f1b From 751d37e749fcb0a06bb21dee4b5b6d0b062ed284 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 26 Dec 2008 17:49:49 +1000 Subject: makepkg: quote all uses of BUILDSCRIPT Allows specifying alternative build script with spaces in name Signed-off-by: Allan McRae [Dan: backport some of the fixes to maint] Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 8a6dcb2f..06595094 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1094,9 +1094,9 @@ devel_update() { # if [ "$newpkgver" != "" ]; then if [ "$newpkgver" != "$pkgver" ]; then - sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" ./$BUILDSCRIPT - sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" ./$BUILDSCRIPT - source $BUILDSCRIPT + sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT" + sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT" + source "$BUILDSCRIPT" fi fi } @@ -1360,7 +1360,7 @@ if [ "$CLEANCACHE" = "1" ]; then fi fi -if [ -z $BUILDSCRIPT ]; then +if [ -z "$BUILDSCRIPT" ]; then error "$(gettext "BUILDSCRIPT is undefined! Ensure you have updated %s.")" "$confdir/makepkg.conf" exit 1 fi -- cgit v1.2.3-24-g4f1b From f4651c49af94164f2c129ea6eb3d78b86be4d5bc Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 2 Jan 2009 14:34:52 +1000 Subject: makepkg: tidy version package tests The use if "! -z" to check if a string is not null is not good practice so replace with the "-n" option. Also use the AND comparison within one test rather than on two separate tests. Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 06595094..b18665c5 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1034,27 +1034,27 @@ devel_check() { # number to avoid having to determine the version number twice. # Also do a brief check to make sure we have the VCS tool available. oldpkgver=$pkgver - if [ ! -z ${_darcstrunk} ] && [ ! -z ${_darcsmod} ] ; then + if [ -n "${_darcstrunk}" -a -n "${_darcsmod}" ] ; then [ $(type -p darcs) ] || return 0 msg "$(gettext "Determining latest darcs revision...")" newpkgver=$(date +%Y%m%d) - elif [ ! -z ${_cvsroot} ] && [ ! -z ${_cvsmod} ] ; then + elif [ -n "${_cvsroot}" -a -n "${_cvsmod}" ] ; then [ $(type -p cvs) ] || return 0 msg "$(gettext "Determining latest cvs revision...")" newpkgver=$(date +%Y%m%d) - elif [ ! -z ${_gitroot} ] && [ ! -z ${_gitname} ] ; then + elif [ -n "${_gitroot}" -a -n "${_gitname}" ] ; then [ $(type -p git) ] || return 0 msg "$(gettext "Determining latest git revision...")" newpkgver=$(date +%Y%m%d) - elif [ ! -z ${_svntrunk} ] && [ ! -z ${_svnmod} ] ; then + elif [ -n "${_svntrunk}" -a -n "${_svnmod}" ] ; then [ $(type -p svn) ] || return 0 msg "$(gettext "Determining latest svn revision...")" newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 's/^Last Changed Rev: \([0-9]*\)$/\1/p') - elif [ ! -z ${_bzrtrunk} ] && [ ! -z ${_bzrmod} ] ; then + elif [ -n "${_bzrtrunk}" -a -n "${_bzrmod}" ] ; then [ $(type -p bzr) ] || return 0 msg "$(gettext "Determining latest bzr revision...")" newpkgver=$(bzr revno ${_bzrtrunk}) - elif [ ! -z ${_hgroot} ] && [ ! -z ${_hgrepo} ] ; then + elif [ -n "${_hgroot}" -a -n "${_hgrepo}" ] ; then [ $(type -p hg) ] || return 0 msg "$(gettext "Determining latest hg revision...")" if [ -d ./src/$_hgrepo ] ; then -- cgit v1.2.3-24-g4f1b From 2f59996c54da473294de4adf44d521299a045a84 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 2 Jan 2009 04:07:13 +1000 Subject: makepkg: detect incorrect usage of provides array Using > or < in the provides array is wrong so make it cause an error. Fixes FS#12540. Also, use bash substitution rather than spawning new processes where possible in the error checking. Move split package detection to a better position. Signed-off-by: Allan McRae [Dan: backport to maint] Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index b18665c5..04d2aca1 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1439,11 +1439,11 @@ if [ -z "$pkgrel" ]; then error "$(gettext "%s is not allowed to be empty.")" "pkgrel" exit 1 fi -if [ $(echo "$pkgver" | grep '-') ]; then +if [ "$pkgver" != "${pkgver//-/}" ]; then error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver" exit 1 fi -if [ $(echo "$pkgrel" | grep '-') ]; then +if [ "$pkgrel" != "${pkgrel//-/}" ]; then error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel" exit 1 fi @@ -1465,6 +1465,14 @@ if ! in_array $CARCH ${arch[@]}; then fi fi +for provide in ${provides[@]}; do + if [ $provide != ${provide///} ]; then + error "$(gettext "Provides array cannot contain comparison (< or >) operators.")" + exit 1 + fi +done +unset provide + if [ "$install" -a ! -f "$install" ]; then error "$(gettext "Install scriptlet (%s) does not exist.")" "$install" exit 1 -- cgit v1.2.3-24-g4f1b From cb03817ee85905db8a06278f1f7efaa3e9174bf9 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 2 Jan 2009 22:23:59 -0600 Subject: Small makefile update Use the proper call for symlink creation Signed-off-by: Dan McGee --- scripts/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/Makefile.am b/scripts/Makefile.am index fd8fab7f..10e179e1 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -59,6 +59,7 @@ pacman-optimize: $(srcdir)/pacman-optimize.sh.in rankmirrors: $(srcdir)/rankmirrors.py.in repo-add: $(srcdir)/repo-add.sh.in repo-remove: $(srcdir)/repo-add.sh.in - ln -sf repo-add repo-remove + rm -f repo-remove + $(LN_S) repo-add repo-remove # vim:set ts=2 sw=2 noet: -- cgit v1.2.3-24-g4f1b