From 41271634c929d29211a2c9222e8f7258f6b0fe6b Mon Sep 17 00:00:00 2001 From: langfingaz Date: Mon, 24 May 2021 15:09:45 +0200 Subject: [PATCH] arch-repo: list VCS packages --- build-archiso.sh | 14 ++-- pkg/de-p1st-repo/PKGBUILD | 6 +- pkg/de-p1st-repo/arch-repo-push-new.sh | 2 +- pkg/de-p1st-repo/arch-repo-receive-new.sh | 99 +++-------------------- pkg/de-p1st-repo/arch-repo-vercmp.sh | 31 ++++++- pkg/de-p1st-repo/iterate-files-test.sh | 4 +- pkg/de-p1st-repo/lib/pkginfo.sh | 60 ++++++++++++++ pkg/de-p1st-repo/lib/pkgver.sh | 53 ++++++++++++ pkg/de-p1st-repo/lib/util.sh | 19 +++++ 9 files changed, 189 insertions(+), 99 deletions(-) create mode 100644 pkg/de-p1st-repo/lib/pkginfo.sh create mode 100644 pkg/de-p1st-repo/lib/pkgver.sh create mode 100644 pkg/de-p1st-repo/lib/util.sh diff --git a/build-archiso.sh b/build-archiso.sh index b2427dd..e725414 100755 --- a/build-archiso.sh +++ b/build-archiso.sh @@ -19,27 +19,27 @@ PACMAN_CFG_ADDITION='pkg/de-p1st-pacman/pacman.d/de-p1st' # will be used to exte ################################ if [ "$1" = "clean" ] ; then - sudo rm -r "${BUILD_DIR}" || exit + sudo rm -r "${BUILD_DIR}" || exit $? elif [ -d "${BUILD_DIR}" ] ; then echo "Build dir does already exist and may not be empty!" echo "Run '$0 clean' to start a clean ISO build." exit 1 fi -mkdir "$BUILD_DIR" || exit +mkdir "$BUILD_DIR" || exit $? # The releng profile is used to create the official monthly installation ISO PROFILE=/usr/share/archiso/configs/releng/ if [ ! -d "${PROFILE}" ] ; then echo "Installing dependency 'archiso' with sudo ..." - sudo pacman -S --needed archiso || exit + sudo pacman -S --needed archiso || exit $? fi -cp -r "$PROFILE" "$BUILD_DIR"/profile || exit +cp -r "$PROFILE" "$BUILD_DIR"/profile || exit $? # extend the builder's pacman.conf (add de-p1st mirrors) # https://wiki.archlinux.org/index.php/Archiso#Custom_local_repository -cat "${PACMAN_CFG_ADDITION}" >> "$BUILD_DIR"/profile/pacman.conf || exit +cat "${PACMAN_CFG_ADDITION}" >> "$BUILD_DIR"/profile/pacman.conf || exit $? for PKG in "${PKGS[@]}"; do echo "${PKG}" >> "${BUILD_DIR}"/profile/packages.x86_64 @@ -47,7 +47,7 @@ done ### -mkdir "${BUILD_DIR}/work_dir" && mkdir "${BUILD_DIR}/out_dir" || exit +mkdir "${BUILD_DIR}/work_dir" && mkdir "${BUILD_DIR}/out_dir" || exit $? echo "running 'sudo mkarchiso' ..." -sudo mkarchiso -v -w "${BUILD_DIR}/work_dir" -o "${BUILD_DIR}/out_dir" "${BUILD_DIR}/profile" || exit +sudo mkarchiso -v -w "${BUILD_DIR}/work_dir" -o "${BUILD_DIR}/out_dir" "${BUILD_DIR}/profile" || exit $? diff --git a/pkg/de-p1st-repo/PKGBUILD b/pkg/de-p1st-repo/PKGBUILD index 3c68c10..cd60625 100644 --- a/pkg/de-p1st-repo/PKGBUILD +++ b/pkg/de-p1st-repo/PKGBUILD @@ -2,7 +2,7 @@ _pkgname=repo _reponame=arch pkgname="de-p1st-$_pkgname" -pkgver=0.2.3 +pkgver=0.2.4 pkgrel=1 pkgdesc="Bash script to manage remote Arch Linux repository" arch=('any') @@ -20,5 +20,9 @@ package() { install -Dm0555 arch-repo-receive-new.sh "$pkgdir"/usr/bin/arch-repo-receive-new install -Dm0555 arch-repo-vercmp.sh "$pkgdir"/usr/bin/arch-repo-vercmp + install -Dm0644 lib/util.sh "$pkgdir"/usr/lib/"${pkgname}"/util.sh + install -Dm0644 lib/pkginfo.sh "$pkgdir"/usr/lib/"${pkgname}"/pkginfo.sh + install -Dm0644 lib/pkgver.sh "$pkgdir"/usr/lib/"${pkgname}"/pkgver.sh + install -Dm0644 -o0 arch-repo.cfg "$pkgdir"/etc/de-p1st-repo/arch-repo.cfg } diff --git a/pkg/de-p1st-repo/arch-repo-push-new.sh b/pkg/de-p1st-repo/arch-repo-push-new.sh index 340cbf0..84ed280 100644 --- a/pkg/de-p1st-repo/arch-repo-push-new.sh +++ b/pkg/de-p1st-repo/arch-repo-push-new.sh @@ -1,6 +1,6 @@ #!/bin/bash -source /etc/de-p1st-repo/arch-repo.cfg || exit +source /etc/de-p1st-repo/arch-repo.cfg || exit $? # Enable nullglob for the case that not all patterns match, e.g. just *.zst but not *.xz packages exist. shopt -s nullglob diff --git a/pkg/de-p1st-repo/arch-repo-receive-new.sh b/pkg/de-p1st-repo/arch-repo-receive-new.sh index aa9a402..1ddd3c5 100644 --- a/pkg/de-p1st-repo/arch-repo-receive-new.sh +++ b/pkg/de-p1st-repo/arch-repo-receive-new.sh @@ -1,6 +1,9 @@ #!/bin/bash -source /etc/de-p1st-repo/arch-repo.cfg || exit +source /usr/lib/de-p1st-repo/util.sh || exit $? +source /usr/lib/de-p1st-repo/pkgver.sh || exit $? +source /usr/lib/de-p1st-repo/pkginfo.sh || exit $? +source /etc/de-p1st-repo/arch-repo.cfg || exit $? @@ -44,36 +47,10 @@ function add_to_db(){ local PKGNAME PKGNAME="$1" - # - # get latest version for $PKGNAME - # + # get path to latest version of $PKGNAME + PKG=$(latest_pkgver_path "${PKGNAME}") || return $? - # pick one random version as starting point for the latest version - local LATEST - for PKGVER in db/"${PKGNAME}"/*; do - PKGVER=$(basename "${PKGVER}") # strip directory and suffix from filename - LATEST="$PKGVER" - break - done - - local cmp - for PKGVER in db/"$PKGNAME"/*; do - PKGVER=$(basename "${PKGVER}") # strip directory and suffix from filename - - # compare the currently known latest version - # with the next version - cmp=$(vercmp "$LATEST" "$PKGVER") || return $? - # if the new version is larger, save it as LATEST - if [ "$cmp" -lt "0" ]; then - LATEST="$PKGVER" - fi - done - - # - # add latest version of PKGNAME to database - # - - PKG=$(cat "db/${PKGNAME}/${LATEST}") || return $? + # add to database repo-add --new "${REMOTE_DB_NAME}.db.tar.gz" "${PKG}" || return $? } @@ -95,7 +72,7 @@ function sort_all_pkgname_pkgver(){ # create files "db/$pkgname/$pkgver" with content "$PKG" (path to package file) # function sort_new_pkgname_pkgver(){ - # return: 0 on success; array $NEW_PKGNAMES + # return: array $NEW_PKGNAMES echo "Sorting new packages by package name and package version ..." @@ -132,13 +109,13 @@ function sort_new_pkgname_pkgver(){ # function sort_pkgname_pkgver(){ # $1: PKG (path to package file) - # return: 0 on success; variables $PKGINFO, $PKGNAME, $PKGVER + # return: variables $PKGINFO, $PKGNAME, $PKGVER local PKG PKG="$1" - get_pkginfo "$PKG" || { echo "get_pkginfo failed"; return 1; } - get_pkgname "$PKGINFO" || { echo "get_pkgname failed"; echo "Content of PKGINFO: ${PKGINFO}"; return 1; } - get_pkgver "$PKGINFO" || { echo "get_pkgver failed"; echo "Content of PKGINFO: ${PKGINFO}"; return 1; } + get_pkginfo "$PKG" || { echo "get_pkginfo failed"; return 1; } + PKGNAME=$(get_pkgname "$PKGINFO") || { echo "get_pkgname failed"; echo "Content of PKGINFO: ${PKGINFO}"; return 1; } + PKGVER=$(get_pkgver "$PKGINFO") || { echo "get_pkgver failed"; echo "Content of PKGINFO: ${PKGINFO}"; return 1; } echo "Creating file ./db/${PKGNAME}/${PKGVER} with content ${PKG} ..." mkdir -p "db/${PKGNAME}" || return $? @@ -146,58 +123,6 @@ function sort_pkgname_pkgver(){ } -# -# get content of .PKGINFO from package-file -# -function get_pkginfo(){ - # $1: path to package file - # return: 0 on success; variable $PKGINFO - - if endswith "$1" ".pkg.tar.xz"; then - PKGINFO=$(tar -xf "$1" -O .PKGINFO --force-local) || { echo "tar failed"; return 1; } - elif endswith "$1" ".pkg.tar.zst"; then - PKGINFO=$(tar -I zstd -xf "$1" -O .PKGINFO --force-local) || { echo "tar failed"; return 1; } - else - echo "$1 does not seem to be a package!" - return 1 - fi -} - - -# -# get pkgname from $PKGINFO -# -function get_pkgname(){ - # return: 0 on success; variable $PKGNAME - - # remove "pkgname = " as well as tailing whitespace characters - local tmp - tmp=$(echo "${PKGINFO}" | grep '^pkgname') || { echo "grep failed"; return 1; } - PKGNAME=$(echo "${tmp}" | sed 's|^pkgname\s*=\s*||; s|\s*$||') || { echo "sed failed"; return 1; } -} -# -# get pkgver from $PKGINFO -# -function get_pkgver(){ - # return: 0 on success; variable $PKGVER - - # remove "pkgver = " as well as tailing whitespace characters - local tmp - tmp=$(echo "${PKGINFO}" | grep '^pkgver') || { echo "grep failed"; return 1; } - PKGVER=$(echo "${tmp}" | sed 's|^pkgver\s*=\s*||; s|\s*$||') || { echo "sed failed"; return 1; } -} - - -# Inspired by: https://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value/18558871#18558871 -# -# $1 begins with $2 -# -beginswith() { case $1 in "$2"*) true;; *) false;; esac; } -# -# $1 ends with $2 -# -endswith() { case $1 in *"$2") true;; *) false;; esac; } - # # generate index.html diff --git a/pkg/de-p1st-repo/arch-repo-vercmp.sh b/pkg/de-p1st-repo/arch-repo-vercmp.sh index b6adbc0..9ba470f 100644 --- a/pkg/de-p1st-repo/arch-repo-vercmp.sh +++ b/pkg/de-p1st-repo/arch-repo-vercmp.sh @@ -5,11 +5,15 @@ # print all outdated packages # -source /etc/de-p1st-repo/arch-repo.cfg || exit +source /usr/lib/de-p1st-repo/util.sh || exit $? +source /usr/lib/de-p1st-repo/pkgver.sh || exit $? +source /usr/lib/de-p1st-repo/pkginfo.sh || exit $? +source /etc/de-p1st-repo/arch-repo.cfg || exit $? function main(){ + cd "${REMOTE_PKG_DIR}" || return $? echo "Note: You may run 'arch-repo-push-new' and 'pacman -Sy' first ..." all_pkg_vers || return $? @@ -23,6 +27,31 @@ function main(){ else echo "There are no pending AUR updates in repository ${REMOTE_DB_NAME}." fi + + get_vcs_packages || return $? + if [ "${#VCS_PKGS[@]}" -gt "0" ]; then + echo "" + echo "Note: Some VCS packages were found which are possibly outdated:" + for VCS_PKG in "${VCS_PKGS[@]}"; do + echo " ${VCS_PKG}" + done + fi +} + +function get_vcs_packages(){ + # return: array GIT_PKGS with all VCS packages + VCS_PKGS=() + + # https://wiki.archlinux.org/title/VCS_package_guidelines#VCS_sources + # https://github.com/AladW/aurutils/pull/283/files + readonly AURVCS='.*-(bzr|git|hg|svn)$' + + for PKG_VER in "${PKG_VERS[@]}"; do + PKGNAME=$(first_word "${PKG_VER}") || return $? + if echo "${PKGNAME}" | grep -E "$AURVCS"; then + VCS_PKGS+=("${PKGNAME}") + fi + done } # diff --git a/pkg/de-p1st-repo/iterate-files-test.sh b/pkg/de-p1st-repo/iterate-files-test.sh index bd15ead..9ae7fab 100644 --- a/pkg/de-p1st-repo/iterate-files-test.sh +++ b/pkg/de-p1st-repo/iterate-files-test.sh @@ -1,9 +1,9 @@ #!/bin/bash -source /etc/de-p1st-repo/arch-repo.cfg || exit +source /etc/de-p1st-repo/arch-repo.cfg || exit $? -cd "${LOCAL_PKG_DIR}" || exit +cd "${LOCAL_PKG_DIR}" || exit $? match="0" for PKG in ./*.pkg.tar.{xz,zst}; do diff --git a/pkg/de-p1st-repo/lib/pkginfo.sh b/pkg/de-p1st-repo/lib/pkginfo.sh new file mode 100644 index 0000000..9b05472 --- /dev/null +++ b/pkg/de-p1st-repo/lib/pkginfo.sh @@ -0,0 +1,60 @@ +# +# get content of .PKGINFO from package-file +# +function get_pkginfo(){ + # $1: path to package file + # return: variable $PKGINFO + + if endswith "$1" ".pkg.tar.xz"; then + PKGINFO=$(tar -xf "$1" -O .PKGINFO --force-local) || { echo "tar failed"; return 1; } + elif endswith "$1" ".pkg.tar.zst"; then + PKGINFO=$(tar -I zstd -xf "$1" -O .PKGINFO --force-local) || { echo "tar failed"; return 1; } + else + echo "$1 does not seem to be a package!" + return 1 + fi +} + + +# +# get pkgname from $PKGINFO +# +function get_pkgname(){ + # return: stdout: package name + + # remove "pkgname = " as well as tailing whitespace characters + local tmp + tmp=$(echo "${PKGINFO}" | grep '^pkgname =') || { echo "grep failed"; return 1; } + local PKGNAME + PKGNAME=$(echo "${tmp}" | sed 's|^pkgname\s*=\s*||; s|\s*$||') || { echo "sed failed"; return 1; } + + echo "${PKGNAME}" +} +# +# get pkgver from $PKGINFO +# +function get_pkgver(){ + # return: stdout: package version + + # remove "pkgver = " as well as tailing whitespace characters + local tmp + tmp=$(echo "${PKGINFO}" | grep '^pkgver =') || { echo "grep failed"; return 1; } + local PKGVER + PKGVER=$(echo "${tmp}" | sed 's|^pkgver\s*=\s*||; s|\s*$||') || { echo "sed failed"; return 1; } + + echo "${PKGVER}" +} +# +# get url from $PKGINFO +# +function get_pkgurl(){ + # return: stdout: url + + # remove "url = " as well as tailing whitespace characters + local tmp + tmp=$(echo "${PKGINFO}" | grep '^url =') || { echo "grep failed"; return 1; } + local PKGURL + PKGURL=$(echo "${tmp}" | sed 's|^url\s*=\s*||; s|\s*$||') || { echo "sed failed"; return 1; } + + echo "${PKGURL}" +} diff --git a/pkg/de-p1st-repo/lib/pkgver.sh b/pkg/de-p1st-repo/lib/pkgver.sh new file mode 100644 index 0000000..63c6fe5 --- /dev/null +++ b/pkg/de-p1st-repo/lib/pkgver.sh @@ -0,0 +1,53 @@ +# +# get package-file with latest version for given package name +# +function latest_pkgver_path(){ + # precond: In current working directory there is a subdir "db" + # $1: package name + # return: stdout: path to package file + local PKGNAME + PKGNAME="$1" + + # get latest version for $PKGNAME + local LATEST_PKGVER + LATEST_PKGVER=$(latest_pkgver "${PKGNAME}") || return $? + # get the path to package file + local PKG + PKG=$(cat "db/${PKGNAME}/${LATEST_PKGVER}") || return $? + + echo "${PKG}" +} + +# +# get latest version of package +# +function latest_pkgver(){ + # precond: In current working directory there is a subdir "db" + # $1: package name + # return: stdout: latest pkgver + local PKGNAME + PKGNAME="$1" + + # pick one random version as starting point for the latest version + local LATEST_PKGVER + for PKGVER in db/"${PKGNAME}"/*; do + PKGVER=$(basename "${PKGVER}") || return $? # strip directory and suffix from filename + LATEST_PKGVER="${PKGVER}" + break + done + + local cmp + for PKGVER in db/"${PKGNAME}"/*; do + PKGVER=$(basename "${PKGVER}") || return $? # strip directory and suffix from filename + + # compare the currently known latest version + # with the next version + cmp=$(vercmp "${LATEST_PKGVER}" "${PKGVER}") || return $? + # if the new version is larger, save it as LATEST_PKGVER + if [ "${cmp}" -lt "0" ]; then + LATEST_PKGVER="${PKGVER}" + fi + done + + echo "${LATEST_PKGVER}" +} diff --git a/pkg/de-p1st-repo/lib/util.sh b/pkg/de-p1st-repo/lib/util.sh new file mode 100644 index 0000000..fd0a547 --- /dev/null +++ b/pkg/de-p1st-repo/lib/util.sh @@ -0,0 +1,19 @@ +function first_word() { + # return: The first word of $1. + # In detail: "" if $1 starts with a space. Otherwise: All characters until the first space of $1. + # + # source: https://unix.stackexchange.com/a/201744/315162 + + echo "${1%% *}" +} + + +# Inspired by: https://stackoverflow.com/questions/2172352/in-bash-how-can-i-check-if-a-string-begins-with-some-value/18558871#18558871 +# +# $1 begins with $2 +# +beginswith() { case $1 in "$2"*) true;; *) false;; esac; } +# +# $1 ends with $2 +# +endswith() { case $1 in *"$2") true;; *) false;; esac; }