-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·90 lines (76 loc) · 2.81 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·90 lines (76 loc) · 2.81 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
90
#!/bin/bash
# Ensure running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo ./install.sh)"
exit 1
fi
SERVICE_FILE="linux-nitrosense.service"
DESKTOP_FILE="linux-nitrosense.desktop"
BINARY_PATH="target/release/linux-nitrosense"
BUNDLED_BIN="./linux-nitrosense"
INSTALL_BIN="/usr/bin/linux-nitrosense"
REPO="Packss/linux-nitrosense-rust"
# 1. Check for bundled binary in current directory
if [ -f "$BUNDLED_BIN" ]; then
echo "Found bundled binary at $BUNDLED_BIN. Installing..."
cp "$BUNDLED_BIN" "$INSTALL_BIN"
# 2. Check for local build artifact
elif [ -f "$BINARY_PATH" ]; then
echo "Found local build at $BINARY_PATH. Installing..."
cp "$BINARY_PATH" "$INSTALL_BIN"
# 3. Ask user: Download or Build?
else
echo "Binary not found locally."
read -p "Do you want to [d]ownload the latest release or [b]uild from source? (d/b): " choice
if [ "$choice" = "d" ] || [ "$choice" = "D" ]; then
echo "Downloading latest release from GitHub ($REPO)..."
# Fetch latest release tag
LATEST_URL=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep "browser_download_url.*linux-nitrosense" | cut -d '"' -f 4)
if [ -z "$LATEST_URL" ]; then
echo "Error: Could not find a release asset named 'linux-nitrosense' in $REPO."
echo "Falling back to build from source..."
choice="b"
else
wget -O "$INSTALL_BIN" "$LATEST_URL" || curl -L -o "$INSTALL_BIN" "$LATEST_URL"
if [ $? -ne 0 ]; then
echo "Download failed."
exit 1
fi
echo "Download complete."
fi
fi
if [ "$choice" = "b" ] || [ "$choice" = "B" ]; then
echo "Building from source..."
if command -v cargo &> /dev/null; then
# Build as non-root user if SUDO_USER is set
if [ -n "$SUDO_USER" ]; then
sudo -u "$SUDO_USER" cargo build --release
else
cargo build --release
fi
if [ ! -f "$BINARY_PATH" ]; then
echo "Build failed."
exit 1
fi
cp "$BINARY_PATH" "$INSTALL_BIN"
else
echo "Cargo not found. Please install Rust or choose download option."
exit 1
fi
fi
fi
if [ ! -f "$INSTALL_BIN" ]; then
echo "Installation failed: Binary not created."
exit 1
fi
chmod +x "$INSTALL_BIN"
echo "Installing systemd service..."
cp "$SERVICE_FILE" /etc/systemd/system/
systemctl daemon-reload
systemctl enable linux-nitrosense.service
systemctl restart linux-nitrosense.service
echo "Installing desktop entry..."
cp "$DESKTOP_FILE" /usr/share/applications/
echo "Installation complete!"
echo "Service status:"
systemctl status linux-nitrosense.service --no-pager