--- get the "name" of the current active theme
-function get_theme()
- local _uci = UCI.cursor()
- local _base = _uci:get("luci", "main", "mediaurlbase") -- only pathname
- _uci:unload("luci")
+-- compare versions using "<=" "<" ">" ">=" "=" "<<" ">>"
+function ipkg_ver_compare(ver1, comp, ver2)
+ if not ver1 or not (#ver1 > 0)
+ or not ver2 or not (#ver2 > 0)
+ or not comp or not (#comp > 0) then return nil end
+ -- correct compare string
+ if comp == "<>" or comp == "><" or comp == "!=" or comp == "~=" then comp = "~="
+ elseif comp == "<=" or comp == "<" or comp == "=<" then comp = "<="
+ elseif comp == ">=" or comp == ">" or comp == "=>" then comp = ">="
+ elseif comp == "=" or comp == "==" then comp = "=="
+ elseif comp == "<<" then comp = "<"
+ elseif comp == ">>" then comp = ">"
+ else return nil end
+
+ local av1 = UTIL.split(ver1, "[%.%-]", nil, true)
+ local av2 = UTIL.split(ver2, "[%.%-]", nil, true)
+
+ for i = 1, math.max(table.getn(av1),table.getn(av2)), 1 do
+ local s1 = av1[i] or ""
+ local s2 = av2[i] or ""
+ local n1 = tonumber(s1)
+ local n2 = tonumber(s2)
+
+ -- one numeric and other empty string then set other to 0
+ if n1 and not n2 and (not s2 or #s2 == 0) then n2 = 0 end
+ if n2 and not n1 and (not s1 or #s1 == 0) then n1 = 0 end