-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathlauncher.sh.template
executable file
·45 lines (38 loc) · 1.67 KB
/
launcher.sh.template
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
#!/usr/bin/env bash
cake_instances=()
if command -v uci >/dev/null 2>&1 && uci show cake-autorate >/dev/null 2>&1
then
cake_uci_sections=$(uci show cake-autorate | grep -oE "^cake-autorate\..*\.enabled=" | cut -d. -f2 | cut -d= -f1)
for cake_uci_section in ${cake_uci_sections}
do
enabled=$(uci get cake-autorate.${cake_uci_section}.enabled)
[[ "${enabled}" != "1" ]] && continue # Skip disabled instances
printf '%s\n' "# This file is automatically generated. Do not edit!" > "%%CONFIG_PREFIX%%/config.${cake_uci_section}.sh.tmp"
printf '%s\n\n' "# You can edit the UCI configuration file /etc/config/cake-autorate." >> "%%CONFIG_PREFIX%%/config.${cake_uci_section}.sh.tmp"
uci show cake-autorate.${cake_uci_section} >> "%%CONFIG_PREFIX%%/config.${cake_uci_section}.sh.tmp"
sed -i "s/^cake-autorate.${cake_uci_section}.//g" "%%CONFIG_PREFIX%%/config.${cake_uci_section}.sh.tmp"
sed -i -E "/^(enabled=|cake_autorate$)/d" "%%CONFIG_PREFIX%%/config.${cake_uci_section}.sh.tmp"
mv "%%CONFIG_PREFIX%%/config.${cake_uci_section}.sh.tmp" "%%CONFIG_PREFIX%%/config.${cake_uci_section}.sh"
cake_instances+=("%%CONFIG_PREFIX%%/config.${cake_uci_section}.sh")
done
else
cake_instances=(%%CONFIG_PREFIX%%/config.*.sh)
fi
cake_instance_pids=()
trap kill_cake_instances INT TERM EXIT
kill_cake_instances()
{
trap - INT TERM EXIT
echo "Killing all instances of cake one-by-one now."
for ((cake_instance=0; cake_instance<${#cake_instances[@]}; cake_instance++))
do
kill "${cake_instance_pids[${cake_instance}]}" 2>/dev/null || true
done
wait
}
for cake_instance in "${cake_instances[@]}"
do
%%SCRIPT_PREFIX%%/cake-autorate.sh "${cake_instance}" &
cake_instance_pids+=(${!})
done
wait