The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service. feat(scripts): wire reset-config into 3m-ui CLI wrapper + install hint The new '3m-ui reset-config' Go subcommand (commit 8639b01) lets SSH operators undo panel misconfigurations (wrong port / 127.0.0.1 bind / broken SSL). This change exposes it through the systemd management wrapper and documents it in the install banner. scripts/3m-ui.sh: - Add 'reset_config' function: stops the panel service (required by the Go binary since it writes config.yaml + DB rows the running panel might cache), invokes 3m-ui-bin reset-config <flags>, then restarts the panel. - --help / -h short-circuits the stop/restart cycle (read-only). - Add 'reset-config' to the main case dispatch. - Document the new subcommand + flags in usage() with examples. scripts/install.sh: - Append a line to the post-install banner pointing operators at '3m-ui reset-config --panel --yes' for SSH rescue scenarios. USAGE sudo 3m-ui reset-config # interactive y/N, panel scope sudo 3m-ui reset-config --panel --yes # scripted rescue (common case) sudo 3m-ui reset-config --all --yes # full reset sudo 3m-ui reset-config --help # full help (no service touched) Smoke-tested with a fake binary: dispatch + flag passthrough + env vars all correct; --help does not stop the service.
236 lines
7.6 KiB
Bash
Executable File
236 lines
7.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# 3m-ui unified management logic
|
|
# The command entrypoint is /usr/local/bin/3m-ui.
|
|
# The actual Go application is /usr/local/lib/3m-ui/3m-ui-bin.
|
|
|
|
set -eu
|
|
|
|
APP_NAME="3m-ui"
|
|
ROOT="${THREE_M_UI_ROOT:-}"
|
|
BASE="$ROOT/usr/local/lib/3m-ui"
|
|
APP_BIN="$BASE/3m-ui-bin"
|
|
VERSION_FILE="$BASE/VERSION"
|
|
DATA_DIR="${THREE_M_UI_DATA_DIR:-}"
|
|
if [ -z "$DATA_DIR" ] && [ -s "$BASE/DATA_DIRECTORY" ]; then DATA_DIR="$(cat "$BASE/DATA_DIRECTORY")"; fi
|
|
DATA_DIR="${DATA_DIR:-$ROOT/var/lib/3m-ui}"
|
|
CONFIG_DIR="$ROOT/etc/3m-ui"
|
|
CONFIG_FILE="$CONFIG_DIR/config.yaml"
|
|
SERVICE="3m-ui"
|
|
|
|
say() { printf '%s\n' "$*"; }
|
|
err() { say "Error: $*" >&2; exit 1; }
|
|
|
|
need_root() {
|
|
[ "$(id -u)" = 0 ] || err "Please run as root."
|
|
}
|
|
|
|
init_system() {
|
|
if command -v systemctl >/dev/null 2>&1 && [ -d "$ROOT/run/systemd/system" ]; then
|
|
printf '%s' systemd
|
|
elif command -v rc-service >/dev/null 2>&1; then
|
|
printf '%s' openrc
|
|
else
|
|
printf '%s' unsupported
|
|
fi
|
|
}
|
|
|
|
service_action() {
|
|
action="$1"
|
|
case "$(init_system)" in
|
|
systemd) systemctl "$action" "$SERVICE" ;;
|
|
openrc) rc-service "$SERVICE" "$action" ;;
|
|
*) err "No supported init system found." ;;
|
|
esac
|
|
}
|
|
|
|
status() {
|
|
case "$(init_system)" in
|
|
systemd) systemctl --no-pager --full status "$SERVICE" || true ;;
|
|
openrc) rc-service "$SERVICE" status || true ;;
|
|
*) say "init: unsupported" ;;
|
|
esac
|
|
say ""
|
|
if [ -x "$APP_BIN" ]; then
|
|
say "Application: $APP_BIN"
|
|
if ! "$APP_BIN" --version 2>/dev/null; then
|
|
if [ -s "$VERSION_FILE" ]; then
|
|
say "Version: $(cat "$VERSION_FILE")"
|
|
else
|
|
say "Version: unavailable (installed binary does not expose --version)"
|
|
fi
|
|
fi
|
|
else
|
|
say "Application binary not found: $APP_BIN"
|
|
fi
|
|
}
|
|
|
|
logs() {
|
|
case "$(init_system)" in
|
|
systemd) journalctl -u "$SERVICE" -n 100 --no-pager ;;
|
|
openrc) tail -n 100 "$DATA_DIR/logs/3m-ui.log" 2>/dev/null || tail -n 100 "/var/log/3m-ui/3m-ui.log" 2>/dev/null || say "No log file found." ;;
|
|
*) say "No supported log backend found." ;;
|
|
esac
|
|
}
|
|
|
|
version() {
|
|
[ -x "$APP_BIN" ] || err "3m-ui application is not installed."
|
|
if "$APP_BIN" --version 2>/dev/null; then
|
|
return 0
|
|
fi
|
|
if [ -s "$VERSION_FILE" ]; then
|
|
say "3m-ui $(cat "$VERSION_FILE")"
|
|
return 0
|
|
fi
|
|
err "Unable to determine installed version."
|
|
}
|
|
|
|
uninstall() {
|
|
"$BASE/uninstall.sh" "$@"
|
|
}
|
|
|
|
config() {
|
|
action="${1:-show}"
|
|
case "$action" in
|
|
show)
|
|
if [ -f "$CONFIG_FILE" ]; then
|
|
say "Config file: $CONFIG_FILE"
|
|
say "---"
|
|
cat "$CONFIG_FILE"
|
|
else
|
|
err "Config file not found: $CONFIG_FILE"
|
|
fi
|
|
;;
|
|
port)
|
|
new_port="$2"
|
|
case "$new_port" in
|
|
''|*[!0-9]*) err "Usage: 3m-ui config port <1-65535>" ;;
|
|
esac
|
|
[ "$new_port" -ge 1 ] 2>/dev/null && [ "$new_port" -le 65535 ] 2>/dev/null || err "Port must be 1-65535."
|
|
[ -f "$CONFIG_FILE" ] || err "Config file not found: $CONFIG_FILE"
|
|
# Read current port
|
|
old_port=$(awk '/^ port:/ {print $2; exit}' "$CONFIG_FILE" 2>/dev/null || echo "8080")
|
|
if [ "$old_port" = "$new_port" ]; then
|
|
say "Port is already $new_port — no change needed."
|
|
return 0
|
|
fi
|
|
# Replace port in config.yaml
|
|
sed -i "s/^ port: .*/ port: $new_port/" "$CONFIG_FILE"
|
|
say "Port changed: $old_port → $new_port"
|
|
say "Restarting 3m-ui to apply..."
|
|
service_action restart
|
|
sleep 1
|
|
if service_is_active; then
|
|
say "✓ 3m-ui restarted. Configured port: $new_port (a separate HTTPS listener follows the panel TLS settings)."
|
|
else
|
|
say "✗ 3m-ui failed to start. Check logs: 3m-ui logs"
|
|
fi
|
|
;;
|
|
*)
|
|
err "Unknown config action: $action. Use 'show' or 'port <number>'."
|
|
;;
|
|
esac
|
|
}
|
|
|
|
service_is_active() {
|
|
case "$(init_system)" in
|
|
systemd) systemctl is-active --quiet "$SERVICE" ;;
|
|
openrc) rc-service "$SERVICE" status >/dev/null 2>&1 ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
reset_config() {
|
|
# --help / -h should NOT stop/restart the panel — it's a read-only help
|
|
# invocation. Detect it and pass through directly.
|
|
for a in "$@"; do
|
|
case "$a" in
|
|
--help|-h)
|
|
(cd "$DATA_DIR" && THREE_M_UI_CONFIG="$CONFIG_FILE" THREE_M_UI_DATA_DIR="$DATA_DIR" "$APP_BIN" reset-config "$@")
|
|
return $?
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# reset-config modifies config.yaml + DB rows the running panel may have
|
|
# cached. The Go binary refuses to run reset-config while the panel is up
|
|
# (it might race writes), so stop the service first, run reset, then restart.
|
|
say "Stopping 3m-ui service (reset-config requires the panel to be stopped)..."
|
|
service_action stop >/dev/null 2>&1 || true
|
|
# Pass through all flags (--panel / --access / --public / --all / --yes / -y)
|
|
# to the Go binary's reset-config subcommand.
|
|
(cd "$DATA_DIR" && THREE_M_UI_CONFIG="$CONFIG_FILE" THREE_M_UI_DATA_DIR="$DATA_DIR" "$APP_BIN" reset-config "$@")
|
|
rc=$?
|
|
say ""
|
|
say "Restarting 3m-ui service..."
|
|
service_action start || true
|
|
if [ $rc -ne 0 ]; then
|
|
err "reset-config failed (exit $rc). Check the message above; the panel was restarted with the old config."
|
|
fi
|
|
}
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: 3m-ui <command>
|
|
|
|
Commands:
|
|
status Show service and application status
|
|
start Start 3m-ui
|
|
restart Restart 3m-ui
|
|
stop Stop 3m-ui
|
|
logs Show recent service logs
|
|
version Show installed 3m-ui version
|
|
config Show or edit config (see below)
|
|
uninstall Remove 3m-ui but preserve data/config (use --purge to delete)
|
|
backup Stop service, snapshot data/config/binaries, resume service
|
|
restore Restore a complete snapshot: restore /path/snapshot.tar.gz
|
|
reset-admin Generate and display a new random administrator password
|
|
reset-config Reset panel config via SSH rescue (see below)
|
|
healthcheck Probe the actual configured HTTP/HTTPS panel
|
|
help Show this help
|
|
|
|
Config sub-commands:
|
|
3m-ui config show Display current config.yaml
|
|
3m-ui config port <1-65535> Change panel port and restart
|
|
|
|
Reset-config sub-commands (SSH rescue when web UI is unreachable):
|
|
3m-ui reset-config Reset panel listen/SSL (default scope)
|
|
3m-ui reset-config --panel Clear server.listen + disable SSL
|
|
3m-ui reset-config --access Clear listener public_host/SNI/ALPN
|
|
3m-ui reset-config --public Clear server.public_url
|
|
3m-ui reset-config --all Apply all three scopes
|
|
3m-ui reset-config --panel --yes Skip y/N prompt (scripted rescue)
|
|
3m-ui reset-config --help Show full reset-config help
|
|
|
|
Run '3m-ui' without arguments to open the interactive management menu.
|
|
EOF
|
|
}
|
|
|
|
main() {
|
|
need_root
|
|
cmd=${1:-}
|
|
case "$cmd" in
|
|
status) status ;;
|
|
start) service_action start ;;
|
|
restart) service_action restart ;;
|
|
stop) service_action stop ;;
|
|
logs) logs ;;
|
|
version) version ;;
|
|
config) shift; config "$@" ;;
|
|
uninstall) shift; uninstall "$@" ;;
|
|
backup) shift; "$BASE/install.sh" --backup "$@" ;;
|
|
restore) shift; "$BASE/install.sh" --restore "$@" ;;
|
|
init|reset-admin|healthcheck) (cd "$DATA_DIR" && THREE_M_UI_CONFIG="$CONFIG_FILE" THREE_M_UI_DATA_DIR="$DATA_DIR" "$APP_BIN" "$cmd") ;;
|
|
reset-config) shift; reset_config "$@" ;;
|
|
help|-h|--help) usage ;;
|
|
'')
|
|
if [ -x /usr/local/bin/3m-ui ] && [ "$(readlink -f /usr/local/bin/3m-ui 2>/dev/null || true)" = "$APP_BIN" ]; then
|
|
err "Invalid installation: management entrypoint points to the application binary. Re-run the latest installer to migrate it."
|
|
fi
|
|
exec /usr/local/bin/3m-ui
|
|
;;
|
|
*) err "Unknown command: $cmd" ;;
|
|
esac
|
|
}
|
|
|
|
main "$@"
|