From eb20face76a5b1845d28c52975ad92c918d72896 Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Sat, 20 Mar 2021 23:21:36 +0200 Subject: [PATCH] =?UTF-8?q?Tabs=20=E2=86=92=20spaces=20(not=20=EF=BD=89?= =?UTF-8?q?=EF=BD=84=EF=BD=85=EF=BD=8F=EF=BD=8C=EF=BD=8F=EF=BD=87=EF=BD=89?= =?UTF-8?q?=EF=BD=83=EF=BD=81=EF=BD=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abra.sh | 82 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/abra.sh b/abra.sh index 05741ba..ab855ad 100644 --- a/abra.sh +++ b/abra.sh @@ -1,64 +1,64 @@ sub_api_login() { - require_binary jq + require_binary jq - if [ -n $1 ]; then - USERID="$1" - else - read -rp "User ID (format: @bot:example.com): " USERID - fi - if [ -n $2 ]; then - DISPLAY_NAME="$2" - else - read -rp "Display name (e.g. Matrix Bot): " DISPLAY_NAME - fi - if [ -n $3 ]; then - PASSWORD="$3" - else - read -rp "Password: " PASSWORD - fi - if [ -n $4 ]; then - USER_HOMESERVER="$4" - else - read -rp "User homeserver (e.g. matrix.example.com): " USER_HOMESERVER - fi + if [ -n $1 ]; then + USERID="$1" + else + read -rp "User ID (format: @bot:example.com): " USERID + fi + if [ -n $2 ]; then + DISPLAY_NAME="$2" + else + read -rp "Display name (e.g. Matrix Bot): " DISPLAY_NAME + fi + if [ -n $3 ]; then + PASSWORD="$3" + else + read -rp "Password: " PASSWORD + fi + if [ -n $4 ]; then + USER_HOMESERVER="$4" + else + read -rp "User homeserver (e.g. matrix.example.com): " USER_HOMESERVER + fi - USERNAME=$(echo "${USERID/@/}" | cut -d':' -f1) + USERNAME=$(echo "${USERID/@/}" | cut -d':' -f1) - AUTH_DATA="{ - \"identifier\": { \"type\": \"m.id.user\", \"user\": \"$USERNAME\" }, - \"password\": \"$PASSWORD\", - \"type\": \"m.login.password\" + AUTH_DATA="{ + \"identifier\": { \"type\": \"m.id.user\", \"user\": \"$USERNAME\" }, + \"password\": \"$PASSWORD\", + \"type\": \"m.login.password\" }" - debug "Auth data: + debug "Auth data: $AUTH_DATA" - AUTH_RESPONSE=$(curl -s -X POST --header 'Content-Type: application/json' -d "$AUTH_DATA" "https://$USER_HOMESERVER/_matrix/client/r0/login") + AUTH_RESPONSE=$(curl -s -X POST --header 'Content-Type: application/json' -d "$AUTH_DATA" "https://$USER_HOMESERVER/_matrix/client/r0/login") - TOKEN=$(echo "$AUTH_RESPONSE" | jq -r '.access_token') - DEVICE_ID=$(echo "$AUTH_RESPONSE" | jq -r '.device_id') + TOKEN=$(echo "$AUTH_RESPONSE" | jq -r '.access_token') + DEVICE_ID=$(echo "$AUTH_RESPONSE" | jq -r '.device_id') - CONFIGURE_DATA="{ - \"UserId\": \"$USERID\", - \"AccessToken\": \"$TOKEN\", - \"HomeServerURL\": \"$DOMAIN\", - \"DeviceId\": \"LSWJCPGUAZ\", - \"Sync\": true, - \"AutoJoinRooms\": true, - \"DisplayName\": \"autono-bot\" + CONFIGURE_DATA="{ + \"UserId\": \"$USERID\", + \"AccessToken\": \"$TOKEN\", + \"HomeServerURL\": \"$DOMAIN\", + \"DeviceId\": \"LSWJCPGUAZ\", + \"Sync\": true, + \"AutoJoinRooms\": true, + \"DisplayName\": \"autono-bot\" }" - debug "Auth data: + debug "Auth data: $CONFIGURE_DATA" curl -s -X POST "https://$DOMAIN/admin/configureClient" --data-binary $CONFIGURE_DATA | jq } sub_api() { - CMD="$1" + CMD="$1" if type "sub_api_$CMD" > /dev/null 2>&1; then # shellcheck disable=SC2086 - shift + shift "sub_api_$CMD" "$@" else error "Subcommand 'sub_api_$CMD' not found"