#! /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.