generated from coop-cloud/example
Tabs → spaces (not ideological)
This commit is contained in:
parent
03b8fdd809
commit
eb20face76
82
abra.sh
82
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"
|
||||
|
|
Loading…
Reference in New Issue