-
Notifications
You must be signed in to change notification settings - Fork 3
/
amonpm
executable file
·70 lines (56 loc) · 1.63 KB
/
amonpm
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
#!/bin/bash
### BEGIN INIT INFO
# Provides: amonnpm
# Description: Amon package manager - installs plugins.
AGENTPATH='/usr/bin/amon-agent.py'
PLUGIN_PATH="/etc/amonagent/plugins"
PLUGINS_ENABLED="$PLUGIN_PATH/plugins-enabled"
AGENTUSER="amonagent"
function file_exists() {
[ -f "$1" ]
}
# Root user detection
if [ $(echo "$UID") = "0" ]; then
sudo_cmd=''
else
sudo_cmd='sudo'
fi
[ -f $AGENTPATH ] || echo "$AGENTPATH not found"
action=$1
case $action in
install)
$0 update
PLAYBOOK="$PLUGIN_PATH/$2/$2.yml"
if file_exists $PLAYBOOK ; then
$sudo_cmd sh -c "ansible-playbook $PLAYBOOK -i /etc/amonagent/plugins/hosts"
else
printf "\033[31m \n Cant find a plugin named $2\n\033[0m\n"
printf "\033[32m Available plugins: \n\033[0m\n"
$sudo_cmd ls -l $PLUGIN_PATH --time-style='long-iso' | grep '^d' | awk '{print $8}'
fi
su $AGENTUSER -c "python $AGENTPATH restart"
exit $?
;;
list)
$sudo_cmd ls -l $PLUGIN_PATH --time-style='long-iso' | grep '^d' | awk '{print $8}'
exit $?
;;
test)
su $AGENTUSER -c "python $AGENTPATH test_plugins"
exit $?
;;
uninstall)
CONFIGURATION_FILE="$PLUGINS_ENABLED/$2.conf"
$sudo_cmd rm -rf CONFIGURATION_FILE
su $AGENTUSER -c "python $AGENTPATH restart"
exit $?
;;
update)
su $AGENTUSER -c "(cd $PLUGIN_PATH && git pull origin master)"
exit $?
;;
*)
echo "Usage: $0 {install|test|update|uninstall}"
exit 2
;;
esac