feat: scaffold native fnOS application stage 1
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,17 @@
|
||||
{
|
||||
".url": {
|
||||
"havline.main": {
|
||||
"title": "Havline",
|
||||
"icon": "images/icon_{0}.png",
|
||||
"type": "iframe",
|
||||
"protocol": "",
|
||||
"gatewayPrefix": "/app/havline",
|
||||
"gatewaySocket": "app.sock",
|
||||
"url": "/app/havline",
|
||||
"allUsers": false,
|
||||
"control": {
|
||||
"accessPerm": "readonly"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
for var in wizard_nginx_http_port wizard_nginx_https_port; do
|
||||
value="${!var:-}"
|
||||
if [ -n "$value" ] && ! [[ "$value" =~ ^[0-9]+$ ]]; then
|
||||
echo "$var 必须是数字端口" > "$TRIM_TEMP_LOGFILE"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
exit 0
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
mkdir -p "$TRIM_PKGVAR/logs"
|
||||
chown -R "$TRIM_USERNAME:$TRIM_GROUPNAME" "$TRIM_PKGVAR"
|
||||
|
||||
ARCH="$(uname -m)"
|
||||
case "$ARCH" in
|
||||
x86_64|amd64) ARCH_DIR="amd64" ;;
|
||||
aarch64|arm64) ARCH_DIR="arm64" ;;
|
||||
*) echo "不支持的设备架构:$ARCH" > "$TRIM_TEMP_LOGFILE"; exit 1 ;;
|
||||
esac
|
||||
|
||||
BIN="$TRIM_APPDEST/server/$ARCH_DIR/havline"
|
||||
if [ ! -f "$BIN" ]; then
|
||||
echo "找不到原生二进制:$BIN" > "$TRIM_TEMP_LOGFILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chmod +x "$BIN"
|
||||
echo "Havline 数据目录已准备:$TRIM_PKGVAR"
|
||||
exit 0
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
exit 0
|
||||
@@ -0,0 +1,118 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
|
||||
PID_FILE="${TRIM_PKGVAR}/havline.pid"
|
||||
LOG_FILE="${TRIM_PKGVAR}/logs/app.log"
|
||||
SOCKET_PATH="${TRIM_APPDEST}/app.sock"
|
||||
|
||||
mkdir -p "${TRIM_PKGVAR}/logs"
|
||||
|
||||
log_msg() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
check_process() {
|
||||
local pid="$1"
|
||||
kill -0 "$pid" 2>/dev/null
|
||||
}
|
||||
|
||||
status_app() {
|
||||
if [ -f "$PID_FILE" ]; then
|
||||
local pid
|
||||
pid="$(head -n 1 "$PID_FILE" | tr -d '[:space:]')"
|
||||
if [ -n "$pid" ] && check_process "$pid"; then
|
||||
return 0
|
||||
fi
|
||||
rm -f "$PID_FILE"
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
arch_dir() {
|
||||
case "$(uname -m)" in
|
||||
x86_64|amd64) echo "amd64" ;;
|
||||
aarch64|arm64) echo "arm64" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
start_app() {
|
||||
if status_app; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local arch
|
||||
arch="$(arch_dir)" || {
|
||||
echo "不支持的设备架构:$(uname -m)" > "$TRIM_TEMP_LOGFILE"
|
||||
exit 1
|
||||
}
|
||||
|
||||
local bin="${TRIM_APPDEST}/server/${arch}/havline"
|
||||
if [ ! -x "$bin" ]; then
|
||||
echo "找不到原生二进制:$bin" > "$TRIM_TEMP_LOGFILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export HAVLINE_DATA_DIR="$TRIM_PKGVAR"
|
||||
export HAVLINE_LISTEN="127.0.0.1:6893"
|
||||
export HAVLINE_GATEWAY_SOCKET="$SOCKET_PATH"
|
||||
export HAVLINE_GATEWAY_PREFIX="/app/havline"
|
||||
export HAVLINE_UPDATER_SOCKET=""
|
||||
export HAVLINE_NGINX_HTTP_PORT="${wizard_nginx_http_port:-18080}"
|
||||
export HAVLINE_NGINX_HTTPS_PORT="${wizard_nginx_https_port:-9443}"
|
||||
export TZ="${wizard_timezone:-Asia/Shanghai}"
|
||||
|
||||
if [ -n "${wizard_initial_admin_password:-}" ]; then
|
||||
export HAVLINE_INITIAL_ADMIN_PASSWORD="$wizard_initial_admin_password"
|
||||
fi
|
||||
|
||||
rm -f "$SOCKET_PATH"
|
||||
log_msg "Starting Havline native"
|
||||
cd "$TRIM_APPDEST" || exit 1
|
||||
nohup "$bin" >> "$LOG_FILE" 2>&1 &
|
||||
echo "$!" > "$PID_FILE"
|
||||
sleep 1
|
||||
status_app
|
||||
}
|
||||
|
||||
stop_app() {
|
||||
if [ ! -f "$PID_FILE" ]; then
|
||||
rm -f "$SOCKET_PATH"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local pid
|
||||
pid="$(head -n 1 "$PID_FILE" | tr -d '[:space:]')"
|
||||
if [ -n "$pid" ] && check_process "$pid"; then
|
||||
kill -TERM "$pid" 2>> "$LOG_FILE" || true
|
||||
local count=0
|
||||
while check_process "$pid" && [ "$count" -lt 15 ]; do
|
||||
sleep 1
|
||||
count=$((count + 1))
|
||||
done
|
||||
if check_process "$pid"; then
|
||||
kill -KILL "$pid" 2>> "$LOG_FILE" || true
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f "$PID_FILE" "$SOCKET_PATH"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
start)
|
||||
start_app
|
||||
;;
|
||||
stop)
|
||||
stop_app
|
||||
;;
|
||||
status)
|
||||
if status_app; then
|
||||
exit 0
|
||||
fi
|
||||
exit 3
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: ${1:-}" > "$TRIM_TEMP_LOGFILE"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
|
||||
if [ "${wizard_uninstall_mode:-keep}" = "purge" ]; then
|
||||
rm -rf "$TRIM_PKGVAR"
|
||||
fi
|
||||
|
||||
rm -f "$TRIM_APPDEST/app.sock"
|
||||
exit 0
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
exit 0
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
if [ -f "$TRIM_PKGVAR/havline.db" ] && [ ! -r "$TRIM_PKGVAR/havline.db" ]; then
|
||||
echo "数据库不可读:$TRIM_PKGVAR/havline.db" > "$TRIM_TEMP_LOGFILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$TRIM_PKGVAR/session_secret" ] && [ ! -r "$TRIM_PKGVAR/session_secret" ]; then
|
||||
echo "会话密钥不可读:$TRIM_PKGVAR/session_secret" > "$TRIM_TEMP_LOGFILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
exit 0
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"defaults": {
|
||||
"run-as": "package"
|
||||
},
|
||||
"username": "havline",
|
||||
"groupname": "havline"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,14 @@
|
||||
appname = havline
|
||||
version = 1.9.0
|
||||
display_name = Havline
|
||||
desc = NAS 公网访问管理:原生应用阶段一
|
||||
platform = all
|
||||
source = thirdparty
|
||||
maintainer = Havline
|
||||
maintainer_url = https://jayhub.top/mrlee/Havline
|
||||
distributor = Havline
|
||||
desktop_uidir = ui
|
||||
desktop_applaunchname = havline.main
|
||||
ctl_stop = true
|
||||
os_min_version = 1.1.3100
|
||||
changelog = 原生应用阶段一:Go 主程序、统一网关和启停脚本
|
||||
@@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"stepTitle": "基础设置",
|
||||
"items": [
|
||||
{
|
||||
"type": "select",
|
||||
"field": "wizard_timezone",
|
||||
"label": "时区",
|
||||
"initValue": "Asia/Shanghai",
|
||||
"options": [
|
||||
{ "label": "Asia/Shanghai", "value": "Asia/Shanghai" },
|
||||
{ "label": "UTC", "value": "UTC" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,35 @@
|
||||
[
|
||||
{
|
||||
"stepTitle": "管理员初始化",
|
||||
"items": [
|
||||
{
|
||||
"type": "password",
|
||||
"field": "wizard_initial_admin_password",
|
||||
"label": "初始管理员密码",
|
||||
"rules": [
|
||||
{ "required": true, "message": "请输入初始管理员密码" },
|
||||
{ "min": 8, "message": "密码至少 8 位" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "tips",
|
||||
"helpText": "首次启动时使用该密码创建 admin 管理员。登录后请在系统设置中修改密码。"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"stepTitle": "基础设置",
|
||||
"items": [
|
||||
{
|
||||
"type": "select",
|
||||
"field": "wizard_timezone",
|
||||
"label": "时区",
|
||||
"initValue": "Asia/Shanghai",
|
||||
"options": [
|
||||
{ "label": "Asia/Shanghai", "value": "Asia/Shanghai" },
|
||||
{ "label": "UTC", "value": "UTC" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"stepTitle": "卸载选项",
|
||||
"items": [
|
||||
{
|
||||
"type": "radio",
|
||||
"field": "wizard_uninstall_mode",
|
||||
"label": "数据处理",
|
||||
"initValue": "keep",
|
||||
"options": [
|
||||
{ "label": "保留数据(推荐)", "value": "keep" },
|
||||
{ "label": "删除全部数据", "value": "purge" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "tips",
|
||||
"helpText": "删除数据将移除数据库、证书、Nginx 配置、FRP 与 Cloudflare 配置,且无法恢复。"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user