So much foo
This commit is contained in:
parent
bd6c747207
commit
98f4b6bdf3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
.eunit
|
.eunit
|
||||||
deps
|
deps
|
||||||
|
tester
|
||||||
*.o
|
*.o
|
||||||
*.beam
|
*.beam
|
||||||
*.plt
|
*.plt
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -37,7 +37,7 @@ list_pending(PackageName) ->
|
|||||||
{ok, {R, N, {z, z, z}}} ->
|
{ok, {R, N, {z, z, z}}} ->
|
||||||
{R, N};
|
{R, N};
|
||||||
{error, invalid_package_string} ->
|
{error, invalid_package_string} ->
|
||||||
zx:error_exit("~tp is not a valid package name.", [PackageName], ?LINE)
|
error_exit("~tp is not a valid package name.", [PackageName], ?LINE)
|
||||||
end,
|
end,
|
||||||
case zx_daemon:list_pending(Package) of
|
case zx_daemon:list_pending(Package) of
|
||||||
{ok, []} ->
|
{ok, []} ->
|
||||||
@ -53,12 +53,12 @@ list_pending(PackageName) ->
|
|||||||
ok = lists:foreach(Print, Versions),
|
ok = lists:foreach(Print, Versions),
|
||||||
halt(0);
|
halt(0);
|
||||||
{error, bad_realm} ->
|
{error, bad_realm} ->
|
||||||
zx:error_exit("Bad realm name.", ?LINE);
|
error_exit("Bad realm name.", ?LINE);
|
||||||
{error, bad_package} ->
|
{error, bad_package} ->
|
||||||
zx:error_exit("Bad package name.", ?LINE);
|
error_exit("Bad package name.", ?LINE);
|
||||||
{error, network} ->
|
{error, network} ->
|
||||||
Message = "Network issues are preventing connection to the realm.",
|
Message = "Network issues are preventing connection to the realm.",
|
||||||
zx:error_exit(Message, ?LINE)
|
error_exit(Message, ?LINE)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -82,12 +82,12 @@ list_resigns(Realm) ->
|
|||||||
ok = lists:foreach(Print, PackageIDs),
|
ok = lists:foreach(Print, PackageIDs),
|
||||||
halt(0);
|
halt(0);
|
||||||
{error, bad_realm} ->
|
{error, bad_realm} ->
|
||||||
zx:error_exit("Bad realm name.", ?LINE);
|
error_exit("Bad realm name.", ?LINE);
|
||||||
{error, no_realm} ->
|
{error, no_realm} ->
|
||||||
zx:error_exit("Realm \"~ts\" is not configured.", ?LINE);
|
error_exit("Realm \"~ts\" is not configured.", ?LINE);
|
||||||
{error, network} ->
|
{error, network} ->
|
||||||
Message = "Network issues are preventing connection to the realm.",
|
Message = "Network issues are preventing connection to the realm.",
|
||||||
zx:error_exit(Message, ?LINE)
|
error_exit(Message, ?LINE)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ add_package(PackageName) ->
|
|||||||
{ok, {Realm, Name, {z, z, z}}} ->
|
{ok, {Realm, Name, {z, z, z}}} ->
|
||||||
add_package(Realm, Name);
|
add_package(Realm, Name);
|
||||||
_ ->
|
_ ->
|
||||||
zx:error_exit("~tp is not a valid package name.", [PackageName], ?LINE)
|
error_exit("~tp is not a valid package name.", [PackageName], ?LINE)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -263,14 +263,14 @@ recv_or_die(Socket) ->
|
|||||||
{ok, Response} ->
|
{ok, Response} ->
|
||||||
{ok, Response};
|
{ok, Response};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
zx:error_exit("Action failed with: ~tp", [Reason], ?LINE);
|
error_exit("Action failed with: ~tp", [Reason], ?LINE);
|
||||||
Unexpected ->
|
Unexpected ->
|
||||||
zx:error_exit("Unexpected message: ~tp", [Unexpected], ?LINE)
|
error_exit("Unexpected message: ~tp", [Unexpected], ?LINE)
|
||||||
end;
|
end;
|
||||||
{tcp_closed, Socket} ->
|
{tcp_closed, Socket} ->
|
||||||
zx:error_exit("Lost connection to node unexpectedly.", ?LINE)
|
error_exit("Lost connection to node unexpectedly.", ?LINE)
|
||||||
after 5000 ->
|
after 5000 ->
|
||||||
zx:error_exit("Connection timed out.", ?LINE)
|
error_exit("Connection timed out.", ?LINE)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -450,3 +450,29 @@ disconnect(Socket) ->
|
|||||||
Message = "Shutdown connection ~p failed with: ~p",
|
Message = "Shutdown connection ~p failed with: ~p",
|
||||||
log(warning, Message, [Socket, Error])
|
log(warning, Message, [Socket, Error])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%% Error exits
|
||||||
|
|
||||||
|
-spec error_exit(Error, Line) -> no_return()
|
||||||
|
when Error :: term(),
|
||||||
|
Line :: non_neg_integer().
|
||||||
|
%% @private
|
||||||
|
%% Format an error message in a way that makes it easy to locate.
|
||||||
|
|
||||||
|
error_exit(Error, Line) ->
|
||||||
|
error_exit(Error, [], Line).
|
||||||
|
|
||||||
|
|
||||||
|
-spec error_exit(Format, Args, Line) -> no_return()
|
||||||
|
when Format :: string(),
|
||||||
|
Args :: [term()],
|
||||||
|
Line :: non_neg_integer().
|
||||||
|
%% @private
|
||||||
|
%% Format an error message in a way that makes it easy to locate.
|
||||||
|
|
||||||
|
error_exit(Format, Args, Line) ->
|
||||||
|
File = filename:basename(?FILE),
|
||||||
|
ok = log(error, "~ts:~tp: " ++ Format, [File, Line | Args]),
|
||||||
|
halt(1).
|
||||||
|
|||||||
@ -11,6 +11,9 @@
|
|||||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||||
-license("GPL-3.0").
|
-license("GPL-3.0").
|
||||||
|
|
||||||
|
% FIXME
|
||||||
|
-compile(export_all).
|
||||||
|
|
||||||
-export([subscribe/2, unsubscribe/2, fetch/3, query/3]).
|
-export([subscribe/2, unsubscribe/2, fetch/3, query/3]).
|
||||||
-export([start/1, stop/1]).
|
-export([start/1, stop/1]).
|
||||||
-export([start_link/1, init/2]).
|
-export([start_link/1, init/2]).
|
||||||
@ -20,9 +23,9 @@
|
|||||||
|
|
||||||
%%% Types
|
%%% Types
|
||||||
|
|
||||||
-type incoming() :: ping
|
%-type incoming() :: ping
|
||||||
| {sub, Channel :: term(), Message :: term()}
|
% | {sub, Channel :: term(), Message :: term()}
|
||||||
| term().
|
% | term().
|
||||||
|
|
||||||
|
|
||||||
%%% Interface
|
%%% Interface
|
||||||
@ -250,7 +253,8 @@ handle_message(Socket, Bin) ->
|
|||||||
Invalid ->
|
Invalid ->
|
||||||
{ok, {Addr, Port}} = zomp:peername(Socket),
|
{ok, {Addr, Port}} = zomp:peername(Socket),
|
||||||
Host = inet:ntoa(Addr),
|
Host = inet:ntoa(Addr),
|
||||||
ok = log(warning, "Invalid message from ~tp:~p: ", [Invalid]),
|
Warning = "Invalid message from ~s:~p: ~tp",
|
||||||
|
ok = log(warning, Warning, [Host, Port, Invalid]),
|
||||||
ok = zx_net:disconnect(Socket),
|
ok = zx_net:disconnect(Socket),
|
||||||
terminate()
|
terminate()
|
||||||
end.
|
end.
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
-license("GPL-3.0").
|
-license("GPL-3.0").
|
||||||
|
|
||||||
-export([ensure_keypair/1, have_public_key/1, have_private_key/1,
|
-export([ensure_keypair/1, have_public_key/1, have_private_key/1,
|
||||||
prompt_keygen/0, create_keypair/0, generate_rsa/1,
|
prompt_keygen/0, grow_a_pair/0, generate_rsa/1,
|
||||||
load/2, verify/3]).
|
load/2, verify/3]).
|
||||||
|
|
||||||
-include("zx_logger.hrl").
|
-include("zx_logger.hrl").
|
||||||
@ -102,16 +102,16 @@ prompt_keygen() ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
-spec create_keypair() -> no_return().
|
-spec grow_a_pair() -> no_return().
|
||||||
%% @private
|
%% @private
|
||||||
%% Execute the key generation procedure for 16k RSA keys once and then terminate.
|
%% Execute the key generation procedure for 16k RSA keys once and then terminate.
|
||||||
|
|
||||||
create_keypair() ->
|
grow_a_pair() ->
|
||||||
ok = file:set_cwd(zx_lib:zomp_dir()),
|
ok = file:set_cwd(zx_lib:zomp_dir()),
|
||||||
KeyID = prompt_keygen(),
|
KeyID = prompt_keygen(),
|
||||||
case generate_rsa(KeyID) of
|
case generate_rsa(KeyID) of
|
||||||
{ok, _, _} -> halt(0);
|
{ok, _, _} -> halt(0);
|
||||||
Error -> zx:error_exit("create_keypair/0 error: ~tp", [Error], ?LINE)
|
Error -> error_exit("grow_a_pair/0 error: ~tp", [Error], ?LINE)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ openssl() ->
|
|||||||
false ->
|
false ->
|
||||||
ok = log(error, "OpenSSL could not be found in this system's PATH."),
|
ok = log(error, "OpenSSL could not be found in this system's PATH."),
|
||||||
ok = log(error, "Install OpenSSL and then retry."),
|
ok = log(error, "Install OpenSSL and then retry."),
|
||||||
zx:error_exit("Missing system dependenct: OpenSSL", ?LINE);
|
error_exit("Missing system dependenct: OpenSSL", ?LINE);
|
||||||
Path ->
|
Path ->
|
||||||
log(info, "OpenSSL executable found at: ~ts", [Path])
|
log(info, "OpenSSL executable found at: ~ts", [Path])
|
||||||
end,
|
end,
|
||||||
@ -276,5 +276,31 @@ load(Type, {Realm, KeyName}) ->
|
|||||||
verify(Data, Signature, PubKey) ->
|
verify(Data, Signature, PubKey) ->
|
||||||
case public_key:verify(Data, sha512, Signature, PubKey) of
|
case public_key:verify(Data, sha512, Signature, PubKey) of
|
||||||
true -> ok;
|
true -> ok;
|
||||||
false -> zx:error_exit("Bad package signature!", ?LINE)
|
false -> error_exit("Bad package signature!", ?LINE)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%% Error exits
|
||||||
|
|
||||||
|
-spec error_exit(Error, Line) -> no_return()
|
||||||
|
when Error :: term(),
|
||||||
|
Line :: non_neg_integer().
|
||||||
|
%% @private
|
||||||
|
%% Format an error message in a way that makes it easy to locate.
|
||||||
|
|
||||||
|
error_exit(Error, Line) ->
|
||||||
|
error_exit(Error, [], Line).
|
||||||
|
|
||||||
|
|
||||||
|
-spec error_exit(Format, Args, Line) -> no_return()
|
||||||
|
when Format :: string(),
|
||||||
|
Args :: [term()],
|
||||||
|
Line :: non_neg_integer().
|
||||||
|
%% @private
|
||||||
|
%% Format an error message in a way that makes it easy to locate.
|
||||||
|
|
||||||
|
error_exit(Format, Args, Line) ->
|
||||||
|
File = filename:basename(?FILE),
|
||||||
|
ok = log(error, "~ts:~tp: " ++ Format, [File, Line | Args]),
|
||||||
|
halt(1).
|
||||||
|
|||||||
@ -29,7 +29,9 @@
|
|||||||
namify_zsp/1, namify_tgz/1,
|
namify_zsp/1, namify_tgz/1,
|
||||||
find_latest_compatible/2, installed/1,
|
find_latest_compatible/2, installed/1,
|
||||||
realm_conf/1, load_realm_conf/1,
|
realm_conf/1, load_realm_conf/1,
|
||||||
extract_zsp_or_die/1, halt_if_exists/1]).
|
extract_zsp_or_die/1, halt_if_exists/1,
|
||||||
|
build/0,
|
||||||
|
rm_rf/1, rm/1]).
|
||||||
|
|
||||||
-include("zx_logger.hrl").
|
-include("zx_logger.hrl").
|
||||||
|
|
||||||
@ -203,7 +205,7 @@ read_project_meta(Dir) ->
|
|||||||
Path = filename:join(Dir, "zomp.meta"),
|
Path = filename:join(Dir, "zomp.meta"),
|
||||||
case file:consult(Path) of
|
case file:consult(Path) of
|
||||||
{ok, Meta} ->
|
{ok, Meta} ->
|
||||||
maps:from_list(Meta);
|
{ok, maps:from_list(Meta)};
|
||||||
Error ->
|
Error ->
|
||||||
ok = log(error, "Failed to open \"zomp.meta\" with ~tp", [Error]),
|
ok = log(error, "Failed to open \"zomp.meta\" with ~tp", [Error]),
|
||||||
ok = log(error, "Wrong directory?"),
|
ok = log(error, "Wrong directory?"),
|
||||||
@ -670,13 +672,13 @@ extract_zsp_or_die(FileName) ->
|
|||||||
Files;
|
Files;
|
||||||
{error, {FileName, enoent}} ->
|
{error, {FileName, enoent}} ->
|
||||||
Message = "Can't find file ~ts.",
|
Message = "Can't find file ~ts.",
|
||||||
zx:error_exit(Message, [FileName], ?LINE);
|
error_exit(Message, [FileName], ?LINE);
|
||||||
{error, invalid_tar_checksum} ->
|
{error, invalid_tar_checksum} ->
|
||||||
Message = "~ts is not a valid zsp archive.",
|
Message = "~ts is not a valid zsp archive.",
|
||||||
zx:error_exit(Message, [FileName], ?LINE);
|
error_exit(Message, [FileName], ?LINE);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
Message = "Extracting package file failed with: ~160tp.",
|
Message = "Extracting package file failed with: ~160tp.",
|
||||||
zx:error_exit(Message, [Reason], ?LINE)
|
error_exit(Message, [Reason], ?LINE)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -687,6 +689,70 @@ extract_zsp_or_die(FileName) ->
|
|||||||
|
|
||||||
halt_if_exists(Path) ->
|
halt_if_exists(Path) ->
|
||||||
case filelib:is_file(Path) of
|
case filelib:is_file(Path) of
|
||||||
true -> zx:error_exit("~ts already exists! Halting.", [Path], ?LINE);
|
true -> error_exit("~ts already exists! Halting.", [Path], ?LINE);
|
||||||
false -> ok
|
false -> ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
-spec build() -> ok.
|
||||||
|
%% @private
|
||||||
|
%% Run any local `zxmake' script needed by the project for non-Erlang code (if present),
|
||||||
|
%% then add the local `ebin/' directory to the runtime search path, and finally build
|
||||||
|
%% the Erlang part of the project with make:all/0 according to the local `Emakefile'.
|
||||||
|
|
||||||
|
build() ->
|
||||||
|
ZxMake = "zxmake",
|
||||||
|
ok =
|
||||||
|
case filelib:is_regular(ZxMake) of
|
||||||
|
true ->
|
||||||
|
Out = os:cmd(ZxMake),
|
||||||
|
log(info, Out);
|
||||||
|
false ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
true = code:add_patha(filename:absname("ebin")),
|
||||||
|
up_to_date = make:all(),
|
||||||
|
ok.
|
||||||
|
|
||||||
|
|
||||||
|
-spec rm_rf(file:filename()) -> ok | {error, file:posix()}.
|
||||||
|
%% @private
|
||||||
|
%% Recursively remove files and directories. Equivalent to `rm -rf'.
|
||||||
|
|
||||||
|
rm_rf(Path) ->
|
||||||
|
case filelib:is_dir(Path) of
|
||||||
|
true ->
|
||||||
|
Pattern = filename:join(Path, "**"),
|
||||||
|
Contents = lists:reverse(lists:sort(filelib:wildcard(Pattern))),
|
||||||
|
ok = lists:foreach(fun rm/1, Contents),
|
||||||
|
file:del_dir(Path);
|
||||||
|
false ->
|
||||||
|
file:delete(Path)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
-spec rm(file:filename()) -> ok | {error, file:posix()}.
|
||||||
|
%% @private
|
||||||
|
%% An omnibus delete helper.
|
||||||
|
|
||||||
|
rm(Path) ->
|
||||||
|
case filelib:is_dir(Path) of
|
||||||
|
true -> file:del_dir(Path);
|
||||||
|
false -> file:delete(Path)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%% Error exits
|
||||||
|
|
||||||
|
-spec error_exit(Format, Args, Line) -> no_return()
|
||||||
|
when Format :: string(),
|
||||||
|
Args :: [term()],
|
||||||
|
Line :: non_neg_integer().
|
||||||
|
%% @private
|
||||||
|
%% Format an error message in a way that makes it easy to locate.
|
||||||
|
|
||||||
|
error_exit(Format, Args, Line) ->
|
||||||
|
File = filename:basename(?FILE),
|
||||||
|
ok = log(error, "~ts:~tp: " ++ Format, [File, Line | Args]),
|
||||||
|
halt(1).
|
||||||
|
|||||||
1177
zomp/lib/otpr/zx/0.1.0/src/zx_local.erl
Normal file
1177
zomp/lib/otpr/zx/0.1.0/src/zx_local.erl
Normal file
File diff suppressed because it is too large
Load Diff
2
zomp/zx
2
zomp/zx
@ -7,4 +7,4 @@ ZX_DIR="$ZOMP_DIR/lib/otpr/zx/$VERSION"
|
|||||||
pushd "$ZX_DIR" > /dev/null
|
pushd "$ZX_DIR" > /dev/null
|
||||||
./make_zx
|
./make_zx
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
erl -pa "$ZX_DIR/ebin" -run zx start $@
|
erl -pa "$ZX_DIR/ebin" -run zx run $@
|
||||||
|
|||||||
@ -6,4 +6,4 @@ set ZX_DIR="%ZOMP_DIR%\lib\otpr\zx\%VERSION%"
|
|||||||
pushd "%ZX_DIR%"
|
pushd "%ZX_DIR%"
|
||||||
escript.exe make_zx
|
escript.exe make_zx
|
||||||
popd
|
popd
|
||||||
erl.exe -pa "%ZX_DIR%/ebin" -run zx start "%*"
|
erl.exe -pa "%ZX_DIR%/ebin" -run zx run "%*"
|
||||||
|
|||||||
10
zx_dev
10
zx_dev
@ -1,13 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
pushd $(dirname $BASH_SOURCE) > /dev/null
|
pushd $(dirname $BASH_SOURCE) > /dev/null
|
||||||
export ZX_DEV_ROOT=$PWD
|
ZX_DEV_ROOT=$PWD
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
export ZOMP_DIR="$ZX_DEV_ROOT/zomp"
|
export ZOMP_DIR="$ZX_DEV_ROOT/tester"
|
||||||
export VERSION=$(cat "$ZOMP_DIR/etc/version.txt")
|
rm -rf "$ZOMP_DIR"
|
||||||
|
cp -r "$ZX_DEV_ROOT/zomp" "$ZOMP_DIR"
|
||||||
|
VERSION=$(cat "$ZOMP_DIR/etc/version.txt")
|
||||||
export ZX_DIR="$ZOMP_DIR/lib/otpr/zx/$VERSION"
|
export ZX_DIR="$ZOMP_DIR/lib/otpr/zx/$VERSION"
|
||||||
|
|
||||||
pushd "$ZX_DIR" > /dev/null
|
pushd "$ZX_DIR" > /dev/null
|
||||||
./make_zx
|
./make_zx
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
erl -pa "$ZX_DIR/ebin" -run zx start $@
|
erl -pa "$ZX_DIR/ebin" -run zx run $@
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user