This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
forked from AndreStemmann/Jitsi-Meet-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jitsi_conflinker.sh
205 lines (188 loc) · 5.79 KB
/
jitsi_conflinker.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash -
#===============================================================================
#
# FILE: jitsi_conflinker.sh
#
# USAGE: ./jitsi_conflinker.sh
#
# DESCRIPTION: backup relevant sourcefiles and symlink customized configs instead
#
# OPTIONS: adapt variables as needed
# REQUIREMENTS: run as root
# AUTHOR: Andre Stemmann
# ORGANIZATION: AirITSystems GmbH
# CREATED: 20.04.2020 16:42
# REVISION: v0.2
#===============================================================================
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
set -o nounset # Treat unset variables as an error
# ===============================================================================
# BASE VARIABLES
# ===============================================================================
# script vars
start=$(date +%s)
TODAY=$(date +%Y%m%d%H)
PROGGI=$(basename "$0")
READLINK=$(readlink -f "$0")
BASEDIR=$(dirname "$READLINK")
# user vars
LOGPATH="/var/log"
LOGFILE="${LOGPATH}/syslog"
ERRORLOG="${LOGPATH}/syslog"
APP="jitsi-meet-conflinker"
SERVICE1="jitsi-videobridge2"
SERVICE2="nginx"
SERVICE3="jicofo"
SERVICE4="prosody"
BACKDST="/var/backups"
BACKUPROOT="${BACKDST}/${APP}_backup_${TODAY}"
# ===============================================================================
# BASE FUNCTIONS
# ===============================================================================
function log () {
echo "$PROGGI ; $(date '+%Y%m%d %H:%M:%S') ; $*" | tee -a "${LOGFILE}"
}
function errorlog () {
echo "${PROGGI}_ERRORLOG ; $(date '+%Y%m%d %H:%M:%S') ; $*" | tee -a "${ERRORLOG}"
}
function usercheck () {
if [[ $UID -ne 0 ]]; then
errorlog "...Become user root and try again"
exit 1
fi
}
function folder () {
if [ ! -d "$1" ]; then
mkdir -p "$1"
log "...Create Backupfolder structure for $APP original configs $1"
else
log "...Folder $1 already exists"
fi
}
function distrocheck () {
if [[ -r /etc/os-release ]]; then
. /etc/os-release
if [[ $ID = ubuntu ]]; then
log "...Running ${ID}_${VERSION_ID} "
folder "${BACKUPROOT}"
else
errorlog "...Not running an debian based distribution. ID=$ID, VERSION=$VERSION"
folder "${BACKUPROOT}"
fi
else
errorlog "...$APP is not running a distribution with /etc/os-release available"
errorlog "...Please perform backup manually"
exit 1
fi
}
function service_off () {
if systemctl is-active --quiet "$1"; then
log "...stopping $1"
systemctl stop "$1"
sleep 3
else
log "...service $1 already stopped"
if ! systemctl is-active --quiet "$1"; then
log "...service $1 stopped"
else
log "...service $1 still running, trying to SIGTERM it now"
kill -15 "$1"
sleep 3
if ! systemctl is-active --quiet "$1"; then
log "...service $1 stopped"
else
log "...service $1 still running, trying to SIGKILL it now"
kill -9 "$1"
sleep 3
fi
fi
fi
}
function symlinker () {
cd "$BASEDIR" || errorlog "failed to cd into $BASEDIR"
cd "$1" || errorlog "failed to cd into $1"
# find files for reference in local repo, store them in array
# e.g. ./etc/jitsi/videobridge/20-jvb-udp-buffers.conf_org
sourcefiles=($(find . -maxdepth 5 -type f))
for i in "${sourcefiles[@]}"
do
# clean leading dot on elements
# e.g. /etc/jitsi/videobridge/20-jvb-udp-buffers.conf_org
j=${i/\./}
# clean trailling _org on source repo files
# e.g. /etc/jitsi/videobridge/20-jvb-udp-buffers.conf
k=${j/_org/}
# rsync original file to backup-location
# e.g. rsync /etc/jitsi/videobridge/20-jvb-udp-buffers.conf /var/backups/jitsi-meet_backup_20200427/
rsync -avz --relative --remove-source-files "${k}" "${BACKUPROOT}/"
# rename backed up file to *_BAK
# e.g. /var/backups/jitsi-meet_backup_20200427/etc/jitsi/videobridge/20-jvb-udp-buffers.conf_BAK
mv "${BACKUPROOT}""${k}" "${BACKUPROOT}""${k}_BAK"
# gather absolute path from sourcefile
# /opt/jitsi-custom-configs/jitsi/etc/jitsi/videobridge/20-jvb-udp-buffers.conf
l=$(realpath "$i")
# /opt/jitsi-custom-configs/jitsi/etc/jitsi/videobridge/20-jvb-udp-buffers.conf /etc/jitsi/videobridge/20-jvb-udp-buffers.conf
ln -s "${l}" "${k}"
done
}
function service_on () {
systemctl start "$1"
sleep 3
if systemctl is-active --quiet "$1"; then
log "...$1 is safe and sound"
else
errorlog "...Failed to start $1"
errorlog "...Trying it again"
systemctl start "$1"
sleep 3
if ! systemctl is-active --quiet "$1"; then
log "...$1 is safe and sound"
else
errorlog "...Failed to start $1"
errorlog "...CRITICAL - check manually"
fi
fi
}
function grantrights_jitsi () {
cd "$BASEDIR" || errorlog "...failed to cd into $BASEDIR"
cd "$1" || errorlog "...failed to cd into $1"
PWDIR=$(pwd "$1")
chown -R jicofo:jitsi "${PWDIR}"/etc/jitsi/jicofo
chown -R jvb:jitsi "${PWDIR}"/etc/jitsi/videobridge
chown -R jicofo:jitsi /etc/jitsi/jicofo
chown -R jvb:jitsi /etc/jitsi/videobridge
}
function grantrights_prosody () {
cd "$BASEDIR" || errorlog "...failed to cd into $BASEDIR"
cd "$1" || errorlog "...failed to cd into $1"
PWDIR=$(pwd "$1")
chown -R root:prosody "${PWDIR}"/etc/prosody
chown -R root:prosody /etc/prosody
}
# ===============================================================================
# MAIN RUN
# ===============================================================================
cd "$BASEDIR" || errorlog "...failed to cd into $BASEDIR"
echo "Symlink Jitsi Configs"
echo "#########################"
echo "logfile location : $LOGFILE"
sleep 3
usercheck
distrocheck
folder "$BACKUPROOT"
service_off $SERVICE2
service_off $SERVICE1
service_off $SERVICE3
service_off $SERVICE4
symlinker "./jitsi"
symlinker "./prosody"
grantrights_jitsi "./jitsi"
grantrights_prosody "./prosody"
service_on $SERVICE1
service_on $SERVICE3
service_on $SERVICE4
service_on $SERVICE2
end=$(date +%s)
runtime=$((end-start))
log "...Runtime $runtime Seconds"
exit 0