-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-setup.sh
103 lines (91 loc) · 3.01 KB
/
auto-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
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
#!/bin/bash
echo "INFO: Starting IP Alert Setup"
shopt -s lastpipe
shopt -so pipefail
jq --version >/dev/null 2>&1
jq_ok=$?
[[ "$jq_ok" -eq 127 ]] && \
echo "ERROR: jq not installed" && exit 2
[[ "$jq_ok" -ne 0 ]] && \
echo "ERROR: unknown error in jq" && exit 2
curl --version >/dev/null 2>&1
curl_ok=$?
[[ "$curl_ok" -eq 127 ]] && \
echo "fatal: curl not installed" && exit 2
while true; do
read -p "Enter webhook: " webhook
# check webhook includes "https://discord.com/api/webhooks/"
if [[ $webhook == *"discord.com/api/webhooks/"* ]]; then
break
elif [ -n "$webhook" ]; then
echo "ERROR: Invalid webhook URL"
else
echo "ERROR: Webhook is required"
fi
done
while true; do
read -p "Enter server name: " server_name
if [ -n "$server_name" ]; then
break
fi
echo "ERROR: Server name is required"
done
read -p "Enter title (Default: Ip Check): " title
if [ -z "$title" ]; then
title="Ip Check"
fi
while true; do
read -p "Is private ip? [Y/N] (Default: N): " private_ip
if [ -z "$private_ip" ]; then
description=$(curl https://ip.ontdb.com/)
break
elif "$private_ip" == "Y" || "$private_ip" == "y"; then
description=$(hostname -I)
break
elif "$private_ip" == "N" || "$private_ip" == "n"; then
description=$(curl https://ip.ontdb.com/)
break
else
echo "ERROR: Please enter Y or N"
fi
done
mkdir -p /opt/ipalert
echo "===========[CONFIG]==========="
echo "Webhook: $webhook"
echo "Server name: $server_name"
echo "Title: $title"
echo "Description: $description (Automatically generated)"
echo "==================================="
while true; do
read -p "Is this correct? [Y/N] (Default: Y): " correct
if [ -z "$correct" ]; then
break
elif "$correct" == "Y" || "$correct" == "y"; then
break
elif "$correct" == "N" || "$correct" == "n"; then
echo "ERROR: Please try again"
exit 1
else
echo "ERROR: Please enter Y or N"
fi
done
echo "INFO: Starting download discord.sh"
curl -L -o /opt/ipalert/discord.sh https://raw.githubusercontent.com/ChaoticWeg/discord.sh/v1.6.1/discord.sh > /dev/null 2>&1
chmod +x /opt/ipalert/discord.sh
echo "INFO: Downloaded to /opt/ipalert/discord.sh"
echo "INFO: Generating send command"
echo "/opt/ipalert/discord.sh --webhook-url=$webhook --username $server_name --title $title --description $description --timestamp" > /opt/ipalert/run.sh
chmod +x /opt/ipalert/run.sh
echo "INFO: Generated send command to /opt/ipalert/run.sh"
echo "INFO: Adding crontab entry"
echo "*0 * * * * root /opt/ipalert/run.sh" >> /etc/crontab
echo "INFO: Added crontab entry"
echo "INFO: IP Alert Setup Done!"
echo "INFO: If contab entry is not working, please run the following command:"
echo "INFO: crontab -e"
echo "INFO: And add the following line:"
echo "INFO: 0 * * * * /opt/ipalert/run.sh"
echo "INFO: Then save and exit (:wq)"
echo "INFO: If you want to change the webhook, please run this script again."
echo ""
exit 0