SHA256
53 lines
1.3 KiB
Bash
Executable File
53 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
[ "$(whoami)" != "root" ] && echo "Error: installation only works as root!" >&2 && exit 1
|
|
|
|
API_ENDPOINT="https://git.ccc-rheintal.ch/api/v1/repos/spacefreak/pbc"
|
|
|
|
TMPDIR=''
|
|
function cleanup_tmpdir() {
|
|
[ -n "$TMPDIR" -a -d "$TMPDIR" ] && rm -r "$TMPDIR"
|
|
trap - EXIT
|
|
}
|
|
|
|
function download_files() {
|
|
local path rc
|
|
local query_params=''
|
|
[ -n "$GIT_TAG" ] && query_params="?ref=$GIT_TAG"
|
|
|
|
while (( $# > 0 )); do
|
|
path=$1
|
|
shift
|
|
curl -s --output-dir "$TMPDIR/" --remote-name "$API_ENDPOINT/raw/$path$query_params"
|
|
rc=$?
|
|
if (( $rc != 0 )); then
|
|
return $rc
|
|
fi
|
|
done
|
|
}
|
|
|
|
GIT_TAG=$(curl -s "$API_ENDPOINT/tags" | jq -r '.[] | .name' | sort --version-sort | tail -n 1)
|
|
if [ -n "$GIT_TAG" ]; then
|
|
echo "Info: installing pbc version $GIT_TAG"
|
|
else
|
|
echo "Warning: no Git tag found, installing from repository default branch" >&2
|
|
fi
|
|
|
|
TMPDIR=$(mktemp -d)
|
|
trap cleanup_tmpdir EXIT
|
|
|
|
! download_files config.example pbc && echo "Error downloading files!" >&2 && exit 10
|
|
chmod +x "$TMPDIR/pbc"
|
|
chmod o= "$TMPDIR/config.example"
|
|
|
|
"$TMPDIR/pbc" install
|
|
rc=$?
|
|
if (( $rc != 0 )); then
|
|
echo "Error installing pbc requirements!" >&2
|
|
exit $rc
|
|
fi
|
|
|
|
! mv "$TMPDIR/pbc" /usr/local/bin/pbc && echo 'Error moving file!' >&2 && exit 20
|
|
|
|
echo "Success!"
|