diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2023-06-19 06:00:29 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2023-12-14 17:13:11 -0500 |
commit | a403d7fd1b207952e5536e15d0e7ef0484b8c9ed (patch) | |
tree | 3b9c0a6253e7ea378434e8fbedc6d672828c1da4 | |
parent | d337c16daaa445a65872df54b9eb71b709b41d0f (diff) |
[meld-pkgbuilds]: initial script
-rwxr-xr-x | meld-pkgbuilds | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/meld-pkgbuilds b/meld-pkgbuilds new file mode 100755 index 0000000..9f72a0d --- /dev/null +++ b/meld-pkgbuilds @@ -0,0 +1,158 @@ +#!/bin/bash + +readonly ARCH_DIR=/packages/arch +readonly AUR_DIR=/packages/aur +readonly ABSLIBRE_DIR=/packages/abslibre +readonly ARCH_URL=https://gitlab.archlinux.org/archlinux/packaging +readonly AUR_URL=https://aur.archlinux.org + +readonly DEBUG=0 + + +meld_pkgbuilds() # (pkgname [--reverse]) +{ + verify_writable_pkgbuild_dir() + { + [[ -w "$1" || -z "$1" ]] || mkdir "$1" || ! echo "lacking write permission for $1 - quitting" + } + + clone_or_pull() # (git_url "target_dir") + { + # eg: | ${ARCH_URL} | | pkgname | + # eg: https://gitlab.archlinux.org/archlinux/packaging/packages/qutebrowser.git + + local git_url=$1 +# local repo_or_pkgname=${git_url##*/} +# local repo=$1 +# local git_url=${ARCH_URL}/${repo}.git +# local target_dir="$2"/${repo_or_pkgname} + local target_dir="$2" + +if (( DEBUG )) ; then [[ ! -d "${target_dir}"/.git ]] && + echo "git clone ${git_url} \"${target_dir}\"" || + echo "(cd \"${target_dir}\" ; git pull ;)" ; fi + + if [[ ! -d "${target_dir}"/.git ]] + then git clone ${git_url}.git "${target_dir}" + else (cd "${target_dir}" ; git pull ;) + fi + } + + find_statefile() + { + local state_dir="${ARCH_DIR}"/state + local statefile="$(find "${state_dir}" -maxdepth 2 -type f -name ${pkgname})" + + echo "${statefile}" + [[ -n "${statefile}" ]] + } + + find_pkgbuild() # (pkgbuilds_dir) + { + local pkgbuilds_dir="$1" + local depth=$([[ "${pkgbuilds_dir}/" =~ ^"${ABSLIBRE_DIR}" ]] && echo 2 || echo 1) + + find ${pkgbuilds_dir}/ -maxdepth ${depth} -type d -name ${pkgname} | sort ${sort_order} + } + + + local pkgname_rx='^[-@\._\+0-9a-z]+$' ; + local pkgname=$( [[ "$1" =~ ${pkgname_rx} ]] && echo "$1" ) + local sort_order=$( [[ "$2" == '--reverse' ]] && echo "$2" ) + [[ -z "${pkgname}" ]] && echo "invalid pkgname: '$1'" && return 1 + + local arch_dir="$( find_pkgbuild ${ARCH_DIR} | head -n 1)" + local aur_dir="$( find_pkgbuild ${AUR_DIR} | head -n 1)" + local abslibre_dir="$(find_pkgbuild ${ABSLIBRE_DIR} | head -n 1)" + local testing_dir="${ABSLIBRE_DIR}"/libre-testing/${pkgname} + local source_dir="${arch_dir}" + local statefile + local repo +# local is_writable=$(touch "${abslibre_dir}"/PKGBUILD &> /dev/null ; echo $((!$?))) +# local repo=$(echo $(LANG=C pacman -Si ${pkgname} | grep ^Repository | cut -d : -f 2)) + + [[ -n "${arch_dir}" || -n "${aur_dir}" || -n "${abslibre_dir}" ]] && echo "PKGBUILDs found:" + [[ -n "${arch_dir}" ]] && find_pkgbuild ${ARCH_DIR} | sed 's|^| |' + [[ -n "${aur_dir}" ]] && find_pkgbuild ${AUR_DIR} | sed 's|^| |' + [[ -n "${abslibre_dir}" ]] && find_pkgbuild ${ABSLIBRE_DIR} | sed 's|^| |' + + # warnings + (( $(find_pkgbuild ${ARCH_DIR} | wc -l) > 1 )) && echo "multiple arch PKGBUILDs found (use --reverse if necessary)" + (( $(find_pkgbuild ${ABSLIBRE_DIR} | wc -l) > 1 )) && echo "multiple abslibre PKGBUILDs found (use --reverse if necessary)" + [[ -n "${arch_dir}" && -n "${aur_dir}" ]] && echo "multiple upstream PKGBUILDs found (arch and AUR)" + + # sanity checks + verify_writable_pkgbuild_dir "${source_dir}" || exit 1 + verify_writable_pkgbuild_dir "${abslibre_dir}" || exit 1 + verify_writable_pkgbuild_dir "${testing_dir}" || exit 1 + +(( DEBUG )) && echo "pkgname='$pkgname'" +(( DEBUG )) && echo "arch_dir='$arch_dir'" +(( DEBUG )) && echo "aur_dir='$aur_dir'" +(( DEBUG )) && echo "abslibre_dir='$abslibre_dir'" +(( DEBUG )) && echo "testing_dir='$testing_dir'" +(( DEBUG )) && echo "source_dir='$source_dir'" +# (( DEBUG )) && exit 0 +# (( DEBUG )) && source_dir='' + + + # consult the arch 'state' repo first + if [[ -z "$source_dir" ]] + then echo "PKGBUILD not found in arch cache ... trying arch ...." + clone_or_pull ${ARCH_URL}/state "${ARCH_DIR}"/state + if statefile="$(find_statefile)" + then repo=$(basename $(dirname "${statefile}")) + source_dir="${ARCH_DIR}"/${pkgname} + + # eg: 'qutebrowser' (extra/any) + echo "found statefile for '${pkgname}' (${repo%-*}/${repo##*-})" + fi + fi + +(( DEBUG )) && echo "source_dir='$source_dir'" + + # search arch VCS for PKGBUILD + if [[ -n "${source_dir}" ]] + then echo "cloning from arch ...." + clone_or_pull ${ARCH_URL}/packages/${pkgname} "${source_dir}" + fi + +(( DEBUG )) && echo "source_dir='$source_dir'" + + # search AUR VCS for PKGBUILD + if [[ -f "${source_dir}"/PKGBUILD ]] + then echo "PKGBUILD found in arch" + else echo "PKGBUILD not found in arch ... trying AUR ...." + source_dir="${AUR_DIR}"/${pkgname} # posibbly same as $aur_dir + + [[ -f ${source_dir}/PKGBUILD ]] && echo "PKGBUILD found in AUR cache" + + clone_or_pull ${AUR_URL}/${pkgname} "${source_dir}" + [[ -f "${source_dir}"/PKGBUILD ]] || + clone_or_pull ${AUR_URL}/${pkgname}-git "${source_dir}" + + [[ -f ${source_dir}/PKGBUILD ]] || echo "PKGBUILD found in AUR" + fi + + [[ -f ${source_dir}/PKGBUILD ]] || ! echo "PKGBUILD not found - quitting" || return 1 + + if [[ -z "${abslibre_dir}" ]] + then echo "no such parabola PKGBUILD" + abslibre_dir="${testing_dir}" + + # copy upstream recipe files and recurse + mkdir "${abslibre_dir}" + cp "${source_dir}"/* "${abslibre_dir}"/ + meld-pkgbuilds "$@" ; return $? ; + fi + +(( DEBUG )) && echo out && return + + ls -l "${source_dir}"/ "${abslibre_dir}"/ ; echo ; + (set -x ; meld "${source_dir}"/ "${abslibre_dir}"/) + + return 0 +} + + +meld_pkgbuilds $@ |