-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_streams.sh
More file actions
51 lines (40 loc) · 1.6 KB
/
import_streams.sh
File metadata and controls
51 lines (40 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
#
# Import Ant Media Server streams.
#
# Usage:
# ./import_streams.sh <app_name> <file_name>
# Example:
# ./import_streams.sh live live_streams.json
APP_NAME=$1
FILE=$2
CONFIG_FILE="/usr/local/antmedia/webapps/$APP_NAME/WEB-INF/red5-web.properties"
BASE_URL="http://localhost:5080"
if [ -z "$APP_NAME" ] || [ -z "$FILE" ]; then
echo "Usage: $0 <app_name> <file_name>"
exit 1
fi
jwt_token() {
iat=$(date +%s)
header='{"alg":"HS256","typ":"JWT"}'
payload="{\"iat\":$iat}"
header_base64=$(echo -n "$header" | openssl base64 -e | tr -d '=' | tr '/+' '_-' | tr -d '\n')
payload_base64=$(echo -n "$payload" | openssl base64 -e | tr -d '=' | tr '/+' '_-' | tr -d '\n')
data="$header_base64.$payload_base64"
secret=$(grep "^jwtSecretKey=" "$CONFIG_FILE" | cut -d'=' -f2)
signature=$(echo -n "$data" | openssl dgst -sha256 -hmac "$secret" -binary | openssl base64 | tr -d '=' | tr '/+' '_-' | tr -d '\n')
echo "$data.$signature"
}
JWT_TOKEN=$(jwt_token)
JWT_SECRET=$(grep "^jwtSecretKey=" "$CONFIG_FILE" | cut -d'=' -f2)
jwtControlEnabled=$(grep "^jwtControlEnabled=" "$CONFIG_FILE" | cut -d'=' -f2)
if [ "$jwtControlEnabled" = "true" ] && [ -n "$JWT_SECRET" ]; then
CURL_CMD=(curl -s -X POST -H "Authorization: Bearer $JWT_TOKEN" -H "accept: application/json" -H "Content-Type: application/json")
else
CURL_CMD=(curl -s -X POST -H "accept: application/json" -H "Content-Type: application/json")
fi
URL="$BASE_URL/$APP_NAME/rest/v2/broadcasts/create?autoStart=false"
jq -c '.[]' "$FILE" | while read -r stream; do
"${CURL_CMD[@]}" "$URL" -d "$stream"
echo ""
done