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, {application,zx,
[{description,"An Erlang development tool and Zomp user client"}, [{description,"An Erlang development tool and Zomp user client"},
{vsn,"0.9.2"}, {vsn,"0.10.3"},
{applications,[stdlib,kernel]}, {applications,[stdlib,kernel]},
{modules,[zx,zx_auth,zx_conn,zx_conn_sup,zx_daemon,zx_key, {modules,[zx,zx_auth,zx_conn,zx_conn_sup,zx_daemon,zx_key,
zx_lib,zx_local,zx_net,zx_peer,zx_peer_man, 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 %%% @end
-module(zx). -module(zx).
-vsn("0.9.2"). -vsn("0.10.3").
-behavior(application). -behavior(application).
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>"). -copyright("Craig Everett <zxq9@zxq9.com>").
@ -130,39 +130,39 @@ do(["help", "sysop"]) ->
do(["--version"]) -> do(["--version"]) ->
done(version()); done(version());
do(["run", PackageString | ArgV]) -> do(["run", PackageString | ArgV]) ->
ok = zx_daemon:connect(), ok = connect(),
not_done(run(PackageString, ArgV)); not_done(run(PackageString, ArgV));
do(["integrate", "desktop", PackageString]) -> do(["integrate", "desktop", PackageString]) ->
ok = zx_daemon:connect(), ok = connect(),
done(integrate0(PackageString)); done(integrate0(PackageString));
do(["list", "realms"]) -> do(["list", "realms"]) ->
done(zx_local:list_realms()); done(zx_local:list_realms());
do(["list", "packages", Realm]) -> do(["list", "packages", Realm]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:list_packages(Realm)); done(zx_local:list_packages(Realm));
do(["list", "versions", PackageName]) -> do(["list", "versions", PackageName]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:list_versions(PackageName)); done(zx_local:list_versions(PackageName));
do(["list", "gui"]) -> do(["list", "gui"]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:list_type(gui)); done(zx_local:list_type(gui));
do(["list", "cli"]) -> do(["list", "cli"]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:list_type(cli)); done(zx_local:list_type(cli));
do(["list", "app"]) -> do(["list", "app"]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:list_type(app)); done(zx_local:list_type(app));
do(["list", "lib"]) -> do(["list", "lib"]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:list_type(lib)); done(zx_local:list_type(lib));
do(["latest", PackageString]) -> do(["latest", PackageString]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:latest(PackageString)); done(zx_local:latest(PackageString));
do(["describe", PackageString]) -> do(["describe", PackageString]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:describe(PackageString)); done(zx_local:describe(PackageString));
do(["upgrade"]) -> do(["upgrade"]) ->
ok = zx_daemon:connect(), ok = connect(),
done(upgrade()); done(upgrade());
do(["import", "realm", RealmFile]) -> do(["import", "realm", RealmFile]) ->
done(zx_local:import_realm(RealmFile)); done(zx_local:import_realm(RealmFile));
@ -188,22 +188,22 @@ do(["drop", "mirror", Address]) ->
do(["drop", "mirror", Address, Port]) -> do(["drop", "mirror", Address, Port]) ->
done(zx_local:drop_mirror(Address, Port)); done(zx_local:drop_mirror(Address, Port));
do(["create", "project"]) -> do(["create", "project"]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:create_project()); done(zx_local:create_project());
do(["runlocal" | ArgV]) -> do(["runlocal" | ArgV]) ->
ok = zx_daemon:connect(), ok = connect(),
not_done(run_local(ArgV)); not_done(run_local(ArgV));
do(["rundir", Path | ArgV]) -> do(["rundir", Path | ArgV]) ->
ok = zx_daemon:connect(), ok = connect(),
not_done(run_dir(Path, ArgV)); not_done(run_dir(Path, ArgV));
do(["init"]) -> do(["init"]) ->
ok = zx_daemon:connect(), ok = connect(),
ok = compatibility_check([unix]), ok = compatibility_check([unix]),
done(zx_local:initialize()); done(zx_local:initialize());
do(["list", "deps"]) -> do(["list", "deps"]) ->
done(zx_local:list_deps()); done(zx_local:list_deps());
do(["list", "deps", PackageString]) -> do(["list", "deps", PackageString]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:list_deps(PackageString)); done(zx_local:list_deps(PackageString));
do(["set", "dep", PackageString]) -> do(["set", "dep", PackageString]) ->
done(zx_local:set_dep(PackageString)); done(zx_local:set_dep(PackageString));
@ -216,12 +216,12 @@ do(["set", "version", VersionString]) ->
ok = compatibility_check([unix]), ok = compatibility_check([unix]),
done(zx_local:set_version(VersionString)); done(zx_local:set_version(VersionString));
do(["provides", Module]) -> do(["provides", Module]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:provides(Module)); done(zx_local:provides(Module));
do(["search"]) -> do(["search"]) ->
done(help(user)); done(help(user));
do(["search" | Terms]) -> do(["search" | Terms]) ->
ok = zx_daemon:connect(), ok = connect(),
Strings = string:join(Terms, " "), Strings = string:join(Terms, " "),
done(zx_local:search(Strings)); done(zx_local:search(Strings));
do(["update", "meta"]) -> do(["update", "meta"]) ->
@ -247,7 +247,7 @@ do(["approve", PackageString]) ->
do(["reject", PackageString]) -> do(["reject", PackageString]) ->
done(zx_auth:reject(PackageString)); done(zx_auth:reject(PackageString));
do(["sync", "keys"]) -> do(["sync", "keys"]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_auth:sync_keys()); done(zx_auth:sync_keys());
do(["create", "user"]) -> do(["create", "user"]) ->
done(zx_local:create_user()); done(zx_local:create_user());
@ -266,7 +266,7 @@ do(["list", "packagers", PackageName]) ->
do(["list", "maintainers", PackageName]) -> do(["list", "maintainers", PackageName]) ->
done(zx_auth:list_maintainers(PackageName)); done(zx_auth:list_maintainers(PackageName));
do(["list", "sysops", Realm]) -> do(["list", "sysops", Realm]) ->
ok = zx_daemon:connect(), ok = connect(),
done(zx_local:list_sysops(Realm)); done(zx_local:list_sysops(Realm));
do(["export", "realm"]) -> do(["export", "realm"]) ->
done(zx_local:export_realm()); done(zx_local:export_realm());
@ -335,6 +335,33 @@ not_done(ok) -> ok;
not_done(Error) -> done(Error). 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() -spec compatibility_check(Platforms) -> ok | no_return()
when Platforms :: unix | win32. when Platforms :: unix | win32.
%% @private %% @private
@ -582,7 +609,7 @@ list(Realm, Name, Version) ->
-spec latest(package_id()) -> Result -spec latest(package_id()) -> Result
when Result :: {ok, package_id()} when Result :: {ok, version()}
| {error, Reason}, | {error, Reason},
Reason :: bad_realm Reason :: bad_realm
| bad_package | bad_package
@ -1013,7 +1040,7 @@ upgrade() ->
{ok, Available} when Available < Current -> {ok, Available} when Available < Current ->
{ok, AvailableString} = zx_lib:version_to_string(Available), {ok, AvailableString} = zx_lib:version_to_string(Available),
Message = "Local version is newer than ~s. Nothing to do.", Message = "Local version is newer than ~s. Nothing to do.",
ok = tell(Message, [AvailableString]); tell(Message, [AvailableString]);
Error -> Error ->
Error Error
end. end.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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