Repository navigation
Expand file tree
/
Copy pathdeploy-armbian.sh
More file actions
121 lines (103 loc) · 4.18 KB
/
Copy pathdeploy-armbian.sh
File metadata and controls
121 lines (103 loc) · 4.18 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
# @file deploy-armbian.sh
# @description Automated deployment script for CloudNest on Armbian Linux SBC servers.
# Assumes Node.js and npm are already installed (system-wide or via NVM).
# @module Deployment
# @dependencies bash, nodejs (pre-installed), systemd
# @author Agent Architecture Directive
#!/usr/bin/env bash
set -e
echo "============================================================="
echo " 🚀 CloudNest Armbian Deployment Installer"
echo "============================================================="
# Ensure script is executed with root privileges
if [ "$EUID" -ne 0 ]; then
echo "❌ Error: Please run this script as root (sudo ./deploy-armbian.sh)"
exit 1
fi
# ─── Pre-flight: Verify Node.js & npm availability ───────────────
NODE_BIN=$(which node 2>/dev/null || true)
NPM_BIN=$(which npm 2>/dev/null || true)
if [ -z "$NODE_BIN" ] || [ -z "$NPM_BIN" ]; then
echo "❌ Error: node or npm not found in PATH."
echo ""
echo " If you use a Node Version Manager (nvm, fnm, n, etc.),"
echo " make sure the correct version is activated before running"
echo " this script. For example with nvm:"
echo ""
echo " export NVM_DIR=\"\$HOME/.nvm\""
echo " [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\""
echo " nvm use --lts"
echo " sudo -E env \"PATH=\$PATH\" ./deploy-armbian.sh"
echo ""
echo " Alternatively, install Node.js system-wide first."
exit 1
fi
echo "✓ Node.js : $($NODE_BIN -v) ($NODE_BIN)"
echo "✓ npm : $($NPM_BIN -v) ($NPM_BIN)"
APP_DIR="/opt/cloudnest"
STORAGE_DIR="/var/cloudnest/storage"
SERVICE_NAME="cloudnest.service"
# ─── Step 1: Install system-level dependencies ───────────────────
echo ""
echo "Step 1: Installing System Dependencies..."
apt-get update -y
apt-get install -y sqlite3 build-essential
# ─── Step 2: Prepare application directory ────────────────────────
echo ""
echo "Step 2: Preparing Application Directory ($APP_DIR)..."
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
mkdir -p "$STORAGE_DIR"
chmod 775 "$STORAGE_DIR"
# Skip copy if already running from /opt/cloudnest
if [ "$(realpath "$SCRIPT_DIR")" = "$(realpath "$APP_DIR")" ]; then
echo "✓ Project already located in $APP_DIR — skipping copy."
else
mkdir -p "$APP_DIR"
echo " Copying project files to $APP_DIR..."
cp -r "$SCRIPT_DIR/." "$APP_DIR/"
fi
# ─── Step 3: Install Node.js production dependencies ─────────────
echo ""
echo "Step 3: Installing Production Dependencies..."
cd "$APP_DIR"
"$NPM_BIN" install --production
# ─── Step 4: Setup systemd service ───────────────────────────────
echo ""
echo "Step 4: Setting up Systemd Service..."
cat <<EOF > /etc/systemd/system/$SERVICE_NAME
[Unit]
Description=CloudNest Personal Cloud Storage Server
After=network.target local-fs.target
[Service]
Type=simple
User=root
WorkingDirectory=$APP_DIR
ExecStart=$NODE_BIN $APP_DIR/server/index.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production
Environment=PORT=3000
Environment=CLOUDNEST_STORAGE_ROOT=$STORAGE_DIR
[Install]
WantedBy=multi-user.target
EOF
echo "Reloading Systemd daemon & enabling service..."
systemctl daemon-reload
systemctl enable $SERVICE_NAME
systemctl restart $SERVICE_NAME
# ─── Step 5: Status check ────────────────────────────────────────
echo ""
echo "Step 5: Status Check..."
sleep 2
if systemctl is-active --quiet $SERVICE_NAME; then
echo "============================================================="
echo " ✅ CloudNest Deployment Successfully Completed!"
echo "============================================================="
echo " - Storage Path : $STORAGE_DIR"
echo " - Service : active (running)"
echo " - Web Interface: http://$(hostname -I | awk '{print $1}'):3000"
echo "============================================================="
else
echo "⚠️ Warning: Service may not have started correctly."
echo " Check logs with: journalctl -u $SERVICE_NAME -n 50 --no-pager"
fi