-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
253 lines (219 loc) · 7.44 KB
/
Copy pathinstaller.sh
File metadata and controls
253 lines (219 loc) · 7.44 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/env bash
# MonikaShell Portable Installer
# Designed for common Linux distributions.
set -e
# When piped via curl | bash, stdin is the script itself.
# We append < /dev/tty to read commands to allow interactive prompts.
REPO_URL="https://github.com/AnarchDevelopment/MonikaShell.git"
echo "========================================"
echo " MonikaShell Installer"
echo "========================================"
echo ""
# 1. Detect User & Root
CURRENT_USER=$(whoami)
DEFAULT_DIR="/home/$CURRENT_USER/MonikaShell"
if [ "$CURRENT_USER" = "root" ]; then
DEFAULT_DIR="/root/MonikaShell"
echo "WARNING: Installing under /root is NOT recommended."
read -p "Are you sure you want to proceed as root? [y/N]: " root_confirm < /dev/tty
case "$root_confirm" in
[yY][eE][sS]|[yY])
;;
*)
echo "Installation aborted."
exit 1
;;
esac
fi
# 2. First Admin
read -p "Set a username for your first admin user [admin]: " ADMIN_USER < /dev/tty
ADMIN_USER=${ADMIN_USER:-admin}
# Hide password input
prompt="Set a password for your first admin user: "
while IFS= read -p "$prompt" -r -s -n 1 char < /dev/tty; do
if [[ $char == $'\0' ]]; then
break
fi
prompt='*'
ADMIN_PASS+="$char"
done
echo ""
# 3. Installation Directory
read -p "Server will be installed to [$DEFAULT_DIR]. Proceed? [Y/n/custom_path]: " DIR_CONFIRM < /dev/tty
if [[ "$DIR_CONFIRM" =~ ^[nN] ]]; then
echo "Installation aborted."
exit 1
elif [[ "$DIR_CONFIRM" != "" && ! "$DIR_CONFIRM" =~ ^[yY] ]]; then
INSTALL_DIR="$DIR_CONFIRM"
else
INSTALL_DIR="$DEFAULT_DIR"
fi
# 4. Port Configuration
read -p "Which port should the backend API run on? [8080]: " API_PORT < /dev/tty
API_PORT=${API_PORT:-8080}
# 5. Systemd Service
read -p "Create a systemd service for the server to run on boot? [y/N]: " SYSTEMD_CONFIRM < /dev/tty
# 6. Site Configuration
read -p "App name? [MonikaShell]: " APP_NAME < /dev/tty
APP_NAME=${APP_NAME:-MonikaShell}
read -p "Site URL (e.g., https://shell.example.com) [http://localhost]: " SITE_URL < /dev/tty
SITE_URL=${SITE_URL:-http://localhost}
read -p "Site description [My remote terminal panel]: " SITE_DESC < /dev/tty
SITE_DESC=${SITE_DESC:-My remote terminal panel}
# 7. Stop After Required Setup
read -p "Basic installation is complete. Would you like to configure appearance settings now? [Y/n]: " APP_CONFIRM < /dev/tty
THEME="Dark"
BORDER="8px"
if [[ ! "$APP_CONFIRM" =~ ^[nN] ]]; then
read -p "What is the desired default theme for the app? [Light/Dark]: " THEME < /dev/tty
THEME=${THEME:-Dark}
read -p "What is the desired Border Radius for the app? (use 'px' or 'rem') [8px]: " BORDER < /dev/tty
BORDER=${BORDER:-8px}
fi
echo ""
echo "========================================"
echo " Proceeding with installation..."
echo "========================================"
echo ""
# Install dependencies
SUDO=""
if [ "$CURRENT_USER" != "root" ]; then
if ! command -v sudo &> /dev/null; then
echo "sudo is not installed. We need root privileges to install dependencies."
exit 1
fi
SUDO="sudo"
fi
# MonikaShell requires Node.js >= 22 (better-sqlite3 v13).
REQUIRED_NODE_MAJOR=22
node_major_version() {
if ! command -v node &> /dev/null; then
echo 0
return 1
fi
node -p "process.versions.node.split('.')[0]"
}
node_compatible() {
local major
major=$(node_major_version) || return 1
[ "$major" -ge "$REQUIRED_NODE_MAJOR" ]
}
install_deps() {
echo "Installing required dependencies (git, nodejs >= $REQUIRED_NODE_MAJOR)..."
if command -v apt-get &> /dev/null; then
$SUDO apt-get update
if ! command -v curl &> /dev/null; then
$SUDO apt-get install -y curl
fi
curl -fsSL https://deb.nodesource.com/setup_22.x | $SUDO -E bash -
$SUDO apt-get install -y nodejs git build-essential python3-dev
elif command -v dnf &> /dev/null; then
if ! command -v curl &> /dev/null; then
$SUDO dnf install -y curl
fi
curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO bash -
$SUDO dnf install -y nodejs git gcc-c++ make python3-devel
elif command -v yum &> /dev/null; then
if ! command -v curl &> /dev/null; then
$SUDO yum install -y curl
fi
curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO bash -
$SUDO yum install -y nodejs git gcc-c++ make python3-devel
elif command -v pacman &> /dev/null; then
$SUDO pacman -Sy --noconfirm nodejs npm git curl base-devel python
else
echo "Could not detect package manager. Please install Node.js >= $REQUIRED_NODE_MAJOR and Git manually."
exit 1
fi
}
if ! command -v git &> /dev/null || ! command -v npm &> /dev/null || ! node_compatible; then
install_deps
fi
if ! node_compatible; then
echo "ERROR: MonikaShell requires Node.js >= $REQUIRED_NODE_MAJOR, but the system has $(command -v node &> /dev/null && node -v || echo 'no Node.js')."
exit 1
fi
echo "Using Node.js $(node -v) (required >= $REQUIRED_NODE_MAJOR)."
if [ -d "$INSTALL_DIR" ]; then
echo "Directory $INSTALL_DIR already exists. Assuming update..."
cd "$INSTALL_DIR"
git pull
else
git clone "$REPO_URL" "$INSTALL_DIR"
cd "$INSTALL_DIR"
fi
echo "Installing frontend dependencies..."
cd frontend
npm install --production=false
# We would typically run 'npm run build' here for production, but the dev server is fine for now
echo "Installing build tools (required for native modules)..."
if command -v apt-get &> /dev/null; then
$SUDO apt-get install -y build-essential python3-dev
elif command -v dnf &> /dev/null; then
$SUDO dnf install -y gcc-c++ make python3-devel
elif command -v yum &> /dev/null; then
$SUDO yum install -y gcc-c++ make python3-devel
elif command -v pacman &> /dev/null; then
$SUDO pacman -Sy --noconfirm base-devel python
fi
echo "Installing backend dependencies..."
cd ../backend
npm install
# Rebuild native modules (e.g. better-sqlite3) for the current Node ABI.
# Required when Node.js was just upgraded so old binaries don't crash at runtime.
npm rebuild 2>/dev/null || true
# Setup env for backend
cat << EOF > .env
PORT=$API_PORT
ADMIN_USER=$ADMIN_USER
ADMIN_PASS=$ADMIN_PASS
APP_NAME=$APP_NAME
SITE_URL=$SITE_URL
SITE_DESC=$SITE_DESC
THEME=$THEME
BORDER_RADIUS=$BORDER
EOF
cd ..
# Optional Systemd setup
SERVICE_NAME="monikashell"
if [[ "$SYSTEMD_CONFIRM" =~ ^[yY] ]]; then
echo "Setting up systemd service (requires sudo)..."
SERVICE_FILE="/tmp/monikashell.service"
cat << EOF > $SERVICE_FILE
[Unit]
Description=MonikaShell Backend
After=network.target
[Service]
Type=simple
User=$CURRENT_USER
WorkingDirectory=$INSTALL_DIR/backend
ExecStart=/bin/bash -lc 'node index.js'
Restart=on-failure
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
EOF
$SUDO mv $SERVICE_FILE /etc/systemd/system/monikashell.service
$SUDO systemctl daemon-reload
$SUDO systemctl enable monikashell
$SUDO systemctl start monikashell
echo "Service $SERVICE_NAME started."
fi
echo ""
echo "========================================"
echo " Installation complete!"
echo "========================================"
echo ""
echo "MonikaShell is installed at:"
echo "$INSTALL_DIR"
echo ""
if [[ "$SYSTEMD_CONFIRM" =~ ^[yY] ]]; then
echo "Service:"
echo "$SERVICE_NAME"
echo ""
fi
echo "URL:"
echo "$SITE_URL"
echo ""
echo "To start manually, run:"
echo "cd $INSTALL_DIR/backend && node index.js"