Realmfile creation
This commit is contained in:
parent
71661e2027
commit
e60a5d4191
85
zx
85
zx
@ -85,11 +85,15 @@ start(["set", "dep", PackageString]) ->
|
|||||||
set_dep(PackageID);
|
set_dep(PackageID);
|
||||||
start(["set", "version", VersionString]) ->
|
start(["set", "version", VersionString]) ->
|
||||||
set_version(VersionString);
|
set_version(VersionString);
|
||||||
|
start(["add", "realm", RealmFile]) ->
|
||||||
|
add_realm(RealmFile);
|
||||||
start(["drop", "dep", PackageString]) ->
|
start(["drop", "dep", PackageString]) ->
|
||||||
PackageID = package_id(PackageString),
|
PackageID = package_id(PackageString),
|
||||||
drop_dep(PackageID);
|
drop_dep(PackageID);
|
||||||
start(["drop", "key", KeyID]) ->
|
start(["drop", "key", KeyID]) ->
|
||||||
drop_key(KeyID);
|
drop_key(KeyID);
|
||||||
|
start(["drop", "realm", Realm]) ->
|
||||||
|
drop_realm(Realm);
|
||||||
start(["verup", Level]) ->
|
start(["verup", Level]) ->
|
||||||
verup(Level);
|
verup(Level);
|
||||||
start(["runlocal" | Args]) ->
|
start(["runlocal" | Args]) ->
|
||||||
@ -115,6 +119,8 @@ start(["create", "plt"]) ->
|
|||||||
create_plt();
|
create_plt();
|
||||||
start(["create", "realm"]) ->
|
start(["create", "realm"]) ->
|
||||||
create_realm();
|
create_realm();
|
||||||
|
start(["create", "realmfile", Realm]) ->
|
||||||
|
create_realmfile(Realm);
|
||||||
start(["create", "sysop"]) ->
|
start(["create", "sysop"]) ->
|
||||||
create_sysop();
|
create_sysop();
|
||||||
start(_) ->
|
start(_) ->
|
||||||
@ -538,6 +544,22 @@ update_version(Realm, Name, OldVersion, NewVersion, OldMeta) ->
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%% Add realm
|
||||||
|
|
||||||
|
-spec add_realm(Path) -> no_return()
|
||||||
|
when Path :: file:filename().
|
||||||
|
|
||||||
|
add_realm(Path) ->
|
||||||
|
case filelib:is_regular(Path) of
|
||||||
|
true ->
|
||||||
|
ok = log(info, "I would install this now, were I implemented."),
|
||||||
|
halt(0);
|
||||||
|
false ->
|
||||||
|
ok = log(warning, "Realm file not found at ~ts.", [Path]),
|
||||||
|
halt(1)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
%%% Drop dependency
|
%%% Drop dependency
|
||||||
|
|
||||||
-spec drop_dep(package_id()) -> no_return().
|
-spec drop_dep(package_id()) -> no_return().
|
||||||
@ -585,6 +607,15 @@ drop_key({Realm, KeyName}) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
%%% Drop realm
|
||||||
|
|
||||||
|
-spec drop_realm(realm()) -> no_return().
|
||||||
|
|
||||||
|
drop_realm(Realm) ->
|
||||||
|
ok = log(info, "I would totally drop ~ts right now if I could.", [Realm]),
|
||||||
|
halt(0).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%% Update version
|
%%% Update version
|
||||||
|
|
||||||
@ -1695,14 +1726,14 @@ create_realm(ZompConf, Realm, ExAddress, ExPort, InPort, UserName, Email) ->
|
|||||||
Timestamp = calendar:now_to_universal_time(erlang:timestamp()),
|
Timestamp = calendar:now_to_universal_time(erlang:timestamp()),
|
||||||
{ok, RealmPubData} = file:read_file(RealmPub),
|
{ok, RealmPubData} = file:read_file(RealmPub),
|
||||||
RealmPubRecord =
|
RealmPubRecord =
|
||||||
{{Realm, filename:basename(RealmPub)},
|
{{Realm, filename:basename(RealmPub, ".pub.der")},
|
||||||
realm,
|
realm,
|
||||||
{realm, Realm},
|
{realm, Realm},
|
||||||
crypto:hash(sha512, RealmPubData),
|
crypto:hash(sha512, RealmPubData),
|
||||||
Timestamp},
|
Timestamp},
|
||||||
{ok, PackagePubData} = file:read_file(PackagePub),
|
{ok, PackagePubData} = file:read_file(PackagePub),
|
||||||
PackagePubRecord =
|
PackagePubRecord =
|
||||||
{{Realm, filename:basename(PackagePub)},
|
{{Realm, filename:basename(PackagePub, ".pub.der")},
|
||||||
package,
|
package,
|
||||||
{realm, Realm},
|
{realm, Realm},
|
||||||
crypto:hash(sha512, PackagePubData),
|
crypto:hash(sha512, PackagePubData),
|
||||||
@ -1719,7 +1750,13 @@ create_realm(ZompConf, Realm, ExAddress, ExPort, InPort, UserName, Email) ->
|
|||||||
" The package and sysop keys will need to be copied to the ~~/.zomp/keys/~s/~n"
|
" The package and sysop keys will need to be copied to the ~~/.zomp/keys/~s/~n"
|
||||||
" directory on your personal or dev machine.~n",
|
" directory on your personal or dev machine.~n",
|
||||||
ok = io:format(Message, [Realm]),
|
ok = io:format(Message, [Realm]),
|
||||||
UserRecord = {{UserName, Realm}, [SysopPub], Email, RealName, 1, Timestamp},
|
UserRecord =
|
||||||
|
{{UserName, Realm},
|
||||||
|
[filename:basename(SysopPub, ".pub.der")],
|
||||||
|
Email,
|
||||||
|
RealName,
|
||||||
|
1,
|
||||||
|
Timestamp},
|
||||||
RealmFile = filename:join(zomp_dir(), Realm ++ ".realm"),
|
RealmFile = filename:join(zomp_dir(), Realm ++ ".realm"),
|
||||||
RealmMeta =
|
RealmMeta =
|
||||||
[{realm, Realm},
|
[{realm, Realm},
|
||||||
@ -1749,6 +1786,42 @@ create_realm(ZompConf, Realm, ExAddress, ExPort, InPort, UserName, Email) ->
|
|||||||
halt(0).
|
halt(0).
|
||||||
|
|
||||||
|
|
||||||
|
-spec create_realmfile(realm()) -> no_return().
|
||||||
|
|
||||||
|
create_realmfile(Realm) ->
|
||||||
|
ConfPath = filename:join(zomp_dir(), realm_file(Realm)),
|
||||||
|
case file:consult(ConfPath) of
|
||||||
|
{ok, RealmConf} ->
|
||||||
|
ok = log(info, "Realm found, creating realm file..."),
|
||||||
|
{realm_keys, RealmKeys} = lists:keyfind(realm_keys, 1, RealmConf),
|
||||||
|
{package_keys, PackageKeys} = lists:keyfind(package_keys, 1, RealmConf),
|
||||||
|
RealmKeyIDs = [element(1, K) || K <- RealmKeys],
|
||||||
|
PackageKeyIDs = [element(1, K) || K <- PackageKeys],
|
||||||
|
create_realmfile(Realm, ConfPath, RealmKeyIDs, PackageKeyIDs);
|
||||||
|
{error, enoent} ->
|
||||||
|
ok = log(warning, "There is no configured realm called ~ts.", [Realm]),
|
||||||
|
halt(1)
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec create_realmfile(Realm, ConfPath, RealmKeyIDs, PackageKeyIDs) -> ok
|
||||||
|
when Realm :: realm(),
|
||||||
|
ConfPath :: file:filename(),
|
||||||
|
RealmKeyIDs :: [key_id()],
|
||||||
|
PackageKeyIDs :: [key_id()].
|
||||||
|
|
||||||
|
create_realmfile(Realm, ConfPath, RealmKeyIDs, PackageKeyIDs) ->
|
||||||
|
{ok, CWD} = file:get_cwd(),
|
||||||
|
ok = file:set_cwd(zomp_dir()),
|
||||||
|
KeyPath = fun({R, K}) -> filename:join(["key", R, K ++ ".pub.der"]) end,
|
||||||
|
RealmKeyPaths = lists:map(KeyPath, RealmKeyIDs),
|
||||||
|
PackageKeyPaths = lists:map(KeyPath, PackageKeyIDs),
|
||||||
|
Targets = [filename:basename(ConfPath) | RealmKeyPaths ++ PackageKeyPaths],
|
||||||
|
OutFile = filename:join(CWD, Realm ++ ".zrf"),
|
||||||
|
ok = erl_tar:create(OutFile, Targets, [compressed]),
|
||||||
|
ok = log(info, "Realm file written to ~ts", [OutFile]),
|
||||||
|
halt(0).
|
||||||
|
|
||||||
|
|
||||||
-spec create_sysop() -> no_return().
|
-spec create_sysop() -> no_return().
|
||||||
|
|
||||||
create_sysop() ->
|
create_sysop() ->
|
||||||
@ -1835,7 +1908,7 @@ fetch(Socket, PackageID) ->
|
|||||||
|
|
||||||
|
|
||||||
-spec request_zrp(Socket, PackageID) -> Result
|
-spec request_zrp(Socket, PackageID) -> Result
|
||||||
when Socket :: gen_tcp:socket(),
|
when Socket :: gen_tcp:socket(),
|
||||||
PackageID :: package_id(),
|
PackageID :: package_id(),
|
||||||
Result :: {ok, Latest :: package_id()}
|
Result :: {ok, Latest :: package_id()}
|
||||||
| {error, Reason :: timeout | term()}.
|
| {error, Reason :: timeout | term()}.
|
||||||
@ -2484,8 +2557,10 @@ usage() ->
|
|||||||
" zx install PackageID~n"
|
" zx install PackageID~n"
|
||||||
" zx set dep PackageID~n"
|
" zx set dep PackageID~n"
|
||||||
" zx set version Version~n"
|
" zx set version Version~n"
|
||||||
|
" zx add realm RealmFile~n"
|
||||||
" zx drop dep PackageID~n"
|
" zx drop dep PackageID~n"
|
||||||
" zx drop key Realm KeyName~n"
|
" zx drop key Realm KeyName~n"
|
||||||
|
" zx drop realm Realm~n"
|
||||||
" zx verup Level~n"
|
" zx verup Level~n"
|
||||||
" zx runlocal [Args]~n"
|
" zx runlocal [Args]~n"
|
||||||
" zx package [Path]~n"
|
" zx package [Path]~n"
|
||||||
@ -2493,6 +2568,7 @@ usage() ->
|
|||||||
" zx create keypair~n"
|
" zx create keypair~n"
|
||||||
" zx create plt~n"
|
" zx create plt~n"
|
||||||
" zx create realm~n"
|
" zx create realm~n"
|
||||||
|
" zx create realmfile Realm~n"
|
||||||
" zx create sysop~n"
|
" zx create sysop~n"
|
||||||
"~n"
|
"~n"
|
||||||
"Where~n"
|
"Where~n"
|
||||||
@ -2500,6 +2576,7 @@ usage() ->
|
|||||||
" Args :: Arguments to pass to the application~n"
|
" Args :: Arguments to pass to the application~n"
|
||||||
" Type :: The project type: a standalone \"app\" or a \"lib\"~n"
|
" Type :: The project type: a standalone \"app\" or a \"lib\"~n"
|
||||||
" Version :: Version string X, X.Y, or X.Y.Z: \"1\", \"1.2\", \"1.2.3\"~n"
|
" Version :: Version string X, X.Y, or X.Y.Z: \"1\", \"1.2\", \"1.2.3\"~n"
|
||||||
|
" RealmFile :: Path to a valid .zrf realm file~n"
|
||||||
" Realm :: The name of a realm as a string [:a-z:]~n"
|
" Realm :: The name of a realm as a string [:a-z:]~n"
|
||||||
" KeyName :: The prefix of a keypair to drop~n"
|
" KeyName :: The prefix of a keypair to drop~n"
|
||||||
" Level :: The version level, one of \"major\", \"minor\", or \"patch\"~n"
|
" Level :: The version level, one of \"major\", \"minor\", or \"patch\"~n"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user