-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.asterisk.room-close.sh
51 lines (41 loc) · 2.09 KB
/
app.asterisk.room-close.sh
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 -e
#
# Asterisk script for closing room.
# If there is only 1 user left in the room, the room is closed.
#
# @package Bash
# @author Yuri Dunaev
# @license MIT
# @version 0.1.0
# @link https://fdn.im
# -------------------------------------------------------------------------------------------------------------------- #
(( EUID != 0 )) && { echo >&2 'This script should be run as root!'; exit 1; }
# Sources.
SRC_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd -P ) # Source directory.
SRC_NAME="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" # Source name.
. "${SRC_DIR}/${SRC_NAME%.*}.ini" # Loading configuration data.
# Variables.
mapfile -t rooms < <( grep '^conf =>' '/etc/asterisk/meetme.conf' | cut -d ' ' -f 3 )
# -------------------------------------------------------------------------------------------------------------------- #
# INITIALIZATION
# -------------------------------------------------------------------------------------------------------------------- #
run() { close; }
# -------------------------------------------------------------------------------------------------------------------- #
# ROOM CLOSE
# -------------------------------------------------------------------------------------------------------------------- #
close() {
for room in "${rooms[@]}"; do
for phone in "${phones[@]:?}"; do
local users; users=$( asterisk -x "meetme list ${room}" | head -n -1 | awk '{ print NR }' )
local last; last=$( asterisk -x "meetme list ${room}" | grep "${phone}" | awk '{ print $4 }' )
case ${users} in
1) [[ ${phone} -eq ${last} ]] && asterisk -x "meetme kick ${room} all" ;;
*) continue ;;
esac
done
done
}
# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------< RUNNING SCRIPT >------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #
run && exit 0 || exit 1