summaryrefslogtreecommitdiff
path: root/db-functions
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-06-18 12:07:09 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-04-16 13:49:57 -0400
commit7850874b1ef1b18de585be108e3be899d95a3a2a (patch)
tree173896aa05b68545672124dbe28b098fec98ee0a /db-functions
parent282bf65c81e278b9237b4c202d325642bc0aa1a3 (diff)
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 '(?<!["=]|\[\[ |\[\[ -[zn] )\$(?!{?#|\(|\? )' and ignored a bunch of false positives.
Diffstat (limited to 'db-functions')
-rw-r--r--db-functions109
1 files changed, 54 insertions, 55 deletions
diff --git a/db-functions b/db-functions
index 3101c0c..39173f3 100644
--- a/db-functions
+++ b/db-functions
@@ -12,7 +12,7 @@ set_umask () {
}
restore_umask () {
- umask $UMASK >/dev/null
+ umask "$UMASK" >/dev/null
}
# just like mv -f, but we touch the file and then copy the content so
@@ -81,7 +81,7 @@ in_array() {
[[ -z $1 ]] && return 1 # Not Found
local item
for item in "$@"; do
- [[ $item = $needle ]] && return 0 # Found
+ [[ $item = "$needle" ]] && return 0 # Found
done
return 1 # Not Found
}
@@ -93,16 +93,16 @@ in_array() {
get_full_version() {
if [[ $1 -eq 0 ]]; then
# zero epoch case, don't include it in version
- echo $2-$3
+ echo "$2-$3"
else
- echo $1:$2-$3
+ echo "$1:$2-$3"
fi
}
script_lock() {
local LOCKDIR="$TMPDIR/.scriptlock.${0##*/}"
if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then
- local _owner="$(/usr/bin/stat -c %U $LOCKDIR)"
+ local _owner="$(/usr/bin/stat -c %U "$LOCKDIR")"
error "Script ${0##*/} is already locked by $_owner."
exit 1
else
@@ -130,12 +130,12 @@ cleanup() {
local arch
trap - EXIT INT QUIT TERM
- for l in ${LOCKS[@]}; do
+ for l in "${LOCKS[@]}"; do
repo=${l%.*}
arch=${l#*.}
if [ -d "$TMPDIR/.repolock.$repo.$arch" ]; then
msg "Removing left over lock from [${repo}] (${arch})"
- repo_unlock $repo $arch
+ repo_unlock "$repo" "$arch"
fi
done
if [ -d "$TMPDIR/.scriptlock.${0##*/}" ]; then
@@ -148,7 +148,7 @@ cleanup() {
date +%s > "${FTP_BASE}/lastupdate"
fi
- [ "$1" ] && exit $1
+ [ "$1" ] && exit "$1"
}
abort() {
@@ -191,9 +191,9 @@ repo_lock () {
fi
_count=0
- while [ $_count -le $_trial ] || $_lockblock ; do
+ while [ "$_count" -le "$_trial" ] || "$_lockblock" ; do
if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then
- _owner="$(/usr/bin/stat -c %U $LOCKDIR)"
+ _owner="$(/usr/bin/stat -c %U "$LOCKDIR")"
warning "Repo [${1}] (${2}) is already locked by $_owner. "
msg2 "Retrying in $LOCK_DELAY seconds..."
else
@@ -201,7 +201,7 @@ repo_lock () {
set_umask
return 0
fi
- sleep $LOCK_DELAY
+ sleep "$LOCK_DELAY"
let _count=$_count+1
done
@@ -324,45 +324,45 @@ getpkgfile() {
elif [ ! -f "${1}" ]; then
error "Package ${1} not found!"
exit 1
- elif ${REQUIRE_SIGNATURE} && [ ! -f "${1}.sig" ]; then
+ elif "${REQUIRE_SIGNATURE}" && [ ! -f "${1}.sig" ]; then
error "Package signature ${1}.sig not found!"
exit 1
fi
- echo ${1}
+ echo "${1}"
}
getpkgfiles() {
local f
- if [ ! -z "$(echo ${@%\.*} | sed "s/ /\n/g" | sort | uniq -D)" ]; then
+ if [ ! -z "$(printf '%s\n' "${@%\.*}" | sort | uniq -D)" ]; then
error 'Duplicate packages found!'
exit 1
fi
- for f in ${@}; do
+ for f in "${@}"; do
if [ ! -f "${f}" ]; then
error "Package ${f} not found!"
exit 1
- elif ${REQUIRE_SIGNATURE} && [ ! -f "${f}.sig" ]; then
+ elif "${REQUIRE_SIGNATURE}" && [ ! -f "${f}.sig" ]; then
error "Package signature ${f}.sig not found!"
exit 1
fi
done
- echo ${@}
+ echo "${@}"
}
check_pkgfile() {
local pkgfile=$1
- local pkgname="$(getpkgname ${pkgfile})"
+ local pkgname="$(getpkgname "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local pkgver="$(getpkgver ${pkgfile})"
+ local pkgver="$(getpkgver "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local pkgarch="$(getpkgarch ${pkgfile})"
+ local pkgarch="$(getpkgarch "${pkgfile}")"
[ $? -ge 1 ] && return 1
- in_array "${pkgarch}" ${ARCHES[@]} 'any' || return 1
+ in_array "${pkgarch}" "${ARCHES[@]}" 'any' || return 1
if echo "${pkgfile##*/}" | grep -q "${pkgname}-${pkgver}-${pkgarch}"; then
return 0
@@ -373,17 +373,17 @@ check_pkgfile() {
check_pkgsvn() {
local pkgfile="${1}"
- local _pkgbase="$(getpkgbase ${pkgfile})"
+ local _pkgbase="$(getpkgbase "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local _pkgname="$(getpkgname ${pkgfile})"
+ local _pkgname="$(getpkgname "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local _pkgver="$(getpkgver ${pkgfile})"
+ local _pkgver="$(getpkgver "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local _pkgarch="$(getpkgarch ${pkgfile})"
+ local _pkgarch="$(getpkgarch "${pkgfile}")"
[ $? -ge 1 ] && return 1
local repo="${2}"
- in_array "${repo}" ${PKGREPOS[@]} || return 1
+ in_array "${repo}" "${PKGREPOS[@]}" || return 1
if [ ! -f "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}" ]; then
mkdir -p "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}"
@@ -392,11 +392,11 @@ check_pkgsvn() {
[ $? -ge 1 ] && return 1
fi
- local svnver="$(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo $(get_full_version ${epoch:-0} ${pkgver} ${pkgrel}) )"
+ local svnver="$(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; get_full_version "${epoch:-0}" "${pkgver}" "${pkgrel}")"
[ "${svnver}" == "${_pkgver}" ] || return 1
- local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo ${pkgname[@]}))
- in_array "${_pkgname}" ${svnnames[@]} || return 1
+ local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo "${pkgname[@]}"))
+ in_array "${_pkgname}" "${svnnames[@]}" || return 1
return 0
}
@@ -404,7 +404,7 @@ check_pkgsvn() {
check_splitpkgs() {
local repo="${1}"
shift
- local pkgfiles=(${@})
+ local pkgfiles=("${@}")
local pkgfile
local pkgdir
local svnname
@@ -412,11 +412,11 @@ check_splitpkgs() {
mkdir -p "${WORKDIR}/check_splitpkgs/"
pushd "${WORKDIR}/check_splitpkgs" >/dev/null
- for pkgfile in ${pkgfiles[@]}; do
+ for pkgfile in "${pkgfiles[@]}"; do
issplitpkg "${pkgfile}" || continue
- local _pkgbase="$(getpkgbase ${pkgfile})"
- local _pkgname="$(getpkgname ${pkgfile})"
- local _pkgarch="$(getpkgarch ${pkgfile})"
+ local _pkgbase="$(getpkgbase "${pkgfile}")"
+ local _pkgname="$(getpkgname "${pkgfile}")"
+ local _pkgarch="$(getpkgarch "${pkgfile}")"
mkdir -p "${repo}/${_pkgarch}/${_pkgbase}"
echo "${_pkgname}" >> "${repo}/${_pkgarch}/${_pkgbase}/staging"
@@ -427,9 +427,8 @@ check_splitpkgs() {
[ $? -ge 1 ] && return 1
fi
- local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo ${pkgname[@]}))
- for svnname in ${svnnames[@]}; do
- echo "${svnname}" >> "${repo}/${_pkgarch}/${_pkgbase}/svn"
+ local svnnames=($(. "${WORKDIR}/pkgbuilds/${repo}-${_pkgarch}/${_pkgbase}"; echo "${pkgname[@]}"))
+ printf '%s\n' in "${svnnames[@]}" >> "${repo}/${_pkgarch}/${_pkgbase}/svn"
done
done
popd >/dev/null
@@ -449,11 +448,11 @@ check_splitpkgs() {
check_pkgrepos() {
local pkgfile=$1
- local pkgname="$(getpkgname ${pkgfile})"
+ local pkgname="$(getpkgname "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local pkgver="$(getpkgver ${pkgfile})"
+ local pkgver="$(getpkgver "${pkgfile}")"
[ $? -ge 1 ] && return 1
- local pkgarch="$(getpkgarch ${pkgfile})"
+ local pkgarch="$(getpkgarch "${pkgfile}")"
[ $? -ge 1 ] && return 1
[ -f "${FTP_BASE}/${PKGPOOL}/${pkgname}-${pkgver}-${pkgarch}"${PKGEXT} ] && return 1
@@ -467,8 +466,8 @@ check_pkgrepos() {
#usage: chk_license ${license[@]}"
chk_license() {
local l
- for l in ${@}; do
- in_array ${l} ${ALLOWED_LICENSES[@]} && return 0
+ for l in "${@}"; do
+ in_array "${l}" "${ALLOWED_LICENSES[@]}" && return 0
done
return 1
@@ -480,16 +479,16 @@ check_repo_permission() {
[ ${#PKGREPOS[@]} -eq 0 ] && return 1
[ -z "${PKGPOOL}" ] && return 1
- in_array "${repo}" ${PKGREPOS[@]} || return 1
+ in_array "${repo}" "${PKGREPOS[@]}" || return 1
[ -w "$FTP_BASE/${PKGPOOL}" ] || return 1
local arch
- for arch in ${ARCHES}; do
+ for arch in "${ARCHES}"; do
local dir="${FTP_BASE}/${repo}/os/${arch}/"
[ -w "${dir}" ] || return 1
- [ -f "${dir}"${repo}${DBEXT} -a ! -w "${dir}"${repo}${DBEXT} ] && return 1
- [ -f "${dir}"${repo}${FILESEXT} -a ! -w "${dir}"${repo}${FILESEXT} ] && return 1
+ [ -f "${dir}${repo}"${DBEXT} -a ! -w "${dir}${repo}"${DBEXT} ] && return 1
+ [ -f "${dir}${repo}"${FILESEXT} -a ! -w "${dir}${repo}"${FILESEXT} ] && return 1
done
return 0
@@ -503,9 +502,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 ${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}"
+ 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}"
else
error "You don't have permission to change ${dbfile}"
@@ -515,12 +514,12 @@ set_repo_permission() {
arch_repo_add() {
local repo=$1
local arch=$2
- local pkgs=(${@:3})
+ local pkgs=("${@:3}")
# 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[@]}"
+ /usr/bin/repo-add -q "${repo}${DBEXT}" "${pkgs[@]}" \
+ || error "repo-add ${repo}${DBEXT} ${pkgs[*]}"
popd >/dev/null
set_repo_permission "${repo}" "${arch}"
@@ -530,15 +529,15 @@ arch_repo_add() {
arch_repo_remove() {
local repo=$1
local arch=$2
- local pkgs=(${@:3})
+ local pkgs=("${@:3}")
local dbfile="${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}"
if [ ! -f "${dbfile}" ]; then
error "No database found at '${dbfile}'"
return 1
fi
- /usr/bin/repo-remove -q "${dbfile}" ${pkgs[@]} \
- || error "repo-remove ${dbfile} ${pkgs[@]}"
+ /usr/bin/repo-remove -q "${dbfile}" "${pkgs[@]}" \
+ || error "repo-remove ${dbfile} ${pkgs[*]}"
set_repo_permission "${repo}" "${arch}"
REPO_MODIFIED=1