2023-01-28 13:19:59 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Hopefully one day this will be a full featured Pleroma client.
|
|
|
|
# Let's see how far we can get. :)
|
|
|
|
|
|
|
|
# Get an oauth token
|
|
|
|
get_oauth_token() {
|
|
|
|
echo "Welcome to ${softwareName}!"
|
|
|
|
echo
|
|
|
|
echo "Let's get you connected to your instance."
|
2023-01-28 18:05:06 -05:00
|
|
|
while [[ -z "${instanceURL}" ]]; do
|
|
|
|
echo
|
|
|
|
read -er -p "Enter the URL of a Pleroma instance: " instanceURL
|
|
|
|
if [[ ! "${instanceURL}" =~ ^https:// ]]; then
|
|
|
|
instanceURL="https://${instanceURL}"
|
2023-01-28 13:19:59 -05:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
redirectURI="file://$(realpath ${0})"
|
2023-01-28 14:57:45 -05:00
|
|
|
# get client id and secret
|
2023-01-29 03:42:10 -05:00
|
|
|
curl -s -X POST -d client_name="${softwareName}" -d "redirect_uris=https://billy.wolfe.casa/ratatoskr-success.html" -d "scopes=read write follow push" -d "website=https://git.stormux.org/storm/ratatoskr" "${instanceURL}/api/v1/apps" |
|
2023-01-28 15:43:21 -05:00
|
|
|
jq --raw-output '"client_id=\"\(.client_id)\"\nclient_secret=\"\(.client_secret)\""' > "${configPath}/${configFile}"
|
2023-01-28 15:41:06 -05:00
|
|
|
# Load the new variables from the configuration file
|
|
|
|
source "${configPath}/${configFile}"
|
|
|
|
# Create the url to get the oauth token
|
2023-01-29 03:42:10 -05:00
|
|
|
local url="${instanceURL}/oauth/authorize?client_id=${client_id}&redirect_uri=https://billy.wolfe.casa/ratatoskr-success.html&response_type=code&scope=read%20write%20follow%20push"
|
2023-01-28 15:41:06 -05:00
|
|
|
echo "Please open the following url in your browser."
|
2023-01-28 18:05:06 -05:00
|
|
|
echo "Copy the generated token, and paste it here, then press enter to continue."
|
2023-01-28 15:41:06 -05:00
|
|
|
echo
|
|
|
|
echo "${url}"
|
|
|
|
echo
|
2023-01-28 18:12:39 -05:00
|
|
|
if command -v xclip &> /dev/null ; then
|
|
|
|
echo "${url}" | xclip -selection clipboard -d "${DISPLAY:-:0}" 2> /dev/null &&
|
|
|
|
echo "For convenience the url has been copied to your clipboard."
|
|
|
|
fi
|
2023-01-28 18:05:06 -05:00
|
|
|
read -er oauth_token
|
|
|
|
echo "oauth_token=\"${oauth_token}\"" >> "${configPath}/${configFile}"
|
2023-01-28 13:19:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Variable initialization
|
|
|
|
configPath="${XDG_CONFIG_HOME:-$HOME/.config}/ratatoskr" # Path for settings, usually ~/.config/ratatoskr
|
2023-01-28 14:57:45 -05:00
|
|
|
configFile="default.conf" # The default config file, eventually will support multiple accounts.
|
2023-01-28 13:19:59 -05:00
|
|
|
softwareName="Ratatoskr" # The name of the client.
|
|
|
|
|
|
|
|
|
|
|
|
# Main code starts here
|
2023-01-28 14:57:45 -05:00
|
|
|
|
|
|
|
# make sure the configuration path exists:
|
|
|
|
mkdir -p "${configPath}"
|
|
|
|
|
2023-01-28 18:05:06 -05:00
|
|
|
# if the default file doesn't exist, create it
|
|
|
|
if [[ ! -e "${configPath}/${configFile}" ]]; then
|
|
|
|
get_oauth_token
|
|
|
|
fi
|
2023-01-28 14:57:45 -05:00
|
|
|
|
2023-01-28 13:19:59 -05:00
|
|
|
exit 0
|