-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
77 lines (66 loc) · 1.98 KB
/
Copy pathinstall.sh
File metadata and controls
77 lines (66 loc) · 1.98 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
#!/bin/bash
set -e
echo "🔧 Checking dependencies..."
# Check if node is installed
if ! command -v node &> /dev/null; then
echo "📦 Node.js not found. Installing..."
sudo apt update -y
sudo apt install -y nodejs
else
echo "✅ Node.js is already installed."
fi
# Check if npm is installed
if ! command -v npm &> /dev/null; then
echo "📦 npm not found. Installing..."
sudo apt update -y
sudo apt install -y npm
else
echo "✅ npm is already installed."
fi
echo "📦 Installing WakeOnWeb dependencies..."
npm install
# Detect the directory where this script is located
SCRIPT_DIR=$(dirname "$(realpath "$0")")
SERVER_FILE="$SCRIPT_DIR/src/server.js"
SERVICE_FILE="/etc/systemd/system/wakeonweb.service"
# Check if server.js exists
if [ ! -f "$SERVER_FILE" ]; then
echo "❌ Error: server.js not found in $SCRIPT_DIR/src/"
echo "Please make sure you have downloaded the repository correctly."
exit 1
fi
update_service() {
echo "🛠️ Creating/updating systemd service file..."
cat <<EOF | sudo tee "$SERVICE_FILE"
[Unit]
Description=WakeOnWeb Service
After=network.target
[Service]
ExecStart=/usr/bin/node $SERVER_FILE
WorkingDirectory=$SCRIPT_DIR
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable wakeonweb
sudo systemctl restart wakeonweb
}
# Check if service already exists
if [ -f "$SERVICE_FILE" ]; then
# Check if ExecStart points to the correct SERVER_FILE
CURRENT_PATH=$(grep ExecStart "$SERVICE_FILE" | awk '{print $2}')
if [[ "$CURRENT_PATH" != "$SERVER_FILE" ]]; then
echo "⚠️ Existing service points to a different path. Updating..."
update_service
else
echo "✅ Service already exists and points to the correct path. Restarting..."
sudo systemctl restart wakeonweb
fi
else
update_service
fi
# Show the access URL
ip=$(hostname -I | awk '{print $1}')
echo "✅ WakeOnWeb is running at http://$ip:8093"