-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
124 lines (94 loc) · 3.44 KB
/
install.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
#!/bin/bash
# @version 1.0.6
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
function printRed() {
echo -e "\e[31m${*}\e[0m"
}
function printGreen() {
printf "\e[32m${1}\e[0m"
}
function printBold() {
printf "\033[1m${1}\033[0m"
}
function fail() {
printRed $1
exit 1
}
printBold "|\n| SyAgent Installer\n| =\n|"
if [ $(id -u) != "0" ]; then
fail "|\n| Error: Please run the agent as root\n| \tThe agent will NOT run as root but root required to make the installation success\n|"
fi
SYSTEM="$(uname -s 2> /dev/null || uname -v)"
OS="$(uname -o 2> /dev/null || uname -rs)"
MACHINE="$(uname -m 2> /dev/null)"
printBold "System : ${SYSTEM}"
printBold "Operating System : ${OS}"
printBold "Machine : ${MACHINE}"
if [ $# -lt 1 ]
then
fail "|\n| Usage: bash $0 'token'\n|"
fi
if [ ! -n "$(command -v crontab)" ]; then
echo "|" && read -p "| SyAgent needs cron. Do you want to install it? [Y/n] " input_variable_install
if [ -z $input_variable_install ] || [ $input_variable_install == "Y" ] || [ $input_variable_install == "y" ]; then
if [ -n "$(command -v apt-get)" ]; then
apt-get -y update
apt-get -y install cron
elif [ -n "$(command -v pacman)" ]; then
pacman -S --noconfirm cronie
fi
elif [ -n "$(command -v yum)" ]; then
yum -y install cronie
if [ ! -n "$(command -v crontab)" ]; then
yum -y install vixie-cron
fi
fi
if [ ! -n "$(command -v crontab)" ]; then
fail "|\n| Error: Cannot install CronTab, please install the CronTab and run the script again\n|"
fi
fi
if [ -z "$(ps -Al | grep cron | grep -v grep)" ]; then
echo "|" && read -p "| Cron is is down. Do you want to start it? [Y/n] " input_variable_service
if [ -z $input_variable_service ] || [ $input_variable_service == "Y" ] || [ $input_variable_service == "y" ]; then
if [ -n "$(command -v apt-get)" ]; then
service cron start
elif [ -n "$(command -v yum)" ]; then
chkconfig crond on
service crond start
elif [ -n "$(command -v pacman)" ]; then
systemctl start cronie
systemctl enable cronie
fi
fi
if [ -z "$(ps -Al | grep cron | grep -v grep)" ]; then
fail "|\n| Error: Error when trying to start the Cron\n|"
fi
fi
if [ -f /etc/syAgent/sh-agent.sh ]; then
rm -Rf /etc/syAgent
if id -u syAgent >/dev/null 2>&1; then
(crontab -u syAgent -l | grep -v "/etc/syAgent/sh-agent.sh") | crontab -u syAgent - && userdel syAgent
else
(crontab -u root -l | grep -v "/etc/syAgent/sh-agent.sh") | crontab -u root -
fi
fi
mkdir -p /etc/syAgent
printBold "| Downloading sh-agent.sh to /etc/syAgent\n|\n| + $(wget -nv -o /dev/stdout -O /etc/syAgent/sh-agent.sh --no-check-certificate https://raw.githubusercontent.com/syagent/agent-2/main/sh-agent.sh)"
if [ -f /etc/syAgent/sh-agent.sh ]; then
echo "$1" >/etc/syAgent/sa-auth.log
useradd syAgent -r -d /etc/syAgent -s /bin/false
chown -R syAgent:syAgent /etc/syAgent && chmod -R 700 /etc/syAgent
chmod +s `type -p ping`
crontab -u syAgent -l 2>/dev/null | {
cat
echo "*/1 * * * * bash /etc/syAgent/sh-agent.sh > /etc/syAgent/sh-cron.log 2>&1"
} | crontab -u syAgent -
printBold "| ================================================\n"
printGreen "| Success: The syAgent agent installed\n"
printBold "| ================================================\n"
if [ -f $0 ]; then
rm -f $0
fi
else
fail "\tError: The syAgent agent is not installed\n"
fi