From 7d584af432202470d9d8fefd74a7f7ed044c4ab3 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 20 Apr 2017 23:05:42 -0400 Subject: random tidy up --- src/abslibre-tools/diff-unfree | 10 +++++----- src/aur | 2 +- src/chroot-tools/distcc-tool | 2 +- src/chroot-tools/hooks-chcleanup.sh | 1 + src/chroot-tools/librechroot | 6 +++--- src/dagpkg | 28 ++++++++++++++-------------- src/lib/conf.sh.in | 2 +- src/librefetch/librefetch-install.in | 2 +- src/pkgbuild-summarize-nonfree | 1 - src/repo-diff | 29 ++++++++++++++++++----------- src/toru/toru-path | 13 +++++++------ 11 files changed, 52 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/abslibre-tools/diff-unfree b/src/abslibre-tools/diff-unfree index 3670f7f..2d54379 100755 --- a/src/abslibre-tools/diff-unfree +++ b/src/abslibre-tools/diff-unfree @@ -25,8 +25,6 @@ . "$(librelib messages)" . "$(librelib conf)" -load_files libretools -check_vars libretools DIFFPROG || exit 1 usage() { print "Usage: %s [community|packages] [unfree-package] [repo]" "${0##*/}" @@ -39,9 +37,11 @@ usage() { main() { if [[ "$1" == "--help" ]]; then usage - exit 0 + return 0 fi + load_files libretools + check_vars libretools DIFFPROG || return 1 local package_guess=${PWD##*/} local repo=${1:-$(basename "${PWD%/*}")} @@ -57,14 +57,14 @@ main() { if [[ ! -r PKGBUILD ]]; then error "This is not a build dir." - exit 1 + return 1 fi tmp_dir="$(mktemp --tmpdir -d "${package}.XXXXXX")" if [[ ! -d "${tmp_dir}" ]]; then error "Can't create temp dir" - exit 1 + return 1 fi unfree_dir="${tmp_dir}/${svnrepo}/${package}/${trunk}" diff --git a/src/aur b/src/aur index 03336eb..8f69505 100755 --- a/src/aur +++ b/src/aur @@ -94,7 +94,7 @@ main() { fi done if $diffed; then - read -p "Press enter to continue." + read -rp "Press enter to continue." fi # Go back to our copy to continue working diff --git a/src/chroot-tools/distcc-tool b/src/chroot-tools/distcc-tool index d799c4a..6f7a684 100755 --- a/src/chroot-tools/distcc-tool +++ b/src/chroot-tools/distcc-tool @@ -142,7 +142,7 @@ parse_DISTCC_HOSTS() { ;; # TCP_HOST or OLDSTYLE_TCP_HOST *) - declare HOSTID= PORT= LIMIT= OPTIONS= + declare HOSTID='' PORT='' LIMIT='' OPTIONS='' if [[ $HOSTSPEC =~ ^([^:/]+)(:([0-9]+))?(/([0-9]+))?(,.*)?$ ]]; then # TCP_HOST HOSTID=${BASH_REMATCH[1]} diff --git a/src/chroot-tools/hooks-chcleanup.sh b/src/chroot-tools/hooks-chcleanup.sh index e76eac0..3a13aab 100644 --- a/src/chroot-tools/hooks-chcleanup.sh +++ b/src/chroot-tools/hooks-chcleanup.sh @@ -20,6 +20,7 @@ hook_pre_build+=("clean_chroot") clean_chroot() ( local copydir=$1 + if $INCHROOT; then cd /startdir "$(librelib chroot/chcleanup)" diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index fba7e91..7b1c8c2 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -75,10 +75,10 @@ hack_arch_nspawn_flags() { # We're running an ARM chroot on a non-ARM processor # Make sure that qemu-static is set up with binfmt_misc - if [[ $(grep -xF \ - -e 'enabled'\ + if [[ $(grep -c -xF \ + -e 'enabled' \ -e 'interpreter /usr/bin/qemu-arm-static' \ - /proc/sys/fs/binfmt_misc/arm 2>/dev/null |wc -l) -lt 2 ]]; then + /proc/sys/fs/binfmt_misc/arm 2>/dev/null) -lt 2 ]]; then error 'Cannot cross-compile for ARM on x86' plain 'This requires a binfmt_misc entry for qemu-arm-static.' prose 'Such a binfmt_misc entry is provided by the %s diff --git a/src/dagpkg b/src/dagpkg index c7fbb49..d6f7cca 100755 --- a/src/dagpkg +++ b/src/dagpkg @@ -28,7 +28,6 @@ set -e # Globals: # - temp_dir -# - log # - name (sort of, it's also local to visit_pkgbuild() ) # - prev # - I @@ -77,8 +76,8 @@ source_pkgbuild() { # Visit a PKGBUILD for graph building. visit_pkgbuild() { - # The name of the previous package - prev="${1}" + log=$1 # The file to appund our results to + prev=$2 # The name of the previous package local name source_pkgbuild @@ -114,7 +113,7 @@ visit_pkgbuild() { local d w for d in "${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}"; do # Cleanup dependency versions - d=${d%%<*}; d=${d%%>*}; d=${d%%=*} + d=${d%%[<>=]*} # Where's the pkgbuild? w=$(toru-where "$d") @@ -125,7 +124,7 @@ visit_pkgbuild() { # Go to this dir pushd "$w" &>/dev/null - visit_pkgbuild "$name" + visit_pkgbuild "$log" "$name" popd &>/dev/null done @@ -151,27 +150,28 @@ main() { source_pkgbuild # A temporary work dir and log file - temp_dir="${1:-$(mktemp -dt ${name}-testpkg-XXXX)}" - log="${temp_dir}/buildorder" + temp_dir="${1:-$(mktemp -dt "${name}-testpkg-XXXX")}" + local log="${temp_dir}/buildorder" # Mark array for DFS-based topological sort. See # https://en.wikipedia.org/wiki/Topological_sort for an explanation of # the algorithm. Key: package name, value: 0 for unvisited package, 1 # during visit, 2 after visit. - declare -A marks + declare -gA marks # If we specified a work dir on the cli it means we want to skip # dependency graph creation and jump to build whatever is there if [ -z "${1}" ]; then # Visit the root PKGBUILD to make the graph. - visit_pkgbuild "" + visit_pkgbuild "$log" "" else msg "Resuming build..." fi # enter work dir pushd "${temp_dir}" &>/dev/null - nl ${log} | while read order pkg; do + local w + while read -r order pkg; do # skip if already built if test -f "${pkg}/built_ok"; then warning "tried to build %s twice" "%{pkg}" @@ -179,7 +179,7 @@ main() { fi # where's this package? - local w="$(toru-where "$pkg")" + w="$(toru-where "$pkg")" test -z "$w" && continue # copy to work dir if not already @@ -191,7 +191,7 @@ main() { term_title "%s(%s)" "$pkg" "$order" - msg "Building %s" ${pkg} + msg "Building %s" "${pkg}" # upgrade the system # this would probably have to go on HOOKPREBUILD if you're working @@ -215,11 +215,11 @@ main() { touch built_ok popd &>/dev/null - done + done < <(nl "$log") popd &>/dev/null # cleanup - rm -rf ${log} "${temp_dir}" + rm -rf "${log}" "${temp_dir}" term_title "done" } diff --git a/src/lib/conf.sh.in b/src/lib/conf.sh.in index 095c4f1..1e4acd9 100644 --- a/src/lib/conf.sh.in +++ b/src/lib/conf.sh.in @@ -239,7 +239,7 @@ load_PKGBUILD() { local file=${1:-./PKGBUILD} unset_PKGBUILD # shellcheck disable=2034 - CARCH="$(get_var makepkg CARCH "`uname -m`")" + CARCH="$(get_var makepkg CARCH "$(uname -m)")" . "$file" pkgbase=${pkgbase:-${pkgname[0]}} } diff --git a/src/librefetch/librefetch-install.in b/src/librefetch/librefetch-install.in index 02d24e6..bb2fd5e 100644 --- a/src/librefetch/librefetch-install.in +++ b/src/librefetch/librefetch-install.in @@ -56,7 +56,7 @@ post_install() { local file=$1 if grep -q 'librefetch' "$file"; then print ":: %s: librefetch is already in %q" "${0##*/}" "$(realpath -s "$file")" - local line del=false + local line for line in "${old_code[@]}"; do if has_line "$file" "$line"; then print ":: %s: ... but it's an old version" "${0##*/}" diff --git a/src/pkgbuild-summarize-nonfree b/src/pkgbuild-summarize-nonfree index a0fb538..cf9277e 100755 --- a/src/pkgbuild-summarize-nonfree +++ b/src/pkgbuild-summarize-nonfree @@ -21,7 +21,6 @@ . "$(librelib messages)" # Make sure these match pkgbuild-check-nonfree -declare -ri _E_OK=0 declare -ri _E_ERROR=1 declare -ri _E_LIC_UNKNOWN=2 declare -ri _E_LIC_NOGPL=4 diff --git a/src/repo-diff b/src/repo-diff index ab7aaed..df5e49b 100755 --- a/src/repo-diff +++ b/src/repo-diff @@ -30,8 +30,12 @@ usage() { flag 'parabola' 'expands to Parabola GNU/Linux-libre repo url' } -b() { bsdtar ztf "$1" | cut -d "/" -f1 | sort -u ; } -n() { echo "$1".db | tr "/" "-"; } +b() { + bsdtar tf "$1" | cut -d "/" -f1 | sort -u +} +n() { + tr "/" "-" <<<"$1".db +} # hopefully simple way to convert # parabola/libre/i686 @@ -47,11 +51,11 @@ g() { main() { if test $# -eq 0; then usage - exit 0 + return 0 fi - mkdir ${0##*/}.$$ - pushd ${0##*/}.$$ >/dev/null + local tmpdir; tmpdir="$(mktemp -d -t "${0##*/}.XXXXXXXXXX")" + pushd "$tmpdir" >/dev/null d="" for i in $1 $2; do @@ -59,20 +63,23 @@ main() { test -z "$n" && exit 1 - wget -O "$n" -nv $(g "$i") - b "$n" >${n}.orig + wget -O "$n" -nv "$(g "$i")" + b "$n" > "${n}.orig" d+=" ${n}.orig" done { - printf "$(gettext "Difference between %s and %s")\n---\n" $1 $2 - which diffstat &>/dev/null && diff -auN "${d[@]}" | diffstat + print 'Difference between %s and %s' "$1" "$2" + echo '---' + if type diffstat &>/dev/null; then + diff -auN "${d[@]}" | diffstat + fi diff -auN "${d[@]}" - } >../${n}.diff + } > "../${n}.diff" popd >/dev/null - rm -r ${0##*/}.$$ + rm -r "$tmpdir" print "Difference save on %s" "${n}.diff" } diff --git a/src/toru/toru-path b/src/toru/toru-path index fac4e5a..07efb11 100755 --- a/src/toru/toru-path +++ b/src/toru/toru-path @@ -37,12 +37,12 @@ main() { check_vars abs ABSROOT || exit 1 if [ ! -w "$TORUPATH" ]; then - error "Toru's path isn't writable. Please check $TORUPATH" + error "Toru's path isn't writable. Please check your TORUPATH: %q" "$TORUPATH" exit 1 fi - lastsyncfile=${TORUPATH}/lastsync.paths - pathfile=${TORUPATH}/paths.tch + local lastsyncfile=${TORUPATH}/lastsync.paths + local pathfile=${TORUPATH}/paths.tch if [ ! -e "${pathfile}" ]; then tcamgr create "${pathfile}" @@ -50,10 +50,10 @@ main() { # TODO: ability to use flags to pass in other directories to fullrepos + local fullrepos=() # This loops over ${REPOS[@]} backward. This is because early entries # in REPOS have higher precidence, but the way this is implemented, # the later entries have precedence, so we need to flip the order. - fullrepos=() for (( i = ${#REPOS[@]}-1 ; i >= 0 ; i-- )); do $VERBOSE && msg "Processing [%s]" "${REPOS[$i]}" @@ -64,7 +64,7 @@ main() { # Find PKGBUILDs in ${fullrepos[@]} find_args=("${fullrepos[@]}" -mindepth 2 -maxdepth 3 -type f -name PKGBUILD) - if ! $FORCE && [[ -e $lastsyncfile ]]; then + if [[ -e $lastsyncfile ]] && ! $FORCE; then # if lastfilesync exists, only look at things that have # changed since then (unless $FORCE is on) find_args+=(-newer "${lastsyncfile}") @@ -75,9 +75,10 @@ main() { # Add information from each of the PKGBUILDs to the toru cache. msg "Updating path cache" msg2 "%d PKGBUILDs to update" ${#pkgbuilds[@]} + local _pkgbuild fullpath for _pkgbuild in "${pkgbuilds[@]}"; do # plain "$_pkgbuild" - if ! load_PKGBUILD "${_pkgbuild}" >/dev/null 2>&1; then + if ! load_PKGBUILD "${_pkgbuild}" &>/dev/null; then error "%q contains errors, skipping" "${_pkgbuild}" continue fi -- cgit v1.2.2