-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·182 lines (160 loc) · 6.27 KB
/
install.sh
File metadata and controls
executable file
·182 lines (160 loc) · 6.27 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
# ServerHub Quick Install Script
# Downloads and installs the latest release from GitHub
# Copyright (c) Nikolaos Protopapas. All rights reserved.
# Licensed under the MIT License.
set -e
INSTALL_DIR="$HOME/.local"
CONFIG_DIR="$HOME/.config/serverhub"
WIDGETS_DIR="$INSTALL_DIR/share/serverhub/widgets"
REPO="nickprotop/ServerHub"
echo "Installing ServerHub from latest release..."
echo ""
# 1. Detect architecture
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
BINARY_NAME="serverhub-linux-x64"
;;
aarch64|arm64)
BINARY_NAME="serverhub-linux-arm64"
;;
*)
echo "Error: Unsupported architecture: $ARCH"
echo "Supported: x86_64, aarch64/arm64"
exit 1
;;
esac
echo "Detected architecture: $ARCH"
echo "Binary to download: $BINARY_NAME"
echo ""
# 2. Get latest release info
echo "Fetching latest release..."
RELEASE_JSON=$(curl -s "https://api.github.com/repos/$REPO/releases/latest")
RELEASE_TAG=$(echo "$RELEASE_JSON" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$RELEASE_TAG" ]; then
echo "Error: Could not fetch latest release information"
echo "Please check your internet connection or install manually from:"
echo "https://github.com/$REPO/releases"
exit 1
fi
echo "Latest release: $RELEASE_TAG"
echo ""
# 3. Construct download URLs
BINARY_URL="https://github.com/$REPO/releases/download/$RELEASE_TAG/$BINARY_NAME"
WIDGETS_URL="https://github.com/$REPO/releases/download/$RELEASE_TAG/widgets.tar.gz"
# 4. Create directories
mkdir -p "$INSTALL_DIR/bin"
mkdir -p "$WIDGETS_DIR"
mkdir -p "$CONFIG_DIR/widgets"
# 5. Download binary
echo "Downloading ServerHub binary..."
if ! curl -L -f -o "/tmp/serverhub" "$BINARY_URL"; then
echo "Error: Failed to download binary from $BINARY_URL"
exit 1
fi
chmod +x "/tmp/serverhub"
mv "/tmp/serverhub" "$INSTALL_DIR/bin/serverhub"
echo "✓ Installed binary to $INSTALL_DIR/bin/serverhub"
# 6. Download and extract widgets
echo "Downloading bundled widgets..."
if ! curl -L -f -o "/tmp/widgets.tar.gz" "$WIDGETS_URL"; then
echo "Error: Failed to download widgets from $WIDGETS_URL"
exit 1
fi
tar -xzf "/tmp/widgets.tar.gz" -C "$WIDGETS_DIR/"
chmod +x "$WIDGETS_DIR/"*.sh "$WIDGETS_DIR/"*.py 2>/dev/null || true
widget_count=$(ls -1 "$WIDGETS_DIR/"*.sh "$WIDGETS_DIR/"*.py 2>/dev/null | wc -l)
echo "✓ Installed $widget_count bundled widgets to $WIDGETS_DIR"
# Clean up
rm -f "/tmp/widgets.tar.gz"
# 7. Download and install uninstaller
echo "Downloading uninstaller..."
UNINSTALL_URL="https://github.com/$REPO/releases/download/$RELEASE_TAG/uninstall.sh"
if curl -L -f -o "/tmp/serverhub-uninstall" "$UNINSTALL_URL" 2>/dev/null; then
chmod +x "/tmp/serverhub-uninstall"
mv "/tmp/serverhub-uninstall" "$INSTALL_DIR/bin/serverhub-uninstall"
echo "✓ Installed uninstaller to $INSTALL_DIR/bin/serverhub-uninstall"
else
echo "Warning: Could not download uninstaller (non-critical)"
fi
# 8. Config will be auto-generated on first run
if [ ! -f "$CONFIG_DIR/config.yaml" ]; then
echo "✓ Config will be auto-generated on first run at $CONFIG_DIR/config.yaml"
else
echo "✓ Config already exists at $CONFIG_DIR/config.yaml"
fi
# 9. Install shell completion (bash)
if [ -f "$HOME/.bashrc" ]; then
echo "Installing bash completion..."
# Generate and append completion to bashrc if not already there
if ! grep -q "serverhub completion bash" "$HOME/.bashrc" 2>/dev/null; then
echo "" >> "$HOME/.bashrc"
echo "# ServerHub completion" >> "$HOME/.bashrc"
echo 'if command -v serverhub &> /dev/null; then' >> "$HOME/.bashrc"
echo ' source <(serverhub completion bash 2>/dev/null || true)' >> "$HOME/.bashrc"
echo 'fi' >> "$HOME/.bashrc"
echo "✓ Installed bash completion (reload shell to activate)"
else
echo "✓ Bash completion already configured"
fi
elif [ -f "$HOME/.zshrc" ]; then
echo "Installing zsh completion..."
if ! grep -q "serverhub completion zsh" "$HOME/.zshrc" 2>/dev/null; then
echo "" >> "$HOME/.zshrc"
echo "# ServerHub completion" >> "$HOME/.zshrc"
echo 'if command -v serverhub &> /dev/null; then' >> "$HOME/.zshrc"
echo ' source <(serverhub completion zsh 2>/dev/null || true)' >> "$HOME/.zshrc"
echo 'fi' >> "$HOME/.zshrc"
echo "✓ Installed zsh completion (reload shell to activate)"
else
echo "✓ Zsh completion already configured"
fi
fi
# 10. Add to PATH if needed
PATH_ADDED=false
if ! echo "$PATH" | grep -q "$INSTALL_DIR/bin"; then
echo ""
if [ -f "$HOME/.bashrc" ]; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc"
echo "✓ Added ~/.local/bin to PATH in ~/.bashrc"
SHELL_RC="$HOME/.bashrc"
PATH_ADDED=true
elif [ -f "$HOME/.zshrc" ]; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.zshrc"
echo "✓ Added ~/.local/bin to PATH in ~/.zshrc"
SHELL_RC="$HOME/.zshrc"
PATH_ADDED=true
else
echo "Warning: Could not detect shell config file (.bashrc or .zshrc)"
echo " Add manually: export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
else
echo "✓ ~/.local/bin is already in PATH"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✓ Installation complete!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
if [ "$PATH_ADDED" = true ]; then
echo "To get started, either reload your shell config:"
echo ""
echo " source $SHELL_RC"
echo ""
echo "Or run directly with the full path:"
echo ""
echo " ~/.local/bin/serverhub"
echo ""
else
echo "Run 'serverhub' to get started!"
echo ""
fi
echo "Other commands:"
echo " serverhub --discover - Find and add custom widgets"
echo " serverhub --help - Show all options"
echo ""
echo "To uninstall ServerHub:"
echo " serverhub-uninstall - Remove ServerHub from your system"
echo ""
echo "Documentation: https://github.com/$REPO"