Skip to content

Instantly share code, notes, and snippets.

@dgulinobw
Last active February 16, 2018 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgulinobw/5922c30085bfd9b2ca000076fa7b82b6 to your computer and use it in GitHub Desktop.
Save dgulinobw/5922c30085bfd9b2ca000076fa7b82b6 to your computer and use it in GitHub Desktop.
Create new erlang .rel, .boot, .script files given an existing .rel file. Will create new files based on erlang VM this script is run in.
#!/usr/bin/env escript
%% -*- erlang -*-
%% Author: Drew Gulino
-module(new_rel_file).
-export([main/1]).
write_terms(Filename, List) ->
Format = fun(Term) -> io_lib:format("~tp.~n", [Term]) end,
Text = lists:map(Format, List),
file:write_file(Filename, Text).
main([]) ->
io:format("get_rel_update OLD_REL_FILENAME");
main(Args) ->
OldRelFile = Args,
%20.0+: Appname = hd(string:split(OldRelFile,"_")),
Appname = lists:nth(1,string:tokens(OldRelFile,".")),
io:format("Appname: ~p~n",[Appname]),
{ok, Rel} = file:consult(OldRelFile),
[{release,_,_Erts,Mods}] = Rel,
L = lists:map(fun(M) -> element(1,M) end, Mods),
lists:foreach(fun(M) -> application:load(M) end, L),
Apps = application:loaded_applications(),
As = [{Name,Version} || {Name,_,Version} <- Apps],
NewErtsVersion = erlang:system_info(version),
NewOtpRelease = erlang:system_info(otp_release),
NewRel = {release, {"release",NewOtpRelease}, {erts,NewErtsVersion}, As},
NewFilenameBase = Appname ++ "_" ++ NewErtsVersion,
NewFilename = NewFilenameBase ++ ".rel",
io:format("New Rel File: ~p~n",[NewFilename]),
write_terms(NewFilename, [NewRel]),
io:format("Creating .boot, .script~n"),
Result = systools:make_script(NewFilenameBase, [local]),
io:format("Result: ~p~n", [Result]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment