From 13a1d5883c9aa81ee10d61cbe4c2f2223dad9a50 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 14 Feb 2012 10:11:43 -0600 Subject: scripts: unset CDPATH if cd is used This wonderful/awful little bash shell variable wrecks havoc on `cd` calls in shell scripts. Unset CDPATH in makepkg where we use `cd` quite heavily. In pacman-optimize, we can move the change directory logic into the bsdtar call so we are left with no usages of `cd` in the script. Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 2 ++ scripts/pacman-optimize.sh.in | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 80bb1c94..5e8687e7 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -36,6 +36,8 @@ export TEXTDOMAINDIR='@localedir@' # file -i does not work on Mac OSX unless legacy mode is set export COMMAND_MODE='legacy' +# Ensure CDPATH doesn't screw with our cd calls +unset CDPATH myver='@PACKAGE_VERSION@' confdir='@sysconfdir@' diff --git a/scripts/pacman-optimize.sh.in b/scripts/pacman-optimize.sh.in index 47d8814a..8a4e7224 100644 --- a/scripts/pacman-optimize.sh.in +++ b/scripts/pacman-optimize.sh.in @@ -122,8 +122,7 @@ find "$dbroot" -type f | sort | xargs md5sum > "$workdir/pacsums.old" # step 2: tar it up msg "$(gettext "Tar'ing up %s...")" "$dbroot" -cd "$dbroot" -bsdtar -czf "$workdir/pacman-db.tar.gz" ./ +bsdtar -czf "$workdir/pacman-db.tar.gz" -C "$dbroot" ./ if (( $? )); then rm -rf "$workdir" die_r "$(gettext "Tar'ing up %s failed.")" "$dbroot" -- cgit v1.2.3-70-g09d2 From edd81f3e8b505be2f7c7a18d3c28956b82264c45 Mon Sep 17 00:00:00 2001 From: Christoph Vigano Date: Tue, 14 Feb 2012 21:31:04 +0100 Subject: makepkg: fix syntax error in remove_deps This fixes a problem that occurs if you tell makepkg to remove installed dependencies (just to be sure) but there are none. As the $ was missing in front of deplist, the check never happened and 'pacman -Rn' was called which obviously failed. Dan: later reported as FS#28448. Signed-off-by: Christoph Vigano Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 5e8687e7..9766c8c6 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -521,7 +521,7 @@ remove_deps() { local deplist deplist=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \ <(printf "%s\n" "${current_pkglist[@]}") || true)) - if [[ -z deplist ]]; then + if [[ -z $deplist ]]; then return fi -- cgit v1.2.3-70-g09d2 From ca4142714137b16feabac09c4cda86b0a75036f8 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Wed, 15 Feb 2012 22:50:51 -0500 Subject: parseopts: normalize options into an array Modify parse_options logic to fill an array instead of printing parsed options. Avoid eval like the plague. Because it is the plague. Fixes bugs such as FS#28445. Signed-off-by: Dave Reisner Signed-off-by: Dan McGee --- scripts/library/parse_options.sh | 32 +++++++++++--------------------- scripts/makepkg.sh.in | 6 +++--- scripts/pacman-key.sh.in | 6 +++--- 3 files changed, 17 insertions(+), 27 deletions(-) (limited to 'scripts') diff --git a/scripts/library/parse_options.sh b/scripts/library/parse_options.sh index 48fd42cd..39038de6 100644 --- a/scripts/library/parse_options.sh +++ b/scripts/library/parse_options.sh @@ -23,17 +23,15 @@ parse_options() { [[ ${match} = ${1:2}:: && -n $2 && ${2:0:1} != "-" ]] && needsargument=1 if (( ! needsargument )); then - printf ' %s' "$1" + OPTRET+=("$1") else if [[ -n $2 ]]; then - printf ' %s ' "$1" + OPTRET+=("$1" "$2") shift - printf "'%q" "$1" while [[ -n $2 && ${2:0:1} != "-" ]]; do shift - printf " %q" "$1" + OPTRET+=("$1") done - printf "'" else printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'$1'" >&2 ret=1 @@ -57,26 +55,22 @@ parse_options() { ( -n ${1:$i+1} || ( -n $2 && ${2:0:1} != "-" ) ) ]] && needsargument=1 if (( ! needsargument )); then - printf ' -%s' "${1:i:1}" + OPTRET+=("-${1:i:1}") else if [[ -n ${1:$i+1} ]]; then - printf ' -%s ' "${1:i:1}" - printf "'%q" "${1:$i+1}" + OPTRET+=("-${1:i:1}" "${1:i+1}") while [[ -n $2 && ${2:0:1} != "-" ]]; do shift - printf " %q" "$1" + OPTRET+=("$1") done - printf "'" else if [[ -n $2 ]]; then - printf ' -%s ' "${1:i:1}" + OPTRET+=("-${1:i:1}" "$2") shift - printf "'%q" "$1" while [[ -n $2 && ${2:0:1} != "-" ]]; do shift - printf " %q" "$1" + OPTRET+=("$1") done - printf "'" else printf "@SCRIPTNAME@: $(gettext "option %s requires an argument\n")" "'-${1:i:1}'" >&2 @@ -91,15 +85,11 @@ parse_options() { fi done else - unused_options="${unused_options} '$1'" + unused_options+=("$1") fi shift done - printf " --" - [[ $unused_options ]] && printf ' %s' "${unused_options[@]}" - [[ $1 ]] && printf " '%s'" "$@" - printf "\n" - + OPTRET+=('--' "${unused_options[@]}") return $ret -} \ No newline at end of file +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 9766c8c6..805c31a9 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1906,11 +1906,11 @@ OPT_LONG+=",version,config:" # Pacman Options OPT_LONG+=",noconfirm,noprogressbar" -if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then +if ! parse_options $OPT_SHORT $OPT_LONG "$@"; then echo; usage; exit 1 # E_INVALID_OPTION; fi -eval set -- "$OPT_TEMP" -unset OPT_SHORT OPT_LONG OPT_TEMP +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET while true; do case "$1" in diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 45ece51b..4b678041 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -504,11 +504,11 @@ OPT_LONG="add::,config:,delete:,edit-key:,export::,finger::,gpgdir:" OPT_LONG+=",help,import:,import-trustdb:,init,keyserver:,list-keys::,list-sigs::" OPT_LONG+=",lsign-key:,populate::,recv-keys:,refresh-keys::,updatedb" OPT_LONG+=",verify:,version" -if ! OPT_TEMP="$(parse_options $OPT_SHORT $OPT_LONG "$@")"; then +if ! parse_options $OPT_SHORT $OPT_LONG "$@"; then echo; usage; exit 1 # E_INVALID_OPTION; fi -eval set -- "$OPT_TEMP" -unset OPT_SHORT OPT_LONG OPT_TEMP +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET if [[ $1 == "--" ]]; then usage; -- cgit v1.2.3-70-g09d2