dalci-build-helper/upload-to-dalci-repo

100 lines
2.5 KiB
Text
Raw Permalink Normal View History

2025-09-06 09:26:04 +02:00
#!/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"
2025-09-16 21:23:31 +02:00
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
}
2025-09-06 22:03:37 +02:00
show_cursor() {
tput cnorm
}
hide_cursor() {
tput civis
}
trap show_cursor INT TERM
hide_cursor
2025-09-16 21:23:31 +02:00
configfile="${XDG_CONFIG_HOME:-$HOME/.config}/upload-to-dalci-repo.cfg"
2025-09-06 09:26:04 +02:00
## check for config file
2025-09-16 21:23:31 +02:00
if [[ -r "$configfile" ]]; then
2025-09-06 09:26:04 +02:00
configfile_secured="${TMPDIR:-/tmp}/tmp.upload-to-dalci-repo.cfg"
else
echo -e "\b$color_error no configuration found"
2025-09-16 21:23:31 +02:00
cat > "$configfile" << EOF
2025-09-06 09:26:04 +02:00
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"
2025-09-06 22:03:37 +02:00
show_cursor
2025-09-16 21:23:31 +02:00
exit
2025-09-06 09:26:04 +02:00
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
# shellcheck source=/dev/null
source "$configfile"
2025-09-06 22:03:37 +02:00
check_for_pkg() {
2025-09-16 21:23:31 +02:00
mapfile -t pkg < <(find ./ -maxdepth 1 -name "*.pkg.tar.zst")
if [ ${#pkg[@]} -gt 0 ]; then
2025-09-06 22:03:37 +02:00
:
else
echo -e "\b$color_error no packges found."
echo -e "\b\tPlease run this script from inside the directory"
echo -e "\b\twhich holds the Arch-packages."
echo -e "\b$color_ok Exiting now."
show_cursor
2025-09-16 21:23:31 +02:00
exit
2025-09-06 22:03:37 +02:00
fi
}
2025-09-06 09:26:04 +02:00
upload_package() {
for file in ./*; do
if [[ "$file" != *.pkg.tar.zst ]]; then
2025-09-10 04:11:14 +02:00
:
2025-09-06 09:26:04 +02:00
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
}
2025-09-06 22:03:37 +02:00
check_for_pkg
2025-09-06 09:26:04 +02:00
upload_package & show_progress $!
2025-09-16 21:23:31 +02:00
echo -e "\b$color_ok Done!"
2025-09-06 09:26:04 +02:00
show_cursor