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."
|
|
|
|
while true; do
|
|
|
|
read -e -p "Enter the URL of a Pleroma instance: " instanceURL
|
|
|
|
if [[ ! "${instanceURL}" =~ ^https://[a-zA-Z0-9._-]+\.[a-zA-Z]{2,}$ ]]; then
|
|
|
|
echo "Invalid URL format. Please enter a valid URL that starts with 'https'."
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
redirectURI="file://$(realpath ${0})"
|
2023-01-28 14:57:45 -05:00
|
|
|
# get client id and secret
|
|
|
|
curl -s -X POST -d client_name="${softwareName}" -d redirect_uris="://${redirectURI}" "${instanceURL}/api/v1/apps" |
|
|
|
|
jq 'to_entries | .[] | "export \(.key)='\''\(.value)'\''"' > "${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 13:19:59 -05:00
|
|
|
get_oauth_token
|
2023-01-28 14:57:45 -05:00
|
|
|
|
2023-01-28 13:19:59 -05:00
|
|
|
exit 0
|