Files
op-packages/linkeasefull/files/linkeasefull.init
T

150 lines
5.1 KiB
Bash

#!/bin/sh /etc/rc.common
START=100
STOP=10
USE_PROCD=1
PROG=/usr/bin/linkease-full
LINKEASE_LIBEXEC=/usr/libexec/linkeasefull
LINKEASE_FULL_PORT=19290
LINKEASE_BASE_PATH=/apps/
LINKEASE_LEGACY_ADDR=0.0.0.0:8897
LOCAL_API=/var/run/linkease.sock
is_persistent_data_root_parent() {
[ -n "$1" ] || return 1
case "$1" in
/tmp|/tmp/*|/var|/var/*|/run|/run/*|/dev|/dev/*|/proc|/proc/*|/sys|/sys/*|/rom|/rom/*|/overlay|/overlay/*) return 1 ;;
esac
[ -d "$1" ] || return 1
return 0
}
resolve_data_root_parent() {
if [ -n "$data_root_parent" ]; then
is_persistent_data_root_parent "$data_root_parent"
return $?
fi
local_home="$(uci -q get linkease.@linkease[0].local_home || true)"
if is_persistent_data_root_parent "$local_home"; then
data_root_parent="$local_home"
return 0
fi
if [ -f /etc/config/quickstart ]; then
quickstart_main_dir="$(uci -q get quickstart.main.main_dir || true)"
if [ -n "$quickstart_main_dir" ]; then
if is_persistent_data_root_parent "$quickstart_main_dir"; then
data_root_parent="$quickstart_main_dir"
return 0
fi
fi
fi
return 1
}
sync_shared_local_home() {
[ -x /usr/sbin/linkease-config.sh ] || return 0
/usr/sbin/linkease-config.sh local_save "$data_root_parent" >/dev/null 2>&1 || true
}
linkease_enabled() {
[ "$(uci -q get linkease.@linkease[0].enabled 2>/dev/null)" = "1" ]
}
read_config() {
section="$1"
config_get_bool enabled "$section" enabled 1
config_get data_root_parent "$section" data_root_parent ""
if ! resolve_data_root_parent; then
data_root_parent=""
return 1
fi
data_root="$data_root_parent/.linkease_data"
recycle_root="$data_root_parent/.linkease_recycle"
apptunnel_config_dir="/tmp/linkeasefull/apptunnel-config"
}
start_service() {
config_load linkeasefull
config_foreach read_config linkeasefull
[ "$enabled" = "1" ] || return 1
[ -x "$PROG" ] || return 1
if linkease_enabled; then
echo "linkeasefull: linkease is enabled; please disable linkease before starting linkeasefull" >&2
return 1
fi
if [ -z "$data_root_parent" ]; then
echo "linkeasefull: please choose a persistent disk storage path in LuCI" >&2
return 1
fi
sync_shared_local_home
rm -f "$LOCAL_API"
mkdir -p "$data_root/users/admin" "$data_root/system" "$data_root/tmp" "$recycle_root"
mkdir -p "$data_root/apptunnel" "$data_root/mountremote" "$data_root/logs"
mkdir -p "$apptunnel_config_dir"
# Do not set LINKEASE_CONFIG on OpenWrt. That variable belongs to
# Docker/file-backend deployments where users explicitly mount
# LINKEASE_CONFIG/preconfig.data. OpenWrt binding state is authoritative in
# UCI and must be accessed through /usr/sbin/linkease-config.sh. This is
# intentional: the user's data disk may be replaced, and the device must
# still be able to recover its binding from flash-backed OpenWrt config.
#
# Do not export LINKEASE_APPTUNNEL_PRECONFIG_SCRIPT or
# LINKEASE_APPTUNNEL_DEFAULT_ROOT_DIR here. Different devices have different
# storage roots, and hard-coded env wiring can pin apptunnel to a removed
# disk. The embedded clientruntime must discover linkease-config.sh and call
# local_load/local_save-compatible business APIs for the current root.
procd_open_instance linkeasefull
procd_set_param limits nofile="65535 65535"
procd_set_param command "$PROG"
procd_set_param env \
"SERVER_HOST=0.0.0.0" \
"SERVER_PORT=$LINKEASE_FULL_PORT" \
"SERVER_MODE=release" \
"SERVER_BASE_PATH=$LINKEASE_BASE_PATH" \
"LINKEASE_AUTH_PROVIDER=openwrt_luci" \
"LINKEASE_EDITION=nas-full" \
"KAIPLUS_ENABLED=0" \
"LINKEASE_DATA_ROOT=$data_root" \
"LINKEASE_RECYCLE_ROOT=$recycle_root" \
"LINKEASE_APPTUNNEL_INTERNAL_ADDR=127.0.0.1:19810" \
"LINKEASE_APPTUNNEL_LEGACY_ADDR=$LINKEASE_LEGACY_ADDR" \
"LINKEASE_APPTUNNEL_LOCAL_API=$LOCAL_API" \
"LINKEASE_APPTUNNEL_CONFIG_DIR=$apptunnel_config_dir" \
"LINKEASE_APPTUNNEL_DATA_DIR=$data_root/apptunnel" \
"LINKEASE_APPTUNNEL_CACHE_DIR=$data_root/apptunnel/cache" \
"LINKEASE_APPTUNNEL_RUNTIME_DIR=$data_root/apptunnel/runtime" \
"LINKEASE_APPTUNNEL_LOG_DIR=$data_root/logs" \
"APPTUNNEL_MOUNTREMOTE_MODE=real" \
"APPTUNNEL_MOUNTREMOTE_LINKREMOTE_AGENT_BINARY=/usr/bin/linkremote-agent" \
"APPTUNNEL_MOUNTREMOTE_SMBD_BINARY=$LINKEASE_LIBEXEC/linkmount_bin/linkmount_bin" \
"APPTUNNEL_MOUNTREMOTE_WORK_DIR=$data_root/mountremote" \
"APPTUNNEL_MOUNTREMOTE_SOCKET_DIR=$data_root/mountremote" \
"APPTUNNEL_MOUNTREMOTE_SAMBA_DIR=$data_root/mountremote/samba" \
"APPTUNNEL_MOUNTREMOTE_STORE_PATH=$data_root/mountremote/mounts.json" \
"APPTUNNEL_MOUNTREMOTE_STARTUP_RECONCILE=true" \
"APPTUNNEL_MOUNTREMOTE_ROOT_WATCH_DIR=$data_root/mountremote/root-watch" \
"APPTUNNEL_MOUNTREMOTE_ALLOWED_MOUNT_PREFIX=$data_root_parent" \
"MOUNTREMOTE_ALLOWED_MOUNT_PREFIX=$data_root_parent" \
"LINKEASE_LINKMOUNT_BIN=$LINKEASE_LIBEXEC/linkmount_bin/linkmount_bin" \
"LINKEASE_LINKMOUNT_LIB_DIR=$LINKEASE_LIBEXEC/linkmount_bin/lib" \
"USER_DATA_PATH=$data_root/users/admin" \
"SYSTEM_DATA_PATH=$data_root/system" \
"TEMP_PATH=$data_root/tmp"
procd_set_param respawn
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
service_triggers() {
procd_add_reload_trigger "linkeasefull"
}