annotate mod_rest/example/rest.sh @ 5662:81f1c617f4c7

mod_push2: Add note about luaossl patch
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Tue, 19 Sep 2023 21:39:14 -0500
parents acd2f397ce6b
children e5ad3f1f48bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5281
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 #!/bin/bash -eu
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 # Copyright (c) Kim Alvefur
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 # This file is MIT/X11 licensed.
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
5329
107d60c70c1a mod_rest/rest.sh: List dependencies in comment
Kim Alvefur <zash@zash.se>
parents: 5281
diff changeset
6 # Dependencies:
107d60c70c1a mod_rest/rest.sh: List dependencies in comment
Kim Alvefur <zash@zash.se>
parents: 5281
diff changeset
7 # - https://httpie.io/
5636
b3484a112300 mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents: 5432
diff changeset
8 # - https://hg.sr.ht/~zash/httpie-oauth2
5329
107d60c70c1a mod_rest/rest.sh: List dependencies in comment
Kim Alvefur <zash@zash.se>
parents: 5281
diff changeset
9
5637
acd2f397ce6b mod_rest/rest.sh: Silence shellcheck SC1091
Kim Alvefur <zash@zash.se>
parents: 5636
diff changeset
10 # shellcheck disable=SC1091
acd2f397ce6b mod_rest/rest.sh: Silence shellcheck SC1091
Kim Alvefur <zash@zash.se>
parents: 5636
diff changeset
11
5281
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 # Settings
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 HOST=""
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 DOMAIN=""
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/restrc" ]; then
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 # Config file can contain the above settings
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 source "${XDG_CONFIG_HOME:-$HOME/.config}/restrc"
5636
b3484a112300 mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents: 5432
diff changeset
19
b3484a112300 mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents: 5432
diff changeset
20 if [ -z "${SCOPE:-}" ]; then
b3484a112300 mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents: 5432
diff changeset
21 SCOPE="openid xmpp"
b3484a112300 mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents: 5432
diff changeset
22 fi
5281
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 fi
5432
1c52efb6fd42 mod_rest/rest.sh: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 5431
diff changeset
24
5281
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 if [[ $# == 0 ]]; then
5636
b3484a112300 mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents: 5432
diff changeset
26 echo "${0##*/} [-h HOST] [/path] kind=(message|presence|iq) ...."
5281
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 # Last arguments are handed to HTTPie, so refer to its docs for further details
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 exit 0
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 fi
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 if [[ "$1" == "-h" ]]; then
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 HOST="$2"
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 shift 2
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 elif [ -z "${HOST:-}" ]; then
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 HOST="$(hostname)"
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 fi
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 if [[ "$HOST" != *.* ]]; then
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 # Assumes subdomain of your DOMAIN
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 if [ -z "${DOMAIN:-}" ]; then
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 DOMAIN="$(hostname -d)"
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 fi
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 if [[ "$HOST" == *:* ]]; then
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 HOST="${HOST%:*}.$DOMAIN:${HOST#*:}"
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 else
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 HOST="$HOST.$DOMAIN"
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 fi
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 fi
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 # For e.g /disco/example.com and such GET queries
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 GET_PATH=""
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 if [[ "$1" == /* ]]; then
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 GET_PATH="$1"
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 shift 1
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 fi
4ed65a6c2a6a mod_rest: Add an example bash script for using mod_rest
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57
5636
b3484a112300 mod_rest/rest.sh: Update to use httpie-oauth2 plugin
Kim Alvefur <zash@zash.se>
parents: 5432
diff changeset
58 https --check-status -p b --session rest -A oauth2 -a "$HOST" --oauth2-scope "$SCOPE" "$HOST/rest$GET_PATH" "$@"