-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
54 lines (42 loc) · 1.16 KB
/
setup.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
#!/bin/bash
# exit code 3: insufficient number of arguments provided
# 4: non-root executer
# 5: required command not found
# 6: ptr-client compilation failure
if [ -z "$1" ]; then
echo "Usage: bash $0 IGI_SERVER_IP"
exit 3
fi
if [ "$(whoami)" != "root" ]; then
echo "You must be root to run this script"
exit 4
fi
command_ls=("whoami" "git" "make" "mkdir" "sed" "mv" "apt" "grep")
for cmd in "${command_ls[@]}"; do
if ! command -v "$cmd" &> /dev/null ; then
echo "$cmd not found"
exit 5
fi
done
make
if [ ! -f ptr-client ]; then
echo "ptr-client not compiled"
exit 6
fi
parent_path="$(pwd)"
binary_path="$parent_path/ptr-client"
igi_sh_path="$parent_path/igi.sh"
mkdir data
data_path="$parent_path/data"
sed -i "s|PTRCLIENT_PATH|$binary_path|" igi_template.sh
sed -i "s|DUMP_DIR_PATH|$data_path|" igi_template.sh
sed -i "s|TARGET_IP|$1|" igi_template.sh
mv igi_template.sh igi.sh
apt update
apt install -y cron
if [ ! -z "$(grep igi.sh /var/spool/cron/crontabs/root)" ]; then
echo "Crontab already set up"
exit 0
fi
echo "*/15 * * * * bash $igi_sh_path" | crontab -
/etc/init.d/cron start