53 lines
1.9 KiB
Bash
Executable File
53 lines
1.9 KiB
Bash
Executable File
#!/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."
|
|
while [[ -z "${instanceURL}" ]]; do
|
|
echo
|
|
read -er -p "Enter the URL of a Pleroma instance: " instanceURL
|
|
if [[ ! "${instanceURL}" =~ ^https:// ]]; then
|
|
instanceURL="https://${instanceURL}"
|
|
fi
|
|
done
|
|
redirectURI="file://$(realpath ${0})"
|
|
# get client id and secret
|
|
curl -s -X POST -d client_name="${softwareName}" -d redirect_uris="://${redirectURI}" "${instanceURL}/api/v1/apps" |
|
|
jq --raw-output '"client_id=\"\(.client_id)\"\nclient_secret=\"\(.client_secret)\""' > "${configPath}/${configFile}"
|
|
# Load the new variables from the configuration file
|
|
source "${configPath}/${configFile}"
|
|
# Create the url to get the oauth token
|
|
local url="${instanceURL}/oauth/authorize?client_id=${client_id}&redirect_uri=${redirectURI}&response_type=code&scope=read+write+follow"
|
|
echo "Please open the following url in your browser."
|
|
echo "Copy the generated token, and paste it here, then press enter to continue."
|
|
echo
|
|
echo "${url}"
|
|
echo
|
|
read -er oauth_token
|
|
echo "oauth_token=\"${oauth_token}\"" >> "${configPath}/${configFile}"
|
|
}
|
|
|
|
|
|
# Variable initialization
|
|
configPath="${XDG_CONFIG_HOME:-$HOME/.config}/ratatoskr" # Path for settings, usually ~/.config/ratatoskr
|
|
configFile="default.conf" # The default config file, eventually will support multiple accounts.
|
|
softwareName="Ratatoskr" # The name of the client.
|
|
|
|
|
|
# Main code starts here
|
|
|
|
# make sure the configuration path exists:
|
|
mkdir -p "${configPath}"
|
|
|
|
# if the default file doesn't exist, create it
|
|
if [[ ! -e "${configPath}/${configFile}" ]]; then
|
|
get_oauth_token
|
|
fi
|
|
|
|
exit 0
|