OSDN Git Service

[FIX] : remove trailing whitespace, require final newline
[alterlinux/alterlinux.git] / fullbuild.sh
1 #!/usr/bin/env bash
2
3 script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && pwd )"
4
5 channnels=(
6     "xfce"
7     "lxde"
8     "cinnamon"
9     "i3"
10 )
11
12 architectures=(
13     "x86_64"
14     "i686"
15 )
16
17 work_dir=temp
18 simulation=false
19 retry=5
20
21
22 # Color echo
23 # usage: echo_color -b <backcolor> -t <textcolor> -d <decoration> [Text]
24 #
25 # Text Color
26 # 30 => Black
27 # 31 => Red
28 # 32 => Green
29 # 33 => Yellow
30 # 34 => Blue
31 # 35 => Magenta
32 # 36 => Cyan
33 # 37 => White
34 #
35 # Background color
36 # 40 => Black
37 # 41 => Red
38 # 42 => Green
39 # 43 => Yellow
40 # 44 => Blue
41 # 45 => Magenta
42 # 46 => Cyan
43 # 47 => White
44 #
45 # Text decoration
46 # You can specify multiple decorations with ;.
47 # 0 => All attributs off (ノーマル)
48 # 1 => Bold on (太字)
49 # 4 => Underscore (下線)
50 # 5 => Blink on (点滅)
51 # 7 => Reverse video on (色反転)
52 # 8 => Concealed on
53
54 echo_color() {
55     local backcolor
56     local textcolor
57     local decotypes
58     local echo_opts
59     local arg
60     local OPTIND
61     local OPT
62
63     echo_opts="-e"
64
65     while getopts 'b:t:d:n' arg; do
66         case "${arg}" in
67             b) backcolor="${OPTARG}" ;;
68             t) textcolor="${OPTARG}" ;;
69             d) decotypes="${OPTARG}" ;;
70             n) echo_opts="-n -e"     ;;
71         esac
72     done
73
74     shift $((OPTIND - 1))
75
76     echo ${echo_opts} "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${*}\e[m"
77 }
78
79
80 # Show an INFO message
81 # $1: message string
82 _msg_info() {
83     local echo_opts="-e"
84     local arg
85     local OPTIND
86     local OPT
87     while getopts 'n' arg; do
88         case "${arg}" in
89             n) echo_opts="${echo_opts} -n" ;;
90         esac
91     done
92     shift $((OPTIND - 1))
93     echo ${echo_opts} "$( echo_color -t '36' '[fullbuild.sh]')    $( echo_color -t '32' 'Info') ${*}"
94 }
95
96
97 # Show an Warning message
98 # $1: message string
99 _msg_warn() {
100     local echo_opts="-e"
101     local arg
102     local OPTIND
103     local OPT
104     while getopts 'n' arg; do
105         case "${arg}" in
106             n) echo_opts="${echo_opts} -n" ;;
107         esac
108     done
109     shift $((OPTIND - 1))
110     echo ${echo_opts} "$( echo_color -t '36' '[fullbuild.sh]') $( echo_color -t '33' 'Warning') ${*}" >&2
111 }
112
113
114 # Show an debug message
115 # $1: message string
116 _msg_debug() {
117     local echo_opts="-e"
118     local arg
119     local OPTIND
120     local OPT
121     while getopts 'n' arg; do
122         case "${arg}" in
123             n) echo_opts="${echo_opts} -n" ;;
124         esac
125     done
126     shift $((OPTIND - 1))
127     if [[ ${debug} = true ]]; then
128         echo ${echo_opts} "$( echo_color -t '36' '[fullbuild.sh]')   $( echo_color -t '35' 'Debug') ${*}"
129     fi
130 }
131
132
133 # Show an ERROR message then exit with status
134 # $1: message string
135 # $2: exit code number (with 0 does not exit)
136 _msg_error() {
137     local echo_opts="-e"
138     local arg
139     local OPTIND
140     local OPT
141     local OPTARG
142     while getopts 'n' arg; do
143         case "${arg}" in
144             n) echo_opts="${echo_opts} -n" ;;
145         esac
146     done
147     shift $((OPTIND - 1))
148     echo ${echo_opts} "$( echo_color -t '36' '[fullbuild.sh]')   $( echo_color -t '31' 'Error') ${1}" >&2
149     if [[ -n "${2:-}" ]]; then
150         exit ${2}
151     fi
152 }
153
154
155
156 trap_exit() {
157     local status=${?}
158     echo
159     _msg_error "fullbuild.sh has been killed by the user."
160     exit ${status}
161 }
162
163
164 build() {
165     options="${share_options} -a ${arch} ${cha}"
166
167     if [[ ! -e "${work_dir}/fullbuild.${cha}_${arch}" ]]; then
168         _msg_info "Build ${cha} with ${arch} architecture."
169         sudo bash ${script_path}/build.sh ${options}
170         touch "${work_dir}/fullbuild.${cha}_${arch}"
171     fi
172     sudo pacman -Sccc --noconfirm > /dev/null 2>&1
173
174     if [[ ! -e "${work_dir}/fullbuild.${cha}_${arch}_jp" ]]; then
175         _msg_info "Build the Japanese version of ${cha} on the ${arch} architecture."
176         sudo bash ${script_path}/build.sh -j ${options}
177         touch "${work_dir}/fullbuild.${cha}_${arch}_jp"
178     fi
179     sudo pacman -Sccc --noconfirm > /dev/null 2>&1
180 }
181
182 _help() {
183     echo "usage ${0} [options] [channel]"
184     echo
185     echo " General options:"
186     echo "    -a <options>       Set other options in build.sh"
187     echo "    -c                 Build all channel (DO NOT specify the channel !!)"
188     echo "    -d                 Use the default build.sh arguments. (${default_options})"
189     echo "    -g                 Use gitversion."
190     echo "    -h                 This help message."
191     echo "    -m <architecture>  Set the architecture to build."
192     echo "    -r <interer>       Set the number of retries."
193     echo "                       Defalut: ${retry}"
194     echo "    -s                 Enable simulation mode."
195     echo
196     echo " !! WARNING !!"
197     echo " Do not set channel or architecture with -a."
198     echo " Be sure to enclose the build.sh argument with '' to avoid mixing it with the fullbuild.sh argument."
199     echo " Example: ${0} -a '-b -k zen'"
200     echo
201     echo "Run \"build.sh -h\" for channel details."
202     echo -n " Channel: "
203     "${script_path}/build.sh" --channellist
204 }
205
206
207 share_options="--noconfirm"
208 default_options="-b -l -u alter -p alter"
209
210 while getopts 'a:dghr:sc' arg; do
211     case "${arg}" in
212         a) share_options="${share_options} ${OPTARG}" ;;
213         c) all_channel=true ;;
214         d) share_options="${share_options} ${default_options}" ;;
215         m) architectures=(${OPTARG}) ;;
216         g)
217             if [[ ! -d "${script_path}/.git" ]]; then
218                 _msg_error "There is no git directory. You need to use git clone to use this feature."
219                 exit 1
220             else
221                 share_options="${share_options} --gitversion"
222             fi
223             ;;
224         s) simulation=true;;
225         r) retry="${OPTARG}" ;;
226         h) _help ; exit 0 ;;
227         *) _help ; exit 1 ;;
228     esac
229 done
230 shift $((OPTIND - 1))
231
232
233 if [[ "${all_channel}" = true  ]]; then
234     if [[ -n "${*}" ]]; then
235         _msg_error "Do not specify the channel." "1"
236     else
237         channnels=($("${script_path}/build.sh" --channellist))
238     fi
239 elif [[ -n "${*}" ]]; then
240     channnels=(${@})
241 fi
242
243 _msg_info "Options: ${share_options}"
244 _msg_info "Press Enter to continue or Ctrl + C to cancel."
245 read
246
247
248 trap 'trap_exit' 1 2 3 15
249
250 if [[ ! -d "${work_dir}" ]]; then
251     mkdir -p "${work_dir}"
252 fi
253
254 for cha in ${channnels[@]}; do
255     for arch in ${architectures[@]}; do
256         if [[ "${simulation}" = true ]]; then
257                 echo "build.sh ${share_options} -a ${arch} ${cha}"
258                 echo "build.sh ${share_options} -j -a ${arch} ${cha}"
259         else
260             for i in $(seq 1 ${retry}); do
261                 if [[ -n $(cat "${script_path}/channels/${cha}/architecture" | grep -h -v ^'#' | grep -x "${arch}") ]]; then
262                     build
263                 fi
264             done
265         fi
266     done
267 done
268
269
270 if [[ "${simulation}" = false ]]; then
271     _msg_info "All editions have been built"
272 fi