From 649a75c2bf8e4b7a2a85b3fd8d6c14d2bdd14c9f Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Thu, 4 Jan 2018 20:30:15 +0900 Subject: [PATCH] Nothing --- src/zx.erl | 36 ------------------------------------ zx_install.escript | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 zx_install.escript diff --git a/src/zx.erl b/src/zx.erl index c03de85..aa83610 100644 --- a/src/zx.erl +++ b/src/zx.erl @@ -3216,39 +3216,3 @@ error_exit(Format, Args, Path, Line) -> File = filename:basename(Path), ok = log(error, "~ts:~tp: " ++ Format, [File, Line | Args]), halt(1). - - - -%%% Logger - --spec log(Level, Format) -> ok - when Level :: info - | warning - | error, - Format :: string(). -%% @private -%% @equiv log(Level, Format, []) - -log(Level, Format) -> - log(Level, Format, []). - - --spec log(Level, Format, Args) -> ok - when Level :: info - | warning - | error, - Format :: string(), - Args :: [term()]. -%% @private -%% A logging abstraction to hide whatever logging back end is actually in use. -%% Format must adhere to Erlang format string rules, and the arity of Args must match -%% the provided format. - -log(Level, Format, Args) -> - Tag = - case Level of - info -> "[INFO]"; - warning -> "[WARNING]"; - error -> "[ERROR]" - end, - io:format("~s ~p: " ++ Format ++ "~n", [Tag, self() | Args]). diff --git a/zx_install.escript b/zx_install.escript new file mode 100644 index 0000000..dbb9b2e --- /dev/null +++ b/zx_install.escript @@ -0,0 +1,42 @@ +#! /usr/bin/env escript + +%% ZX install script + +-spec main(Argv :: [string()]) -> no_return(). + +main(_) -> + ZompDir = zomp_dir(), + case filelib:is_dir(ZompDir) of + false -> unpack(ZompDir); + true -> halt(0) + end. + + +-spec unpack(ZompDir :: file:filename()) -> no_return(). + +unpack(ZompDir) -> + ZompFile = filename:join(ZompDir, "zomp.conf"), + ok = filelib:ensure_dir(ZompFile), + ok = erl_tar:extract("zx.tgz", [compressed, {cwd, ZompFile}]), + halt(0). + + +-spec zomp_dir() -> file:filename(). +%% @private +%% Check the host OS and return the absolute path to the zomp filesystem root. + +zomp_dir() -> + case os:type() of + {unix, _} -> + Home = os:getenv("HOME"), + Dir = ".zomp", + filename:join(Home, Dir); + {win32, _} -> + Drive = os:getenv("HOMEDRIVE"), + Path = os:getenv("HOMEPATH"), + Dir = "zomp", + filename:join([Drive, Path, Dir]); + Unknown -> + ok = io:format("zx_install: ERROR Unknown host system type: ~tp", [Unknown]), + halt(1) + end.