6 RELEASE_NAME
=$
(basename $
(dirname $
(dirname $
(dirname $
(which $0)))))
9 LOCAL
=$
(dirname $
(which $0))
16 -module(clean_release).
17 -export([clean_release/1]).
19 clean_release([ReleaseName]) ->
20 RelFile = atom_to_list(ReleaseName) ++ \".rel\",
21 case file:consult(RelFile) of
22 {ok, [{release, {RelName, RelVsn}, ErtsSpec, ReleaseSpecs}]} -> do_rest(RelFile, ReleaseSpecs);
23 {error, Reason} -> io:format(\"ERROR - Could not find file ~s~n\", [RelFile]), exit(Reason)
25 os:cmd(\"cd ../;rm -rf \" ++ string:strip(os:cmd(\"basename `pwd`\"))).
27 do_rest(RelFile, ReleaseSpecs) ->
28 io:format(\"Finding Orphans in ~p among current release specs ~p~n\", [RelFile, ReleaseSpecs]),
29 {ok, FileNameList} = file:list_dir(\"../\"),
30 Dirs = [FileName || FileName <- FileNameList, filelib:is_dir(\"../\" ++ FileName)] --
31 [string:strip(os:cmd(\"basename `pwd`\"), right, $\n)],
32 BigListOfReleaseSpecs = lists:foldl(fun(Dir, Acc) ->
33 OtherRelFile = \"../\" ++ Dir ++ \"/\" ++ RelFile,
34 io:format(\"Checking external release file ~p~n\", [OtherRelFile]),
35 case file:consult(OtherRelFile) of
36 {ok, [{release, {RelName, RelVsn}, ErtsSpec, ReleaseSpecs_}]} ->
41 Orphans = ReleaseSpecs -- BigListOfReleaseSpecs,
42 io:format(\"Removing orphan release specs ~p from ../../lib ~n\", [Orphans]),
43 lists:foreach(fun(Orphan) ->
44 os:cmd(\"rm -rf ../../lib/\" ++ atom_to_list(element(1, Orphan)) ++ \"-\" ++ element(2, Orphan))
48 erlc clean_release.erl
50 CMD
="erl -s clean_release clean_release $RELEASE_NAME -s erlang halt -noshell"