More friendly url entry. Will now add https:// if not provided.

This commit is contained in:
stormdragon2976 2023-01-28 18:05:06 -05:00
parent c03ae7f739
commit a7ac37b77c

View File

@ -8,13 +8,11 @@ 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'."
while [[ -z "${instanceURL}" ]]; do
echo
else
break
read -er -p "Enter the URL of a Pleroma instance: " instanceURL
if [[ ! "${instanceURL}" =~ ^https:// ]]; then
instanceURL="https://${instanceURL}"
fi
done
redirectURI="file://$(realpath ${0})"
@ -26,10 +24,12 @@ get_oauth_token() {
# 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."
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}"
}
@ -44,6 +44,9 @@ softwareName="Ratatoskr" # The name of the client.
# 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