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