[eos-pkgbuild-setup] better support for epoch in PKGBUILD; workround for github release asset file naming issue with ':' and *+'

This commit is contained in:
manuel
2025-01-12 00:16:42 +02:00
parent 5151e8d80f
commit 26639da989
5 changed files with 129 additions and 50 deletions
+28 -16
View File
@@ -20,9 +20,10 @@
# The assets can be downloaded from:
# https://github.com/USER/REPONAME/releases/download/TAG
echo2() { echo "$@" >&2 ; }
DIE() {
echo "ERROR: ""$1" >&2
echo "Usage: $0 TAG asset(s)" >&2
echo2 "ERROR: ""$1"
echo2 "Usage: $0 TAG asset(s)"
exit 1
}
@@ -44,7 +45,9 @@ Main() {
done
local asset
local assets=()
local coloned=()
local existing_tags
local remo
# Note: we do this in the git folder, not in the asset folder
@@ -56,28 +59,37 @@ Main() {
done
test "$TAG" = "$xx" || DIE "TAG '$TAG' is not in existing tags [$existing_tags]"
if [ 1 -eq 1 ] ; then
if true ; then
for asset in "$@" ; do
test -r "$asset" || DIE "asset '$asset' does not exist."
assets+=("-a" "$asset")
[ $quietly = no ] && echo "adding asset $(basename "$asset")" >&2
remo=${asset/:/COLON} # convert special chars for github !!
remo=${remo/+/PLUS} # convert special chars for github !!
if [ "$remo" != "$asset" ] ; then
cp "$asset" "$remo"
coloned+=("$remo")
assets+=("-a" "$remo")
else
assets+=("-a" "$asset")
fi
[ $quietly = no ] && echo2 "adding asset $(basename "$asset")"
done
if [ $quietly = no ] ; then
hub release edit "${assets[@]}" -m "" "$TAG"
else
hub release edit "${assets[@]}" -m "" "$TAG" 2> /dev/null
fi
else
for asset in "$@" ; do
test -r "$asset" || DIE "asset '$asset' does not exist."
if [ -z "$(release-asset-names "$TAG" "$asset")" ] ; then
[ $quietly = no ] && echo "adding asset $(basename "$asset") to '$TAG'" >&2
hub release edit -a "$asset" -m "" "$TAG"
sleep 0.5
else
DIE "asset '$asset' already exists at github!?"
fi
done
rm -f "${coloned[@]}"
# else
# for asset in "$@" ; do
# test -r "$asset" || DIE "asset '$asset' does not exist."
# if [ -z "$(release-asset-names "$TAG" "$asset")" ] ; then
# [ $quietly = no ] && echo2 "adding asset $(basename "$asset") to '$TAG'"
# hub release edit -a "$asset" -m "" "$TAG"
# sleep 0.5
# else
# DIE "asset '$asset' already exists at github!?"
# fi
# done
fi
}
+29 -5
View File
@@ -189,19 +189,36 @@ AddsAndRemoves() {
ShowFileInfo "removals from remote" "${remove_remote[@]}"
local allow=true # true or false
local arr=() remo renamed_to_remo=()
if $allow ; then
# local adds
if [ ${#add_local[@]} -gt 0 ] ; then
for file in "${add_local[@]}" ; do
download-release-assets "$tag" "$file" || return $?
## local file name may include : or +, so convert them for github
# remo=${file/:/COLON}
# remo=${remo/+/PLUS}
download-release-assets "$tag" "$remo" || return $?
# [ "$remo" != "$file" ] && mv "$remo" "$file"
sleep 1
done
fi
# remote adds
if [ ${#add_remote[@]} -gt 0 ] ; then
add-release-assets "$tag" "${add_remote[@]}" || return $?
# rename local name with :/+ to COLON/PLUS for remote
arr=()
for file in "${add_remote[@]}" ; do
remo=${file/:/COLON}
remo=${remo/+/PLUS}
arr+=("$remo")
if [ "$file" != "$remo" ] ; then
cp "$file" "$remo"
renamed_to_remo+=("$remo")
fi
done
add-release-assets "$tag" "${arr[@]}" || return $?
rm -f "${renamed_to_remo[@]}"
sleep 1
fi
@@ -212,7 +229,14 @@ AddsAndRemoves() {
# remote removes
if [ ${#remove_remote[@]} -gt 0 ] ; then
delete-release-assets --quietly "$tag" "${remove_remote[@]}" || return $?
arr=()
# rename :/+ to COLON/PLUS
for file in "${remove_remote[@]}" ; do
remo=${file/:/COLON}
remo=${remo/+/PLUS}
arr+=("$remo")
done
delete-release-assets --quietly "$tag" "${arr[@]}" || return $?
sleep 1
fi
fi
@@ -233,7 +257,7 @@ FilterPackages() { grep -P '\.xz$|\.zst$' ; } # Note: exclude *.sig files for
Main() {
local tag=""
local dryrun=no
local keep=5 # keeps max 5 of each package
local keep=5 # keeps max 5 latest of each package
local locals=""
local remotes=""
@@ -242,7 +266,7 @@ Main() {
Tag || return $?
locals=$(/usr/bin/ls -1 | FilterPackages)
remotes=$(release-asset-names "$tag" | FilterPackages)
remotes=$(release-asset-names "$tag" | FilterPackages | sed -e 's|COLON|:|g' -e 's|PLUS|+|')
AddsAndRemoves || return $?
}
+14 -4
View File
@@ -579,14 +579,24 @@ _diff_file_and_data() {
_ckbcomp_updatehook() {
local -r pname=ckbcomp
[ -x /bin/$pname ] || return 2
if [ ! -x /bin/$pname ] ; then
echo "info: package $pname is not installed but needed by the fast update"
return 2
fi
local url_pkgname="https://salsa.debian.org/installer-team/console-setup/raw/master/Keyboard/$pname"
local ret=0 # assume changes exist
local tmpfile=$(mktemp)
curl --fail -Lsm 30 -o$tmpfile "$url_pkgname" || { rm -f $tmpfile; return 3; }
diff $tmpfile /bin/$pname >/dev/null || { rm -f $tmpfile; return 0; }
if ! curl --fail -Lsm 30 -o$tmpfile "$url_pkgname" ; then
echo "info: fast update check failed"
ret=3
elif diff $tmpfile /bin/$pname >/dev/null ; then
echo "no real changes"
ret=1
fi
rm -f $tmpfile
return 1
return $ret
}
# Special hooks. Implemented via package hooks.
+20 -8
View File
@@ -12,6 +12,7 @@ printf2() { printf "$@" >&2 ; } # output to stderr
DIE() {
echo2 "Error: $@"
echo2 "Call stack lines: ${BASH_LINENO[*]}"
if [ "${FUNCNAME[1]}" = "Main" ] ; then
Usage
fi
@@ -393,7 +394,7 @@ LocalVersion()
;;
esac
pkg-name-components --real VR "$pkgs"
pkg-name-components --real EVR "$pkgs"
}
AurMarkingFail() {
@@ -1231,13 +1232,22 @@ ListPkgsWithName() {
local compr="$2"
local name
local tmp=""
local dir=${Pkgname%/*}
if [ "$Pkgname" = "$dir" ] ; then
dir="."
else
Pkgname=${Pkgname##*/}
fi
Pushd "$dir"
tmp=$(/bin/ls -1v "$Pkgname"-*.pkg.tar.$compr 2> /dev/null | grep -E "${Pkgname}-[^-]+-[^-]+-[^\.]+\.pkg\.tar\.$compr$")
Popd
[ "$tmp" ] || return
for name in $tmp ; do
if [ "$(echo "$name" | pkg-name-components N)" = "$Pkgname" ] ; then
echo "$name"
echo "$dir/$name"
fi
done
}
@@ -1451,6 +1461,8 @@ Main2()
local -r WAITING="${CYAN}VERSION SKIP${RESET}"
local -r CHANGED="${YELLOW}CHANGED${RESET}"
local ret=""
local fastmsg=""
local fastfunc=""
listing_updates=yes
@@ -1476,20 +1488,20 @@ Main2()
tmpcurr="$(LocalVersion "$ASSETSDIR/$Pkgname")"
case "$tmpcurr" in
"") DIE "LocalVersion for '$xx' failed" ;;
"-")
"-" | 0)
# package (and version) not found
tmpcurr="$notexist"
;;
esac
if [ "${ASSET_FAST_UPDATE_CHECKS[$pkgdirname]}" ] ; then
${ASSET_FAST_UPDATE_CHECKS[$pkgdirname]}
fastfunc="${ASSET_FAST_UPDATE_CHECKS[$pkgdirname]}"
if [ "$fastfunc" ] ; then
fastmsg="$($fastfunc)"
ret=$?
case "$ret" in
0) ;; # there are changes, so carry on!
1) ShowResult "$OK ($tmpcurr)" "$hookout"; continue ;;
2) echo2 -n "warning: fast check: prerequisite for the check is missing. " ;;
3) echo2 -n "warning: fast check: hook failed. " ;;
1) ShowResult "$OK ($tmpcurr)" "$fastmsg"; continue ;;
2|3) ;;
*) echo2 "error: fast check hook returned $ret"; continue ;;
esac
fi
+38 -17
View File
@@ -2,34 +2,55 @@
HubRelease() {
if which logstuff >& /dev/null ; then
if ! logstuff state ; then
logstuff on
fi
logstuff state || logstuff on
fi
hub release "$@"
}
DIE() {
echo "$progname: error: $1" >&2
Usage 1
}
Usage() {
local progname=$(basename "$0")
cat <<EOF
Usage: $progname tag [file-pattern]
EOF
[ -n "$1" ] && exit "$1"
echo "Usage: $progname tag [file-pattern]" >&2
[ "$1" ] && exit $1
}
Main()
{
local -r progname=${0##*/}
local tag="$1"
local pattern="$2"
local file_pattern="$2"
local patternspec=""
local pwd_orig="$PWD"
local tmpdir=""
local remo good_file good_files=()
if [ -z "$tag" ] ; then
Usage 0
fi
if [ -n "$pattern" ] ; then
pattern="-i $pattern"
fi
[ -d .git ] || DIE "current folder must have a .git subfolder."
HubRelease download $tag $pattern
[ "$tag" ] || Usage 0
[ "$file_pattern" ] && patternspec="-i $file_pattern"
tmpdir=$(mktemp -d)
pushd "$tmpdir" >/dev/null
ln -s "$pwd_orig/.git"
# download specified release assets
HubRelease download $tag $patternspec
# convert names of downloaded files if needed
for remo in $(/bin/ls -1) ; do
good_file=${remo/COLON/:}
good_file=${good_file/PLUS/+}
[ "$remo" != "$good_file" ] && mv "$remo" "$good_file"
good_files+=("$good_file")
done
mv "${good_files[@]}" "$pwd_orig"
popd >/dev/null
rm -rf "$tmpdir"
}
Main "$@"