-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathms
More file actions
144 lines (133 loc) · 6.06 KB
/
Copy pathms
File metadata and controls
144 lines (133 loc) · 6.06 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
#!/data/data/com.termux/files/usr/bin/bash
case "${1:-}" in
start)
echo "Starting Mobile Server..."
if pgrep nginx >/dev/null 2>&1; then echo " Nginx Already running"; elif nginx -t >/dev/null 2>&1; then nginx && echo " Nginx Running" || echo " Nginx Failed"; else echo " Nginx Config error — run 'nginx -t'"; fi
if pgrep php-fpm >/dev/null 2>&1; then echo " PHP-FPM Already running"; else php-fpm 2>/dev/null && echo " PHP-FPM Running" || echo " PHP-FPM Failed"; fi
if pgrep mariadbd >/dev/null 2>&1 || pgrep mysqld >/dev/null 2>&1; then echo " MariaDB Already running"; else mariadbd-safe >/dev/null 2>&1 & sleep 2; if pgrep mariadbd >/dev/null 2>&1 || pgrep mysqld >/dev/null 2>&1; then echo " MariaDB Running"; else echo " MariaDB Failed"; fi; fi
if pgrep ttyd >/dev/null 2>&1; then echo " ttyd Already running"; else ttyd -W -p 7681 bash -l >/dev/null 2>&1 & sleep 1; if pgrep ttyd >/dev/null 2>&1; then echo " ttyd Running"; else echo " ttyd Failed"; fi; fi
;;
stop)
echo "Stopping Mobile Server..."
for svc in nginx php-fpm mariadbd ttyd; do
if pgrep "$svc" >/dev/null 2>&1; then
pkill -9 "$svc" 2>/dev/null || true
sleep 1
if pgrep "$svc" >/dev/null 2>&1; then
printf " %-10s Force killed\n" "$svc"
else
printf " %-10s Stopped\n" "$svc"
fi
else
printf " %-10s Not running\n" "$svc"
fi
done
# mariadbd-safe spawns mysqld as the actual server process
if pgrep mysqld >/dev/null 2>&1; then
pkill -9 mysqld 2>/dev/null || true
printf " %-10s Stopped\n" "mysqld"
fi
echo "Mobile Server stopped"
;;
restart)
"$0" stop
sleep 1
"$0" start
;;
status)
IP=$(ifconfig 2>/dev/null | awk '/^[a-z]/{i=$1} /inet /{if(i!="lo:" && $2!="127.0.0.1" && $2~/^192\.168\./){print $2;exit}}')
[ -z "$IP" ] && IP=$(ifconfig 2>/dev/null | awk '/^[a-z]/{i=$1} /inet /{if(i!="lo:" && $2!="127.0.0.1"){print $2;exit}}')
[ -z "$IP" ] && IP="127.0.0.1"
echo "╔╦╗╔═╗╔╗ ╦╦ ╦ ╔═╗ ╔═╗╔═╗╦═╗╦ ╦╔═╗╦═╗"
echo "║║║║ ║╠╩╗║║ ║ ║╣ ╚═╗║╣ ╠╦╝╚╗╔╝║╣ ╠╦╝"
echo "╩ ╩╚═╝╚═╝╩╩ ╩═╝╚═╝ ╚═╝╚═╝╩╚═ ╚╝ ╚═╝╩╚═"
echo ""
echo "========================================"
echo " Mobile Server Status"
echo "========================================"
echo ""
echo "Terminal: http://${IP}:7681"
echo ""
echo "Website: http://${IP}:8080"
echo ""
PASS_FILE="$HOME/server/.panel_password"
if [ -f "$PASS_FILE" ]; then
echo "Panel Password: $(cat "$PASS_FILE")"
echo ""
fi
echo "Services:"
for svc in nginx php-fpm ttyd; do
if pgrep "$svc" >/dev/null 2>&1; then
printf " %-10s Running\n" "$svc"
else
printf " %-10s Stopped\n" "$svc"
fi
done
if pgrep mariadbd >/dev/null 2>&1 || pgrep mysqld >/dev/null 2>&1; then
printf " %-10s Running\n" "MariaDB"
else
printf " %-10s Stopped\n" "MariaDB"
fi
echo ""
echo "========================================"
;;
update)
HOME_DIR="$HOME"
TARGET_DIR="$HOME_DIR/server/sites/default/public_html"
TMP_DIR="$(mktemp -d 2>/dev/null || echo "/tmp/ms-update")"
REPO_URL="https://github.com/SayfullahSayeb/mobile-server.git"
HASH_FILE="$HOME_DIR/server/configs/.update_hash"
echo "Updating Mobile Server from GitHub..."
echo
LATEST_HASH=$(git ls-remote "$REPO_URL" HEAD 2>/dev/null | awk '{print $1}')
if [ -z "$LATEST_HASH" ]; then
echo "[!] Failed to check for updates — no internet connection?"
exit 1
fi
if [ -f "$HASH_FILE" ] && [ "$(cat "$HASH_FILE")" = "$LATEST_HASH" ]; then
echo " Already up to date (commit ${LATEST_HASH:0:8})."
echo
echo "No update needed."
exit 0
fi
if ! git clone --depth 1 "$REPO_URL" "$TMP_DIR" 2>/dev/null; then
echo "[!] Failed to clone repository. Check internet connection."
rm -rf "$TMP_DIR" 2>/dev/null
exit 1
fi
echo " Cloned repository."
echo "$LATEST_HASH" > "$HASH_FILE"
# Remove files from target not in repo (sync deleted files)
KEEP_FILE="$TMP_DIR/.keep_list"
ls -A1 "$TMP_DIR" > "$KEEP_FILE" 2>/dev/null
for f in "$TARGET_DIR"/* "$TARGET_DIR"/.[!.]*; do
[ -e "$f" ] || continue
b="$(basename "$f")"
[ "$b" = "." ] || [ "$b" = ".." ] || [ "$b" = ".git" ] || [ "$b" = "phpmyadmin" ] || [ "$b" = ".update_hash" ] && continue
grep -qxF "$b" "$KEEP_FILE" 2>/dev/null && continue
rm -rf "$f" 2>/dev/null
printf " \xE2\x9C\x97 Removed %s\n" "$b"
done
# Copy all repo files to target
for f in "$TMP_DIR"/* "$TMP_DIR"/.[!.]*; do
[ -e "$f" ] || continue
b="$(basename "$f")"
[ "$b" = "." ] || [ "$b" = ".." ] || [ "$b" = ".git" ] && continue
cp -r "$f" "$TARGET_DIR/" 2>/dev/null
printf " \xE2\x9C\x93 Synced %s\n" "$b"
done
# Update CLI binary
if [ -f "$TMP_DIR/ms" ]; then
cp "$TMP_DIR/ms" "$PREFIX/bin/ms" 2>/dev/null
chmod +x "$PREFIX/bin/ms" 2>/dev/null
printf " \xE2\x9C\x93 Updated CLI\n"
fi
rm -rf "$TMP_DIR" 2>/dev/null
echo
echo "Update completed successfully."
;;
*)
echo "Usage: ms {start|stop|restart|status|update}"
exit 1
;;
esac