Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
95 lines (83 loc) · 2.93 KB
/
Copy pathinstall.sh
File metadata and controls
95 lines (83 loc) · 2.93 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
#!/usr/bin/env bash
set -e
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# PlainNAS install script
# Downloads the latest release from GitHub and installs to /usr/local/bin
REPO="ismartcoding/plainnas"
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="plainnas"
UPDATER_NAME="plainnas-updater"
function error_exit() {
echo "[PlainNAS] ERROR: $1" >&2
exit 1
}
function detect_arch() {
local arch
arch=$(uname -m)
case "$arch" in
x86_64|amd64)
echo "amd64" ;;
aarch64|arm64)
echo "arm64" ;;
*)
error_exit "Unsupported architecture: $arch. Only amd64 and arm64 are supported."
;;
esac
}
function get_latest_release() {
curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" |
grep "tag_name" | head -n 1 | cut -d '"' -f4
}
function download_binary() {
local version="$1"
local arch="$2"
local url="https://github.com/$REPO/releases/download/$version/plainnas-linux-$arch.zip"
echo "[PlainNAS] Downloading $url ..."
curl -fLo "plainnas.zip" "$url" || error_exit "Failed to download binary zip."
unzip -o plainnas.zip || error_exit "Failed to unzip binary."
rm -f plainnas.zip
mv plainnas-linux-$arch "$BINARY_NAME" || error_exit "Failed to rename binary."
mv plainnas-updater-linux-$arch "$UPDATER_NAME" || error_exit "Failed to rename updater."
chmod +x "$BINARY_NAME" "$UPDATER_NAME"
}
function install_binary() {
sudo mv "$BINARY_NAME" "$INSTALL_DIR/" || error_exit "Failed to move binary to $INSTALL_DIR."
sudo mv "$UPDATER_NAME" "$INSTALL_DIR/" || error_exit "Failed to move updater to $INSTALL_DIR."
echo "[PlainNAS] Installed $BINARY_NAME to $INSTALL_DIR."
}
function run_install() {
sudo "$INSTALL_DIR/$BINARY_NAME" install || error_exit "plainnas install step failed."
}
function start_service() {
sudo systemctl enable --now plainnas || error_exit "Failed to start plainnas service."
}
main() {
echo "[PlainNAS] Detecting platform..."
ARCH=$(detect_arch)
VERSION=$(get_latest_release)
if [[ -z "$VERSION" ]]; then
error_exit "Could not determine latest release version."
fi
echo "[PlainNAS] Latest version: $VERSION"
download_binary "$VERSION" "$ARCH"
install_binary
run_install
start_service
echo -e "${GREEN}[PlainNAS] Installation successful!${NC}"
# Get the first non-loopback IPv4 address
SERVER_IP=$(hostname -I | awk '{for(i=1;i<=NF;i++) if ($i!~/^127\./ && $i~/\./) {print $i; exit}}')
if [[ -z "$SERVER_IP" ]]; then
SERVER_IP="localhost"
fi
# Color and clickable links (most terminals support clickable URLs)
echo -e "${CYAN}[PlainNAS] Access the web UI:${NC}"
echo -e " ${BLUE}http://$SERVER_IP:8080${NC} (${GREEN}HTTP${NC})"
echo -e " ${BLUE}https://$SERVER_IP:8443${NC} (${YELLOW}HTTPS${NC}, self-signed cert)"
}
main