-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.sh
91 lines (75 loc) · 2.49 KB
/
installer.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
#!/bin/bash
# Installer Script for simple-ssh-alerts
# A Simple SSH Alert Script based on Python+Telegram
# https://github.com/su-haris/simple-ssh-alerts
REPO_URL="https://github.com/su-haris/simple-ssh-alerts.git"
echo "Installing simple-ssh-alerts"
echo -e
# Check if python is installed
echo "Checking for Python Installation"
if command -v python3 &>/dev/null; then
echo "Python3 is installed."
else
echo "Python3 is not installed."
echo "Proceeding to install Python3."
# Check the distribution
if [ -f /etc/redhat-release ]; then
# Install Python3 on Redhat/CentOS
yum install python3 -yq
elif [ -f /etc/lsb-release ]; then
# Install Python3 on Ubuntu/Debian
apt-get update -q
apt-get install python3 -yq
elif [ -f /etc/os-release ]; then
source /etc/os-release
if [ "$ID" == "amzn" ]; then
# Install Python3 on Amazon Linux
yum install python3 -yq
fi
else
echo "Distribution not supported."
echo "Try to install Python3 manually and try again."
exit 1
fi
echo "Python3 is successfully installed!"
echo -e
fi
# Clone the repository
echo "Cloning repository for the necessary files."
echo -e
git clone -q $REPO_URL
cd simple-ssh-alerts
# Ask the user to input the TELEGRAM_API_KEY
echo -e
echo "Enter your TELEGRAM_API_KEY: "
read TELEGRAM_API_KEY
# Ask the user to input the TELEGRAM_CHAT_ROOM_ID
echo -e
echo "Enter your TELEGRAM_CHAT_ROOM_ID: "
read TELEGRAM_CHAT_ROOM_ID
# Ask the user to input the WHITELIST_IP
echo -e
echo "[OPTIONAL] Press enter to skip"
echo "Enter your WHITELIST_IP (separated by commas)."
read WHITELIST_IP
# Convert comma-separated values to Python list
WHITELIST_IP=$(echo $WHITELIST_IP | sed "s/,/','/g")
WHITELIST_IP="['"$WHITELIST_IP"']"
# Write the values to the file
echo "TELEGRAM_API_KEY = '$TELEGRAM_API_KEY'" > settings.py
echo "TELEGRAM_CHAT_ROOM_ID = '$TELEGRAM_CHAT_ROOM_ID'" >> settings.py
echo "WHITELIST_IP = $WHITELIST_IP" >> settings.py
# Confirm that the values have been written to the file
echo -e
echo "Values written to settings.py"
cat settings.py
# Update /etc/profile to trigger script on SSH
CURRENT_DIR=$(pwd)
echo "if [ -n \"\$SSH_CLIENT\" ]; then
python3 $CURRENT_DIR/ssh_alerts.py \$SSH_CLIENT
fi" | cat >> /etc/profile
# Send a test notification to Telegram to confirm installation works.
python3 "$CURRENT_DIR/ssh_alerts.py" "INSTALLER_SSH"
echo -e
echo "Installation of simple-ssh-alert is complete."
echo "You should have recieved a notification on Telegram if installation was successful."