diff --git a/ratatoskr.sh b/ratatoskr.sh index e70d470..565887a 100755 --- a/ratatoskr.sh +++ b/ratatoskr.sh @@ -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'." - echo - else - break + 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})" @@ -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}" -get_oauth_token +# if the default file doesn't exist, create it +if [[ ! -e "${configPath}/${configFile}" ]]; then + get_oauth_token +fi exit 0