From 6638878c5eb6d5116580d06cc3042a5e9beacb7e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 18 Jun 2014 20:33:06 -0400 Subject: Use printf-formatters instead of string interpolation on msg, error, etc. --- cron-jobs/ftpdir-cleanup | 12 +++++------ cron-jobs/integrity-check | 2 +- cron-jobs/sourceballs | 12 +++++------ cron-jobs/update-web-db | 2 +- db-functions | 51 +++++++++++++++++++++++------------------------ db-move | 10 +++++----- db-remove | 10 +++++----- db-repo-add | 8 ++++---- db-repo-remove | 6 +++--- db-update | 24 +++++++++++----------- testing2x | 6 +++--- 11 files changed, 71 insertions(+), 72 deletions(-) diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup index a2820e1..f6487cf 100755 --- a/cron-jobs/ftpdir-cleanup +++ b/cron-jobs/ftpdir-cleanup @@ -44,17 +44,17 @@ 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})..." + error "Missing packages in [%s] (%s)..." "${repo}" "${arch}" for missing_pkg in "${missing_pkgs[@]}"; do - msg2 "${missing_pkg}" + msg2 '%s' "${missing_pkg}" done fi 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})..." + msg "Removing old packages from [%s] (%s)..." "${repo}" "${arch}" for old_pkg in "${old_pkgs[@]}"; do - msg2 "${old_pkg}" + msg2 '%s' "${old_pkg}" clean_pkg "${FTP_BASE}/${repo}/os/${arch}/${old_pkg}" done fi @@ -70,7 +70,7 @@ 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 - msg2 "${old_pkg}" + msg2 '%s' "${old_pkg}" clean_pkg "$FTP_BASE/${PKGPOOL}/${old_pkg}" done fi @@ -79,7 +79,7 @@ old_pkgs=($(find "${CLEANUP_DESTDIR}" -type f -name "*${PKGEXT}" -mtime +"${CLEA if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old packages from the cleanup directory..." for old_pkg in "${old_pkgs[@]}"; do - msg2 "${old_pkg}" + msg2 '%s' "${old_pkg}" if ! "${CLEANUP_DRYRUN}"; then rm -f "${CLEANUP_DESTDIR}/${old_pkg}" rm -f "${CLEANUP_DESTDIR}/${old_pkg}.sig" diff --git a/cron-jobs/integrity-check b/cron-jobs/integrity-check index e77eac7..677c0d3 100755 --- a/cron-jobs/integrity-check +++ b/cron-jobs/integrity-check @@ -8,7 +8,7 @@ dirname="$(dirname "$0")" script_lock if [ $# -ne 1 ]; then - die "usage: ${0##*/} " + die "usage: %s " "${0##*/}" fi mailto=$1 diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index dee849a..0c2f9f9 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -103,15 +103,15 @@ for repo in "${PKGREPOS[@]}"; do done < "${WORKDIR}/db-${repo}" if [ ${#newpkgs[@]} -ge 1 ]; then - msg "Adding source packages for [${repo}]..." + msg "Adding source packages for [%s]..." "${repo}" for new_pkg in "${newpkgs[@]}"; do - msg2 "${new_pkg}" + msg2 '%s' "${new_pkg}" done fi if [ ${#failedpkgs[@]} -ge 1 ]; then - msg "Failed to create source packages for [${repo}]..." + msg "Failed to create source packages for [%s]..." "${repo}" for failed_pkg in "${failedpkgs[@]}"; do - msg2 "${failed_pkg}" + msg2 '%s' "${failed_pkg}" done fi done @@ -125,7 +125,7 @@ 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 - msg2 "${old_pkg}" + msg2 '%s' "${old_pkg}" if ! "${SOURCE_CLEANUP_DRYRUN}"; then mv_acl "$FTP_BASE/${SRCPOOL}/${old_pkg}" "${SOURCE_CLEANUP_DESTDIR}/${old_pkg}" touch "${SOURCE_CLEANUP_DESTDIR}/${old_pkg}" @@ -137,7 +137,7 @@ old_pkgs=($(find "${SOURCE_CLEANUP_DESTDIR}" -type f -name "*${SRCEXT}" -mtime + if [ ${#old_pkgs[@]} -ge 1 ]; then msg "Removing old source packages from the cleanup directory..." for old_pkg in "${old_pkgs[@]}"; do - msg2 "${old_pkg}" + msg2 '%s' "${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 1a725dc..88bf464 100755 --- a/cron-jobs/update-web-db +++ b/cron-jobs/update-web-db @@ -16,7 +16,7 @@ LOGOUT="/tmp/archweb_update.log" # figure out what operation to perform cmd="${0##*/}" if [[ $cmd != "update-web-db" && $cmd != "update-web-files-db" ]]; then - die "Invalid command name '$cmd' specified!" + die "Invalid command name '%s' specified!" "$cmd" fi script_lock diff --git a/db-functions b/db-functions index 39173f3..9845e45 100644 --- a/db-functions +++ b/db-functions @@ -103,7 +103,7 @@ script_lock() { local LOCKDIR="$TMPDIR/.scriptlock.${0##*/}" if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then local _owner="$(/usr/bin/stat -c %U "$LOCKDIR")" - error "Script ${0##*/} is already locked by $_owner." + error "Script %s is already locked by %s." "${0##*/}" "$_owner" exit 1 else set_umask @@ -114,7 +114,7 @@ script_lock() { script_unlock() { local LOCKDIR="$TMPDIR/.scriptlock.${0##*/}" if [ ! -d "$LOCKDIR" ]; then - warning "Script ${0##*/} was not locked!" + warning "Script %s was not locked!" "${0##*/}" restore_umask return 1 else @@ -134,12 +134,12 @@ cleanup() { repo=${l%.*} arch=${l#*.} if [ -d "$TMPDIR/.repolock.$repo.$arch" ]; then - msg "Removing left over lock from [${repo}] (${arch})" + msg "Removing left over lock from [%s] (%s)" "${repo}" "${arch}" repo_unlock "$repo" "$arch" fi done if [ -d "$TMPDIR/.scriptlock.${0##*/}" ]; then - msg "Removing left over lock from ${0##*/}" + msg "Removing left over lock from %s" "${0##*/}" script_unlock fi rm -rf "$WORKDIR" @@ -177,7 +177,7 @@ repo_lock () { # This is the lock file used by repo-add and repo-remove if [ -f "${DBLOCKFILE}" ]; then - error "Repo [${1}] (${2}) is already locked by repo-{add,remove} process $(cat $DBLOCKFILE)" + error "Repo [%s] (%s) is already locked by repo-{add,remove} process %s" "$1" "$2" "$(<"$DBLOCKFILE")" return 1 fi @@ -194,8 +194,8 @@ repo_lock () { while [ "$_count" -le "$_trial" ] || "$_lockblock" ; do if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then _owner="$(/usr/bin/stat -c %U "$LOCKDIR")" - warning "Repo [${1}] (${2}) is already locked by $_owner. " - msg2 "Retrying in $LOCK_DELAY seconds..." + warning "Repo [%s] (%s) is already locked by %s." "${1}" "${2}" "$_owner" + msg2 "Retrying in %d seconds..." "$LOCK_DELAY" else LOCKS[${#LOCKS[*]}]="$1.$2" set_umask @@ -205,14 +205,14 @@ repo_lock () { let _count=$_count+1 done - error "Repo [${1}] (${2}) is already locked by $_owner. Giving up!" + error "Repo [%s] (%s) is already locked by %s. Giving up!" "${1}" "${2}" "$_owner" return 1 } repo_unlock () { #repo_unlock local LOCKDIR="$TMPDIR/.repolock.$1.$2" if [ ! -d "$LOCKDIR" ]; then - warning "Repo lock [${1}] (${2}) was not locked!" + warning "Repo lock [%s] (%s) was not locked!" "${1}" "${2}" restore_umask return 1 else @@ -267,7 +267,7 @@ getpkgname() { _name="$(_grep_pkginfo "$1" "pkgname")" if [ -z "$_name" ]; then - error "Package '$1' has no pkgname in the PKGINFO. Fail!" + error "Package '%s' has no pkgname in the PKGINFO. Fail!" "$1" exit 1 fi @@ -280,7 +280,7 @@ getpkgver() { _ver="$(_grep_pkginfo "$1" "pkgver")" if [ -z "$_ver" ]; then - error "Package '$1' has no pkgver in the PKGINFO. Fail!" + error "Package '%s' has no pkgver in the PKGINFO. Fail!" "$1" exit 1 fi @@ -292,7 +292,7 @@ getpkgarch() { _ver="$(_grep_pkginfo "$1" "arch")" if [ -z "$_ver" ]; then - error "Package '$1' has no arch in the PKGINFO. Fail!" + error "Package '%s' has no arch in the PKGINFO. Fail!" "$1" exit 1 fi @@ -322,10 +322,10 @@ getpkgfile() { error 'No canonical package found!' exit 1 elif [ ! -f "${1}" ]; then - error "Package ${1} not found!" + error "Package %s not found!" "${1}" exit 1 elif "${REQUIRE_SIGNATURE}" && [ ! -f "${1}.sig" ]; then - error "Package signature ${1}.sig not found!" + error "Package signature %s not found!" "${1}.sig" exit 1 fi @@ -341,10 +341,10 @@ getpkgfiles() { for f in "${@}"; do if [ ! -f "${f}" ]; then - error "Package ${f} not found!" + error "Package %s not found!" "${f}" exit 1 elif "${REQUIRE_SIGNATURE}" && [ ! -f "${f}.sig" ]; then - error "Package signature ${f}.sig not found!" + error "Package signature %s not found!" "${f}.sig" exit 1 fi done @@ -428,8 +428,7 @@ check_splitpkgs() { fi local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo "${pkgname[@]}")) - printf '%s\n' in "${svnnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/svn" - done + printf '%s\n' "${svnnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/svn" done popd >/dev/null @@ -502,12 +501,12 @@ 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 ${dbfile} to $group" - chgrp "$group" "${filesfile}" || error "Could not change group of ${filesfile} to $group" - chmod g+w "${dbfile}" || error "Could not set write permission for group $group to ${dbfile}" - chmod g+w "${filesfile}" || error "Could not set write permission for group $group to ${filesfile}" + 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 ${dbfile}" + error "You don't have permission to change %s" "${dbfile}" fi } @@ -519,7 +518,7 @@ arch_repo_add() { # package files might be relative to repo dir pushd "${FTP_BASE}/${repo}/os/${arch}" >/dev/null /usr/bin/repo-add -q "${repo}${DBEXT}" "${pkgs[@]}" \ - || error "repo-add ${repo}${DBEXT} ${pkgs[*]}" + || error '%s' "repo-add ${repo}${DBEXT} ${pkgs[*]}" popd >/dev/null set_repo_permission "${repo}" "${arch}" @@ -533,11 +532,11 @@ arch_repo_remove() { local dbfile="${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}" if [ ! -f "${dbfile}" ]; then - error "No database found at '${dbfile}'" + error "No database found at '%s'" "${dbfile}" return 1 fi /usr/bin/repo-remove -q "${dbfile}" "${pkgs[@]}" \ - || error "repo-remove ${dbfile} ${pkgs[*]}" + || error '%s' "repo-remove ${dbfile} ${pkgs[*]}" set_repo_permission "${repo}" "${arch}" REPO_MODIFIED=1 diff --git a/db-move b/db-move index 4828e75..cd67953 100755 --- a/db-move +++ b/db-move @@ -4,7 +4,7 @@ . "$(dirname "$0")/db-functions" if [ $# -lt 3 ]; then - msg "usage: ${0##*/} ..." + msg "usage: %s ..." "${0##*/}" exit 1 fi @@ -15,7 +15,7 @@ ftppath_from="${FTP_BASE}/${repo_from}/os/" ftppath_to="${FTP_BASE}/${repo_to}/os/" if ! check_repo_permission "$repo_to" || ! check_repo_permission "$repo_from"; then - die "You don't have permission to move packages from ${repo_from} to ${repo_to}" + die "You don't have permission to move packages from %s to %s" "${repo_from}" "${repo_to}" fi # TODO: this might lock too much (architectures) @@ -55,10 +55,10 @@ for pkgbase in "${args[@]:2}"; do continue 2 fi done - die "${pkgbase} not found in ${repo_from}" + die "%s not found in %s" "${pkgbase}" "${repo_from}" done -msg "Moving packages from [${repo_from}] to [${repo_to}]..." +msg "Moving packages from [%s] to [%s]..." "${repo_from}" "${repo_to}" declare -A add_pkgs declare -A remove_pkgs @@ -74,7 +74,7 @@ for pkgbase in "${args[@]:2}"; do else tarches=("${pkgarch}") fi - msg2 "${pkgbase} (${tarches[*]})" + msg2 "%s (%s)" "${pkgbase}" "${tarches[*]}" pkgnames=($(. "${svnrepo_from}/PKGBUILD"; echo "${pkgname[@]}")) pkgver=$(. "${svnrepo_from}/PKGBUILD"; get_full_version "${epoch:-0}" "${pkgver}" "${pkgrel}") diff --git a/db-remove b/db-remove index f23cd9e..3bb67b0 100755 --- a/db-remove +++ b/db-remove @@ -4,7 +4,7 @@ . "$(dirname "$0")/db-functions" if [ $# -lt 3 ]; then - msg "usage: ${0##*/} ..." + msg "usage: %s ..." "${0##*/}" exit 1 fi @@ -16,7 +16,7 @@ ftppath="$FTP_BASE/$repo/os" svnrepo="$repo-$arch" if ! check_repo_permission "$repo"; then - die "You don't have permission to remove packages from ${repo}" + die "You don't have permission to remove packages from %s" "${repo}" fi if [ "$arch" == "any" ]; then @@ -31,7 +31,7 @@ done remove_pkgs=() for pkgbase in "${pkgbases[@]}"; do - msg "Removing $pkgbase from [$repo]..." + msg "Removing %s from [%s]..." "$pkgbase" "$repo" arch_svn checkout -q "${SVNREPO}/${pkgbase}" "${WORKDIR}/svn/${pkgbase}" >/dev/null if [ -d "${WORKDIR}/svn/$pkgbase/repos/$svnrepo" ]; then @@ -39,8 +39,8 @@ for pkgbase in "${pkgbases[@]}"; do arch_svn rm --force -q "${WORKDIR}/svn/$pkgbase/repos/$svnrepo" arch_svn commit -q "${WORKDIR}/svn/$pkgbase" -m "${0##*/}: $pkgbase removed by $(id -un)" else - warning "$pkgbase not found in $svnrepo" - warning "Removing only $pkgbase from the repo" + warning "%s not found in %s" "$pkgbase" "$svnrepo" + warning "Removing only %s from the repo" "$pkgbase" warning "If it was a split package you have to remove the others yourself!" remove_pkgs[${#remove_pkgs[*]}]=$pkgbase fi diff --git a/db-repo-add b/db-repo-add index a53884e..09ce865 100755 --- a/db-repo-add +++ b/db-repo-add @@ -4,7 +4,7 @@ . "$(dirname "$0")/db-functions" if [ $# -lt 3 ]; then - msg "usage: ${0##*/} ..." + msg "usage: %s ..." "${0##*/}" exit 1 fi @@ -15,7 +15,7 @@ pkgfiles=("${@:3}") ftppath="$FTP_BASE/$repo/os" if ! check_repo_permission "$repo"; then - die "You don't have permission to add packages to ${repo}" + die "You don't have permission to add packages to %s" "${repo}" fi if [ "$arch" == "any" ]; then @@ -31,9 +31,9 @@ done for tarch in "${tarches[@]}"; do for pkgfile in "${pkgfiles[@]}"; do if [[ ! -f "${FTP_BASE}/${repo}/os/${arch}/${pkgfile##*/}" ]]; then - die "Package file ${pkgfile##*/} not found in ${FTP_BASE}/${repo}/os/${arch}/" + die "Package file %s not found in %s" "${pkgfile##*/}" "${FTP_BASE}/${repo}/os/${arch}/" else - msg "Adding $pkgfile to [$repo]..." + msg "Adding %s to [%s]..." "$pkgfile" "$repo" fi done arch_repo_add "${repo}" "${tarch}" "${pkgfiles[@]}" diff --git a/db-repo-remove b/db-repo-remove index df746fb..97a671b 100755 --- a/db-repo-remove +++ b/db-repo-remove @@ -4,7 +4,7 @@ . "$(dirname "$0")/db-functions" if [ $# -lt 3 ]; then - msg "usage: ${0##*/} ..." + msg "usage: %s ..." "${0##*/}" exit 1 fi @@ -15,7 +15,7 @@ pkgnames=("${@:3}") ftppath="$FTP_BASE/$repo/os" if ! check_repo_permission "$repo"; then - die "You don't have permission to remove packages from ${repo}" + die "You don't have permission to remove packages from %s" "${repo}" fi if [ "$arch" == "any" ]; then @@ -30,7 +30,7 @@ done for tarch in "${tarches[@]}"; do for pkgname in "${pkgnames[@]}"; do - msg "Removing $pkgname from [$repo]..." + msg "Removing %s from [%s]..." "$pkgname" "$repo" done arch_repo_remove "${repo}" "${tarch}" "${pkgnames[@]}" repo_unlock "$repo" "$tarch" diff --git a/db-update b/db-update index 0544e7c..9a57b19 100755 --- a/db-update +++ b/db-update @@ -4,14 +4,14 @@ . "$(dirname "$0")/db-functions" if [ $# -ge 1 ]; then - warning "Calling ${0##*/} with a specific repository is no longer supported" + warning "Calling %s with a specific repository is no longer supported" "${0##*/}" exit 1 fi # Find repos with packages to release staging_repos=($(find "${STAGING}" -mindepth 1 -type f -name "*${PKGEXT}" -printf '%h\n' | sort -u)) if [ $? -ge 1 ]; then - die "Could not read ${STAGING}" + die "Could not read %s" "${STAGING}" fi repos=() @@ -31,25 +31,25 @@ done # check if packages are valid for repo in "${repos[@]}"; do if ! check_repo_permission "${repo}"; then - die "You don't have permission to update packages in ${repo}" + die "You don't have permission to update packages in %s" "${repo}" fi pkgs=($(getpkgfiles "${STAGING}/${repo}/"*${PKGEXT})) if [ $? -eq 0 ]; then for pkg in "${pkgs[@]}"; do if [ -h "${pkg}" ]; then - die "Package ${repo}/${pkg##*/} is a symbolic link" + die "Package %s is a symbolic link" "${repo}/${pkg##*/}" fi if ! check_pkgfile "${pkg}"; then - die "Package ${repo}/${pkg##*/} is not consistent with its meta data" + die "Package %s is not consistent with its meta data" "${repo}/${pkg##*/}" fi if "${REQUIRE_SIGNATURE}" && ! pacman-key -v "${pkg}.sig" >/dev/null 2>&1; then - die "Package ${repo}/${pkg##*/} does not have a valid signature" + die "Package %s does not have a valid signature" "${repo}/${pkg##*/}" fi if ! check_pkgsvn "${pkg}" "${repo}"; then - die "Package ${repo}/${pkg##*/} is not consistent with svn repository" + die "Package %s is not consistent with svn repository" "${repo}/${pkg##*/}" fi if ! check_pkgrepos "${pkg}"; then - die "Package ${repo}/${pkg##*/} already exists in another repository" + die "Package %s already exists in another repository" "${repo}/${pkg##*/}" fi if ! check_packager "${pkg}"; then die "Package ${repo}/${pkg##*/} does not have a valid packager" @@ -62,22 +62,22 @@ for repo in "${repos[@]}"; do fi done if ! check_splitpkgs "${repo}" "${pkgs[@]}"; then - die "Missing split packages for ${repo}" + die "Missing split packages for %s" "${repo}" fi else - die "Could not read ${STAGING}" + die "Could not read %s" "${STAGING}" fi done for repo in "${repos[@]}"; do - msg "Updating [${repo}]..." + msg "Updating [%s]..." "${repo}" any_pkgs=($(getpkgfiles "${STAGING}/${repo}/"*-any${PKGEXT} 2>/dev/null)) for pkgarch in "${ARCHES[@]}"; do add_pkgs=() arch_pkgs=($(getpkgfiles "${STAGING}/${repo}/"*-"${pkgarch}"${PKGEXT} 2>/dev/null)) for pkg in "${arch_pkgs[@]}" "${any_pkgs[@]}"; do pkgfile="${pkg##*/}" - msg2 "${pkgfile} (${pkgarch})" + msg2 "%s (%s)" "${pkgfile}" "${pkgarch}" # any packages might have been moved by the previous run if [ -f "${pkg}" ]; then mv "${pkg}" "$FTP_BASE/${PKGPOOL}" diff --git a/testing2x b/testing2x index 9ff2319..e269248 100755 --- a/testing2x +++ b/testing2x @@ -4,7 +4,7 @@ . "$(dirname "$0")/db-functions" if [ $# -lt 1 ]; then - msg "usage: ${0##*/} ..." + msg "usage: %s ..." "${0##*/}" exit 1 fi @@ -30,7 +30,7 @@ for pkgbase in "$@"; do break fi done - "${found_source}" || die "${pkgbase} not found in [${TESTING_REPO}]" + "${found_source}" || die "%s not found in [%s]" "${pkgbase}" "${TESTING_REPO}" found_target=false for pkgarch in "${ARCHES[@]}" 'any'; do for repo in "${STABLE_REPOS[@]}"; do @@ -42,7 +42,7 @@ for pkgbase in "$@"; do fi done done - "${found_target}" || die "${pkgbase} not found in any of these repos: ${STABLE_REPOS[*]}" + "${found_target}" || die "%s not found in any of these repos: " "${pkgbase}" "${STABLE_REPOS[*]}" fi done -- cgit v1.2.3