#!/bin/sh json_parser(){ echo "$1" | sed \ -e "s/.*$2...//" \ -e 's/\",\".*//' \ -e "s/.\//\//g" \ -e "s/\&/\&/g" } # Initial config echo "- Input the instance: (ex: example.instance.xyz):" read instance base_url="https://$instance" perm="read write" echo "instance=$instance" > config echo "\n- Input the name for your bot (ex: Totally SFW image posting bot):" read botname # Registering the app app_json=$( curl -X POST "$base_url/api/v1/apps" \ -F "client_name=\"$botname\"" \ -F "redirect_uris=urn:ietf:wg:oauth:2.0:oob" \ -F "scope=$perm" \ 2> /dev/null ) client_id=$(json_parser "$app_json" client_id) client_secret=$(json_parser "$app_json" client_secret) echo "client_id=$client_id" >> config echo "client_secret=$client_secret" >> config # Authorizing the user for the app to use echo "\n- Please open the URL below:" auth_url="$base_url/oauth/authorize?resonse_type=code&client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&force_login&scope=$perm" echo $auth_url echo "\n- After logging in, paste the code below:" read code auth_json=$( curl -X POST \ -F "client_id=$client_id" \ -F "client_secret=$client_secret" \ -F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' \ -F 'grant_type=authorization_code' \ -F "code=$code" \ -F "scope=$perm" \ "$base_url/oauth/token" \ 2> /dev/null ) access_token=$(json_parser "$auth_json" access_token) echo $access_token echo "access_token=$access_token" >> config echo "\n- Which visibility you want the published statuses to be? (public, unlisted, private) [public]:" read visibility echo "visibility=$visibility" >> config echo "\n- Mark images as sensitive? (yes, no) [no]" read sensitive [ sesnsitive = "yes" ] && sensitive="true" || sensitive="false" echo "sensitive=$sensitive" >> config echo "tags=nagato_yuki rating:safe" >> config echo "img_dir=/tmp/imgbot" >> config echo "\nAll done! You can now test if it works with './fedibooru.sh'" echo "Don't forget to change the default tags and review your config in the 'config' file" chmod +x ./fedibooru.sh