Files
2025-08-08 21:22:56 -03:00

71 lines
2.0 KiB
Bash
Executable File

remote_url='https://git.chiasson.cloud/api/packages/Olivier/debian/pool/bookworm/main/upload'
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd "$script_dir"
# Build list of package directories (those containing DEBIAN/control)
dirs=()
for d in "$script_dir"/*/; do
[[ -f "$d/DEBIAN/control" ]] && dirs+=("$(basename "$d")")
done
if ((${#dirs[@]} == 0)); then
echo "No package directories with DEBIAN/control found in $script_dir" >&2
exit 1
fi
PS3="Choose a package directory: "
select pkg in "${dirs[@]}"; do
if [[ -n "$pkg" ]]; then
pkg_path="$pkg"
break
fi
echo "Invalid selection"
done
version=$(awk -F': ' '/^Version:/{print $2; exit}' "$pkg_path/DEBIAN/control")
output_file="${pkg_path}_${version}_all.deb"
output_path="builds/${output_file}"
read -p "Enter your username: " user
read -s -p "Enter your password: " pass
echo
mkdir -p builds
# Temporarily move top-level README files out during build, then restore
backup_dir=$(mktemp -d)
moved_readmes=()
restore_readmes() {
for f in "${moved_readmes[@]}"; do
[ -f "$backup_dir/$f" ] && mv "$backup_dir/$f" "$pkg_path/$f"
done
}
# Always clean up backup dir; README files are restored immediately after build
trap 'rm -rf "$backup_dir"' EXIT
for f in README.md readme.md README Readme.md; do
if [ -f "$pkg_path/$f" ]; then
mv "$pkg_path/$f" "$backup_dir/$f"
moved_readmes+=("$f")
fi
done
dpkg-deb --build "$pkg_path" "$output_path"
# Restore README files now so the repo looks unchanged for the rest of the script
restore_readmes
response=$(curl --silent --show-error --user "$user:$pass" --upload-file "$output_path" "$remote_url" 2>&1)
if echo "$response" | grep -q "package file already exists"; then
echo "Upload skipped: package file already exists on the server. You might have forgot to update the version number in the control file"
elif echo "$response" | grep -q "authGroup.Verify"; then
echo "Upload failed: authentication failed"
else
echo "$response"
echo "Package $output_path uploaded successfully"
fi