Tabs → spaces (not ideological)

This commit is contained in:
3wc 2021-03-20 23:21:36 +02:00
parent 03b8fdd809
commit eb20face76
1 changed files with 41 additions and 41 deletions

82
abra.sh
View File

@ -1,64 +1,64 @@
sub_api_login() { sub_api_login() {
require_binary jq require_binary jq
if [ -n $1 ]; then if [ -n $1 ]; then
USERID="$1" USERID="$1"
else else
read -rp "User ID (format: @bot:example.com): " USERID read -rp "User ID (format: @bot:example.com): " USERID
fi fi
if [ -n $2 ]; then if [ -n $2 ]; then
DISPLAY_NAME="$2" DISPLAY_NAME="$2"
else else
read -rp "Display name (e.g. Matrix Bot): " DISPLAY_NAME read -rp "Display name (e.g. Matrix Bot): " DISPLAY_NAME
fi fi
if [ -n $3 ]; then if [ -n $3 ]; then
PASSWORD="$3" PASSWORD="$3"
else else
read -rp "Password: " PASSWORD read -rp "Password: " PASSWORD
fi fi
if [ -n $4 ]; then if [ -n $4 ]; then
USER_HOMESERVER="$4" USER_HOMESERVER="$4"
else else
read -rp "User homeserver (e.g. matrix.example.com): " USER_HOMESERVER read -rp "User homeserver (e.g. matrix.example.com): " USER_HOMESERVER
fi fi
USERNAME=$(echo "${USERID/@/}" | cut -d':' -f1) USERNAME=$(echo "${USERID/@/}" | cut -d':' -f1)
AUTH_DATA="{ AUTH_DATA="{
\"identifier\": { \"type\": \"m.id.user\", \"user\": \"$USERNAME\" }, \"identifier\": { \"type\": \"m.id.user\", \"user\": \"$USERNAME\" },
\"password\": \"$PASSWORD\", \"password\": \"$PASSWORD\",
\"type\": \"m.login.password\" \"type\": \"m.login.password\"
}" }"
debug "Auth data: debug "Auth data:
$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') TOKEN=$(echo "$AUTH_RESPONSE" | jq -r '.access_token')
DEVICE_ID=$(echo "$AUTH_RESPONSE" | jq -r '.device_id') DEVICE_ID=$(echo "$AUTH_RESPONSE" | jq -r '.device_id')
CONFIGURE_DATA="{ CONFIGURE_DATA="{
\"UserId\": \"$USERID\", \"UserId\": \"$USERID\",
\"AccessToken\": \"$TOKEN\", \"AccessToken\": \"$TOKEN\",
\"HomeServerURL\": \"$DOMAIN\", \"HomeServerURL\": \"$DOMAIN\",
\"DeviceId\": \"LSWJCPGUAZ\", \"DeviceId\": \"LSWJCPGUAZ\",
\"Sync\": true, \"Sync\": true,
\"AutoJoinRooms\": true, \"AutoJoinRooms\": true,
\"DisplayName\": \"autono-bot\" \"DisplayName\": \"autono-bot\"
}" }"
debug "Auth data: debug "Auth data:
$CONFIGURE_DATA" $CONFIGURE_DATA"
curl -s -X POST "https://$DOMAIN/admin/configureClient" --data-binary $CONFIGURE_DATA | jq curl -s -X POST "https://$DOMAIN/admin/configureClient" --data-binary $CONFIGURE_DATA | jq
} }
sub_api() { sub_api() {
CMD="$1" CMD="$1"
if type "sub_api_$CMD" > /dev/null 2>&1; then if type "sub_api_$CMD" > /dev/null 2>&1; then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
shift shift
"sub_api_$CMD" "$@" "sub_api_$CMD" "$@"
else else
error "Subcommand 'sub_api_$CMD' not found" error "Subcommand 'sub_api_$CMD' not found"