From 7850874b1ef1b18de585be108e3be899d95a3a2a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 18 Jun 2014 12:07:09 -0400 Subject: Fix quoting around variables, especially arrays. Other than pure quoting, this involved: - swapping */@ for array access in a few places - fiddling with printf in a pipeline - replacing `$(echo ${array[@]})` with `${array[*]}` - replacing `echo $(...)` with `...` When searching for these things, I used the command: grep -Prn --exclude-dir=.git '(?/dev/null || ret=$? + source "$pkgbuild" &>/dev/null || ret=$? # ensure $pkgname and $pkgver variables were found if [ $ret -ne 0 -o -z "$pkgname" -o -z "$pkgver" ]; then @@ -88,8 +88,8 @@ source_pkgbuild() { if [ "${#pkgname[@]}" -gt "1" ]; then pkgbase=${pkgbase:-${pkgname[0]}} - for pkg in ${pkgname[@]}; do - if [ "$(type -t package_${pkg})" != "function" ]; then + for pkg in "${pkgname[@]}"; do + if [ "$(type -t "package_${pkg}")" != "function" ]; then echo -e "%INVALID%\n$pkgbuild\n" return 1 else @@ -98,13 +98,13 @@ source_pkgbuild() { while IFS= read -r line; do var=${line%%=*} var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters - for realvar in ${variables[@]}; do + for realvar in "${variables[@]}"; do if [ "$var" == "$realvar" ]; then eval $line break fi done - done < <(type package_${pkg}) + done < <(type "package_${pkg}") print_info restore_package_variables fi @@ -124,14 +124,14 @@ find_pkgbuilds() { return fi - if [ -f $1/PKGBUILD ]; then - source_pkgbuild $1 + if [ -f "$1/PKGBUILD" ]; then + source_pkgbuild "$1" return fi empty=1 - for dir in $1/*; do - if [ -d $dir ]; then - find_pkgbuilds $dir + for dir in "$1"/*; do + if [ -d "$dir" ]; then + find_pkgbuilds "$dir" unset empty fi done @@ -147,7 +147,7 @@ fi CARCH=$1 shift for dir in "$@"; do - find_pkgbuilds $dir + find_pkgbuilds "$dir" done exit 0 diff --git a/cron-jobs/devlist-mailer b/cron-jobs/devlist-mailer index ca2e46b..61cd32c 100755 --- a/cron-jobs/devlist-mailer +++ b/cron-jobs/devlist-mailer @@ -23,6 +23,6 @@ echo "Subject: $SUBJECT To: $LIST From: $FROM -$stdin" | /usr/sbin/sendmail -F$FROM "$LIST" +$stdin" | /usr/sbin/sendmail -F"$FROM" "$LIST" fi diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup index 2683676..a2820e1 100755 --- a/cron-jobs/ftpdir-cleanup +++ b/cron-jobs/ftpdir-cleanup @@ -1,13 +1,13 @@ #!/bin/bash -. "$(dirname $0)/../config" -. "$(dirname $0)/../db-functions" +. "$(dirname "$0")/../config" +. "$(dirname "$0")/../db-functions" clean_pkg() { local pkg local target - if ! ${CLEANUP_DRYRUN}; then + if ! "${CLEANUP_DRYRUN}"; then for pkg in "$@"; do if [ -h "$pkg" ]; then rm -f "$pkg" "$pkg.sig" @@ -24,16 +24,16 @@ clean_pkg() { script_lock -for repo in ${PKGREPOS[@]}; do - for arch in ${ARCHES[@]}; do - repo_lock ${repo} ${arch} || exit 1 +for repo in "${PKGREPOS[@]}"; do + for arch in "${ARCHES[@]}"; do + repo_lock "${repo}" "${arch}" || exit 1 done done -${CLEANUP_DRYRUN} && warning 'dry run mode is active' +"${CLEANUP_DRYRUN}" && warning 'dry run mode is active' -for repo in ${PKGREPOS[@]}; do - for arch in ${ARCHES[@]}; do +for repo in "${PKGREPOS[@]}"; do + for arch in "${ARCHES[@]}"; do if [ ! -f "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}" ]; then continue fi @@ -45,7 +45,7 @@ for repo in ${PKGREPOS[@]}; do missing_pkgs=($(comm -13 "${WORKDIR}/repo-${repo}-${arch}" "${WORKDIR}/db-${repo}-${arch}")) if [ ${#missing_pkgs[@]} -ge 1 ]; then error "Missing packages in [${repo}] (${arch})..." - for missing_pkg in ${missing_pkgs[@]}; do + for missing_pkg in "${missing_pkgs[@]}"; do msg2 "${missing_pkg}" done fi @@ -53,7 +53,7 @@ for repo in ${PKGREPOS[@]}; do old_pkgs=($(comm -23 "${WORKDIR}/repo-${repo}-${arch}" "${WORKDIR}/db-${repo}-${arch}")) if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old packages from [${repo}] (${arch})..." - for old_pkg in ${old_pkgs[@]}; do + for old_pkg in "${old_pkgs[@]}"; do msg2 "${old_pkg}" clean_pkg "${FTP_BASE}/${repo}/os/${arch}/${old_pkg}" done @@ -69,27 +69,27 @@ find "${WORKDIR}" -maxdepth 1 -type f -name 'db-*' -exec cat {} \; | sort -u > " old_pkgs=($(comm -23 "${WORKDIR}/pool" "${WORKDIR}/db")) if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old packages from package pool..." - for old_pkg in ${old_pkgs[@]}; do + for old_pkg in "${old_pkgs[@]}"; do msg2 "${old_pkg}" clean_pkg "$FTP_BASE/${PKGPOOL}/${old_pkg}" done fi -old_pkgs=($(find ${CLEANUP_DESTDIR} -type f -name "*${PKGEXT}" -mtime +${CLEANUP_KEEP} -printf '%f\n')) +old_pkgs=($(find "${CLEANUP_DESTDIR}" -type f -name "*${PKGEXT}" -mtime +"${CLEANUP_KEEP}" -printf '%f\n')) if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old packages from the cleanup directory..." - for old_pkg in ${old_pkgs[@]}; do + for old_pkg in "${old_pkgs[@]}"; do msg2 "${old_pkg}" - if ! ${CLEANUP_DRYRUN}; then + if ! "${CLEANUP_DRYRUN}"; then rm -f "${CLEANUP_DESTDIR}/${old_pkg}" rm -f "${CLEANUP_DESTDIR}/${old_pkg}.sig" fi done fi -for repo in ${PKGREPOS[@]}; do - for arch in ${ARCHES[@]}; do - repo_unlock ${repo} ${arch} +for repo in "${PKGREPOS[@]}"; do + for arch in "${ARCHES[@]}"; do + repo_unlock "${repo}" "${arch}" done done diff --git a/cron-jobs/integrity-check b/cron-jobs/integrity-check index f6c26cf..e77eac7 100755 --- a/cron-jobs/integrity-check +++ b/cron-jobs/integrity-check @@ -1,6 +1,6 @@ #!/bin/bash -dirname="$(dirname $0)" +dirname="$(dirname "$0")" . "${dirname}/../config" . "${dirname}/../db-functions" @@ -13,12 +13,12 @@ fi mailto=$1 check() { - ${dirname}/check_archlinux/check_packages.py \ + "${dirname}"/check_archlinux/check_packages.py \ --repos="${repos}" \ --abs-tree="/srv/abs/rsync/${arch},/srv/abs/rsync/any" \ --repo-dir="${FTP_BASE}" \ --arch="${arch}" \ - 2>&1 | ${dirname}/devlist-mailer "Integrity Check ${arch}: ${repos}" "${mailto}" + 2>&1 | "${dirname}"/devlist-mailer "Integrity Check ${arch}: ${repos}" "${mailto}" } repos='core,extra,community' diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index 4126c37..dee849a 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -1,15 +1,15 @@ #!/bin/bash -dirname="$(dirname $(readlink -e $0))" +dirname="$(dirname "$(readlink -e "$0")")" . "${dirname}/../config" . "${dirname}/../db-functions" pushd "${WORKDIR}" >/dev/null script_lock -for repo in ${PKGREPOS[@]}; do - for arch in ${ARCHES[@]}; do - repo_lock ${repo} ${arch} || exit 1 +for repo in "${PKGREPOS[@]}"; do + for arch in "${ARCHES[@]}"; do + repo_lock "${repo}" "${arch}" || exit 1 done done @@ -18,8 +18,8 @@ renice +10 -p $$ > /dev/null # Create a readable file for each repo with the following format # - [ ] -for repo in ${PKGREPOS[@]}; do - for arch in ${ARCHES[@]}; do +for repo in "${PKGREPOS[@]}"; do + for arch in "${ARCHES[@]}"; do # Repo does not exist; skip it if [ ! -f "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}" ]; then continue @@ -39,9 +39,9 @@ for repo in ${PKGREPOS[@]}; do done | sort -u > "${WORKDIR}/db-${repo}" done -for repo in ${PKGREPOS[@]}; do - for arch in ${ARCHES[@]}; do - repo_unlock ${repo} ${arch} +for repo in "${PKGREPOS[@]}"; do + for arch in "${ARCHES[@]}"; do + repo_unlock "${repo}" "${arch}" done done @@ -49,22 +49,22 @@ done find "${FTP_BASE}/${SRCPOOL}" -xtype f -name "*${SRCEXT}" -printf '%f\n' | sort -u > "${WORKDIR}/available-src-pkgs" # Check for all packages if we need to build a source package -for repo in ${PKGREPOS[@]}; do +for repo in "${PKGREPOS[@]}"; do newpkgs=() failedpkgs=() while read line; do - pkginfo=(${line}) + pkginfo=("${line}") pkgbase=${pkginfo[0]} pkgver=${pkginfo[1]} pkgarch=${pkginfo[2]} - pkglicense=(${pkginfo[@]:3}) + pkglicense=("${pkginfo[@]:3}") # 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 ! ([[ -z ${ALLOWED_LICENSES[*]} ]] || chk_license "${pkglicense[@]}" || grep -Fqx "${pkgbase}" "${dirname}/sourceballs.force"); then continue fi # Store the expected file name of the source package @@ -73,7 +73,7 @@ for repo in ${PKGREPOS[@]}; do # Build the source package if its not already there if ! grep -Fqx "${pkgbase}-${pkgver}${SRCEXT}" "${WORKDIR}/available-src-pkgs"; then # Check if we had failed before - if in_array "${pkgbase}-${pkgver}${SRCEXT}" ${failedpkgs[@]}; then + if in_array "${pkgbase}-${pkgver}${SRCEXT}" "${failedpkgs[@]}"; then continue fi @@ -104,13 +104,13 @@ for repo in ${PKGREPOS[@]}; do if [ ${#newpkgs[@]} -ge 1 ]; then msg "Adding source packages for [${repo}]..." - for new_pkg in ${newpkgs[@]}; do + for new_pkg in "${newpkgs[@]}"; do msg2 "${new_pkg}" done fi if [ ${#failedpkgs[@]} -ge 1 ]; then msg "Failed to create source packages for [${repo}]..." - for failed_pkg in ${failedpkgs[@]}; do + for failed_pkg in "${failedpkgs[@]}"; do msg2 "${failed_pkg}" done fi @@ -123,22 +123,22 @@ old_pkgs=($(comm -23 "${WORKDIR}/available-src-pkgs.sort" "${WORKDIR}/expected-s if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old source packages..." - ${SOURCE_CLEANUP_DRYRUN} && warning 'dry run mode is active' - for old_pkg in ${old_pkgs[@]}; do + "${SOURCE_CLEANUP_DRYRUN}" && warning 'dry run mode is active' + for old_pkg in "${old_pkgs[@]}"; do msg2 "${old_pkg}" - if ! ${SOURCE_CLEANUP_DRYRUN}; then + if ! "${SOURCE_CLEANUP_DRYRUN}"; then mv_acl "$FTP_BASE/${SRCPOOL}/${old_pkg}" "${SOURCE_CLEANUP_DESTDIR}/${old_pkg}" touch "${SOURCE_CLEANUP_DESTDIR}/${old_pkg}" fi done fi -old_pkgs=($(find ${SOURCE_CLEANUP_DESTDIR} -type f -name "*${SRCEXT}" -mtime +${SOURCE_CLEANUP_KEEP} -printf '%f\n')) +old_pkgs=($(find "${SOURCE_CLEANUP_DESTDIR}" -type f -name "*${SRCEXT}" -mtime +"${SOURCE_CLEANUP_KEEP}" -printf '%f\n')) if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old source packages from the cleanup directory..." - for old_pkg in ${old_pkgs[@]}; do + for old_pkg in "${old_pkgs[@]}"; do msg2 "${old_pkg}" - ${SOURCE_CLEANUP_DRYRUN} || rm -f "${SOURCE_CLEANUP_DESTDIR}/${old_pkg}" + "${SOURCE_CLEANUP_DRYRUN}" || rm -f "${SOURCE_CLEANUP_DESTDIR}/${old_pkg}" done fi diff --git a/cron-jobs/update-web-db b/cron-jobs/update-web-db index 195d1fc..1a725dc 100755 --- a/cron-jobs/update-web-db +++ b/cron-jobs/update-web-db @@ -1,7 +1,7 @@ #!/bin/bash -. "$(dirname $0)/../config" -. "$(dirname $0)/../db-functions" +. "$(dirname "$0")/../config" +. "$(dirname "$0")/../db-functions" # setup paths SPATH="/srv/http/archweb" @@ -43,26 +43,26 @@ case "$cmd" in esac # Lock the repos and get a copy of the db files to work on -for repo in ${REPOS[@]}; do - for arch in ${ARCHES[@]}; do - repo_lock ${repo} ${arch} || exit 1 +for repo in "${REPOS[@]}"; do + for arch in "${ARCHES[@]}"; do + repo_lock "${repo}" "${arch}" || exit 1 dbfile="/srv/ftp/${repo}/os/${arch}/${repo}${dbfileext}" if [ -f "${dbfile}" ]; then mkdir -p "${WORKDIR}/${repo}/${arch}" cp "${dbfile}" "${WORKDIR}/${repo}/${arch}/${repo}${dbfileext}" fi - repo_unlock ${repo} ${arch} + repo_unlock "${repo}" "${arch}" done done # Run reporead on our db copy -pushd $SPATH >/dev/null -for repo in ${REPOS[@]}; do - for arch in ${ARCHES[@]}; do +pushd "$SPATH" >/dev/null +for repo in "${REPOS[@]}"; do + for arch in "${ARCHES[@]}"; do dbcopy="${WORKDIR}/${repo}/${arch}/${repo}${dbfileext}" if [ -f "${dbcopy}" ]; then echo "Updating ${repo}-${arch}" >> "${LOGOUT}" - ./manage.py reporead ${flags} ${arch} "${dbcopy}" >> "${LOGOUT}" 2>&1 + ./manage.py reporead "${flags}" "${arch}" "${dbcopy}" >> "${LOGOUT}" 2>&1 echo "" >> "${LOGOUT}" fi done -- cgit v1.2.3