silence
[m6w6/btr] / lib / btr / btr.sh
1 #!/bin/sh
2
3 function help {
4 echo "btr v0.2.0, (c) Michael Wallner <mike@php.net>"
5 echo
6 echo "Usage: $(basename $0) [-hv] [<options>] <repository>"
7 echo
8 echo " -h, --help Display this help"
9 echo " -v, --verbose Be more verbose"
10 echo
11 echo " Options:"
12 echo " -s, --source=<rules> Use the specified source ruleset"
13 echo " -b, --build=<rules> Use the specified build ruleset"
14 echo " -r, --report=<rules> Use the specifued report ruleset"
15 echo " -B, --branch=<branch> Checkout this branch"
16 echo " -D, --directory=<directory> Use this directory as work root"
17 echo " -S, --suffix=<suffix> Append suffix to the build name"
18 echo " -C, --configure=<options> Define \$CONFIGURE options"
19 echo
20 echo " Rulesets:"
21 for ruleset in source build report
22 do
23 printf " %10s: %s\n" $ruleset \
24 "$(find "$LIBDIR/$ruleset" -name '*.mk' -exec basename {} .mk \; | sort | xargs)"
25 done
26 echo
27 exit
28 }
29
30 function parseopts {
31 local shortoptions="hvB:D:S:C:s:b:r:"
32 local longoptions="help,verbose,branch:,directory:,suffix:,configure:,source:,build:,report:"
33 local options=$(getopt \
34 --options "$shortoptions" \
35 --longoptions "$longoptions" \
36 -- "$@" \
37 )
38
39 if test $? -ne 0 ; then
40 help
41 fi
42
43 eval set -- "$options"
44
45 while test $# -gt 0
46 do
47 case "$1" in
48 -h|--help)
49 help
50 ;;
51 -v|--verbose)
52 VERBOSE=true
53 ;;
54 ####
55 -B|--branch)
56 BRANCH="$2"
57 shift
58 ;;
59 -D|--directory)
60 BTRDIR="$2"
61 shift
62 ;;
63 -S|--suffix)
64 SUFFIX="$2"
65 shift
66 ;;
67 -C|--configure)
68 CONFIGURE="$2"
69 shift
70 ;;
71 ####
72 -s|--source)
73 case "$2" in
74 git)
75 SOURCE_RULES="git"
76 test -z "$BRANCH" && BRANCH="master"
77 ;;
78 svn)
79 SOURCE_RULES="svn"
80 test -z "$BRANCH" && BRANCH="trunk"
81 ;;
82 esac
83 shift
84 ;;
85 -b|--build)
86 case "$2" in
87 *)
88 BUILD_RULES="$2"
89 ;;
90 esac
91 shift
92 ;;
93 -r|--report)
94 case "$2" in
95 *)
96 REPORT_RULES="$2"
97 ;;
98 esac
99 shift
100 ;;
101 ####
102 --)
103 SOURCE_URL="$2"
104 shift
105 ;;
106 esac
107 shift
108 done
109 }
110
111 function error {
112 echo "$@" >&2
113 exit
114 }
115
116 function setup {
117 if test -z "$SOURCE_URL" -o -z "$SOURCE_RULES" -o -z "$BUILD_RULES" -o -z "$REPORT_RULES"
118 then
119 help
120 fi
121
122 export SOURCE_URL BRANCH SOURCE_RULES BUILD_RULES REPORT_RULES
123
124 if test -z "$BTRDIR"
125 then
126 export BTRDIR="/tmp/btr"
127 else
128 export BTRDIR=$(realpath "$BTRDIR")
129 fi
130
131 export REPO=$(basename $(sed -re 's~^.*[/:]~~' <<<"$SOURCE_URL") .git)
132 export SAFE_BRANCH=$(tr ":" "_" <<<$(basename "$BRANCH"))
133
134 if test -z "$SUFFIX"
135 then
136 export BUILD="$REPO@$SAFE_BRANCH"
137 else
138 export BUILD="$REPO@$SAFE_BRANCH-$SUFFIX"
139 fi
140
141 export CLEAN_DIR="btr+clean-$REPO"
142 export BRANCH_DIR="btr+branch-$REPO@$SAFE_BRANCH"
143 export BUILD_DIR="btr+build-$BUILD"
144 export CONFIG_REPORT="btr+config-$BUILD-$DATE"
145 export BUILD_REPORT="btr+build-$BUILD-$DATE"
146 export TEST_REPORT="btr+tests-$BUILD-$DATE"
147 export LAST_REPORT=$(basename $(ls -t "$BTRDIR/btr+tests-$BUILD"* 2>/dev/null | tail -n1) 2>/dev/null)
148 export REPORT=""
149 }
150
151 function show_conf {
152 echo
153 echo "BTRDIR = $BTRDIR"
154 echo "BINDIR = $BINDIR"
155 echo "LIBDIR = $LIBDIR"
156 echo "SOURCE_URL = $SOURCE_URL"
157 echo "SOURCE_RULES = $SOURCE_RULES"
158 echo "BUILD_RULES = $BUILD_RULES"
159 echo "REPORT_RULES = $REPORT_RULES"
160 echo "BRANCH = $BRANCH"
161 echo "SAFE_BRANCH = $SAFE_BRANCH"
162 echo "CLEAN_DIR = $CLEAN_DIR"
163 echo "BRANCH_DIR = $BRANCH_DIR"
164 echo "BUILD_DIR = $BUILD_DIR"
165 echo "CONFIG_REPORT = $CONFIG_REPORT"
166 echo "BUILD_REPORT = $BUILD_REPORT"
167 echo "TEST_REPORT = $TEST_REPORT"
168 echo "LAST_REPORT = $LAST_REPORT"
169 echo
170 }
171
172 function confirm {
173 local CONTINUE
174 echo -n "$1 (y/N) "
175 read -r CONTINUE
176 case $CONTINUE in
177 y*|Y*)
178 echo
179 ;;
180 *)
181 exit -1
182 ;;
183 esac
184 }
185
186 # vim: noet