This repository was archived by the owner on Nov 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimmanager_config
More file actions
executable file
·55 lines (48 loc) · 1.97 KB
/
simmanager_config
File metadata and controls
executable file
·55 lines (48 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env escript
main([]) ->
try
{ok,DefaultDirName}=file:get_cwd(),
NodeName = input("Please enter a node name", make_nodename() ),
Cookie = input("Please enter a network cookie", "oreo" ),
DirName = input("Please enter a directory name", DefaultDirName ),
WebUiPort = input("Please enter the WEB UI port", "9090" ),
file_substitute(filename:join(["priv","templates","simmanager.config.template"]),
filename:join(["config","sys.config"]),
[{"$$PROJECT_HOME$$",DirName},{"$$WEB_UI_PORT$$",WebUiPort}]),
file_substitute(filename:join(["priv","templates","simmanager.args.template"]),
filename:join(["config","vm.args"]),
[{"$$NODE_NAME$$",NodeName},{"$$COOKIE$$",Cookie}]),
file:make_dir(filename:join(["priv","mnesia"]))
catch
_:_ ->
usage()
end;
main(_) ->
usage().
usage() ->
io:format("usage: mqtt_config <project_home_prefix>~n"),
halt(1).
find_hostname()->
{ok,Hostname}=inet:gethostname(),
{ok,{hostent,_RealHostname,_,inet,4,[A|_]}}=inet_res:gethostbyname(Hostname),
{ok,{hostent,VerifiedHostName,_,inet,4,_}}=inet_res:gethostbyaddr(A),
VerifiedHostName.
make_nodename()->
"simmanager@" ++ find_hostname().
replace([],FinalBlob)->
FinalBlob;
replace([{Variable,Value}|T],Blob) when is_integer(Value)->
replace(T,string:replace(Blob,Variable,integer_to_list(Value),all));
replace([{Variable,Value}|T],Blob) when is_list(Value)->
replace(T,string:replace(Blob,Variable,Value,all)).
file_substitute(FileNameIn,FileNameOut,VariableList)->
{ok,FileBin}=file:read_file(FileNameIn),
FileBlob=binary_to_list(FileBin),
NewBlob=replace(VariableList,FileBlob),
file:write_file(FileNameOut,list_to_binary(NewBlob)).
input(Prompt,Default)->
InputData=string:trim(io:get_line( Prompt ++ " [" ++ Default ++ "] :")),
case InputData=="" of
true -> Default;
false -> InputData
end.