add forgejo arch package uploader
This commit is contained in:
parent
f918177309
commit
6612124796
2 changed files with 88 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -10,4 +10,5 @@
|
|||
!LICENSE
|
||||
!qt6-rebuild
|
||||
!REUSE.toml
|
||||
!upload-to-forgejo-repo
|
||||
|
||||
|
|
|
|||
87
upload-to-forgejo-repo
Executable file
87
upload-to-forgejo-repo
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
#!/bin/bash
|
||||
|
||||
# SPDX-License-Identifier: 0BSD
|
||||
# SPDX-FileCopyrightText: 2025 Christian Schendel <doppelhelix@gmail.com>
|
||||
|
||||
set -euo pipefail
|
||||
color_note="\e[1;36m==>\e[0m"
|
||||
color_ok="\e[1;32m==>\e[0m"
|
||||
color_error="\e[1;31m==>\e[0m"
|
||||
color_warning="\e[1;35m==>\e[0m"
|
||||
|
||||
## check for config file
|
||||
if [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/upload-to-dalci-repo.cfg" ]]; then
|
||||
configfile="${XDG_CONFIG_HOME:-$HOME/.config}/upload-to-dalci-repo.cfg"
|
||||
configfile_secured="${TMPDIR:-/tmp}/tmp.upload-to-dalci-repo.cfg"
|
||||
else
|
||||
echo -e "\b$color_error no configuration found"
|
||||
cat > "${XDG_CONFIG_HOME:-$HOME/.config}/upload-to-dalci-repo.cfg" << EOF
|
||||
forgejo_repo_url="https://{domain}/api/packages/{owner}/arch/{group}"
|
||||
forgejo_user="your_username"
|
||||
forgejo_token="your_token_or_password"
|
||||
|
||||
EOF
|
||||
echo -e "\b$color_note example configuration created at"
|
||||
echo -e "\b$color_note ${XDG_CONFIG_HOME:-$HOME/.config}/upload-to-dalci-repo.cfg"
|
||||
echo -e "\b$color_warning please edit it before running this script again"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# secure the config file
|
||||
rm -f "$configfile_secured"
|
||||
while IFS= read -r line; do
|
||||
printf '%s\n' \
|
||||
"$(sed -E "s/^(\s)?+(#.+$|[a-zA-Z0-9_]+=['\"]?[a-zA-Z0-9_~\.\`-]+['\"]).+$/\2/g" <<< "$line")" \
|
||||
>> "$configfile_secured"
|
||||
configfile=$configfile_secured
|
||||
done <<EOF
|
||||
$(cat "$configfile" | grep -v "^$")
|
||||
EOF
|
||||
# now source it, either the original or the filtered variant
|
||||
# shellcheck source=/dev/null
|
||||
source "$configfile"
|
||||
|
||||
show_cursor() {
|
||||
tput cnorm
|
||||
exit
|
||||
}
|
||||
|
||||
hide_cursor() {
|
||||
tput civis
|
||||
}
|
||||
|
||||
trap show_cursor INT TERM
|
||||
hide_cursor
|
||||
|
||||
show_progress() {
|
||||
pid=$1
|
||||
spin='-\|/'
|
||||
i=0
|
||||
while kill -0 "$pid" 2>/dev/null; do
|
||||
i=$(((i + 1) % 4))
|
||||
spinner="${spin:$i:1}"
|
||||
printf '\b%s' "$spinner"
|
||||
sleep .1
|
||||
done
|
||||
}
|
||||
|
||||
upload_package() {
|
||||
for file in ./*; do
|
||||
if [[ "$file" != *.pkg.tar.zst ]]; then
|
||||
echo -e "\b$color_error No arch packages found"
|
||||
exit 1
|
||||
else
|
||||
echo -e "\b$color_note uploading $file"
|
||||
# shellcheck disable=SC2154
|
||||
curl -X PUT "$forgejo_repo_url" \
|
||||
--user "${forgejo_user}:${forgejo_token}" \
|
||||
--header "Content-Type: application/octet-stream" \
|
||||
--data-binary "@$file"
|
||||
fi
|
||||
done
|
||||
echo -e "\b$color_ok packges uploaded"
|
||||
}
|
||||
|
||||
upload_package & show_progress $!
|
||||
show_cursor
|
||||
Loading…
Add table
Add a link
Reference in a new issue