Implement auto-update

This commit is contained in:
Craig Everett 2020-01-31 16:12:49 +09:00
parent fa3eda079f
commit b08556f0f5
49 changed files with 70 additions and 43 deletions

View File

@ -1 +1 @@
0.9.2
0.10.3

View File

@ -1,6 +1,6 @@
{application,zx,
[{description,"An Erlang development tool and Zomp user client"},
{vsn,"0.9.2"},
{vsn,"0.10.3"},
{applications,[stdlib,kernel]},
{modules,[zx,zx_auth,zx_conn,zx_conn_sup,zx_daemon,zx_key,
zx_lib,zx_local,zx_net,zx_peer,zx_peer_man,

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -24,7 +24,7 @@
%%% @end
-module(zx).
-vsn("0.9.2").
-vsn("0.10.3").
-behavior(application).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
@ -130,39 +130,39 @@ do(["help", "sysop"]) ->
do(["--version"]) ->
done(version());
do(["run", PackageString | ArgV]) ->
ok = zx_daemon:connect(),
ok = connect(),
not_done(run(PackageString, ArgV));
do(["integrate", "desktop", PackageString]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(integrate0(PackageString));
do(["list", "realms"]) ->
done(zx_local:list_realms());
do(["list", "packages", Realm]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:list_packages(Realm));
do(["list", "versions", PackageName]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:list_versions(PackageName));
do(["list", "gui"]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:list_type(gui));
do(["list", "cli"]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:list_type(cli));
do(["list", "app"]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:list_type(app));
do(["list", "lib"]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:list_type(lib));
do(["latest", PackageString]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:latest(PackageString));
do(["describe", PackageString]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:describe(PackageString));
do(["upgrade"]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(upgrade());
do(["import", "realm", RealmFile]) ->
done(zx_local:import_realm(RealmFile));
@ -188,22 +188,22 @@ do(["drop", "mirror", Address]) ->
do(["drop", "mirror", Address, Port]) ->
done(zx_local:drop_mirror(Address, Port));
do(["create", "project"]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:create_project());
do(["runlocal" | ArgV]) ->
ok = zx_daemon:connect(),
ok = connect(),
not_done(run_local(ArgV));
do(["rundir", Path | ArgV]) ->
ok = zx_daemon:connect(),
ok = connect(),
not_done(run_dir(Path, ArgV));
do(["init"]) ->
ok = zx_daemon:connect(),
ok = connect(),
ok = compatibility_check([unix]),
done(zx_local:initialize());
do(["list", "deps"]) ->
done(zx_local:list_deps());
do(["list", "deps", PackageString]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:list_deps(PackageString));
do(["set", "dep", PackageString]) ->
done(zx_local:set_dep(PackageString));
@ -216,12 +216,12 @@ do(["set", "version", VersionString]) ->
ok = compatibility_check([unix]),
done(zx_local:set_version(VersionString));
do(["provides", Module]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:provides(Module));
do(["search"]) ->
done(help(user));
do(["search" | Terms]) ->
ok = zx_daemon:connect(),
ok = connect(),
Strings = string:join(Terms, " "),
done(zx_local:search(Strings));
do(["update", "meta"]) ->
@ -247,7 +247,7 @@ do(["approve", PackageString]) ->
do(["reject", PackageString]) ->
done(zx_auth:reject(PackageString));
do(["sync", "keys"]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_auth:sync_keys());
do(["create", "user"]) ->
done(zx_local:create_user());
@ -266,7 +266,7 @@ do(["list", "packagers", PackageName]) ->
do(["list", "maintainers", PackageName]) ->
done(zx_auth:list_maintainers(PackageName));
do(["list", "sysops", Realm]) ->
ok = zx_daemon:connect(),
ok = connect(),
done(zx_local:list_sysops(Realm));
do(["export", "realm"]) ->
done(zx_local:export_realm());
@ -335,6 +335,33 @@ not_done(ok) -> ok;
not_done(Error) -> done(Error).
-spec connect() -> ok.
connect() ->
ok = zx_daemon:connect(),
ZxDir = os:getenv("ZX_DIR"),
{ok, Meta} = zx_lib:read_project_meta(ZxDir),
Current = element(3, maps:get(package_id, Meta)),
case latest({"otpr", "zx"}) of
{ok, Latest} -> connect(Current, Latest);
{error, bad_realm} -> ok;
Error -> Error
end.
connect(Current, Latest) when Current >= Latest ->
ok;
connect(Current, Latest) when Current < Latest ->
ok = tell("New ZX version found. Upgrading..."),
ok = upgrade(),
{ok, VS} = zx_lib:version_to_string(Latest),
OldZxDir = os:getenv("ZX_DIR"),
NewZxDir = filename:join(filename:dirname(OldZxDir), VS),
true = os:putenv("ZX_VERSION", VS),
true = os:putenv("ZX_DIR", NewZxDir),
ok = tell("Restarting previous operation..."),
init:restart().
-spec compatibility_check(Platforms) -> ok | no_return()
when Platforms :: unix | win32.
%% @private
@ -582,7 +609,7 @@ list(Realm, Name, Version) ->
-spec latest(package_id()) -> Result
when Result :: {ok, package_id()}
when Result :: {ok, version()}
| {error, Reason},
Reason :: bad_realm
| bad_package
@ -1013,7 +1040,7 @@ upgrade() ->
{ok, Available} when Available < Current ->
{ok, AvailableString} = zx_lib:version_to_string(Available),
Message = "Local version is newer than ~s. Nothing to do.",
ok = tell(Message, [AvailableString]);
tell(Message, [AvailableString]);
Error ->
Error
end.

View File

@ -9,7 +9,7 @@
%%% @end
-module(zx_auth).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -7,7 +7,7 @@
%%% @end
-module(zx_conn).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_conn_sup).
-vsn("0.9.2").
-vsn("0.10.3").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -138,7 +138,7 @@
%%% @end
-module(zx_daemon).
-vsn("0.9.2").
-vsn("0.10.3").
-behavior(gen_server).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -8,7 +8,7 @@
%%% @end
-module(zx_key).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -10,7 +10,7 @@
%%% @end
-module(zx_lib).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_local).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_net).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -8,7 +8,7 @@
%%% @end
-module(zx_peer).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -9,7 +9,7 @@
%%% @end
-module(zx_peer_man).
-vsn("0.9.2").
-vsn("0.10.3").
-behavior(gen_server).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_peer_sup).
-vsn("0.9.2").
-vsn("0.10.3").
-behaviour(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -10,7 +10,7 @@
%%% @end
-module(zx_peers).
-vsn("0.9.2").
-vsn("0.10.3").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_proxy).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_sup).
-vsn("0.9.2").
-vsn("0.10.3").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_tty).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_userconf).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -7,7 +7,7 @@
%%% @end
-module(zx_zsp).
-vsn("0.9.2").
-vsn("0.10.3").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -9,7 +9,7 @@
{license,"MIT"}.
{modules,[]}.
{name,"zx"}.
{package_id,{"otpr","zx",{0,9,2}}}.
{package_id,{"otpr","zx",{0,10,3}}}.
{prefix,"zx_"}.
{repo_url,"https://gitlab.com/zxq9/zx"}.
{tags,["tools","package manager","erlang"]}.