Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions pdsadmin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PDSADMIN_BASE_URL="https://raw.githubusercontent.com/bluesky-social/pds/main/pds

# Command to run.
COMMAND="${1:-help}"
SCRIPT_FILE="/pds/${COMMAND}.sh"
shift || true

# Ensure the user is root, since it's required for most commands.
Expand All @@ -17,14 +18,27 @@ fi

# Download the script, if it exists.
SCRIPT_URL="${PDSADMIN_BASE_URL}/${COMMAND}.sh"
SCRIPT_FILE="$(mktemp /tmp/pdsadmin.${COMMAND}.XXXXXX)"
UPDATE_FILE="$(mktemp /tmp/pdsadmin.${COMMAND}.XXXXXX)"

if ! curl --fail --silent --show-error --location --output "${SCRIPT_FILE}" "${SCRIPT_URL}"; then
if ! curl --fail --silent --show-error --location --output "${UPDATE_FILE}" "${SCRIPT_URL}"; then
echo "ERROR: ${COMMAND} not found"
exit 2
fi
chmod +x "${UPDATE_FILE}"

chmod +x "${SCRIPT_FILE}"
if "${SCRIPT_FILE}" "$@"; then
rm --force "${SCRIPT_FILE}"
# Install the command on first use, else if modified ask permission to update it
if [[ ! -f "${SCRIPT_FILE}" ]]; then
mv --force "${UPDATE_FILE}" "${SCRIPT_FILE}"
elif ! cmp --quiet "${SCRIPT_FILE}" "${UPDATE_FILE}"; then
read -p "Update command \"${COMMAND}\" [yes]? " choice
case $choice in
""|[Yy]* ) # Default allow
mv --force "${UPDATE_FILE}" "${SCRIPT_FILE}"
;;
* )
rm --force "${UPDATE_FILE}"
;;
esac
fi

"${SCRIPT_FILE}" "$@"