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