mirror of
https://github.com/Telecominfraproject/wlan-cloud-loadsim.git
synced 2025-10-29 17:52:34 +00:00
56 lines
2.0 KiB
Erlang
Executable File
56 lines
2.0 KiB
Erlang
Executable File
#!/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.
|