Fix noclean handling
[aquarium] / make-dist.sh
1 #!/usr/bin/env bash
2
3 # Make an Aquarium binary distribution out of current working directory.
4 # Use at your own risk (i.e. make sure it compiles etc).
5
6 WHERE=`dirname $0`
7 SHAFULL=`git rev-parse HEAD`
8 SHA=`echo $SHAFULL | cut -c 1-11`
9 DATE_FORMAT=+'%Y%m%d%H%M%S'
10 NOW=`date $DATE_FORMAT`
11 DIST=aquarium-$SHA
12 SERVER_SCRIPTS_SRC=$WHERE/scripts
13 CONF_SRC=$WHERE/src/main/resources
14 ARG1="$1"
15
16 fail() {
17     echo "failed while $1"
18     exit 1
19 }
20
21 checkdist() {
22     [ -e $DIST ] && {
23         echo Folder $DIST exists. Removing it.
24         rm -rf "$DIST"
25         echo
26     }
27     echo Creating dist dirs
28
29     mkdir -pv $DIST
30     mkdir -pv $DIST/bin
31     mkdir -pv $DIST/lib
32     mkdir -pv $DIST/conf
33     mkdir -pv $DIST/logs
34 }
35
36 clean() {
37     local p="$ARG1"
38     if [ -z "$p" ]; then
39       echo
40       echo "==============================="
41       echo "=== mvn clean ================="
42       echo "==============================="
43       echo
44       mvn clean || fail "cleaning compilation artifacts"
45       echo
46     elif [ "$p"="dev" -o "$p"="fast" -o "$p"="noclean" ]; then
47       echo
48       echo "==============================="
49       echo "=== NOT executing mvn clean ==="
50       echo "==============================="
51       echo
52     fi
53 }
54
55 collectdeps() {
56     mvn dependency:copy-dependencies && cp target/dependency/*.jar $DIST/lib || fail "collecting dependencies"
57 }
58
59 build() {
60     echo
61     echo "==============================="
62     echo "=== mvn package ==============="
63     echo "==============================="
64     echo
65     mvn package -DskipTests && {
66         echo "Copying Aquarium classes"
67         aquariumjar=`find target -type f|egrep "aquarium-[0-9\.]+(-SNAPSHOT)?\.jar"`
68         cp $aquariumjar $DIST/lib || fail "copying $aquariumjar"
69     } || fail "building"
70 }
71
72 collectconf() {
73     echo
74     echo Copying config files from $CONF_SRC
75     echo
76     cp $CONF_SRC/log4j.properties $DIST/conf|| fail "copying log4j.properties"
77     cp $CONF_SRC/aquarium.properties $DIST/conf || fail "copying aquarium.properties"
78     cp $CONF_SRC/policy.yaml $DIST/conf || fail "copying policy.yaml"
79     cp $CONF_SRC/roles-agreements.map $DIST/conf || fail "copying roles-agreements.map"
80 }
81
82 collectscripts() {
83     echo
84     echo Copying scripts from $SERVER_SCRIPTS_SRC
85     echo
86     cp $SERVER_SCRIPTS_SRC/aquarium.sh $DIST/bin || fail "copying aquarium.sh"
87     cp $SERVER_SCRIPTS_SRC/test.sh $DIST/bin || fail "copying test.sh"
88 }
89
90 gitmark() {
91     echo $SHAFULL > $DIST/gitsha.txt
92 }
93
94 archive() {
95     ARC=$DIST.tar.gz
96     echo "Creating archive"
97     tar zcvf $ARC $DIST/ || fail "creating archive"
98     echo "File $ARC created succesfully"
99     echo "Cleaning up"
100     ls -al $ARC
101 }
102
103 checkdist      && \
104 clean          && \
105 build          && \
106 collectdeps    && \
107 collectconf    && \
108 collectscripts && \
109 gitmark        && \
110 archive