Added update status in luci
This commit is contained in:
parent
01e7fa8d15
commit
ee65368976
@ -3,7 +3,7 @@
|
||||
"description": "mihomo-kit: profiles, OpenVPN, Tailscale",
|
||||
"read": {
|
||||
"ubus": {
|
||||
"mihomo-kit": [ "status", "ovpn_status", "job" ]
|
||||
"mihomo-kit": [ "status", "ovpn_status", "job", "update_check" ]
|
||||
}
|
||||
},
|
||||
"write": {
|
||||
|
||||
@ -11,6 +11,7 @@ var callStatus = rpc.declare({ object: 'mihomo-kit', method: 'status', expect: {
|
||||
var callOvpnStatus = rpc.declare({ object: 'mihomo-kit', method: 'ovpn_status', expect: { '': {} } });
|
||||
var callJob = rpc.declare({ object: 'mihomo-kit', method: 'job', expect: { '': {} } });
|
||||
var callRun = rpc.declare({ object: 'mihomo-kit', method: 'run', params: [ 'cmd', 'arg' ], expect: { '': {} } });
|
||||
var callUpdateCheck = rpc.declare({ object: 'mihomo-kit', method: 'update_check', expect: { '': {} } });
|
||||
var callConfigGet = rpc.declare({ object: 'mihomo-kit', method: 'config_get', expect: { '': {} } });
|
||||
var callConfigSet = rpc.declare({ object: 'mihomo-kit', method: 'config_set', params: [ 'data' ], expect: { '': {} } });
|
||||
|
||||
@ -96,6 +97,16 @@ return view.extend({
|
||||
}));
|
||||
select.value = st.profile;
|
||||
// mihomo serves its external-ui at /ui; metacubexd/zashboard take the API from the query
|
||||
var updState = E('em', 'проверяю обновления…');
|
||||
callUpdateCheck().then(function(u) {
|
||||
if (u.error)
|
||||
return dom.content(updState, '— не удалось проверить обновления: ' + u.error);
|
||||
var link = function(href, text) { return E('a', { 'href': href, 'target': '_blank', 'rel': 'noreferrer' }, text); };
|
||||
if (u.installed && u.installed.indexOf(u.latest) == 0)
|
||||
return dom.content(updState, '— актуальная');
|
||||
dom.content(updState, [ '— ', E('strong', 'есть обновление: '), link(u.commit, u.latest), ' ' + (u.message || '') ]
|
||||
.concat(u.compare ? [ ' (', link(u.compare, 'что изменилось'), ')' ] : []));
|
||||
}).catch(function(e) { dom.content(updState, '— не удалось проверить обновления: ' + e); });
|
||||
var host = window.location.hostname;
|
||||
var dash = 'http://' + host + ':' + st.api_port + '/ui/?hostname=' + encodeURIComponent(host) +
|
||||
'&port=' + st.api_port + (st.api_secret ? '&secret=' + encodeURIComponent(st.api_secret) : '');
|
||||
@ -104,7 +115,7 @@ return view.extend({
|
||||
row('nikki', st.running ? [ 'работает — ',
|
||||
E('a', { 'href': dash, 'target': '_blank', 'rel': 'noreferrer' }, 'открыть дашборд') ]
|
||||
: E('strong', 'остановлен')),
|
||||
row('Версия kit', st.kit_version || 'неизвестна (появится после «Обновить kit»)'),
|
||||
row('Версия kit', [ st.kit_version || 'неизвестна (появится после «Обновить kit»)', ' ', updState ]),
|
||||
row('Профиль', [ select, ' ',
|
||||
this.button('Включить', 'apply', 'use', function() { return select.value; }) ])
|
||||
])
|
||||
|
||||
15
luci/rpcd.sh
15
luci/rpcd.sh
@ -6,6 +6,7 @@
|
||||
# ovpn_status OpenVPN state (up/down/off) + current OTP; slow (a delay test)
|
||||
# run start a whitelisted command as the background job
|
||||
# job the job's command, state, exit code and output
|
||||
# update_check latest kit commit on the git server vs the installed one
|
||||
# config_get settings for the form (secrets: only whether they are set)
|
||||
# config_set save the form (via "mihomo-kit.sh configure") as the job
|
||||
#
|
||||
@ -256,6 +257,17 @@ m_config_set() {
|
||||
start_job mihomo-kit.sh configure "$env"
|
||||
}
|
||||
|
||||
m_update_check() {
|
||||
out=$(mihomo-kit.sh check-update 2>&1) || reply_error "$(echo "$out" | tail -n 1)"
|
||||
json_init
|
||||
echo "$out" > /tmp/mihomo-kit-upd.$$
|
||||
while read -r k v; do
|
||||
json_add_string "$k" "$v"
|
||||
done < /tmp/mihomo-kit-upd.$$
|
||||
rm -f /tmp/mihomo-kit-upd.$$
|
||||
json_dump
|
||||
}
|
||||
|
||||
m_job() {
|
||||
json_init
|
||||
json_add_string cmd "$(cat "$JOB/cmd" 2>/dev/null)"
|
||||
@ -267,7 +279,7 @@ m_job() {
|
||||
|
||||
case "$1" in
|
||||
list)
|
||||
echo '{"status":{},"ovpn_status":{},"job":{},"run":{"cmd":"str","arg":"str"},"config_get":{},"config_set":{"data":{}}}'
|
||||
echo '{"status":{},"ovpn_status":{},"job":{},"run":{"cmd":"str","arg":"str"},"config_get":{},"config_set":{"data":{}},"update_check":{}}'
|
||||
;;
|
||||
call)
|
||||
case "$2" in
|
||||
@ -277,6 +289,7 @@ case "$1" in
|
||||
run) m_run ;;
|
||||
config_get) m_config_get ;;
|
||||
config_set) m_config_set ;;
|
||||
update_check) m_update_check ;;
|
||||
*) reply_error "unknown method" ;;
|
||||
esac
|
||||
;;
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
# mihomo-kit.sh build [name...] profiles.d/<name>.env -> profiles/<name>.yaml (default: all)
|
||||
# mihomo-kit.sh use <name> switch nikki to profiles/<name>.yaml and restart
|
||||
# mihomo-kit.sh update download the latest kit (KIT_URL) and rebuild
|
||||
# mihomo-kit.sh check-update latest commit on the server vs the installed one
|
||||
# mihomo-kit.sh fix re-apply core version + fixes (after a nikki upgrade)
|
||||
# mihomo-kit.sh ts-login [-f] fresh Tailscale node, print its login URL
|
||||
# (-f: also when the node is already logged in)
|
||||
@ -933,6 +934,28 @@ kit_version() {
|
||||
echo "${_sha:-?} $(date '+%Y-%m-%d %H:%M')" > "$KIT_DIR/VERSION"
|
||||
}
|
||||
|
||||
# Latest commit of the KIT_URL branch (Gitea/Forgejo API). Prints lines:
|
||||
# installed <sha>, latest <sha>, message <first line>, commit <url>, compare <url>
|
||||
cmd_check_update() {
|
||||
_repo=${KIT_URL%/archive/*}
|
||||
_branch=${KIT_URL##*/archive/}
|
||||
_branch=${_branch%.tar.gz}
|
||||
_host=${_repo%/*/*}
|
||||
_json=$(wget -q -T 10 -O - "$_host/api/v1/repos/${_repo#"$_host"/}/branches/$_branch") ||
|
||||
die "no answer from $_host"
|
||||
_id=$(jsonfilter -s "$_json" -e '@.commit.id') || die "unexpected answer from $_host"
|
||||
_cur=$(cut -d' ' -f1 "$KIT_DIR/VERSION" 2>/dev/null)
|
||||
_cur=${_cur%-dirty}
|
||||
echo "installed ${_cur:-?}"
|
||||
echo "latest $(echo "$_id" | cut -c1-7)"
|
||||
echo "message $(jsonfilter -s "$_json" -e '@.commit.message' | head -n 1)"
|
||||
echo "commit $_repo/commit/$_id"
|
||||
case "$_cur" in
|
||||
'' | '?') ;;
|
||||
*) echo "compare $_repo/compare/$_cur...$_id" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
cmd_update() {
|
||||
tmp=$(mktemp -d)
|
||||
log "downloading $KIT_URL"
|
||||
@ -967,9 +990,10 @@ case "${1:-}" in
|
||||
configure) shift; cmd_configure "$@" ;;
|
||||
sub-ids) cmd_sub_ids ;;
|
||||
update) cmd_update ;;
|
||||
check-update) cmd_check_update ;;
|
||||
post-update) cmd_post_update ;;
|
||||
install) cmd_install ;;
|
||||
fix) cmd_fix ;;
|
||||
ts-login) shift; cmd_ts_login "$@" ;;
|
||||
*) sed -n '2,26p' "$SELF" >&2; exit 2 ;;
|
||||
*) sed -n '2,27p' "$SELF" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
Loading…
Reference in New Issue
Block a user