fix(core): remove hardcoded fallback version from constants.uc and use dynamic package lookup for APK and OPKG

This commit is contained in:
Dushnilin
2026-07-27 16:49:52 +03:00
parent 0eec769a90
commit f05a55c37e
2 changed files with 43 additions and 3 deletions
+27 -3
View File
@@ -20,9 +20,19 @@ function detect_installed_version() {
if (env_ver != null && env_ver != "")
return env_ver;
try {
let pkgs = require("core.packages");
if (pkgs && pkgs.version) {
let ver = pkgs.version("tachyon");
if (ver != null && ver != "") return ver;
ver = pkgs.version("luci-app-tachyon");
if (ver != null && ver != "") return ver;
}
} catch (e) {}
for (let path in [
"/usr/lib/opkg/info/luci-app-tachyon.control",
"/usr/lib/opkg/info/tachyon.control"
"/usr/lib/opkg/info/tachyon.control",
"/usr/lib/opkg/info/luci-app-tachyon.control"
]) {
let content = fs.readfile(path);
if (content != null) {
@@ -31,7 +41,21 @@ function detect_installed_version() {
}
}
return "1.2.35";
let apk_db = fs.readfile("/lib/apk/db/installed");
if (apk_db != null) {
let lines = split(as_string(apk_db), "\n");
let current_pkg = "";
for (let line in lines) {
if (substr(line, 0, 2) == "P:")
current_pkg = trim(substr(line, 2));
else if ((current_pkg == "tachyon" || current_pkg == "luci-app-tachyon") && substr(line, 0, 2) == "V:") {
let v = match(trim(substr(line, 2)), /^([0-9]+\.[0-9]+\.[0-9]+)/);
if (v && v[1]) return v[1];
}
}
}
return "";
}
function constants_map() {
+16
View File
@@ -179,6 +179,22 @@ function version(package_name) {
return value != "" ? value : opkg_version(package_name);
}
function module_exports() {
return {
installed: installed,
apk_installed: apk_installed,
opkg_installed: opkg_installed,
version: version,
installed_package_version: version,
apk_version: apk_version,
apk_available_version: apk_available_version,
opkg_version: opkg_version
};
}
if (sourcepath(1) != null && sourcepath(1) != "")
return module_exports();
let mode = ARGV[0] || "";
if (mode == "installed")