diff options
author | Luke Shumaker <lukeshu@parabola.nu> | 2014-06-18 12:07:09 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2018-03-21 12:23:17 -0400 |
commit | 0432cffc42040f852b9a55c27316248da9064b67 (patch) | |
tree | dc4262603be52e79106239454ec2f0d4aec88061 | |
parent | 36087fbd8b030fa6f908fdbb667292e3c078b615 (diff) |
Fixups near unquoted variables
Using the following command to find unquoted variables (and ignoring
more than a a few false positives),
grep -Prn --exclude-dir=.git '(?<!["=]|\[\[ |\[\[ -[zn] )\$(?!{?#|\(|\? )'
one is lead to find a few cleanups that are something other than "add
double-quotes". That's what these are. We'll leave dumb adding of
double-quotes for another commit.
Most of these are still fixing quoting issues, just with a better fix.
- parse_pkgbuilds.sh: Avoid having to escape quotes in `eval` strings
by using `declare -p`. Updates the logic copied from makepkg, with the
latest logic copied from makepkg. See
https://git.archlinux.org/pacman.git/commit/?id=9e52a36794552b77ecf26f7f34b226d096978f1e
- sourceballs: Avoid using ary=($string) to do field separation by
using `read` and test that multiple licenses actually work as
expected.
- sourceballs: Replace `[[ -z ${ary[*]} ]]` with test for the array
length
- db-functions: Replace mangling echo field separators using sed, with
printf formatters
- db-functions: Replace for/echo loop to print an array line by line,
with `printf '%s\n'`
- db-functions: set_repo_permissions: Line up error messages, quote
"$group"
- db-move: Replace `$(echo ${array[@]})` with `${array[*]}`
- testing2x: Use `"$@"` instead of `$*` when looping over an array
Also, not really quoting related but on the same line as a quoting
issue, optimize:
- db-functions: Replace
[[ -n "$(... | sort | uniq -D)" ]]
with
! ... | awk 'a[$0]++{exit 1}'
-rwxr-xr-x | cron-jobs/check_archlinux/parse_pkgbuilds.sh | 21 | ||||
-rwxr-xr-x | cron-jobs/sourceballs | 10 | ||||
-rw-r--r-- | db-functions | 12 | ||||
-rw-r--r-- | test/fixtures/pkg-simple-a/PKGBUILD | 2 | ||||
-rwxr-xr-x | testing2x | 4 |
5 files changed, 16 insertions, 33 deletions
diff --git a/cron-jobs/check_archlinux/parse_pkgbuilds.sh b/cron-jobs/check_archlinux/parse_pkgbuilds.sh index 45f2a45..27dca7b 100755 --- a/cron-jobs/check_archlinux/parse_pkgbuilds.sh +++ b/cron-jobs/check_archlinux/parse_pkgbuilds.sh @@ -10,20 +10,8 @@ variables=('pkgname' 'pkgbase' 'epoch' 'pkgver' 'pkgrel' 'makedepends' 'arch' ${ readonly -a variables splitpkg_overrides backup_package_variables() { - for var in ${splitpkg_overrides[@]}; do - indirect="${var}_backup" - eval "${indirect}=(\${$var[@]})" - done -} - -restore_package_variables() { - for var in ${splitpkg_overrides[@]}; do - indirect="${var}_backup" - if [ -n "${!indirect}" ]; then - eval "${var}=(\${$indirect[@]})" - else - unset ${var} - fi + for var in "${splitpkg_overrides[@]}"; do + declare -p "$var" 2>/dev/null || printf 'unset %q\n' "$var" done } @@ -72,6 +60,7 @@ print_info() { } source_pkgbuild() { + local restore_package_variables ret=0 dir=$1 pkgbuild=$dir/PKGBUILD @@ -93,7 +82,7 @@ source_pkgbuild() { echo -e "%INVALID%\n$pkgbuild\n" return 1 else - backup_package_variables + restore_package_variables=$(backup_package_variables) pkgname=$pkg while IFS= read -r line; do var=${line%%=*} @@ -106,7 +95,7 @@ source_pkgbuild() { done done < <(type package_${pkg}) print_info - restore_package_variables + eval "$restore_package_variables" fi done else diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index 5908758..14947ab 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -56,19 +56,15 @@ done | sort -u > "${WORKDIR}/available-src-pkgs" for repo in ${PKGREPOS[@]}; do newpkgs=() failedpkgs=() - while read line; do - pkginfo=(${line}) - pkgbase=${pkginfo[0]} - pkgver=${pkginfo[1]} - pkgarch=${pkginfo[2]} - pkglicense=(${pkginfo[@]:3}) + while read -r pkgbase pkgver pkgarch pkglicense; do + read -ra pkglicense <<<"$pkglicense" # Should this package be skipped? if grep -Fqx "${pkgbase}" "${dirname}/sourceballs.skip"; then continue fi # Check if the license or .force file does not enforce creating a source package - if ! ([[ -z ${ALLOWED_LICENSES[@]} ]] || chk_license ${pkglicense[@]} || grep -Fqx "${pkgbase}" "${dirname}/sourceballs.force"); then + if ! ((( ${#ALLOWED_LICENSES[@]} == 0 )) || chk_license "${pkglicense[@]}" || grep -Fqx "${pkgbase}" "${dirname}/sourceballs.force"); then continue fi # Store the expected file name of the source package diff --git a/db-functions b/db-functions index cb44ba9..b4d8e7f 100644 --- a/db-functions +++ b/db-functions @@ -282,7 +282,7 @@ getpkgfile() { getpkgfiles() { local f files - if [[ ! -z "$(echo ${@%\.*} | sed "s/ /\n/g" | sort | uniq -D)" ]]; then + if ! printf '%s\n' "${@%\.*}" | awk 'a[$0]++{exit 1}'; then error 'Duplicate packages found!' exit 1 fi @@ -357,9 +357,7 @@ check_splitpkgs() { fi local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo ${pkgname[@]})) - for svnname in ${svnnames[@]}; do - echo "${svnname}" >> "${repo}/${_pkgarch}/${_pkgbase}/svn" - done + printf '%s\n' "${svnnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/svn" done popd >/dev/null @@ -429,9 +427,9 @@ set_repo_permission() { if [[ -w ${dbfile} ]]; then local group=$(/usr/bin/stat --printf='%G' "$(dirname "${dbfile}")") - chgrp $group "${dbfile}" || error "Could not change group of %s to %s" "$dbfile" "$group" - chgrp $group "${filesfile}" || error "Could not change group of %s to %s" "$filesfile" "$group" - chmod g+w "${dbfile}" || error "Could not set write permission for group %s to %s" "$group" "$dbfile" + chgrp "$group" "${dbfile}" || error "Could not change group of %s to %s" "$dbfile" "$group" + chgrp "$group" "${filesfile}" || error "Could not change group of %s to %s" "$filesfile" "$group" + chmod g+w "${dbfile}" || error "Could not set write permission for group %s to %s" "$group" "$dbfile" chmod g+w "${filesfile}" || error "Could not set write permission for group %s to %s" "$group" "$filesfile" else error "You don't have permission to change %s" "$dbfile" diff --git a/test/fixtures/pkg-simple-a/PKGBUILD b/test/fixtures/pkg-simple-a/PKGBUILD index 329a4a3..eaa841b 100644 --- a/test/fixtures/pkg-simple-a/PKGBUILD +++ b/test/fixtures/pkg-simple-a/PKGBUILD @@ -4,7 +4,7 @@ pkgrel=1 pkgdesc="A package called ${pkgname}" arch=('i686' 'x86_64') url='http://www.archlinux.org/' -license=('GPL') +license=('GPL' 'LGPL') depends=('glibc') options=(!strip) @@ -10,7 +10,7 @@ fi # Lock everything to reduce possibility of interfering task between the different repo-updates script_lock -for repo in ${TESTING_REPO} ${STABLE_REPOS[@]}; do +for repo in "${TESTING_REPO}" "${STABLE_REPOS[@]}"; do for pkgarch in ${ARCHES[@]}; do repo_lock ${repo} ${pkgarch} || exit 1 done @@ -18,7 +18,7 @@ done declare -A pkgs -for pkgbase in $*; do +for pkgbase in "$@"; do if [[ ! -d ${WORKDIR}/${pkgbase} ]]; then arch_svn export -q "${SVNREPO}/${pkgbase}/repos" "${WORKDIR}/${pkgbase}" >/dev/null |