From 0bfccb2b48a081c15b7cf75577166fdf7e573faa Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Sat, 15 Mar 2025 14:10:11 +0100 Subject: [PATCH] Add pdsadmin script. --- pdsadmin.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 pdsadmin.sh diff --git a/pdsadmin.sh b/pdsadmin.sh new file mode 100644 index 0000000..913d2b4 --- /dev/null +++ b/pdsadmin.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -o errexit +set -o nounset +set -o pipefail + +PDSADMIN_BASE_URL="https://raw.githubusercontent.com/bluesky-social/pds/main/pdsadmin" + +# Command to run. +COMMAND="${1:-help}" +shift || true + +# Ensure the user is root, since it's required for most commands. +if [[ "${EUID}" -ne 0 ]]; then + echo "ERROR: This script must be run as root" + exit 1 +fi + +# Download the script, if it exists. +SCRIPT_URL="${PDSADMIN_BASE_URL}/${COMMAND}.sh" +SCRIPT_FILE="$(mktemp /tmp/pdsadmin.${COMMAND}.XXXXXX)" + +if ! curl --fail --silent --show-error --location --output "${SCRIPT_FILE}" "${SCRIPT_URL}"; then + echo "ERROR: ${COMMAND} not found" + exit 2 +fi + +chmod +x "${SCRIPT_FILE}" +if "${SCRIPT_FILE}" "$@"; then + rm --force "${SCRIPT_FILE}" +fi