Moving stuff around
This commit is contained in:
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#! /usr/bin/env escript
|
||||
|
||||
%% ZX install script
|
||||
|
||||
-mode(compile).
|
||||
|
||||
-spec main(Argv :: [string()]) -> no_return().
|
||||
|
||||
main(_) ->
|
||||
OS = os:type(),
|
||||
ZompDir = zomp_dir(OS),
|
||||
case filelib:is_dir(ZompDir) of
|
||||
true ->
|
||||
Message = "Installation directory (~ts) already exists. Aborting.~n",
|
||||
ok = io:format(Message, [ZompDir]),
|
||||
halt(0);
|
||||
false ->
|
||||
unpack(OS, ZompDir)
|
||||
end.
|
||||
|
||||
|
||||
-spec unpack(OS, ZompDir) -> no_return()
|
||||
when OS :: {Family :: unix | win32,
|
||||
Name :: atom()},
|
||||
ZompDir :: file:filename().
|
||||
|
||||
unpack(OS, ZompDir) ->
|
||||
BaseDir = filename:dirname(ZompDir),
|
||||
ok = erl_tar:extract("zomp.tar.gz", [compressed, {cwd, BaseDir}]),
|
||||
add_launcher(OS, ZompDir).
|
||||
|
||||
|
||||
-spec add_launcher(OS, ZompDir) -> no_return()
|
||||
when OS :: {Family :: unix | win32,
|
||||
Name :: atom()},
|
||||
ZompDir :: file:filename().
|
||||
|
||||
add_launcher({unix, linux}, ZompDir) ->
|
||||
add_unix_link(ZompDir),
|
||||
ok = io:format("Should attempt a FreeDesktop icon addition here.~n"),
|
||||
halt(0);
|
||||
add_launcher({unix, _}, ZompDir) ->
|
||||
add_unix_link(ZompDir),
|
||||
halt(0);
|
||||
add_launcher({win32, nt}, _ZompDir) ->
|
||||
ok = io:format("This is going to be a bit of a rodeo...~n"),
|
||||
halt(0).
|
||||
|
||||
|
||||
-spec add_unix_link(ZompDir) -> ok
|
||||
when ZompDir :: file:filename().
|
||||
|
||||
add_unix_link(ZompDir) ->
|
||||
Home = filename:dirname(ZompDir),
|
||||
Link = filename:join(Home, "bin/zx"),
|
||||
HomeBin = filename:dirname(Link),
|
||||
Target = filename:join(ZompDir, "zx.sh"),
|
||||
ok = filelib:ensure_dir(Link),
|
||||
LinkCommand = "env LANG=en ln -s " ++ Target ++ " " ++ Link,
|
||||
ModeCommand = "env LANG=en chmod +x " ++ Target,
|
||||
ok = os_cmd(LinkCommand),
|
||||
ok = os_cmd(ModeCommand),
|
||||
Path = os:getenv("PATH"),
|
||||
Parts = string:lexemes(Path, ":"),
|
||||
Message =
|
||||
case lists:member(HomeBin, Parts) of
|
||||
true ->
|
||||
"A link to ~ts has been created at ~ts.~n"
|
||||
"~ts seems to be in $PATH already.~n"
|
||||
"You should be able to run any zomp/zx program by typing `zx` "
|
||||
"from anywhere in your system.~n"
|
||||
"Creating launchers to the link that start specific programs may be "
|
||||
"conveinent.~n"
|
||||
"A desktop launcher would need to run the command:~n"
|
||||
" zx run [some_program]~n"
|
||||
"Or alternately (if ~~/bin/ is not in your launcher's $PATH):~n"
|
||||
" ~ts run [some_program]~n";
|
||||
false ->
|
||||
"A link to ~ts has been created at ~ts. "
|
||||
"~ts seems to be NOT in your $PATH. "
|
||||
"You will need to add that to $PATH if you want to be able to run "
|
||||
"zx by simply typing `zx` from anywhere in your system."
|
||||
"Creating launchers to the link that start specific programs may be "
|
||||
"conveinent.~n"
|
||||
"A desktop launcher would need to run the command:~n"
|
||||
" ~ts run [some_program]~n"
|
||||
end,
|
||||
io:format(Message, [Target, Link, HomeBin, Target]).
|
||||
|
||||
|
||||
-spec os_cmd(Command :: string()) -> ok.
|
||||
|
||||
os_cmd(Command) ->
|
||||
case os:cmd(Command) of
|
||||
"" ->
|
||||
ok;
|
||||
Output ->
|
||||
ok = io:format("Output of: ~tp~n", [Command]),
|
||||
io:format("~ts~n", [Output])
|
||||
end.
|
||||
|
||||
|
||||
-spec zomp_dir(OS) -> file:filename()
|
||||
when OS :: {Family :: unix | win32,
|
||||
Name :: atom()}.
|
||||
%% @private
|
||||
%% Check the host OS and return the absolute path to the zomp filesystem root.
|
||||
|
||||
zomp_dir({unix, _}) ->
|
||||
Home = os:getenv("HOME"),
|
||||
filename:join(Home, "zomp");
|
||||
zomp_dir({win32, _}) ->
|
||||
Drive = os:getenv("HOMEDRIVE"),
|
||||
Path = os:getenv("HOMEPATH"),
|
||||
filename:join([Drive, Path, "zomp"]);
|
||||
zomp_dir(Unknown) ->
|
||||
Message = "zx_install: ERROR Unknown host system type: ~tp",
|
||||
ok = io:format(Message, [Unknown]),
|
||||
halt(1).
|
||||
Reference in New Issue
Block a user