%% %% This is part of a blog article: %% http://joefreeman.co.uk/blog/2009/08/deploying-an-erlang-appliance-with-suse-studio/ %% %% Copyright (C) 2009, Joe Freeman %% Available under http://en.wikipedia.org/wiki/MIT_License %% -module(make_release). -export([start/0]). % The name of the release -define(NAME, "Echo Server"). % The release version -define(VERSION, "R1"). % The applications that this release requires -define(APPS, [kernel, stdlib, echo_server]). % The full filename to use for the release files (without the extension) -define(FILENAME, "/usr/local/Echo-1.0/echo-1.0"). %% This is the exported function which should be called to build the %% release. A release file (.rel) is generated, and then a boot script %% (.script) is generated and compiled (.boot). start() -> Release = generate_release(?NAME, ?VERSION, ?APPS), write_to_file(?FILENAME, Release), systools:make_script(?FILENAME, [local]), init:stop(). %% Get version of runtime system, and the specified applications, generate a %% release file and then write it to file. generate_release(Name, Version, Apps) -> ErtsVsn = erlang:system_info(version), lists:foreach(fun(App) -> application:load(App) end, Apps), AppsVsns = lists:map(fun(App) -> {App, get_app_vsn(App)} end, Apps), {release, {Name, Version}, {erts, ErtsVsn}, AppsVsns}. %% Get the version of an application. get_app_vsn(App) -> {ok, Vsn} = application:get_key(App, vsn), Vsn. %% Write terms to a file. This is sort-of the opposite to file:consult/1. %% Beware when using long lists as they may get truncated. Note that ".rel" is %% appended to the filename. write_to_file(Filename, Release) -> FilenameWithExtension = Filename ++ ".rel", {ok, File} = file:open(FilenameWithExtension, write), io:format(File, "~p.", [Release]), file:close(File).