OSDN Git Service

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