mirror of
https://github.com/kenzok8/small-package.git
synced 2026-02-04 05:47:19 +08:00
update 2025-12-29 11:44:37
This commit is contained in:
@@ -9,7 +9,7 @@ LUCI_DEPENDS:=+lsblk +docker +dockerd +luci-lib-taskd +luci-lib-docker +docker-c
|
||||
|
||||
PKG_MAINTAINER:=tkme <tkme@qq.com>
|
||||
|
||||
PKG_VERSION:=1.1.0
|
||||
PKG_VERSION:=1.1.1
|
||||
PKG_RELEASE:=1
|
||||
|
||||
define Package/luci-app-zdinnav/conffiles
|
||||
|
||||
@@ -23,7 +23,10 @@ local resetHttp_button = isResetHttp and ("," .. translate(
|
||||
m = taskd.docker_map("zdinnav", "zdinnav", "/usr/libexec/istorec/zdinnav.sh", translate("ZdinNav"),
|
||||
translate("ZdinNav software is a bookmark management tool for websites.") .. translate("Git website:") ..
|
||||
' <a href=\"https://github.com/MyTkme/ZdinNav-Link\" target=\"_blank\">https://github.com/MyTkme/ZdinNav-Link</a>' ..
|
||||
'<br/>' .. translate("Default Ultra-Super Administrator:zdinnav Password:pwd123") .. '<br/>' ..
|
||||
'<br/>' .. translatef(
|
||||
"If you have any suggestions for this program, please join my %sgroup — your participation will help make it even better!",
|
||||
"<a target=\"_blank\" href=\"https://qm.qq.com/q/2jzO6bYQEI\">QQ</a>") .. '<br/>' ..
|
||||
translate("Default Ultra-Super Administrator:zdinnav Password:pwd123") .. '<br/>' ..
|
||||
(isInstalled and (translate(
|
||||
"If you forget the super administrator passwor, you can <a href=\"javascript:void(0)\" onclick=\"onResetPassword()\">reset it here</a>") ..
|
||||
resetHttp_button) or ""))
|
||||
@@ -52,16 +55,13 @@ s.anonymous = true
|
||||
s:tab("general", translate("General Settings"),
|
||||
translate("The following parameters will only take effect during installation or upgrade."))
|
||||
|
||||
-- 第一次安装时的配置
|
||||
if not isInstalled then
|
||||
-- 高级设置(第二个页签)
|
||||
s:tab("advanced", translate("Advanced Settings"), translate(
|
||||
"Takes effect when the database is initially created, or when the /ZdinNav/ folder under the configuration file path does not contain any data.") ..
|
||||
"<br/><span style=\"color:red;\">" ..
|
||||
translate(
|
||||
"Modifying errors may result in data loss or system failure to boot properly. Please proceed with caution!") ..
|
||||
"</span>")
|
||||
end
|
||||
-- 高级设置(第二个页签)
|
||||
s:tab("advanced", translate("Advanced Settings"), translate(
|
||||
"Takes effect when the database is initially created, or when the /ZdinNav/ folder under the configuration file path does not contain any data.") ..
|
||||
"<br/><span style=\"color:red;\">" ..
|
||||
translate(
|
||||
"Modifying errors may result in data loss or system failure to boot properly. Please proceed with caution!") ..
|
||||
"</span>")
|
||||
|
||||
-- 第一个标签页的选项
|
||||
o = s:taboption("general", Value, "port", translate("Port") .. "<b>*</b>")
|
||||
@@ -82,47 +82,42 @@ end
|
||||
o.default = default_path
|
||||
|
||||
-- 离线安装配置
|
||||
if not isInstalled then
|
||||
local auto_arch = util.trim(util.exec("/usr/libexec/istorec/zdinnav.sh auto_get_arch"))
|
||||
o = s:taboption("general", Flag, "enable_offline_installation", translate("Enable Offline Installation"))
|
||||
o.default = "0"
|
||||
o.rmempty = false
|
||||
local auto_arch = util.trim(util.exec("/usr/libexec/istorec/zdinnav.sh auto_get_arch"))
|
||||
o = s:taboption("general", Flag, "enable_offline_installation", translate("Enable Offline Installation"))
|
||||
o.default = "0"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:taboption("general", DummyValue, "offline_installation_path", translate("Offline Installation Path"))
|
||||
o:depends("enable_offline_installation", "1")
|
||||
o.template = "cbi/dvalue"
|
||||
o.rawhtml = true
|
||||
o.value = [[<div>]] .. translate("Offline Installation Description") .. auto_arch .. [[<br/>]] ..
|
||||
translate("Offline Installation Path Rules") .. [[(]] .. translate("Config path") ..
|
||||
[[/downloads/*.tar):<span class="span-offline-installation-path" name="span_offline_installation_path">]] ..
|
||||
default_path ..
|
||||
[[/downloads/*.tar</span><br/><button class="a-btn-offline btn cbi-button cbi-button-apply" type="button" onclick="offline_installation_Verify()">]] ..
|
||||
translate("Offline Installation Path Verify") .. [[</button></div>]]
|
||||
o = s:taboption("general", DummyValue, "offline_installation_path", translate("Offline Installation Path"))
|
||||
o:depends("enable_offline_installation", "1")
|
||||
o.template = "cbi/dvalue"
|
||||
o.rawhtml = true
|
||||
o.value = [[<div>]] .. translate("Offline Installation Description") .. auto_arch .. [[<br/>]] ..
|
||||
translate("Offline Installation Path Rules") .. [[(]] .. translate("Config path") ..
|
||||
[[/downloads/*.tar):<span class="span-offline-installation-path" name="span_offline_installation_path">]] ..
|
||||
default_path ..
|
||||
[[/downloads/*.tar</span><br/><button class="a-btn-offline btn cbi-button cbi-button-apply" type="button" onclick="offline_installation_Verify()">]] ..
|
||||
translate("Offline Installation Path Verify") .. [[</button></div>]]
|
||||
|
||||
o = s:taboption("general", Value, "config_path_change_tag")
|
||||
o.template = "zdinnav/local_install"
|
||||
o.default = "config_path"
|
||||
o.datatype = "enable_offline_installation"
|
||||
end
|
||||
o = s:taboption("general", Value, "config_path_change_tag")
|
||||
o.template = "zdinnav/local_install"
|
||||
o.default = "config_path"
|
||||
o.datatype = "enable_offline_installation"
|
||||
|
||||
-- 第一次安装时的配置
|
||||
if not isInstalled then
|
||||
-- 第二个标签页的选项
|
||||
o = s:taboption("advanced", Value, "database_type", translate("Database Type"))
|
||||
o.datatype = "string"
|
||||
o:value("Sqlite", "Sqlite")
|
||||
o:value("PostgreSQL", "PostgreSQL")
|
||||
o:value("MySql", "MySql")
|
||||
-- 第二个标签页的选项
|
||||
o = s:taboption("advanced", Value, "database_type", translate("Database Type"))
|
||||
o.datatype = "string"
|
||||
o:value("Sqlite", "Sqlite")
|
||||
o:value("PostgreSQL", "PostgreSQL")
|
||||
o:value("MySql", "MySql")
|
||||
|
||||
o = s:taboption("advanced", Value, "connection_settings", translate("Connection Settings"))
|
||||
o.datatype = "string"
|
||||
o = s:taboption("advanced", Value, "connection_settings", translate("Connection Settings"))
|
||||
o.datatype = "string"
|
||||
|
||||
o = s:taboption("advanced", Value, "administrator_account", translate("Administrator Account"))
|
||||
o.datatype = "string"
|
||||
o = s:taboption("advanced", Value, "administrator_account", translate("Administrator Account"))
|
||||
o.datatype = "string"
|
||||
|
||||
o = s:taboption("advanced", Value, "administrator_password", translate("Password"))
|
||||
o.password = true
|
||||
o.datatype = "string"
|
||||
end
|
||||
o = s:taboption("advanced", Value, "administrator_password", translate("Password"))
|
||||
o.password = true
|
||||
o.datatype = "string"
|
||||
|
||||
return m
|
||||
|
||||
@@ -54,7 +54,7 @@ local container_running = container_status == "running"
|
||||
<input
|
||||
class="btn cbi-button cbi-button-apply"
|
||||
name="start"
|
||||
onclick="window.open('<%=protocol_type%>://'+location.hostname+':<%=port%>/', '_blank')"
|
||||
onclick="window.open('<%=protocol_type%>://'+location.hostname+':<%=port%>/','智淀导航','noopener')"
|
||||
type="button"
|
||||
value="<%:Open ZdinNav%>"
|
||||
/>
|
||||
|
||||
@@ -7,6 +7,9 @@ msgstr "智淀导航"
|
||||
msgid "ZdinNav software is a bookmark management tool for websites."
|
||||
msgstr "智淀导航:网站书签管理的工具,"
|
||||
|
||||
msgid "If you have any suggestions for this program, please join my %sgroup — your participation will help make it even better!"
|
||||
msgstr "如果你对该程序有建议可以加入到我的 %s群 ,欢迎你的加入它更完美!"
|
||||
|
||||
msgid "Default Ultra-Super Administrator:zdinnav Password:pwd123"
|
||||
msgstr "默认超高级管理员:zdinnav 密码:pwd123"
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ msgstr "智淀导航"
|
||||
msgid "ZdinNav software is a bookmark management tool for websites."
|
||||
msgstr "智淀导航:网站书签管理的工具,"
|
||||
|
||||
msgid "If you have any suggestions for this program, please join my %sgroup — your participation will help make it even better!"
|
||||
msgstr "如果你对该程序有建议可以加入到我的 %s群 ,欢迎你的加入它更完美!"
|
||||
|
||||
msgid "Default Ultra-Super Administrator:zdinnav Password:pwd123"
|
||||
msgstr "默认超高级管理员:zdinnav 密码:pwd123"
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
config main
|
||||
option 'port' '9200'
|
||||
option 'config_path' ''
|
||||
option 'enable_offline_installation' '0'
|
||||
option 'database_type' 'Sqlite'
|
||||
option 'connection_settings' 'Data Source=ZdinNav.db;Mode=ReadWriteCreate;Password=ZdinNav'
|
||||
option 'administrator_account' 'zdinnav'
|
||||
option 'administrator_password' 'pwd123'
|
||||
|
||||
config zdinnav_config
|
||||
option 'docker_url' 'tkme/zdinnav'
|
||||
option 'version_hub_url' 'https://registry.hub.docker.com/v2/repositories/tkme/zdinnav/tags/'
|
||||
option 'version_url' 'https://raw.githubusercontent.com/MyTkme/ZdinNav-Link/refs/heads/main/version/version.txt'
|
||||
option 'version' '1.0.0'
|
||||
71
luci-app-zdinnav/root/etc/uci-defaults/luci-app-zdinnav
Executable file
71
luci-app-zdinnav/root/etc/uci-defaults/luci-app-zdinnav
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/bin/sh
|
||||
|
||||
# 生成到:config rule 'zdinnav_config' 节点下面
|
||||
# uci -q batch <<-EOF >/dev/null
|
||||
# delete zdinnav.zdinnav_config
|
||||
# set zdinnav.zdinnav_config=rule
|
||||
# set zdinnav.zdinnav_config.name='zdinnav'
|
||||
# set zdinnav.zdinnav_config.test_option='test'
|
||||
# commit zdinnav
|
||||
# EOF
|
||||
|
||||
# 配置文件路径
|
||||
zdinnav_config="/etc/config/zdinnav"
|
||||
|
||||
# 用户的基本配置数据(如果之前存在记录,将会保存)
|
||||
zdinnav_main_port=""
|
||||
zdinnav_main_config_path=""
|
||||
zdinnav_main_enable_offline_installation=""
|
||||
zdinnav_main_database_type=""
|
||||
zdinnav_main_connection_settings=""
|
||||
zdinnav_main_administrator_account=""
|
||||
zdinnav_main_administrator_password=""
|
||||
# 隐藏的配置信息
|
||||
zdinnav_config_version="1.0.0"
|
||||
|
||||
# 如果存在旧版文件(保留用户配置,并删除文件)
|
||||
if [ -f "$zdinnav_config" ]; then
|
||||
# 读取用户的旧版配置信息
|
||||
zdinnav_main_port=$(uci get zdinnav.@main[0].port 2>/dev/null || echo "")
|
||||
zdinnav_main_config_path=$(uci get zdinnav.@main[0].config_path 2>/dev/null || echo "")
|
||||
zdinnav_main_database_type=$(uci get zdinnav.@main[0].database_type 2>/dev/null || echo "")
|
||||
zdinnav_main_connection_settings=$(uci get zdinnav.@main[0].connection_settings 2>/dev/null || echo "")
|
||||
zdinnav_main_administrator_account=$(uci get zdinnav.@main[0].administrator_account 2>/dev/null || echo "")
|
||||
zdinnav_main_administrator_password=$(uci get zdinnav.@main[0].administrator_password 2>/dev/null || echo "")
|
||||
# 隐藏的配置信息
|
||||
zdinnav_config_version=$(uci get zdinnav.@zdinnav_config[0].version 2>/dev/null || echo "1.0.0")
|
||||
# 删除旧版配置信息
|
||||
rm -f "$zdinnav_config"
|
||||
fi
|
||||
|
||||
# 重新创建文件
|
||||
touch "$zdinnav_config"
|
||||
|
||||
# 生成新的配置信息
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
add zdinnav main
|
||||
set zdinnav.@main[0].port='$zdinnav_main_port'
|
||||
set zdinnav.@main[0].config_path='$zdinnav_main_config_path'
|
||||
set zdinnav.@main[0].enable_offline_installation='0'
|
||||
set zdinnav.@main[0].database_type='$zdinnav_main_database_type'
|
||||
set zdinnav.@main[0].connection_settings='$zdinnav_main_connection_settings'
|
||||
set zdinnav.@main[0].administrator_account='$zdinnav_main_administrator_account'
|
||||
set zdinnav.@main[0].administrator_password='$zdinnav_main_administrator_password'
|
||||
|
||||
add zdinnav zdinnav_config
|
||||
set zdinnav.@zdinnav_config[0].version='$zdinnav_config_version'
|
||||
|
||||
add zdinnav zdinnav_const_config
|
||||
set zdinnav.@zdinnav_const_config[0].default_port='9200'
|
||||
set zdinnav.@zdinnav_const_config[0].default_database_type='Sqlite'
|
||||
set zdinnav.@zdinnav_const_config[0].default_connection_settings='Data Source=ZdinNav.db;Mode=ReadWriteCreate;Password=ZdinNav'
|
||||
set zdinnav.@zdinnav_const_config[0].default_administrator_account='zdinnav'
|
||||
set zdinnav.@zdinnav_const_config[0].default_administrator_password='pwd123'
|
||||
set zdinnav.@zdinnav_const_config[0].docker_url='tkme/zdinnav'
|
||||
set zdinnav.@zdinnav_const_config[0].git_url='https://github.com/MyTkme/ZdinNav-Link'
|
||||
set zdinnav.@zdinnav_const_config[0].version_hub_url='https://registry.hub.docker.com/v2/repositories/tkme/zdinnav/tags/'
|
||||
set zdinnav.@zdinnav_const_config[0].version_url='https://raw.githubusercontent.com/MyTkme/ZdinNav-Link/refs/heads/main/version/version.txt'
|
||||
commit zdinnav
|
||||
EOF
|
||||
|
||||
exit 0
|
||||
@@ -13,6 +13,17 @@ auto_arch() {
|
||||
esac
|
||||
}
|
||||
|
||||
# 设置文件夹权限
|
||||
file_permissions() {
|
||||
local config_path="$1"
|
||||
#设置文件夹权限
|
||||
# chmod 777 "$config_path" 2>/dev/null
|
||||
# 递归设置目录权限
|
||||
find "$config_path" -type d -exec chmod 777 {} \; 2>/dev/null
|
||||
# 递归设置文件权限
|
||||
find "$config_path" -type f -exec chmod 766 {} \; 2>/dev/null
|
||||
}
|
||||
|
||||
# 创建文件夹
|
||||
create_folder() {
|
||||
local config_path="$1"
|
||||
@@ -20,11 +31,10 @@ create_folder() {
|
||||
local config_password="$3"
|
||||
local config_database="$4"
|
||||
local config_connection="$5"
|
||||
|
||||
[ ! -d "$config_path/logs" ] && mkdir -p "$config_path/logs"
|
||||
[ ! -d "$config_path/database" ] && mkdir -p "$config_path/database"
|
||||
[ ! -d "$config_path/configuration" ] && mkdir -p "$config_path/configuration"
|
||||
# 设置文件夹权限
|
||||
chmod -R 777 "$config_path"
|
||||
|
||||
# 数据库初始化配置
|
||||
sed -e "s|ACCOUNT_VAR|${config_account}|g" \
|
||||
@@ -34,6 +44,9 @@ create_folder() {
|
||||
sed -e "s|DBTYPE_VAR|${config_database}|g" \
|
||||
-e "s|CONNECTIONSTRING_VAR|${config_connection}|g" \
|
||||
"/usr/share/zdinnav/zdinNavSettings.json" >"${config_path}/configuration/zdinNavSettings.json"
|
||||
|
||||
# 设置文件夹权限
|
||||
file_permissions "$config_path"
|
||||
}
|
||||
|
||||
# 创建docker可以执行的接口命令
|
||||
@@ -154,10 +167,12 @@ compare_versions() {
|
||||
# 获取最新版号
|
||||
get_version() {
|
||||
local platform="$1"
|
||||
local version_url=$(uci get zdinnav.@zdinnav_config[0].version_url 2>/dev/null)
|
||||
local version_hub_url=$(uci get zdinnav.@zdinnav_config[0].version_hub_url 2>/dev/null)
|
||||
local version_url=$(uci get zdinnav.@zdinnav_const_config[0].version_url 2>/dev/null)
|
||||
local version_hub_url=$(uci get zdinnav.@zdinnav_const_config[0].version_hub_url 2>/dev/null)
|
||||
local content=""
|
||||
|
||||
echo "智淀导航docker版本获取中...,Fetching ZdinNav Docker version..." >&2
|
||||
|
||||
# 检查wget是否安装
|
||||
if ! which wget >/dev/null 2>&1; then
|
||||
echo "错误: wget未安装!Error: wget is not installed!" >&2
|
||||
@@ -210,36 +225,12 @@ get_version() {
|
||||
echo "$version"
|
||||
}
|
||||
|
||||
# 合并配置文件
|
||||
merge_config() {
|
||||
local zdinnav_config="/etc/config/zdinnav"
|
||||
local zdinnav_config_opkg="/etc/config/zdinnav-opkg"
|
||||
# 检查是否需要合并
|
||||
if [ ! -f "$zdinnav_config" ] || [ ! -f "$zdinnav_config_opkg" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# 1.1.0 新加配置
|
||||
local version_hub_url=$(uci get zdinnav.@zdinnav_config[0].version_hub_url 2>/dev/null)
|
||||
if [ -z "$version_hub_url" ]; then
|
||||
local version_hub_url_opkg=$(uci get zdinnav-opkg.@zdinnav_config[0].version_hub_url 2>/dev/null)
|
||||
uci set zdinnav.@zdinnav_config[0].version_hub_url=$version_hub_url_opkg
|
||||
fi
|
||||
|
||||
# 提交配置
|
||||
uci commit zdinnav
|
||||
# 删除新版配置文件
|
||||
chmod 777 "$zdinnav_config_opkg" 2>/dev/null
|
||||
rm -f "$zdinnav_config_opkg"
|
||||
}
|
||||
|
||||
# 安装
|
||||
do_install() {
|
||||
# 检查配置是否需要合并
|
||||
merge_config
|
||||
# 读取配置文件数据
|
||||
local port=$(uci get zdinnav.@main[0].port 2>/dev/null)
|
||||
local config=$(uci get zdinnav.@main[0].config_path 2>/dev/null)
|
||||
local docker_url=$(uci get zdinnav.@zdinnav_config[0].docker_url 2>/dev/null)
|
||||
local docker_url=$(uci get zdinnav.@zdinnav_const_config[0].docker_url 2>/dev/null)
|
||||
local version=$(uci get zdinnav.@zdinnav_config[0].version 2>/dev/null)
|
||||
local offline_installation=$(uci get zdinnav.@main[0].enable_offline_installation 2>/dev/null)
|
||||
local zdinnav_account=$(uci get zdinnav.@main[0].administrator_account 2>/dev/null)
|
||||
@@ -250,6 +241,7 @@ do_install() {
|
||||
|
||||
if [ -z "$config" ]; then
|
||||
echo "config path is empty!"
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -257,6 +249,7 @@ do_install() {
|
||||
RET=$?
|
||||
if [ ! "$RET" = "0" ]; then
|
||||
echo "mkdir config path failed"
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -269,15 +262,13 @@ do_install() {
|
||||
local version_local="${basename#*_}"
|
||||
if [ -z "$version_local" ]; then
|
||||
echo "无法解析安装包,请不要修改安装包文件名。Unable to parse the installation package. Do not modify its file name."
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
# 停止并删除并旧版本
|
||||
local docker_state=$(docker ps --all -f 'name=^/zdinnav' --format '{{.State}}')
|
||||
if [ -n "$docker_state" ]; then
|
||||
if [ "$docker_state" = "running" ]; then
|
||||
docker stop zdinnav
|
||||
fi
|
||||
docker rm zdinnav
|
||||
docker rm -f zdinnav
|
||||
fi
|
||||
if [[ "$(docker images -q $docker_url:$version 2>/dev/null)" != "" ]]; then
|
||||
docker rmi "$docker_url:$version"
|
||||
@@ -286,6 +277,7 @@ do_install() {
|
||||
docker load -i "$latest_tar"
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo "docker load 执行失败,请检查*.tar安装包是否正确。The 'docker load' command failed. Please verify the integrity of the *.tar file."
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
version=$version_local
|
||||
@@ -293,10 +285,12 @@ do_install() {
|
||||
local zdinnav_tag=$(docker images --format "{{.Repository}} {{.Tag}} {{.CreatedAt}}" | grep -E ".*/zdinnav" | sort -r | head -n 1 | awk '{print $2}')
|
||||
if [ "$zdinnav_tag" != "$version"]; then
|
||||
echo "安装失败,请重新下载安装包,下载后勿修改,放至指定位置后重装。Installation failed. Redownload the package unmodified, move it to the specified location, and retry installation."
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "无法找到安装包。Cannot find the installation package."
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
@@ -317,6 +311,7 @@ do_install() {
|
||||
RET=$?
|
||||
if [ ! "$RET" = "0" ]; then
|
||||
echo "convert docker-compose.yaml failed"
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -336,15 +331,16 @@ do_install() {
|
||||
if [[ -z "$zdinnav_State" || "$zdinnav_State" != "running" ]]; then
|
||||
echo "智淀导航运行失败,请检查*.tar安装包是否支持该平台。The zdinnav application failed to start. Ensure the *.tar package is compatible with the current platform."
|
||||
# 移除错误docker数据
|
||||
docker stop zdinnav
|
||||
docker rm zdinnav
|
||||
docker rm -f zdinnav
|
||||
docker rmi "$docker_url:$version"
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 更新版本记录
|
||||
uci set zdinnav.@zdinnav_config[0].version=$version
|
||||
uci set zdinnav.@main[0].enable_offline_installation='0'
|
||||
uci commit zdinnav
|
||||
|
||||
if [[ -n "$latest_tar" && -f "$latest_tar" ]]; then
|
||||
@@ -354,19 +350,21 @@ do_install() {
|
||||
|
||||
# 升级/应用
|
||||
do_upgrade() {
|
||||
# 检查配置是否需要合并
|
||||
merge_config
|
||||
# 读取配置文件数据
|
||||
local port=$(uci get zdinnav.@main[0].port 2>/dev/null)
|
||||
local config=$(uci get zdinnav.@main[0].config_path 2>/dev/null)
|
||||
local docker_url=$(uci get zdinnav.@zdinnav_config[0].docker_url 2>/dev/null)
|
||||
local docker_url=$(uci get zdinnav.@zdinnav_const_config[0].docker_url 2>/dev/null)
|
||||
local version=$(uci get zdinnav.@zdinnav_config[0].version 2>/dev/null)
|
||||
local offline_installation=$(uci get zdinnav.@main[0].enable_offline_installation 2>/dev/null)
|
||||
local zdinnav_account=$(uci get zdinnav.@main[0].administrator_account 2>/dev/null)
|
||||
local zdinnav_password=$(uci get zdinnav.@main[0].administrator_password 2>/dev/null)
|
||||
local zdinnav_database=$(uci get zdinnav.@main[0].database_type 2>/dev/null)
|
||||
local zdinnav_connection=$(uci get zdinnav.@main[0].connection_settings 2>/dev/null)
|
||||
local latest_tar=""
|
||||
|
||||
if [ -z "$config" ]; then
|
||||
echo "config path is empty!"
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -374,32 +372,86 @@ do_upgrade() {
|
||||
RET=$?
|
||||
if [ ! "$RET" = "0" ]; then
|
||||
echo "mkdir config path failed"
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 获取最新版
|
||||
local latest_version=$(get_version "$(auto_arch)")
|
||||
local is_update=$(compare_versions "$latest_version" "$version")
|
||||
|
||||
# 检查是否需要升级应用
|
||||
if [ "$is_update" = "1" ]; then
|
||||
echo "发现新版本:$latest_version。New version found: $latest_version."
|
||||
local docker_state=$(docker ps --all -f 'name=^/zdinnav' --format '{{.State}}')
|
||||
if [ -n "$docker_state" ]; then
|
||||
if [ "$docker_state" = "running" ]; then
|
||||
docker stop zdinnav
|
||||
if [ "$offline_installation" = "1" ]; then
|
||||
# 离线升级(检查安装包是否存在需要检查安装包是否存在)
|
||||
latest_tar=$(ls -t "$config/downloads/"*.tar 2>/dev/null | head -n 1)
|
||||
if [ -n "$latest_tar" ]; then
|
||||
local basename="${latest_tar%.tar}"
|
||||
# 获取版本号:zdinnav_linux-amd64-1.0.0.tar 返回:linux-amd64-1.0.0
|
||||
local version_local="${basename#*_}"
|
||||
if [ -z "$version_local" ]; then
|
||||
echo "无法解析安装包,请不要修改安装包文件名。Unable to parse the installation package. Do not modify its file name."
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
docker rm zdinnav
|
||||
local is_update=$(compare_versions "$version_local" "$version")
|
||||
if [ "$is_update" -ne 1 ]; then
|
||||
# 删除安装包
|
||||
rm -f "$latest_tar"
|
||||
echo "当前已经是最新版:$version。You're already on the latest version: $version." >&2
|
||||
return 0
|
||||
fi
|
||||
# 停止并删除并旧版本
|
||||
local docker_state=$(docker ps --all -f 'name=^/zdinnav' --format '{{.State}}')
|
||||
if [ -n "$docker_state" ]; then
|
||||
docker rm -f zdinnav
|
||||
fi
|
||||
if [[ "$(docker images -q $docker_url:$version 2>/dev/null)" != "" ]]; then
|
||||
docker rmi "$docker_url:$version"
|
||||
fi
|
||||
# 安装docker离线文件
|
||||
docker load -i "$latest_tar"
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo "docker load 执行失败,请检查*.tar安装包是否正确。The 'docker load' command failed. Please verify the integrity of the *.tar file."
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
version=$version_local
|
||||
# 离线安装版本检查
|
||||
local zdinnav_tag=$(docker images --format "{{.Repository}} {{.Tag}} {{.CreatedAt}}" | grep -E ".*/zdinnav" | sort -r | head -n 1 | awk '{print $2}')
|
||||
if [ "$zdinnav_tag" != "$version"]; then
|
||||
echo "安装失败,请重新下载安装包,下载后勿修改,放至指定位置后重装。Installation failed. Redownload the package unmodified, move it to the specified location, and retry installation."
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "无法找到安装包。Cannot find the installation package."
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$(docker images -q $docker_url:$version 2>/dev/null)" != "" ]]; then
|
||||
docker rmi "$docker_url:$version"
|
||||
fi
|
||||
# 更新版本
|
||||
version=$latest_version
|
||||
else
|
||||
if [[ -n "$latest_version" && "$latest_version" != "1" ]]; then
|
||||
echo "当前已经是最新版:$version。You're already on the latest version: $version."
|
||||
# 获取最新版
|
||||
local latest_version=$(get_version "$(auto_arch)")
|
||||
# 这里只能判断是否为空(为空表示无法获取最新版本号)
|
||||
if [ -z "$latest_version" ]; then
|
||||
sleep 1
|
||||
return 1
|
||||
fi
|
||||
local is_update=$(compare_versions "$latest_version" "$version")
|
||||
# 检查是否需要升级应用
|
||||
if [ "$is_update" -eq 1 ]; then
|
||||
echo "发现新版本:$latest_version。New version found: $latest_version."
|
||||
local docker_state=$(docker ps --all -f 'name=^/zdinnav' --format '{{.State}}')
|
||||
if [ -n "$docker_state" ]; then
|
||||
docker rm -f zdinnav
|
||||
fi
|
||||
if [[ "$(docker images -q $docker_url:$version 2>/dev/null)" != "" ]]; then
|
||||
docker rmi "$docker_url:$version"
|
||||
fi
|
||||
# 更新版本
|
||||
version=$latest_version
|
||||
else
|
||||
if [[ -n "$latest_version" && "$latest_version" != "1" ]]; then
|
||||
echo "当前已经是最新版:$version。You're already on the latest version: $version."
|
||||
sleep 1
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
[ -z $port ] && port=9200
|
||||
@@ -411,31 +463,50 @@ do_upgrade() {
|
||||
RET=$?
|
||||
if [ ! "$RET" = "0" ]; then
|
||||
echo "convert docker-compose.yaml failed"
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $config
|
||||
# 创建文件夹,创建配置文件
|
||||
$(create_folder "$config" "$zdinnav_account" "$zdinnav_password" "$zdinnav_database" "$zdinnav_connection")
|
||||
|
||||
cd $config
|
||||
|
||||
docker-compose down || true
|
||||
docker-compose up -d
|
||||
|
||||
# 离线安装时,校验
|
||||
if [ "$offline_installation" = "1" ]; then
|
||||
# 休眠3秒后,校验是否正常运行
|
||||
sleep 3
|
||||
local zdinnav_State=$(docker ps --all -f 'name=^/zdinnav' --format '{{.State}}')
|
||||
if [[ -z "$zdinnav_State" || "$zdinnav_State" != "running" ]]; then
|
||||
echo "智淀导航运行失败,请检查*.tar安装包是否支持该平台。The zdinnav application failed to start. Ensure the *.tar package is compatible with the current platform."
|
||||
# 移除错误docker数据
|
||||
docker rm -f zdinnav
|
||||
docker rmi "$docker_url:$version"
|
||||
sleep 1
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 更新版本记录
|
||||
uci set zdinnav.@zdinnav_config[0].version=$version
|
||||
uci set zdinnav.@main[0].enable_offline_installation='0'
|
||||
uci commit zdinnav
|
||||
|
||||
if [[ -n "$latest_tar" && -f "$latest_tar" ]]; then
|
||||
rm -f "$latest_tar"
|
||||
fi
|
||||
}
|
||||
|
||||
# 移除应用
|
||||
do_remove() {
|
||||
local docker_url=$(uci get zdinnav.@zdinnav_config[0].docker_url 2>/dev/null)
|
||||
local docker_url=$(uci get zdinnav.@zdinnav_const_config[0].docker_url 2>/dev/null)
|
||||
local version=$(uci get zdinnav.@zdinnav_config[0].version 2>/dev/null)
|
||||
local docker_state=$(docker ps --all -f 'name=^/zdinnav' --format '{{.State}}')
|
||||
if [ -n "$docker_state" ]; then
|
||||
if [ "$docker_state" = "running" ]; then
|
||||
docker stop zdinnav
|
||||
fi
|
||||
docker rm zdinnav
|
||||
docker rm -f zdinnav
|
||||
fi
|
||||
if [[ "$(docker images -q $docker_url:$version 2>/dev/null)" != "" ]]; then
|
||||
docker rmi "$docker_url:$version"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"luci-app-zdinnav": {
|
||||
"description": "Grant UCI access for luci-app-zdinnav",
|
||||
"read": {
|
||||
"uci": [ "zdinnav" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "zdinnav" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user