added the make package target. Builds a faxien style package.
[otp-base.git] / tools / utilities / clean_release
blob920269079084042761b5be595c0ddb1984dc8eae
1 #!/bin/bash
3 if [ $# -eq 1 ]; then
4 RELEASE_NAME=$1
5 else
6 RELEASE_NAME=$(basename $(dirname $(dirname $(dirname $(which $0)))))
7 fi
9 LOCAL=$(dirname $(which $0))
11 echo $LOCAL
12 echo $RELEASE_NAME
13 cd $LOCAL
15 echo "
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)
24 end,
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_}]} ->
37 Acc ++ ReleaseSpecs_;
38 _ ->
39 Acc
40 end end, [], Dirs),
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))
45 end, Orphans).
46 " > clean_release.erl
48 erlc clean_release.erl
50 CMD="erl -s clean_release clean_release $RELEASE_NAME -s erlang halt -noshell"
51 $CMD