-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
59 lines (46 loc) · 1.34 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
#!/bin/bash
CURL=/usr/bin/curl
SCRIPT=discord_bot.sh
SCRIPT_URL=https://raw.githubusercontent.com/t4top/mina-node-discord-bot/main/$SCRIPT
# prompt for webhook url
while true; do
read -p "Enter Discord Webhook URL: " WEBHOOK_URL
if [ -z "$WEBHOOK_URL" ]; then
echo "Webhook URL cannot be empty."
else
break
fi
done
# change to user home directory
cd ~
# download bot script
$CURL -fsSL $SCRIPT_URL > $SCRIPT
# sustitute webhook url
sed -i "s@ENTER_DISCORD_WEBHOOK_URL_HERE@$WEBHOOK_URL@g" $SCRIPT
# make the script executable
chmod +x $SCRIPT
read -n1 -r -p "Would you like to run under systemd instead of cron? (y/n) " YESNO
echo
if [ $YESNO = "y" ] || [ $YESNO = "Y" ] ; then
sudo mv $SCRIPT /usr/local/bin/$SCRIPT
sudo tee /etc/systemd/user/mina-discord-bot.service &>/dev/null << E-O-F
[Unit]
Description=Mina Discord Bot Service
After=network-online.target
[Service]
Type=simple
Restart=always
RestartSec=15min
ExecStart=/usr/local/bin/$SCRIPT
[Install]
WantedBy=default.target
E-O-F
systemctl --user start mina-discord-bot.service
systemctl --user enable mina-discord-bot.service
systemctl --user status mina-discord-bot.service
else
# add the script to cronjob
(crontab -l | grep $PWD/$SCRIPT) || (crontab -l 2>/dev/null; echo "*/15 * * * * $PWD/$SCRIPT >/dev/null 2>&1") | crontab -
# execute the script
$PWD/$SCRIPT
fi