-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
88 lines (74 loc) · 2.28 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
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
#!/bin/bash
# WOL Server Installer for Raspberry Pi
echo "WOL Server Installer for Raspberry Pi"
# Check if Node.js is installed
if ! command -v node &> /dev/null; then
echo "Node.js not found. Installing..."
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
else
echo "Node.js is already installed."
fi
# Check Node.js version
NODE_VERSION=$(node -v)
echo "Node.js version: $NODE_VERSION"
# Install arp-scan
echo "Installing arp-scan..."
sudo apt-get update
sudo apt-get install -y arp-scan
# Verify arp-scan installation
if ! command -v arp-scan &> /dev/null; then
echo "Failed to install arp-scan. Please check your system configuration."
exit 1
fi
# Create installation directory
INSTALL_DIR="/opt/wol-server"
echo "Creating installation directory: $INSTALL_DIR"
sudo mkdir -p $INSTALL_DIR
# Copy files
echo "Copying files..."
sudo cp wol-server.js $INSTALL_DIR/
sudo cp package.json $INSTALL_DIR/
sudo cp .env.example $INSTALL_DIR/.env
# Set correct permissions
echo "Setting permissions..."
sudo chown -R $USER:$USER $INSTALL_DIR
# Install dependencies
echo "Installing dependencies..."
cd $INSTALL_DIR
npm install --production
# Create systemd service
echo "Creating systemd service..."
SERVICE_FILE="/etc/systemd/system/wol-server.service"
sudo bash -c "cat > $SERVICE_FILE" << EOL
[Unit]
Description=Wake on LAN Server
After=network.target
[Service]
Type=simple
User=$USER
WorkingDirectory=$INSTALL_DIR
ExecStart=/usr/bin/node $INSTALL_DIR/wol-server.js
Restart=always
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
EOL
# Configure service
echo "Configuring service..."
sudo systemctl daemon-reload
sudo systemctl enable wol-server
sudo systemctl start wol-server
# Get server IP address
IP_ADDRESS=$(hostname -I | awk '{print $1}')
PORT=$(grep PORT $INSTALL_DIR/.env | cut -d '=' -f2 || echo "8080")
echo ""
echo "======================================"
echo "Installation Complete!"
echo "Your WOL server is running at: http://$IP_ADDRESS:$PORT"
echo "Check status: sudo systemctl status wol-server"
echo "View logs: sudo journalctl -u wol-server -f"
echo ""
echo "Don't forget to edit the .env file to set your JWT_SECRET and ALLOWED_ORIGINS:"
echo "sudo nano $INSTALL_DIR/.env"
echo "======================================"