SHA256
53 lines
1.4 KiB
Bash
Executable File
53 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
(( EUID != 0 )) && echo "Error: installation only works as root!" >&2 && exit 1
|
|
|
|
API_ENDPOINT="https://git.ccc-rheintal.ch/api/v1/repos/spacefreak/pbc"
|
|
|
|
WORK_DIR=''
|
|
function cleanup_work_dir() {
|
|
[ -n "$WORK_DIR" ] && [ -d "$WORK_DIR" ] && rm -r "$WORK_DIR"
|
|
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 -fsSL --output-dir "$WORK_DIR/" --remote-name "$API_ENDPOINT/raw/$path$query_params"
|
|
rc=$?
|
|
if (( rc != 0 )); then
|
|
return $rc
|
|
fi
|
|
done
|
|
}
|
|
|
|
GIT_TAG=$(curl -fsSL "$API_ENDPOINT/tags" | grep -o '{"name":"[^"]*"' | sed 's/^{"name":"//;s/"$//' | grep -E '^v[0-9]+' | 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
|
|
|
|
WORK_DIR=$(mktemp -d)
|
|
trap cleanup_work_dir EXIT
|
|
|
|
! download_files config.example pbc && echo "Error downloading files!" >&2 && exit 10
|
|
chmod +x "$WORK_DIR/pbc"
|
|
chmod o= "$WORK_DIR/config.example"
|
|
|
|
"$WORK_DIR/pbc" install
|
|
rc=$?
|
|
if (( rc != 0 )); then
|
|
echo "Error installing pbc requirements!" >&2
|
|
exit $rc
|
|
fi
|
|
|
|
! install -m 0755 -o root -g root "$WORK_DIR/pbc" /usr/local/bin/pbc && echo 'Error installing file!' >&2 && exit 20
|
|
|
|
echo "Success!"
|