Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·89 lines (74 loc) · 2.95 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·89 lines (74 loc) · 2.95 KB
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
#!/bin/bash
# Exit on any error
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo -e "${GREEN}Starting ServerWatch Agent installation...${NC}"
# Check for required tools
command -v curl >/dev/null 2>&1 || { echo -e "${RED}curl is required. Please install it (e.g., 'sudo apt install curl').${NC}"; exit 1; }
command -v openssl >/dev/null 2>&1 || { echo -e "${RED}OpenSSL is required. Please install it (e.g., 'sudo apt install openssl').${NC}"; exit 1; }
# Prompt for password
echo "Please enter the password for ServerWatch Agent:"
read -s SERVERWATCH_PASSWORD
if [ -z "$SERVERWATCH_PASSWORD" ]; then
echo -e "${RED}Password cannot be empty. Exiting.${NC}"
exit 1
fi
# Prompt for alertzy account key
echo "Please enter your Alertzy account key:"
read -s SERVERWATCH_ALERTZY_KEY
if [ -z "$SERVERWATCH_ALERTZY_KEY" ]; then
echo -e "${RED}Alertzy account key cannot be empty. Exiting.${NC}"
exit 1
fi
# Set install directory
INSTALL_DIR="$HOME/ServerWatch-agent"
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
# Download the pre-built binary
echo "Downloading ServerWatch-Agent binary..."
curl -sSL -o ServerWatch-Agent https://raw.githubusercontent.com/AlexanderHeffernan/ServerWatch/main/agent/bin/ServerWatch-Agent
chmod +x ServerWatch-Agent
# Generate unique self-signed certificate and key
if [ ! -f "serverwatch.crt" ] || [ ! -f "serverwatch.key" ]; then
echo "Generating self-signed certificate and key..."
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout serverwatch.key \
-out serverwatch.crt \
-subj "/C=US/ST=YourState/L=YourCity/O=ServerWatch/OU=Agent/CN=$(hostname)" \
-addext "subjectAltName=DNS:$(hostname)"
chmod 600 serverwatch.crt serverwatch.key
fi
# Set up systemd service
SERVICE_FILE="/etc/systemd/system/serverwatch-agent.service"
echo "Configuring systemd service..."
sudo bash -c "cat > $SERVICE_FILE" <<EOL
[Unit]
Description=ServerWatch Agent
After=network.target
[Service]
ExecStart=$INSTALL_DIR/ServerWatch-Agent
WorkingDirectory=$INSTALL_DIR
Environment="SERVERWATCH_PASSWORD=$SERVERWATCH_PASSWORD"
Environment="SERVERWATCH_ALERTZY_KEY=$SERVERWATCH_ALERTZY_KEY"
Restart=always
User=$(whoami)
[Install]
WantedBy=multi-user.target
EOL
# Reload and enable service
sudo systemctl daemon-reload
sudo systemctl enable serverwatch-agent.service
sudo systemctl start serverwatch-agent.service
# Verify it's running
if sudo systemctl is-active serverwatch-agent.service >/dev/null; then
echo -e "${GREEN}ServerWatch Agent installed and running at https://$(hostname):49160/metrics${NC}"
echo "Default password is 'Password123'. Test with:"
echo "curl --insecure https://127.0.0.1:49160/metrics?password=Password123"
else
echo -e "${RED}Failed to start ServerWatch Agent. Check logs with 'journalctl -u serverwatch-agent.service'${NC}"
exit 1
fi
echo -e "${GREEN}Installation complete! Visit https://alexanderheffernan.github.io/ServerWatch/ to connect.${NC}"