FediStatusPoster/runconfig.sh

47 lines
2.0 KiB
Bash
Raw Normal View History

2024-03-09 17:42:07 -08:00
#! /usr/bin/env sh
# FediStatusPoster - Simple CLI tools and scripts to post to the fediverse
# Copyright (C) 2024 <@Anon@yandere.cc>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Get the runtime path of the bot
ABS_PATH="$(readlink -f "$0")"
RUN_DIR="$(dirname "$ABS_PATH")"
ENTRY="${RUN_DIR}/fedistatusposter.sh"
print_usage() {
echo "$(basename "$0") [credential_file] [passphrase_file] usage:"
echo " credential_file The location of the credential file for fedistatusposter"
echo " passphrase_file The location of the decryption keyfile for a gpg symmetrically encrypted credential file"
echo ""
echo "If no encryption is being used, make sure to pass an empty string to passphrase_file. Arguments are requiered and positional"
}
[ ! $# -ge 2 ] && echo "Invalid number of arguments..." && print_usage && exit 1
TOKEN_FILE="$1"
PASSPHRASE_FILE="$2"
[ ! -f "$TOKEN_FILE" ] && echo "Cannot find: ${TOKEN_FILE}" && print_usage && exit 1
shift 2
[ ! -f "$TOKEN_FILE" ] && echo "Could not locate: ${TOKEN_FILE}" && exit 1
[ "$PASSPHRASE_FILE" = '-' ] && eval "$(gpg -d -q --pinentry-mode=loopback "${TOKEN_FILE}")"
[ ! -z "$PASSPHRASE_FILE" ] && eval "$(gpg -d -q --passphrase-file "${PASSPHRASE_FILE}" --pinentry-mode=loopback "${TOKEN_FILE}")"
2024-03-09 20:31:04 -08:00
[ -z "$PASSPHRASE_FILE" ] && [ -f "$PASSPHRASE_FILE" ] && . "$(readlink -f "$TOKEN_FILE")"
2024-03-09 17:42:07 -08:00
"$ENTRY" --api-base-url "$API_BASE_URL" --client-id "$CLIENT_ID" --client-secret "$CLIENT_SECRET" --access-token "$ACCESS_TOKEN" "$@"