This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage-repo.sh
executable file
·87 lines (73 loc) · 2.39 KB
/
manage-repo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
set -eu
FORMAT="deb"
NAME="${FORMAT}-${CHANNEL}"
TITLE="Jamulus Repo for Debian/Ubuntu (${CHANNEL})"
GENERATOR_ROOT="${PWD}"
TMP_ROOT="${PWD}/tmp/"
GPGHOME="${TMP_ROOT}/gpghome"
GPG_PUBKEY_FILE="key.asc"
SETUP_SH="setup.sh"
REPO="${TMP_ROOT}/repo"
mkdir -p "$REPO"
setup_gpg() {
[[ "${GPG_PRIVATE_KEY:-}" ]] || {
echo "Missing Github secret GPG_PRIVATE_KEY"
exit 1
}
mkdir -p "$GPGHOME"
chmod 700 "$GPGHOME"
echo "$GPG_PRIVATE_KEY" | gpg --homedir "$GPGHOME" --import -
}
ensure_github_release() {
git tag -f "$NAME" HEAD
git push origin +refs/tags/"$NAME"
if ! gh release view "$NAME" &>/dev/null; then
gh release create "$NAME" --notes "(in creation)"
fi
NAME="$NAME" SETUP_SH="$SETUP_SH" envsubst '$NAME $GITHUB_REPOSITORY $SETUP_SH' < release-body.md > tmp/release-body.md
gh release edit "$NAME" --title "$TITLE" --notes-file tmp/release-body.md
}
download_github_release_packages() {
gh release download "$NAME" --pattern "*.${FORMAT}"
}
generate_and_sign_metadata() {
apt-ftparchive packages . > Packages
apt-ftparchive release . > Release
gpg --homedir "$GPGHOME" --armor --yes --clearsign --output InRelease --detach-sign Release
gpg --homedir "$GPGHOME" --armor --export > "$GPG_PUBKEY_FILE"
# Create setup.sh file. Use envsubst to replace repository information in template file
NAME="$NAME" GITHUB_REPOSITORY="$GITHUB_REPOSITORY" envsubst '$NAME $GITHUB_REPOSITORY' < "${GENERATOR_ROOT}/setup_base.sh.template" > "${SETUP_SH}"
chmod +x "${SETUP_SH}"
}
replace_github_release_metadata_assets() {
METADATA_FILES=( Packages Release InRelease "$GPG_PUBKEY_FILE" "$SETUP_SH" )
for asset in "${METADATA_FILES[@]}"; do
gh release delete-asset "$NAME" "${asset}" --yes || true
done
gh release upload "$NAME" "${METADATA_FILES[@]}"
}
create_repo() {
setup_gpg
ensure_github_release
pushd "$REPO"
download_github_release_packages
generate_and_sign_metadata
replace_github_release_metadata_assets
popd
}
import_latest_packages() {
pushd "$REPO"
gh release download --repo jamulussoftware/jamulus --pattern "*.${FORMAT}"
gh release upload "$NAME" ./*".${FORMAT}"
}
case "${1:-}" in
create_repo)
create_repo
;;
import_latest_packages)
import_latest_packages
;;
*)
echo "Unsupported action ${1:-}"
exit 1
esac