OSDN Git Service

bbba485aef65f1360d7521e9222902b4c023b324
[alterlinux/LUBS.git] / lubs
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: GPL-3.0
3 #
4 # mk-linux419
5 # Twitter: @fascoder_4
6 # Email  : m.k419sabuaka@gmail.com
7 #
8 # Yamada Hayao
9 # Twitter: @Hayao0819
10 # Email  : hayao@fascode.net
11 #
12 # (c) 2019-2020 Fascode Network.
13 #
14 # lubs
15 #
16
17 set -e
18 # set -u
19
20 export LANG=C
21
22 script_path=$(readlink -f "${0%/*}")
23
24 cache_dir="${script_path}/cache"
25 channels_dir="${script_path}/channels"
26 nfb_dir="${script_path}/nfb"
27
28 codename="focal"
29 mirror="http://linux.yz.yamagata-u.ac.jp/ubuntu/"
30 os_name="Ubuntu"
31 iso_name="ubuntu"
32
33 arch=amd64
34 work_dir="${script_path}/work"
35 out_dir="${script_path}/out"
36 iso_label="${os_name}_${codename}_${arch}"
37 iso_publisher='Fascode Network <https://fascode.net>'
38 iso_application="${os_name} Live/Rescue CD"
39 iso_version="${codename}-$(date +%Y.%m.%d)"
40 iso_filename="${iso_name}-${iso_version}-${arch}.iso"
41
42 channel_name="serene"
43
44 username="liveuser"
45 password="liveuser"
46 usershell="/bin/bash"
47
48 debug=false
49 cache_only=false
50
51
52 start_time="$(date +%s)"
53
54 _msg_common() {
55     if [[ "${debug}" = true ]]; then
56         local _current_time
57         local _time
58         _current_time="$(date +%s)"
59         _time="$(("${_current_time}"-"${start_time}"))"
60
61         if [[ "${_time}" -ge 3600 ]]; then
62             echo "[$(date -d @${_time} +%H:%M.%S)]$("${script_path}/echo_color" -t 6 "[LUBS Core]")"
63         elif [[ "${_time}" -ge 60 ]]; then
64             echo "[00:$(date -d @${_time} +%M.%S)]$("${script_path}/echo_color" -t 6 "[LUBS Core]")"
65         else
66             echo "[00:00.$(date -d @${_time} +%S)] $("${script_path}/echo_color" -t 6 "[LUBS Core]")"
67         fi
68     else
69         "${script_path}/echo_color" -t 6 "[LUBS Core]"
70     fi
71 }
72
73 # Show an INFO message
74 # _msg_info <message>
75 _msg_info() {
76     local _msg
77     _msg="${@}"
78     echo "$(_msg_common)  $("${script_path}/echo_color" -t 2 "Info:") ${_msg}"
79 }
80
81 # Show an debug message
82 # _msg_debug <message>
83 _msg_debug() {
84     if [[ "${debug}" = true ]]; then
85         local _msg
86         _msg="${@}"
87         echo "$(_msg_common)  $("${script_path}/echo_color" -t 3 "Debug:") ${_msg}"
88     fi
89 }
90
91 # Show an ERROR message then exit with status
92 # _msg_error <message> <exit code>
93 _msg_error() {
94     local _msg
95     local _error
96     _msg="${1}"
97     _error=${2}
98     echo "$(_msg_common)  $("${script_path}/echo_color" -t 1 "Error:") ${_msg}"
99
100     if [[ ! ${_error} = 0 ]]; then
101         exit ${_error}
102     fi
103 }
104
105 # Unmount chroot dir
106 umount_chroot () {
107     local mount
108
109     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
110         _msg_info "Unmounting ${mount}"
111         umount -fl "${mount}"
112     done
113 }
114
115 # Helper function to run make_*() only one time.
116 run_once() {
117     local name
118     umount_chroot
119     name="$1"
120
121     if [[ ! -e "${work_dir}/build.${name}" ]]; then
122         _msg_info "$(echo $name | sed "s@_@ @g") is starting."
123         "${1}"
124         _msg_info "$(echo $name | sed "s@_@ @g") was done!"
125         touch "${work_dir}/build.${name}"
126     fi
127 }
128
129 run_cmd() {
130     local mount
131
132     for mount in "dev" "dev/pts" "proc" "sys" "run/systemd/resolve/stub-resolv.conf"; do
133         if [[ "${mount}" == "run/systemd/resolve/stub-resolv.conf" ]]; then
134             mount --bind /etc/resolv.conf "${work_dir}/airootfs/${mount}"
135         else
136             mount --bind /${mount} "${work_dir}/airootfs/${mount}"
137         fi
138     done
139     
140     chroot "${work_dir}/airootfs" "${@}"
141
142     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
143         umount -fl "${mount}"
144     done
145 }
146
147 _apt_install() {
148     run_cmd apt-get --no-install-recommends --yes install ${@}
149 }
150
151 # rm helper
152 # Delete the file if it exists.
153 # For directories, rm -rf is used.
154 # If the file does not exist, skip it.
155 # remove <file> <file> ...
156 remove() {
157     local _list
158     local _file
159     _list=($(echo "$@"))
160
161     for _file in "${_list[@]}"; do
162         _msg_debug "Removeing ${_file}"
163
164         if [[ -f ${_file} ]]; then
165             rm -f "${_file}"
166         elif [[ -d ${_file} ]]; then
167             rm -rf "${_file}"
168         fi
169     done
170 }
171
172 # Show help
173 _usage () {
174     echo "usage ${0} [options] [channel]"
175     echo
176     echo " General options:"
177     echo
178     echo "    -a | --arch <str>      Set architecture"
179     echo "                           Default: ${arch}"
180     echo "    -c | --codename <str>  Set ubuntu codename"
181     echo "                           Default: ${codename}"
182     echo "    -m | --mirror <url>    Set apt mirror server."
183     echo "                           Default: ${mirror}"
184     echo "    -o | --out <out_dir>   Set the output directory"
185     echo "                           Default: ${out_dir}"
186     echo "    -w | --work <work_dir> Set the working directory"
187     echo "                           Default: ${work_dir}"
188     echo
189     echo "    -d | --debug           "
190     echo "    -h | --help            This help message and exit"
191     echo
192     echo "You can switch between installed packages, files included in images, etc. by channel."
193     echo
194     echo " Channel:"
195     
196     local _channel
197     local channel_list
198     local description
199
200     for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
201         if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
202             channel_list+=( "${_channel}" )
203         fi
204     done
205
206     for _channel in ${channel_list[@]}; do
207         if [[ -f "${channels_dir}/${_channel}/description.txt" ]]; then
208             description=$(cat "${channels_dir}/${_channel}/description.txt")
209         else
210             description="This channel does not have a description.txt."
211         fi
212
213         echo -ne "    ${_channel}"
214
215         for i in $( seq 1 $(( 23 - ${#_channel} )) ); do
216             echo -ne " "
217         done
218         
219         echo -ne "${description}\n"
220     done
221 }
222
223
224 prepare_build() {
225     if [[ ${EUID} -ne 0 ]]; then
226         _msg_error "This script must be run as root." 1
227     fi
228
229     [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
230     [[ ! -d "${out_dir}" ]] && mkdir -p "${out_dir}"
231     umount_chroot
232
233     # Check codename
234     if [[ -z $(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename}) ]]; then
235         _msg_error "This codename (${channel_name}) is not supported on this channel (${codename})."
236     fi
237
238 }
239
240
241 make_basefs() {
242     local debootstrap_status
243     statusfile="${cache_dir}/${codename}/status"
244
245     debootstrap_status() {
246         if [[ ! -d "$(dirname ${statusfile})" ]]; then
247             mkdir -p "$(dirname ${statusfile})"
248         fi
249         echo "${1}" > "${statusfile}"
250     }
251
252     if [[ -f "${statusfile}" ]] && [[ $(cat "${statusfile}" 2> /dev/null) = "Done" ]]; then
253         _msg_info "${codename} cache is found."
254     else
255         remove "${cache_dir}/${codename}"
256         debootstrap_status "Running"
257         _msg_info "Installing Ubuntu to '${cache_dir}/${codename}/airootfs'..."
258         mkdir -p "${cache_dir}/${codename}/airootfs"
259         debootstrap --arch="${arch}" --verbose --merged-usr "${codename}" "${cache_dir}/${codename}/airootfs" "${mirror}"
260         _msg_info "${codename} installed successfully!"
261         debootstrap_status "Done"
262     fi
263
264     if [[ "${cache_only}" = true ]]; then
265         exit 0
266     fi
267
268     rm -rf "${work_dir}/airootfs" && mkdir -p "${work_dir}/airootfs"
269     _msg_info "copy base files from '${cache_dir}/${codename}/airootfs' to '${work_dir}/airootfs'..."
270     rsync  -au "${cache_dir}/${codename}/airootfs/" "${work_dir}/airootfs"
271     echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' >> "${work_dir}/airootfs/etc/bash.bashrc"
272     run_cmd apt-get update
273     # run_cmd apt-get upgrade
274 }
275
276 make_sourcelist() {
277     cp ${script_path}/source.list.d/${codename}/* ${work_dir}/airootfs/etc/apt
278     sed -i "s@http://archive.ubuntu.com/ubuntu/@${mirror}@g"  ${work_dir}/airootfs/etc/apt/sources.list
279     run_cmd apt-get update
280
281     if [[ -n $(find ${channels_dir}/*/repo -type f) ]]; then
282         _apt_install gnupg
283
284         for repo in $(find ${channels_dir}/*/repo -name '*.list'); do
285             key="$(dirname ${repo})/$(basename ${repo} | sed "s/list/key/")"
286
287             if [[ -f "${key}" ]]; then
288                 if file ${key} | grep -q "PGP/GPG key"; then
289                     cp "${key}" "${work_dir}/airootfs/$(basename ${key})"
290                 else
291                     wget -q -O "${work_dir}/airootfs/$(basename ${key})" "$(cat ${key})"
292                 fi
293
294                 run_cmd apt-key add "$(basename ${key})"
295                 rm "${work_dir}/airootfs/$(basename ${key})"
296                 cp "${repo}" "${work_dir}/airootfs/etc/apt/sources.list.d"
297             fi
298         done
299         run_cmd apt-get update
300     fi
301
302     # PPA
303     local PPA_FILELIST
304     local _PPA_FILE
305     local _ppa
306     PPA_FILELIST=("${channels_dir}/share/ppa_list.${arch}" "${channels_dir}/${channel_name}/ppa_list.${arch}")
307     _apt_install software-properties-common
308
309     for _PPA_FILE in ${PPA_FILELIST[@]}; do
310         if [[ -f "${_PPA_FILE}" ]]; then
311             for _ppa in $(grep -h -v ^'#' ${_PPA_FILE}); do
312                 run_cmd add-apt-repository --yes "${_ppa}"
313             done
314         fi
315     done
316 }
317
318 make_systemd() {
319     _apt_install systemd-sysv
320     run_cmd dbus-uuidgen --ensure=/etc/machine-id
321     run_cmd ln -sf /etc/machine-id /var/lib/dbus/machine-id
322 }
323
324 make_apt_packages() {
325     remove "${work_dir}/airootfs/aptpkglist"
326     _apt_install initramfs-tools
327     run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --yes'
328
329     if [[ -f "${channels_dir}/share/packages.${arch}" ]]; then
330         grep -h -v ^'#' "${channels_dir}/share/packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/aptpkglist"
331     fi
332
333     if [[ -f "${channels_dir}/${channel_name}/packages.${arch}" ]]; then
334         grep -h -v ^'#' "${channels_dir}/${channel_name}/packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/aptpkglist"
335     fi
336
337     if [[ -s "${work_dir}/airootfs/aptpkglist" ]]; then
338         run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends --yes install $(echo $(<aptpkglist))'
339     fi
340
341     remove "${work_dir}/airootfs/aptpkglist"
342 }
343
344 make_snap_packages() {
345     remove "${work_dir}/airootfs/snappkglist"
346
347     if [[ -f "${channels_dir}/share/snap-packages.${arch}" ]]; then
348         grep -h -v ^'#' "${channels_dir}/share/snap-packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/snappkglist"
349     fi
350
351     if [[ -f "${channels_dir}/${channel_name}/snap-packages.${arch}" ]]; then
352         grep -h -v ^'#' "${channels_dir}/${channel_name}/snap-packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/snappkglist"
353     fi
354
355     if [[ -s "${work_dir}/airootfs/snappkglist" ]]; then
356         _apt_install snapd
357         run_cmd env -i bash -c 'snap install $(echo $(<snappkglist))'
358     fi
359
360     remove "${work_dir}/airootfs/snappkglist"
361 }
362
363 make_config() {
364     # Locales
365     run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 LC_ALL=C LANGUAGE=en_US.UTF-8 dpkg-reconfigure locales'
366
367     # resolvconf
368     run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive dpkg-reconfigure resolvconf'
369
370     # NetworkManager
371     cp ${channels_dir}/share/airootfs/etc/NetworkManager/NetworkManager.conf ${work_dir}/airootfs/etc/NetworkManager/NetworkManager.conf
372
373     # Timezone
374     #run_cmd echo -ne "UTC" > '/etc/timezone'
375     #run_cmd dpkg-reconfigure -f noninteractive tzdata
376
377     run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive dpkg-reconfigure network-manager'
378     run_cmd truncate -s 0 /etc/machine-id
379 }
380
381 make_customize_airootfs() {
382     #-- Overwrite airootfs files --#
383     local copy_airootfs
384
385     copy_airootfs() {
386         local _dir="${1%/}"
387
388         if [[ -d "${_dir}" ]]; then
389             cp -af "${_dir}"/* "${work_dir}/airootfs"
390         fi
391     }
392
393     copy_airootfs "${channels_dir}/share/airootfs"
394     copy_airootfs "${channels_dir}/${channel_name}/airootfs"
395
396     #-- Run scripts --#
397     local _customize_siript_options
398     _customize_siript_options="-a ${arch} -u ${username} -p ${password} -s ${usershell}"
399
400     #if ${bash_debug}; then
401     #    _customize_siript_options="$_customize_siript_options -x"
402     #elif ${debug}; then
403     if ${debug}; then
404         _customize_siript_options="$_customize_siript_options -d"
405     fi
406
407     # run_customize_script <script path from lubs> <script path in chroot>
408     local run_customize_script
409     run_customize_script() {
410         if [[ -f "${1}" ]]; then
411             chmod 755 "${1}"
412             run_cmd "${2}" "${_customize_siript_options}"
413         fi
414     }
415     
416     run_customize_script "${work_dir}/airootfs/root/customize_airootfs.sh" "/root/customize_airootfs.sh"
417     run_customize_script "${work_dir}/airootfs/root/customize_airootfs_${channel_name}.sh"  "/root/customize_airootfs_${channel_name}.sh"
418 }
419
420 make_clean() {
421     sed -i "s@${mirror}@http://archive.ubuntu.com/ubuntu/@g"  ${work_dir}/airootfs/etc/apt/sources.list
422     run_cmd apt-get update
423     run_cmd apt-get clean
424     run_cmd apt-get --yes autoremove
425     run_cmd rm -rf "/tmp/* ~/.bash_history"
426 }
427
428 make_squashfs() {
429     # prepare
430     [[ -d "${bootfiles_dir}" ]] && rm -r "${bootfiles_dir}"
431     mkdir -p "${bootfiles_dir}"/{casper,isolinux,install}
432
433     # make squashfs
434     mksquashfs "${work_dir}/airootfs" "${bootfiles_dir}/casper/filesystem.squashfs"
435 }
436
437 make_nfb() {
438     # prepare
439     touch "${bootfiles_dir}/ubuntu"
440     sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/README.diskdefines" > "${bootfiles_dir}/README.diskdefines"
441
442     # casper setup
443     cp "${work_dir}/airootfs/boot/vmlinuz" "${bootfiles_dir}/casper/vmlinuz"
444     cp "${work_dir}/airootfs/boot/initrd.img" "${bootfiles_dir}/casper/initrd"
445     run_cmd dpkg-query -W --showformat='${Package} ${Version}\n' > ${bootfiles_dir}/casper/filesystem.manifest
446     cp -v "${bootfiles_dir}/casper/filesystem.manifest" "${bootfiles_dir}/casper/filesystem.manifest-desktop"
447     sed -i '/casper/d;/discover/d;/laptop-detect/d;/os-prober/d;/ubiquity/d' "${bootfiles_dir}/casper/filesystem.manifest-desktop"
448     printf $(du -sx --block-size=1 "${work_dir}/airootfs" | cut -f1) > "${bootfiles_dir}/casper/filesystem.size"
449
450     # isolinux setup
451     cp "${work_dir}"/airootfs/usr/lib/syslinux/modules/bios/*.c32 "${bootfiles_dir}/isolinux/"
452     cp "${work_dir}/airootfs/usr/lib/ISOLINUX/isolinux.bin" "${bootfiles_dir}/isolinux/"
453     cp "${work_dir}/airootfs/usr/lib/ISOLINUX/isohdpfx.bin" "${bootfiles_dir}/isolinux/"
454     sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/grub.cfg" > "${bootfiles_dir}/isolinux/grub.cfg"
455     sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/isolinux.cfg" > "${bootfiles_dir}/isolinux/isolinux.cfg"
456
457     # memtest86+ setup
458     _apt_install memtest86+
459     cp "${work_dir}/airootfs/boot/memtest86+.bin" "${bootfiles_dir}/install/memtest86+"
460
461     # memtest86 setup
462     if [[ ! -f "${cache_dir}/memtest86-usb.zip" ]]; then
463         wget -O "${cache_dir}/memtest86-usb.zip" "https://www.memtest86.com/downloads/memtest86-usb.zip"
464         bash -c "(unzip -p ${cache_dir}/memtest86-usb.zip memtest86-usb.img > ${cache_dir}/memtest86)"
465     fi
466
467     cp "${cache_dir}/memtest86" "${bootfiles_dir}/install/memtest86"
468 }
469
470 make_efi() {
471     # UEFI 32bit (ia32)
472     grub-mkstandalone \
473         --format=i386-efi \
474         --output="${bootfiles_dir}/isolinux/bootia32.efi" \
475         --locales="" \
476         --fonts="" \
477         "boot/grub/grub.cfg=${bootfiles_dir}/isolinux/grub.cfg"
478     
479     # UEFI 64bit (x64)
480     grub-mkstandalone \
481         --format=x86_64-efi \
482         --output="${bootfiles_dir}/isolinux/bootx64.efi" \
483         --locales="" \
484         --fonts="" \
485         "boot/grub/grub.cfg=${bootfiles_dir}/isolinux/grub.cfg"
486
487     # create efiboot.img
488     truncate -s 10M "${bootfiles_dir}/isolinux/efiboot.img"
489     mkfs.fat -F 16 -f 1 -r 112 "${bootfiles_dir}/isolinux/efiboot.img"
490     mkdir "${bootfiles_dir}/mnt"
491     mount "${bootfiles_dir}/isolinux/efiboot.img" "${bootfiles_dir}/mnt"
492     mkdir -p "${bootfiles_dir}/mnt/efi/boot"
493     cp "${bootfiles_dir}/isolinux/bootia32.efi" "${bootfiles_dir}/mnt/efi/boot"
494     cp "${bootfiles_dir}/isolinux/bootx64.efi" "${bootfiles_dir}/mnt/efi/boot"
495     umount -d "${bootfiles_dir}/mnt"
496     rm -r "${bootfiles_dir}/mnt"
497 }
498
499 make_iso() {
500     cd "${bootfiles_dir}"
501
502     # create checksum (using at booting)
503     bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)"
504
505     # create iso
506     xorriso \
507         -as mkisofs \
508         -iso-level 3 \
509         -full-iso9660-filenames \
510         -volid "${iso_label}" \
511         -appid "${iso_application}" \
512         -publisher "${iso_publisher}" \
513         -preparer "prepared by LUBS" \
514         -eltorito-boot isolinux/isolinux.bin \
515             -no-emul-boot \
516             -boot-load-size 4 \
517             -boot-info-table \
518         -eltorito-alt-boot \
519             -eltorito-platform efi \
520             -eltorito-boot EFI/efiboot.img \
521             -no-emul-boot \
522         -isohybrid-mbr "${bootfiles_dir}/isolinux/isohdpfx.bin" \
523         -isohybrid-gpt-basdat \
524         -eltorito-catalog isolinux/boot.cat \
525         -output "${out_dir}/${iso_filename}" \
526         -graft-points \
527             "." \
528             "/isolinux/isolinux.bin=isolinux/isolinux.bin" \
529             "/EFI/efiboot.img=isolinux/efiboot.img"
530     
531     cd - > /dev/null
532 }
533
534 make_checksum() {
535     cd "${out_dir}"
536     _msg_info "Creating md5 checksum ..."
537     md5sum "${iso_filename}" > "${iso_filename}.md5"
538
539     _msg_info "Creating sha256 checksum ..."
540     sha256sum "${iso_filename}" > "${iso_filename}.sha256"
541     cd - > /dev/null 2>&1
542 }
543
544
545 # 引数解析()
546 # 参考記事:https://0e0.pw/ci83 https://0e0.pw/VJlg
547
548 _opt_short="w:o:ha:-:m:c:d"
549 _opt_long="help,arch:,codename:,debug,help,mirror:,out:,work,cache-only"
550 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
551
552 if [[ ${?} != 0 ]]; then
553     exit 1
554 fi
555
556 eval set -- "${OPT}"
557
558 while :; do
559     case ${1} in
560         -a | --arch)
561             if [[ -z ${2} ]]; then
562                 _msg_error "Please specify the architecture."
563                 exit 1
564             else
565                 arch="${2}"
566             fi
567             shift 2
568             ;;
569         -c | --codename)
570             if [[ -z ${2} ]]; then
571                 _msg_error "Please specify the codename."
572                 exit 1
573             else
574                 codename="${2}"
575             fi
576             shift 2
577             ;;
578         -d | --debug)
579             debug=true
580             shift 1
581             ;;
582         -h | --help)
583             _usage
584             exit 0
585             ;;
586         -m | --mirror)
587             if [[ -z ${2} ]]; then
588                 _msg_error "Please specify the mirror server."
589                 exit 1
590             else
591                 mirror="${2}"
592             fi
593
594             shift 2
595             ;;
596         -o | --out)
597             if [[ -z ${2} ]]; then
598                 _msg_error "Please specify the out dir."
599                 exit 1
600             else
601                 out_dir="${2}"
602             fi
603
604             shift 2
605             ;;
606         -w | --work)
607             if [[ -z ${2} ]]; then
608                 _msg_error "Please specify the out dir."
609                 exit 1
610             else
611                 work_dir="${2}"
612             fi
613
614             shift 2
615             ;;
616         --cache-only)
617             cache_only=true
618             shift 1
619             ;;
620         --)
621             shift
622             break
623             ;;
624         *)
625             _msg_error "Invalid argument '${1}'"
626             _usage 1
627             ;;
628     esac
629 done
630
631 bootfiles_dir="${work_dir}/bootfiles"
632 trap  umount_chroot 0 2 15
633
634 if [[ -n "${1}" ]]; then
635     channel_name="${1}"
636
637     check_channel() {
638         local channel_list
639         local i
640         channel_list=()
641
642         for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
643             if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
644                 channel_list+=( "${_channel}" )
645             fi
646         done
647
648         for i in ${channel_list[@]}; do
649             if [[ "${i}" = "${channel_name}" ]]; then
650                 echo -n "true"
651                 return 0
652             fi
653         done
654
655         echo -n "false"
656         return 1
657     }
658
659     if [[ $(check_channel ${channel_name}) = false ]]; then
660         _msg_error "Invalid channel ${channel_name}"
661         exit 1
662     fi
663 fi
664
665
666 prepare_build
667 run_once make_basefs
668 run_once make_sourcelist
669 run_once make_systemd
670 run_once make_apt_packages
671 #run_once make_snap_packages
672 run_once make_config
673 run_once make_customize_airootfs
674 run_once make_clean
675 run_once make_squashfs
676 run_once make_nfb
677 run_once make_efi
678 run_once make_iso
679 run_once make_checksum