diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-01 17:46:32 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-04 14:28:08 -0400 |
commit | 2ae5371f347603d34a7ccc33681e612db338d11e (patch) | |
tree | 2ecb5b05dcb1ffc2defb31c7f64d6720435f13e5 | |
parent | bb97cfc85d9b711b517985abbd9832bff9c4b37a (diff) |
Have everything use a main() function, where it isn't too tricky to convert
"Ignore space change" is essential to making sense of this patch.
-rwxr-xr-x | src/abslibre-tools/createworkdir | 43 | ||||
-rwxr-xr-x | src/abslibre-tools/libreaddiff | 114 | ||||
-rwxr-xr-x | src/dagpkg | 146 | ||||
-rwxr-xr-x | src/is_built | 52 | ||||
-rwxr-xr-x | src/repo-diff | 50 | ||||
-rwxr-xr-x | src/toru/toru-info | 38 | ||||
-rwxr-xr-x | src/toru/toru-path | 125 | ||||
-rwxr-xr-x | src/toru/toru-where | 11 |
8 files changed, 310 insertions, 269 deletions
diff --git a/src/abslibre-tools/createworkdir b/src/abslibre-tools/createworkdir index 80b2d5e..e3e4143 100755 --- a/src/abslibre-tools/createworkdir +++ b/src/abslibre-tools/createworkdir @@ -27,28 +27,33 @@ set -euE . "$(librelib messages)" . "$(librelib conf)" -load_files libretools -check_vars libretools WORKDIR ABSLIBRERECV ABSLIBRESEND # these are asked for by `xbs download` -trap 'error "Aborting..."' EXIT +main() { + load_files libretools + check_vars libretools WORKDIR ABSLIBRERECV ABSLIBRESEND # these are asked for by `xbs download` -msg "Creating WORKDIR at %s..." "$WORKDIR" -mkdir -p "$WORKDIR" + trap 'error "Aborting..."' EXIT -msg "Creating staging directory in WORKDIR..." -mkdir -p "$WORKDIR/staging" + msg "Creating WORKDIR at %s..." "$WORKDIR" + mkdir -p "$WORKDIR" -cmd=(xbs -b abslibre download) -if ! "${cmd[@]}"; then - error "Could not clone ABSLibre" - plain "Try running this command:" - echo - printf '%q ' "${cmd[@]}" - echo - exit 1 -fi + msg "Creating staging directory in WORKDIR..." + mkdir -p "$WORKDIR/staging" -msg "Finished, your packaging directory tree looks like this now:" -ls --color=auto "${WORKDIR}"/* + cmd=(xbs -b abslibre download) + if ! "${cmd[@]}"; then + error "Could not clone ABSLibre" + plain "Try running this command:" + echo + printf '%q ' "${cmd[@]}" + echo + exit 1 + fi -trap -- EXIT + msg "Finished, your packaging directory tree looks like this now:" + ls --color=auto "${WORKDIR}"/* + + trap -- EXIT +} + +main "$@" diff --git a/src/abslibre-tools/libreaddiff b/src/abslibre-tools/libreaddiff index 17e808b..010c7b9 100755 --- a/src/abslibre-tools/libreaddiff +++ b/src/abslibre-tools/libreaddiff @@ -24,35 +24,42 @@ set -e . "$(librelib messages)" . "$(librelib conf)" -load_files libretools -check_vars libretools WORKDIR -for arg in "$@" ; do - case "$arg" in - -h|--h|--he|--hel|--help|-\?) - { - print 'Usage: %s repo [arch]' "${0##*/}" - echo - prose "This script outputs a diff of package names and versions - in repo between pacman's sync db and abslibre checkout." - } >&2 - exit 0 - ;; - esac -done +main() { + load_files libretools + check_vars libretools WORKDIR -# The repo to find missing packages in. -repo=$1 -# The arch to check in Arch repos, other will have all arches checked. -arch=${2:-mips64el} -# A Python tuple of repos which don't have arch=any packages. -archrepos='("core", "extra", "community")' + for arg in "$@" ; do + case "$arg" in + -h|--h|--he|--hel|--help|-\?) + { + print 'Usage: %s repo [arch]' "${0##*/}" + echo + prose "This script outputs a diff of package names and versions + in repo between pacman's sync db and abslibre checkout." + } >&2 + exit 0 + ;; + esac + done -diff -U0 \ - <( ( - cd /var/lib/pacman/sync - for f in $repo.db ; do - tar xOf $f | python -c 'import sys + # The repo to find missing packages in. + repo=$1 + # The arch to check in Arch repos, other will have all arches checked. + arch=${2:-mips64el} + # A Python tuple of repos which don't have arch=any packages. + archrepos='("core", "extra", "community")' + + diff -U0 \ + <(pacman_list_packages | sort ) \ + <(abslibre_list_packages | sort ) \ + | sed -rn 's/^[+-][^+-].+$/&/p' +} + +pacman_list_packages() { + cd /var/lib/pacman/sync + for f in $repo.db ; do + tar xOf $f | python -c 'import sys arch = None name = None version = None @@ -71,29 +78,32 @@ try: except StopIteration: pass ' - done - ) | sort ) \ - <( ( - cd "${WORKDIR}/abslibre" - # Needed to not include pkgnames specific to other arches. - CARCH=$arch - for f in $repo/* ; do - load_PKGBUILD "$f/PKGBUILD" || continue - is_here=false - for arc in ${arch[@]} ; do - if [[ "$arc" == "any" ]] || [[ "$arc" == "$CARCH" ]] ; then - is_here=true - break - fi - done - if [[ "$is_here" == "true" ]] ; then - for name in "${pkgname[@]}" ; do - if [[ -z "$epoch" ]] ; then - echo $name-$pkgver-$pkgrel - else - echo $name-$epoch:$pkgver-$pkgrel - fi - done - fi - done - ) | sort ) | sed -rn 's/^[+-][^+-].+$/&/p' + done +} + +abslibre_list_packages() { + cd "${WORKDIR}/abslibre" + # Needed to not include pkgnames specific to other arches. + CARCH=$arch + for f in $repo/* ; do + load_PKGBUILD "$f/PKGBUILD" || continue + is_here=false + for arc in ${arch[@]} ; do + if [[ "$arc" == "any" ]] || [[ "$arc" == "$CARCH" ]] ; then + is_here=true + break + fi + done + if [[ "$is_here" == "true" ]] ; then + for name in "${pkgname[@]}" ; do + if [[ -z "$epoch" ]] ; then + echo $name-$pkgver-$pkgrel + else + echo $name-$epoch:$pkgver-$pkgrel + fi + done + fi + done +} + +main "$@" @@ -26,15 +26,6 @@ set -e . "$(librelib messages)" . "$(librelib conf)" -# Source variables from libretools -load_files libretools -check_vars libretools FULLBUILDCMD || exit 1 -#check_vars libretools HOOKPREBUILD HOOKLOCALRELEASE || exit 1 # optional - -# Source variables from makepkg -load_files makepkg -check_vars makepkg CARCH || exit 1 - # Globals: # - temp_dir # - log @@ -60,8 +51,6 @@ trap_exit() { kill "-$signal" "$$" } -setup_traps trap_exit - source_pkgbuild() { # Source this PKGBUILD, if it doesn't exist, exit if ! load_PKGBUILD &>/dev/null; then @@ -86,18 +75,6 @@ source_pkgbuild() { name="${pkgbase:-${pkgname[0]}}" } -source_pkgbuild - -# A temporary work dir and log file -temp_dir="${1:-$(mktemp -dt ${name}-testpkg-XXXX)}" -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 - # Visit a PKGBUILD for graph building. visit_pkgbuild() { # The name of the previous package @@ -159,65 +136,92 @@ visit_pkgbuild() { echo "$name" >> "${log}" } -# 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 "" -else - msg "Resuming build..." -fi - -# enter work dir -pushd "${temp_dir}" &>/dev/null -nl ${log} | while read order pkg; do - # skip if already built - if test -f "${pkg}/built_ok"; then - warning "tried to build %s twice" "%{pkg}" - continue +main() { + # Source variables from libretools + load_files libretools + check_vars libretools FULLBUILDCMD || exit 1 + #check_vars libretools HOOKPREBUILD HOOKLOCALRELEASE || exit 1 # optional + + # Source variables from makepkg + load_files makepkg + check_vars makepkg CARCH || exit 1 + + setup_traps trap_exit + + source_pkgbuild + + # A temporary work dir and log file + temp_dir="${1:-$(mktemp -dt ${name}-testpkg-XXXX)}" + 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 + + # 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 "" + else + msg "Resuming build..." fi - # where's this package? - local w="$(toru-where "$pkg")" - test -z "$w" && continue + # enter work dir + pushd "${temp_dir}" &>/dev/null + nl ${log} | while read order pkg; do + # skip if already built + if test -f "${pkg}/built_ok"; then + warning "tried to build %s twice" "%{pkg}" + continue + fi + + # where's this package? + local w="$(toru-where "$pkg")" + test -z "$w" && continue - # copy to work dir if not already - # this means you can make modifications to the pkgbuild during the - # graph build or remove the dir after a build failure and let dagpkg - # copy a new version - test -d "$pkg" || cp -r "$w" "$pkg" - pushd "$pkg" &>/dev/null + # copy to work dir if not already + # this means you can make modifications to the pkgbuild during the + # graph build or remove the dir after a build failure and let dagpkg + # copy a new version + test -d "$pkg" || cp -r "$w" "$pkg" + pushd "$pkg" &>/dev/null - term_title "%s(%s)" "$pkg" "$order" + 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 - # outside chroots - sudo -E pacman -Syu --noconfirm + # upgrade the system + # this would probably have to go on HOOKPREBUILD if you're working + # outside chroots + sudo -E pacman -Syu --noconfirm - # run the pre build command from libretools.conf - if [[ -n "$HOOKPREBUILD" ]]; then - ${HOOKPREBUILD} - fi + # run the pre build command from libretools.conf + if [[ -n "$HOOKPREBUILD" ]]; then + ${HOOKPREBUILD} + fi - # run the build command - ${FULLBUILDCMD} + # run the build command + ${FULLBUILDCMD} - # Run local release hook with $1 = $repo - if [[ -n "$HOOKLOCALRELEASE" ]]; then - ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")" - fi + # Run local release hook with $1 = $repo + if [[ -n "$HOOKLOCALRELEASE" ]]; then + ${HOOKLOCALRELEASE} "$(basename "$(dirname "$w")")" + fi - # it's built! - touch built_ok + # it's built! + touch built_ok + + popd &>/dev/null + done popd &>/dev/null -done + # cleanup + rm -rf ${log} "${temp_dir}" -popd &>/dev/null -# cleanup -rm -rf ${log} "${temp_dir}" + term_title "done" +} -term_title "done" +main "$@" diff --git a/src/is_built b/src/is_built index d8a0eb1..22c67a7 100755 --- a/src/is_built +++ b/src/is_built @@ -38,31 +38,35 @@ usage() { print " >1: There was an error" } -while getopts 'h' arg; do - case $arg in - h) usage; exit 0 ;; - *) usage >&2; exit 2 ;; - esac -done -if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then - usage >&2 - exit 2 -fi +main() { + while getopts 'h' arg; do + case $arg in + h) usage; exit 0 ;; + *) usage >&2; exit 2 ;; + esac + done + if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then + usage >&2 + exit 2 + fi -pkg=${1} -ver=${2:-0} + pkg=${1} + ver=${2:-0} -r=0 -pver=$(LC_ALL=C pacman -Sddp --print-format '%v' "${pkg}" 2>/dev/null) || r=$? + r=0 + pver=$(LC_ALL=C pacman -Sddp --print-format '%v' "${pkg}" 2>/dev/null) || r=$? -result=$(vercmp "${pver}" "${ver}") -# result: -# -1 : pver < ver -# 0 : pver = ver -# 1 : pver > ver + result=$(vercmp "${pver}" "${ver}") + # result: + # -1 : pver < ver + # 0 : pver = ver + # 1 : pver > ver -if [[ $result -ge 0 ]] && [[ $r -eq 0 ]]; then - exit 0 -else - exit 1 -fi + if [[ $result -ge 0 ]] && [[ $r -eq 0 ]]; then + exit 0 + else + exit 1 + fi +} + +main "$@" diff --git a/src/repo-diff b/src/repo-diff index 10b617c..ab7aaed 100755 --- a/src/repo-diff +++ b/src/repo-diff @@ -30,11 +30,6 @@ usage() { flag 'parabola' 'expands to Parabola GNU/Linux-libre repo url' } -if test $# -eq 0; then - usage - exit 0 -fi - b() { bsdtar ztf "$1" | cut -d "/" -f1 | sort -u ; } n() { echo "$1".db | tr "/" "-"; } @@ -49,28 +44,37 @@ g() { -e "s,^arch\(linux\)\?/,http://mirrors.kernel.org/archlinux/," } -mkdir ${0##*/}.$$ -pushd ${0##*/}.$$ >/dev/null +main() { + if test $# -eq 0; then + usage + exit 0 + fi + + mkdir ${0##*/}.$$ + pushd ${0##*/}.$$ >/dev/null -d="" -for i in $1 $2; do - n=$(n "$i") + d="" + for i in $1 $2; do + n=$(n "$i") - test -z "$n" && exit 1 + 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 + d+=" ${n}.orig" + done -{ - printf "$(gettext "Difference between %s and %s")\n---\n" $1 $2 - which diffstat &>/dev/null && diff -auN "${d[@]}" | diffstat - diff -auN "${d[@]}" -} >../${n}.diff + { + printf "$(gettext "Difference between %s and %s")\n---\n" $1 $2 + which diffstat &>/dev/null && diff -auN "${d[@]}" | diffstat + diff -auN "${d[@]}" + } >../${n}.diff -popd >/dev/null -rm -r ${0##*/}.$$ + popd >/dev/null + rm -r ${0##*/}.$$ + + print "Difference save on %s" "${n}.diff" +} -print "Difference save on %s" "${n}.diff" +main "$@" diff --git a/src/toru/toru-info b/src/toru/toru-info index 31015e4..69799f1 100755 --- a/src/toru/toru-info +++ b/src/toru/toru-info @@ -22,23 +22,27 @@ . "$(librelib messages)" . "$(librelib conf)" -for _pkg in "$@"; do - _pkgbuild="$(toru-where "$_pkg")" +main() { + for _pkg in "$@"; do + _pkgbuild="$(toru-where "$_pkg")" - if [ -f "$_pkgbuild/PKGBUILD" ]; then - if ! load_PKGBUILD "$_pkgbuild/PKGBUILD" 2>/dev/null; then - warning "Errors on %s" "$_pkg" - continue - fi + if [ -f "$_pkgbuild/PKGBUILD" ]; then + if ! load_PKGBUILD "$_pkgbuild/PKGBUILD" 2>/dev/null; then + warning "Errors on %s" "$_pkg" + continue + fi + + deps=("${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}") + repo="$(basename -- "$(dirname -- "$_pkgbuild")")" - deps=("${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}") - repo="$(basename -- "$(dirname -- "$_pkgbuild")")" + msg "%s/%s %s-%s" "$repo" "$_pkg" "$pkgver" "$pkgrel" + msg2 '%s' "$pkgdesc" + msg2 '%s' "$url" + msg2 'Depends: %s' "${deps[*]}" + else + warning "%s doesn't exist" "$_pkg" + fi + done +} - msg "%s/%s %s-%s" "$repo" "$_pkg" "$pkgver" "$pkgrel" - msg2 '%s' "$pkgdesc" - msg2 '%s' "$url" - msg2 'Depends: %s' "${deps[*]}" - else - warning "%s doesn't exist" "$_pkg" - fi -done +main "$@" diff --git a/src/toru/toru-path b/src/toru/toru-path index 56bea42..fac4e5a 100755 --- a/src/toru/toru-path +++ b/src/toru/toru-path @@ -21,71 +21,76 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "$(librelib messages)" -setup_traps +. "$(librelib conf)" -# TODO: better option parsing -TORUPATH=${T:-${TORUPATH}} -VERBOSE=${V:-false} -FORCE=${F:-false} +main() { + setup_traps -. "$(librelib conf)" -load_files libretools -check_vars libretools TORUPATH REPOS || exit 1 -load_files abs -check_vars abs ABSROOT || exit 1 - -if [ ! -w "$TORUPATH" ]; then - error "Toru's path isn't writable. Please check $TORUPATH" - exit 1 -fi - -lastsyncfile=${TORUPATH}/lastsync.paths -pathfile=${TORUPATH}/paths.tch - -if [ ! -e "${pathfile}" ]; then - tcamgr create "${pathfile}" -fi - -# TODO: ability to use flags to pass in other directories to 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]}" - - if [ -d "${ABSROOT}/${REPOS[$i]}" ]; then - fullrepos+=("${ABSROOT}/${REPOS[$i]}") + # TODO: better option parsing + TORUPATH=${T:-${TORUPATH}} + VERBOSE=${V:-false} + FORCE=${F:-false} + + load_files libretools + check_vars libretools TORUPATH REPOS || exit 1 + load_files abs + check_vars abs ABSROOT || exit 1 + + if [ ! -w "$TORUPATH" ]; then + error "Toru's path isn't writable. Please check $TORUPATH" + exit 1 + fi + + lastsyncfile=${TORUPATH}/lastsync.paths + pathfile=${TORUPATH}/paths.tch + + if [ ! -e "${pathfile}" ]; then + tcamgr create "${pathfile}" fi -done - -# Find PKGBUILDs in ${fullrepos[@]} -find_args=("${fullrepos[@]}" -mindepth 2 -maxdepth 3 -type f -name PKGBUILD) -if ! $FORCE && [[ -e $lastsyncfile ]]; then - # if lastfilesync exists, only look at things that have - # changed since then (unless $FORCE is on) - find_args+=(-newer "${lastsyncfile}") -fi -IFS=$'\n' -pkgbuilds=($(find "${find_args[@]}")) - -# Add information from each of the PKGBUILDs to the toru cache. -msg "Updating path cache" -msg2 "%d PKGBUILDs to update" ${#pkgbuilds[@]} -for _pkgbuild in "${pkgbuilds[@]}"; do - # plain "$_pkgbuild" - if ! load_PKGBUILD "${_pkgbuild}" >/dev/null 2>&1; then - error "%q contains errors, skipping" "${_pkgbuild}" - continue + + # TODO: ability to use flags to pass in other directories to 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]}" + + if [ -d "${ABSROOT}/${REPOS[$i]}" ]; then + fullrepos+=("${ABSROOT}/${REPOS[$i]}") + fi + done + + # Find PKGBUILDs in ${fullrepos[@]} + find_args=("${fullrepos[@]}" -mindepth 2 -maxdepth 3 -type f -name PKGBUILD) + if ! $FORCE && [[ -e $lastsyncfile ]]; then + # if lastfilesync exists, only look at things that have + # changed since then (unless $FORCE is on) + find_args+=(-newer "${lastsyncfile}") fi + IFS=$'\n' + pkgbuilds=($(find "${find_args[@]}")) + + # Add information from each of the PKGBUILDs to the toru cache. + msg "Updating path cache" + msg2 "%d PKGBUILDs to update" ${#pkgbuilds[@]} + for _pkgbuild in "${pkgbuilds[@]}"; do + # plain "$_pkgbuild" + if ! load_PKGBUILD "${_pkgbuild}" >/dev/null 2>&1; then + error "%q contains errors, skipping" "${_pkgbuild}" + continue + fi - fullpath="$(dirname -- "${_pkgbuild}")" + fullpath="$(dirname -- "${_pkgbuild}")" - for _pkg in "${pkgbase}" "${pkgname[@]}" "${provides[@]}"; do - $VERBOSE && msg2 '%s -> %s' "${_pkg}" "${fullpath}" - tcamgr put "${pathfile}" "${_pkg%%[<>=]*}" "${fullpath}" + for _pkg in "${pkgbase}" "${pkgname[@]}" "${provides[@]}"; do + $VERBOSE && msg2 '%s -> %s' "${_pkg}" "${fullpath}" + tcamgr put "${pathfile}" "${_pkg%%[<>=]*}" "${fullpath}" + done done -done -date +%s > "${lastsyncfile}" + date +%s > "${lastsyncfile}" +} + +main "$@" diff --git a/src/toru/toru-where b/src/toru/toru-where index 14a40eb..ba7fb0a 100755 --- a/src/toru/toru-where +++ b/src/toru/toru-where @@ -19,7 +19,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "$(librelib conf)" -load_files libretools -check_vars libretools TORUPATH || exit 1 -tcamgr get "${TORUPATH}/paths.tch" "$1" 2>/dev/null || echo "" +main() { + load_files libretools + check_vars libretools TORUPATH || exit 1 + + tcamgr get "${TORUPATH}/paths.tch" "$1" 2>/dev/null || echo "" +} + +main "$@" |