Mirror from bluesky-social/pds
1#!/bin/bash
2set -o errexit
3set -o nounset
4set -o pipefail
5
6PDSADMIN_BASE_URL="https://raw.githubusercontent.com/bluesky-social/pds/main/pdsadmin"
7
8# Command to run.
9COMMAND="${1:-help}"
10shift || true
11
12# Ensure the user is root, since it's required for most commands.
13if [[ "${EUID}" -ne 0 ]]; then
14 echo "ERROR: This script must be run as root"
15 exit 1
16fi
17
18# Download the script, if it exists.
19SCRIPT_URL="${PDSADMIN_BASE_URL}/${COMMAND}.sh"
20SCRIPT_FILE="$(mktemp /tmp/pdsadmin.${COMMAND}.XXXXXX)"
21
22if ! curl --fail --silent --show-error --location --output "${SCRIPT_FILE}" "${SCRIPT_URL}"; then
23 echo "ERROR: ${COMMAND} not found"
24 exit 2
25fi
26
27chmod +x "${SCRIPT_FILE}"
28if "${SCRIPT_FILE}" "$@"; then
29 rm --force "${SCRIPT_FILE}"
30fi