-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig
executable file
·41 lines (38 loc) · 1.2 KB
/
config
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
#!/bin/bash
#read configuration file
function config(){
file="/etc/notifybox/notifybox.conf"
line=$(cat $file | grep "$2")
IFS="=" read -ra line <<< $line
line=${line[1]}
command="$1$line $3"
}
#add new line in .service file
function add_lines(){
number=$(cat -n $1 | grep -E "\[Service\]$" | grep -E -o "[0-9]+")
config "ExecStartPost=" "command_start" "--title '$(echo $3 | sed -e "s/.service//g")' --text 'The service $3 started...'"
sed -i "${number}a\\${command}" $1
config "ExecStopPost=" "command_stop" "--title '$(echo $3 | sed -e "s/.service//g")' --text 'The service $3 is stopped...'"
sed -i "${number}a\\${command}" $1
sed -i "${number}a\\#notifybox" $1
}
#root
if [[ ! $(whoami | grep "root") ]];then
echo -e "\033[1;31m[-]\033[0m You aren't root"
exit
fi
declare -r LIST_SERVICES="/var/cache/notifybox/services.list"
while IFS= read -r line
do
path=$(find /lib/systemd/ -type f -iname "$line")
if [[ $path != "" ]];then
if [[ $(cat $path | grep -E -o "notifybox --") ]];then
echo -e "\033[1;33m[!]\033[0m $line changed by notifybox"
continue
fi
echo -n $line....
add_lines $path "ExecStartPost" "$line"
echo -e "\033[1;32mOK\033[0m"
fi
done < $LIST_SERVICES
systemctl daemon-reload