OSDN Git Service

[update] : i3チャンネルでライブ環境限定のショートカットを表示するように
[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     "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 "    -d                 Use the default build.sh arguments. (${default_options})"
188     echo "    -g                 Use gitversion."
189     echo "    -h                 This help message."
190     echo "    -m <architecture>  Set the architecture to build."
191     echo "    -r <interer>       Set the number of retries."
192     echo "                       Defalut: ${retry}"
193     echo "    -s                 Enable simulation mode."
194     echo
195     echo " !! WARNING !!"
196     echo " Do not set channel or architecture with -a."
197     echo " Be sure to enclose the build.sh argument with '' to avoid mixing it with the fullbuild.sh argument."
198     echo " Example: ${0} -a '-b -k zen'"
199     echo
200     echo "Run \"build.sh -h\" for channel details."
201     echo -n " Channel: "
202     "${script_path}/build.sh" --channellist
203 }
204
205
206 share_options="--noconfirm"
207 default_options="-b -l"
208
209 while getopts 'a:dghr:s' arg; do
210     case "${arg}" in
211         a) share_options="${share_options} ${OPTARG}" ;;
212         d) share_options="${share_options} ${default_options}" ;;
213         m) architectures=(${OPTARG}) ;;
214         g) 
215             if [[ ! -d "${script_path}/.git" ]]; then
216                 _msg_error "There is no git directory. You need to use git clone to use this feature."
217                 exit 1
218             else
219                 share_options="${share_options} --gitversion"
220             fi
221             ;;
222         s) simulation=true;;
223         r) retry="${OPTARG}" ;;
224         h) _help ; exit 0 ;;
225         *) _help ; exit 1 ;;
226     esac
227 done
228 shift $((OPTIND - 1))
229
230 if [[ -n "${*}" ]]; then
231     channnels=(${@})
232 fi
233
234 _msg_info "Options: ${share_options}"
235 _msg_info "Press Enter to continue or Ctrl + C to cancel."
236 read
237
238
239 trap 'trap_exit' 1 2 3 15
240
241 if [[ ! -d "${work_dir}" ]]; then
242     mkdir -p "${work_dir}"
243 fi
244
245 for cha in ${channnels[@]}; do
246     for arch in ${architectures[@]}; do
247         for i in $(seq 1 ${retry}); do
248             if [[ "${simulation}" = true ]]; then
249                 echo "build.sh ${share_options} -a ${arch} ${cha}"
250             else
251                 build
252             fi
253         done
254     done
255 done
256
257
258 _msg_info "All editions have been built"