diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-02 22:31:37 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-02 22:50:36 -0400 |
commit | 05f431335a5e910fb0cd500be0ded78d4954e82c (patch) | |
tree | d50d17fc42917932e82bd56103320468a6ddcaba | |
parent | 3f4c2e4f1f3d28981e5121af97206cdc85427042 (diff) |
libredbdiff: Normalize variable quoting.
-rwxr-xr-x | src/abslibre-tools/libredbdiff | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff index 6a56f06..eadb0a4 100755 --- a/src/abslibre-tools/libredbdiff +++ b/src/abslibre-tools/libredbdiff @@ -40,8 +40,8 @@ field_pkgname_arch=30 cmd="${0##*/}" -arch_packages_tmp="/tmp/${cmd}.arch-packages" -parabola_packages_tmp="/tmp/${cmd}.parabola-packages" +arch_packages_tmp="/tmp/$cmd.arch-packages" +parabola_packages_tmp="/tmp/$cmd.parabola-packages" field_pkgname_total="$((field_pkgname_parabola + field_pkgname_arch))" printf_format="%s %-${field_pkgname_parabola}s%-${field_pkgname_arch}s %s | %s\n" @@ -51,14 +51,14 @@ downloadfile() { local outfile=$1 local url=$2 local mesg=("${@:3}") - if [[ ! -e $outfile ]] ; then + if [[ ! -e "$outfile" ]] ; then msg "${mesg[@]}" if wget -q "$url" -O "$outfile"; then return 255 else die "Failed to download %q. Exiting." "$outfile" fi - elif [[ $init ]]; then + elif [[ -n "$init" ]]; then warning "%q already exists. Skipping." "$outfile" fi } @@ -66,17 +66,17 @@ downloadfile() { enablerepo() { repo="$1" conffile_arg="$2" - msg2 "Enabling repo %q in %q" "$repo" "${conffile_arg}" - sed -i "s/\#\[$repo\]/[$repo]/" "${conffile_arg}" - sed -i "\/\[$repo\]/,+1 s/#Include/Include/" "${conffile_arg}" + msg2 "Enabling repo %q in %q" "$repo" "$conffile_arg" + sed -i "s/\#\[$repo\]/[$repo]/" "$conffile_arg" + sed -i "\/\[$repo\]/,+1 s/#Include/Include/" "$conffile_arg" } createdir() { local dir=$1 - if [[ ! -e $dir ]] ; then + if [[ ! -e "$dir" ]] ; then msg "Creating directory %q" "$dir" mkdir -- "$1" || die "Failed to create directory %q. Exiting." "$dir" - elif [[ $init ]]; then + elif [[ -n "$init" ]]; then warning "%q already exists. Skipping." "$dir" fi } @@ -85,17 +85,17 @@ setmirror() { local distro="$1" local mirror="$2" local mirrorlist="$3" - if [[ $init ]] && [[ $mirror ]]; then + if [[ -n "$init" ]] && [[ -n "$mirror" ]]; then mirrorescaped="${mirror//./\\.}" mirrorescaped="${mirrorescaped//\$/\\$}" - msg2 "Setting %s as the only enabled %s mirror." "${mirror}" "${distro}" - sed -i 's|^#\(Server = '"${mirrorescaped}"'\)$|\1|' "${mirrorlist}" + msg2 "Setting %s as the only enabled %s mirror." "$mirror" "$distro" + sed -i 's|^#\(Server = '"$mirrorescaped"'\)$|\1|' "$mirrorlist" fi } filenotfound() { local file=$1 - if [[ ! -r $1 ]]; then + if [[ ! -r "$1" ]]; then error "Could not read %q." "$file" die "Nothing done. It may be necessary to run %q without \ arguments as root to initialize %s." "$cmd" "$name" @@ -107,45 +107,45 @@ initialize() { createdir "$basedbpath" downloadfile \ - "${conffile}" \ + "$conffile" \ "https://projects.parabola.nu/abslibre.git/plain/libre/pacman/pacman.conf.x86_64" \ "Downloading Parabola %q" \ pacman.conf if [[ $? == 255 ]] ; then - msg2 "Setting DBPath in %q" "${conffile}" - sed -i "s|^#DBPath .*|DBPath = ${dbpath}|" "${conffile}" - enablerepo nonprism "${conffile}" - enablerepo pcr "${conffile}" - enablerepo libre-multilib "${conffile}" - enablerepo multilib "${conffile}" + msg2 "Setting DBPath in %q" "$conffile" + sed -i "s|^#DBPath .*|DBPath = $dbpath|" "$conffile" + enablerepo nonprism "$conffile" + enablerepo pcr "$conffile" + enablerepo libre-multilib "$conffile" + enablerepo multilib "$conffile" fi downloadfile \ - "${conffilearch}" \ + "$conffilearch" \ "https://projects.archlinux.org/svntogit/packages.git/plain/pacman/trunk/pacman.conf.x86_64" \ "Downloading Arch %q" \ pacman.conf if [[ $? == 255 ]] ; then - msg2 "Setting DBPath in %q" "${conffilearch}" - sed -i "s|^#DBPath .*|DBPath = ${dbpatharch}|" "${conffilearch}" - msg2 "Setting Arch mirrorlist file in %q" "${conffilearch}" + msg2 "Setting DBPath in %q" "$conffilearch" + sed -i "s|^#DBPath .*|DBPath = $dbpatharch|" "$conffilearch" + msg2 "Setting Arch mirrorlist file in %q" "$conffilearch" sed -i "s|/etc/pacman\.d/mirrorlist$|$baseconfpath/mirrorlist.archlinux|" \ - "${conffilearch}" - enablerepo multilib "${conffilearch}" + "$conffilearch" + enablerepo multilib "$conffilearch" fi downloadfile \ - "${mirrorlist}" \ + "$mirrorlist" \ "https://repo.parabola.nu/mirrorlist.txt" \ "Downloading Parabola %q" \ mirrorlist if [[ $? == 255 ]] ; then - sed -i 's|^Server|#Server|' "${mirrorlist}" + sed -i 's|^Server|#Server|' "$mirrorlist" setmirror "Parabola" "$mirror" "$mirrorlist" fi downloadfile \ - "${mirrorlistarch}" \ + "$mirrorlistarch" \ "https://projects.archlinux.org/svntogit/packages.git/plain/pacman-mirrorlist/trunk/mirrorlist" \ "Downloading Arch %q" \ mirrorlist @@ -156,48 +156,48 @@ initialize() { repo_test() { for repo in "${repos[@]}" ; do - if [[ $repo == "$1" ]] ; then + if [[ "$repo" == "$1" ]] ; then found=1 return 0 fi done - if [[ $found != 1 ]] ; then + if [[ "$found" != 1 ]] ; then die "The specified Parabola repo \"%s\" cannot be compared. It's not in the list of repos in the configuration variable \"repos\"." "$1" fi } compare_pkgs() { local cmp - if [[ ${verarch[$pkgname]} ]] ; then + if [[ -n "${verarch[$pkgname]}" ]] ; then cmp=$(vercmp "${ver[$pkgname]}" "${verarch[$pkgname]}") - if [[ $cmp -lt 0 ]]; then - printf "${printf_format}" \ + if [[ "$cmp" -lt 0 ]]; then + printf "$printf_format" \ '=' \ - "${pkgname}" \ + "$pkgname" \ "" \ "${ver[$pkgname]}" \ "${verarch[$pkgname]}" fi - elif [[ ${provides[$pkgname]} ]]; then + elif [[ -n "${provides[$pkgname]}" ]]; then local _provides provide read -r -a _provides <<<"${provides[$pkgname]}" for provide in "${_provides[@]}"; do - if [[ ${verarch["$provide"]} ]]; then + if [[ -n "${verarch[$provide]}" ]]; then cmp=$(vercmp "${ver[$pkgname]}" "${verarch[$provide]}") - if [[ $cmp -lt 0 ]]; then - printf "${printf_format}" \ + if [[ "$cmp" -lt 0 ]]; then + printf "$printf_format" \ 'p' \ - "${pkgname}" \ - "${provide}" \ + "$pkgname" \ + "$provide" \ "${ver[$pkgname]}" \ "${verarch[$provide]}" fi fi done else - printf "${printf_format_noarch}" \ + printf "$printf_format_noarch" \ 'o' \ - "${pkgname}" \ + "$pkgname" \ "${ver[$pkgname]}" fi } @@ -206,11 +206,11 @@ print_cmp() { local repo="$1" awk -F/ -v repo="$repo" \ '$1 == repo {print $2}' \ - ${parabola_packages_tmp} | \ + "$parabola_packages_tmp" | \ while read -a line ; do ver["${line[0]}"]="${line[1]}" - provides[${line[0]}]="${line[@]:2}" - pkgname=${line[0]} + provides["${line[0]}"]="${line[*]:2}" + pkgname="${line[0]}" compare_pkgs done } @@ -267,7 +267,7 @@ main() { esac done - if (( $UPDATE )) ; then + if (( UPDATE )) ; then if [[ $EUID != 0 ]]; then die "To initialize %s or update %s pacman databases, %s must be run as root (without arguments). Nothing done." \ "$name" \ @@ -276,12 +276,12 @@ main() { fi check_vars libredbdiff statedir mirror mirrorarch || exit 1 - if ! [[ -e "${conffile}" && \ - -e "${conffilearch}" && \ - -e "${mirrorlist}" && \ - -e "${mirrorlist}" ]]; then + if ! [[ -e "$conffile" && \ + -e "$conffilearch" && \ + -e "$mirrorlist" && \ + -e "$mirrorlist" ]]; then warning "At least one %s configuration file is missing." \ - "${name}" + "$name" msg "Downloading and preparing missing configuration files." init=1 fi @@ -294,17 +294,17 @@ main() { if ! [[ -d "$dbpath" && \ -d "$dbpatharch" ]]; then warning "At least one %s pacman DB directory is missing. Synchronizing %s DB files." \ - "${name}" "${name}" + "$name" "$name" fi createdir "$dbpath" msg "Synchronizing %s pacman databases for Parabola" "$name" - pacman --config "${conffile}" -Sy || + pacman --config "$conffile" -Sy || die "Failed to synchronize pacman database for Parabola. Exiting." createdir "$dbpatharch" msg "Synchronizing %s pacman databases for Arch" "$name" - pacman --config "${conffilearch}" -Sy || + pacman --config "$conffilearch" -Sy || die "Failed to synchronize pacman database for Arch. Exiting." msg "%s pacman databases are updated. %s is ready. Run %q -n to print results." \ @@ -313,32 +313,32 @@ main() { else check_vars libredbdiff statedir repos || exit 1 - filenotfound "${dbpath}/sync/libre.db" - filenotfound "${dbpatharch}/sync/core.db" - filenotfound "${conffile}" - filenotfound "${conffilearch}" + filenotfound "$dbpath/sync/libre.db" + filenotfound "$dbpatharch/sync/core.db" + filenotfound "$conffile" + filenotfound "$conffilearch" unset provides ver verarch declare -gA provides ver verarch - pacman --config "${conffilearch}" -Ss | \ + pacman --config "$conffilearch" -Ss | \ grep -v '^ ' | \ awk -F/ '{print $2}' \ - > ${arch_packages_tmp} || \ + > "$arch_packages_tmp" || \ die "pacman command to get Arch package data has failed. Exiting." - chmod 777 ${arch_packages_tmp} + chmod 777 "$arch_packages_tmp" while read -a line; do verarch["${line[0]}"]="${line[1]}" - done < ${arch_packages_tmp} + done < "$arch_packages_tmp" - expac --config "${conffile}" -S '%r/%n %v %S' \ - > ${parabola_packages_tmp} || \ + expac --config "$conffile" -S '%r/%n %v %S' \ + > "$parabola_packages_tmp" || \ die "expac command to get Parabola package data has failed. Exiting." - chmod 777 ${parabola_packages_tmp} + chmod 777 "$parabola_packages_tmp" - if [[ ${repo_arg} ]] ; then - print_cmp "${repo_arg}" + if [[ -n "$repo_arg" ]] ; then + print_cmp "$repo_arg" else for repo in "${repos[@]}" ; do echo "[$repo]" |