OSDN Git Service

96a9a5f82cb7439a4bf7ab4638bafa08a2c35e11
[alterlinux/LFBS.git] / build.sh
1 #!/usr/bin/env bash
2
3 # SPDX-License-Identifier: GPL-3.0
4 #
5 # kokkiemouse
6 # Twitter: @kokkiemouse
7 # Email  : kokkiemouse@gmail.com
8 #
9 # lfbs
10 #
11
12 set -e
13 # set -u
14
15 #export LANG=C
16
17 script_path=$(readlink -f "${0%/*}")
18 work_dir="${script_path}/work"
19 channels_dir="${script_path}/channels"
20 nfb_dir="${script_path}/nfb"
21 codename="33"
22 os_name="SereneLinux"
23 iso_name="Fedora"
24 language="ja_JP.UTF-8"
25 channel_name="serene"
26 cache_dir="${script_path}/cache"
27 bootsplash=false
28 arch="x86_64"
29
30 out_dir="${script_path}/out"
31 iso_label="${os_name}_${codename}_${arch}"
32 iso_publisher='Fascode Network <https://fascode.net>'
33 iso_application="${os_name} Live/Rescue CD"
34 iso_version="${codename}-$(date +%Y.%m.%d)"
35 iso_filename="${iso_name}-${iso_version}-${arch}.iso"
36 liveuser_name="fedora"
37 liveuser_password="fedora"
38 liveuser_shell="/usr/bin/zsh"
39
40 #-- language config --#
41
42 # Sets the default locale for the live environment.
43 # You can also place a package list for that locale name and install packages specific to that locale.
44 locale_name="en"
45 locale_gen_name="en_US.UTF-8"
46 locale_version="gl"
47 locale_time="UTC"
48 locale_fullname="global"
49
50 debug=false
51 cache_only=false
52 grub2_standalone_cmd=grub2-mkstandalone
53
54 start_time="$(date +%s)"
55
56 _msg_common() {
57     if [[ "${debug}" = true ]]; then
58         local _current_time
59         local _time
60         _current_time="$(date +%s)"
61         _time="$(("${_current_time}"-"${start_time}"))"
62
63         #if [[ "${_time}" -ge 3600 ]]; then
64         if (( "${_time}" >= 3600 )); then
65             echo -n "[$(date -d @${_time} +%H:%M.%S)] "
66         #elif [[ "${_time}" -ge 60 ]]; then
67         elif (( "${_time}" >= 60 )); then
68             echo -n "[00:$(date -d @${_time} +%M.%S)] "
69         else
70             echo -n "[00:00.$(date -d @${_time} +%S)] "
71         fi
72     fi
73 }
74
75 # Show an INFO message
76 # _msg_info <message>
77 _msg_info() {
78     _msg_common
79     "${script_path}/tools/msg.sh" -a "LFBS Core" -l "Info:" -s "6" info "${@}"
80 }
81
82 # Show an debug message
83 # _msg_debug <message>
84 _msg_debug() {
85     _msg_common
86     if [[ "${debug}" = true ]]; then
87         "${script_path}/tools/msg.sh" -a "LFBS Core" -l "Debug:" -s "6" debug "${@}"
88     fi
89 }
90
91 # Show an ERROR message then exit with status
92 # _msg_error <message> <exit code>
93 _msg_error() {
94     _msg_common
95     "${script_path}/tools/msg.sh" -a "LFBS Core" -l "Error:" -s "6" error "${@}"
96     if [[ -n "${2:-}" ]]; then
97         exit ${2}
98     fi
99 }
100
101 # Unmount chroot dir
102 umount_chroot () {
103     local mount
104
105     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
106         if [[ ! "${mount}" == "${work_dir}/airootfs" ]]; then
107             _msg_info "Unmounting ${mount}"
108             umount -fl "${mount}"
109         fi
110     done
111 }
112
113 # Unmount chroot dir and airootfs
114 umount_chroot_airootfs () {
115     local mount
116
117     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
118         _msg_info "Unmounting ${mount}"
119         umount -fl "${mount}"
120     done
121 }
122 # Helper function to run make_*() only one time.
123 run_once() {
124     local name
125     umount_chroot
126     name="$1"
127
128     if [[ ! -e "${work_dir}/build.${name}" ]]; then
129         _msg_info "$(echo $name | sed "s@_@ @g") is starting."
130         "${1}"
131         _msg_info "$(echo $name | sed "s@_@ @g") was done!"
132         touch "${work_dir}/build.${name}"
133     fi
134 }
135
136 run_cmd() {
137     local mount
138
139     for mount in "dev" "dev/pts" "proc" "sys" ; do
140         mount --bind /${mount} "${work_dir}/airootfs/${mount}"
141     done
142     
143     mkdir -p "${work_dir}/airootfs/run/systemd/resolve/"
144     cp /etc/resolv.conf "${work_dir}/airootfs/run/systemd/resolve/stub-resolv.conf"
145     unshare --fork --pid chroot "${work_dir}/airootfs" "${@}"
146
147     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
148         if [[ ! "${mount}" == "${work_dir}/airootfs" ]]; then
149             umount -fl "${mount}"
150         fi
151     done
152 }
153
154 _dnf_install() {    
155     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
156     run_cmd dnf -c /dnf_conf install -y ${@}
157 }
158
159 # rm helper
160 # Delete the file if it exists.
161 # For directories, rm -rf is used.
162 # If the file does not exist, skip it.
163 # remove <file> <file> ...
164 remove() {
165     local _list=($(echo "$@"))
166     local _file
167
168     for _file in "${_list[@]}"; do
169         _msg_debug "Removeing ${_file}"
170
171         if [[ -f ${_file} ]]; then
172             rm -f "${_file}"
173         elif [[ -d ${_file} ]]; then
174             rm -rf "${_file}"
175         fi
176     done
177 }
178
179 # Usage: echo_blank <number>
180 # 指定されたぶんの半角空白文字を出力します
181 echo_blank(){
182     local _blank
183     for _local in $(seq 1 "${1}"); do echo -ne " "; done
184 }
185
186 # Show help
187 _usage () {
188     echo "usage ${0} [options] [channel]"
189     echo
190     echo " General options:"
191     echo
192     echo "    -a | --arch <str>      Set architecture"
193     echo "                           Default: ${arch}"
194     echo "    -b | --bootsplash      Enable Plymouth"
195     echo "    -l | --lang <lang>     Specifies the default language for the live environment"
196     echo "                           Default: ${locale_name}"
197     echo "    -m | --mirror <url>    Set apt mirror server."
198     echo "                           Default: ${mirror}"
199     echo "    -o | --out <dir>       Set the output directory"
200     echo "                           Default: ${out_dir}"
201     echo "    -w | --work <dir>      Set the working directory"
202     echo "                           Default: ${work_dir}"
203     echo "    -c | --cache <dir>     Set the cache directory"
204     echo "                           Default: ${cache_dir}"
205     echo
206     echo "    -d | --debug           Enable debug messages"
207     echo "    -x | --bash-debug      Enable bash debug mode(set -xv)"
208     echo "    -h | --help            This help message and exit"
209     echo
210     echo "You can switch between installed packages, files included in images, etc. by channel."
211     echo
212
213     local blank="23" _arch  _list _dirname _channel
214
215     echo " Language for each architecture:"
216     for _list in ${script_path}/system/locale-* ; do
217         _arch="${_list#${script_path}/system/locale-}"
218         echo -n "    ${_arch}"
219         echo_blank "$(( ${blank} - ${#_arch} ))"
220         "${script_path}/tools/locale.sh" -a "${_arch}" show
221     done
222
223     echo  -e "\n Channel:"
224     local _channel channel_list description
225     for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
226         if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
227             channel_list+=( "${_channel}" )
228         fi
229     done
230     for _channel in ${channel_list[@]}; do
231         if [[ -f "${channels_dir}/${_channel}/description.txt" ]]; then
232             description=$(cat "${channels_dir}/${_channel}/description.txt")
233         else
234             description="This channel does not have a description.txt."
235         fi
236         echo -ne "    ${_channel}"
237         echo_blank "$(( ${blank} - ${#_channel} ))"
238         echo -ne "${description}\n"
239     done
240 }
241
242 dnfstrap() {
243     if [[ ! -d "${cache_dir}" ]]; then
244         mkdir -p "${cache_dir}"
245     fi
246     cp -rf "${script_path}/system/dnfconf.conf" "${work_dir}/airootfs/dnf_conf"
247     if [[ ! -d "${work_dir}/airootfs/dnf_cache" ]]; then
248         mkdir -p "${work_dir}/airootfs/dnf_cache"
249     fi
250     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
251     dnf -c "${work_dir}/airootfs/dnf_conf" --installroot="${work_dir}/airootfs" $(${script_path}/system/repository-json-parser.py ${script_path}/system/repository.json) install ${@} -y
252     umount -fl "${work_dir}/airootfs/dnf_cache"
253 }
254
255 make_basefs() {
256     _msg_info "Installing Fedora to '${work_dir}/airootfs'..."
257     dnfstrap @Core yamad-repo 
258     _msg_info "${codename} installed successfully!"
259     
260     echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' > "${work_dir}/airootfs/etc/bash.bashrc"
261     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
262     run_cmd dnf -c /dnf_conf update --refresh -y
263     run_cmd dnf -c /dnf_conf -y remove $(run_cmd dnf -c /dnf_conf repoquery --installonly --latest-limit=-1 -q)
264     # run_cmd apt-get upgrade
265 }
266
267
268 # Parse files
269 parse_files() {
270     eval $(bash "${script_path}/tools/locale.sh" -s -a "${arch}" get "${locale_name}")
271 }
272
273 prepare_build() {
274     if [[ ${EUID} -ne 0 ]]; then
275         _msg_error "This script must be run as root." 1
276     fi
277     umount_chroot_airootfs
278     # Check codename
279     if [[ -z "$(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename})" ]]; then
280         _msg_error "This codename (${channel_name}) is not supported on this channel (${codename})."
281     fi
282     if [[ ! -d "${work_dir}/squashfsroot/LiveOS/" ]]; then
283         mkdir -p "${work_dir}/squashfsroot/LiveOS/"
284         mkdir -p "${work_dir}/airootfs/"
285         _msg_info "Make rootfs image..."
286         truncate -s 6G "${work_dir}/squashfsroot/LiveOS/rootfs.img"
287         _msg_info "Format rootfs image..."
288         mkfs.ext4 -F "${work_dir}/squashfsroot/LiveOS/rootfs.img"
289     fi    
290     mkdir -p "${out_dir}"
291     _msg_info "Mount rootfs image..."
292     mount -o loop,rw,sync "${work_dir}/squashfsroot/LiveOS/rootfs.img" "${work_dir}/airootfs"
293
294 }
295
296 make_systemd() {
297     _dnf_install dbus-tools
298     run_cmd dbus-uuidgen --ensure=/etc/machine-id
299     if [[ ! -d "${work_dir}/airootfs/var/lib/dbus" ]]; then
300         run_cmd mkdir /var/lib/dbus
301     fi
302     run_cmd ln -sf /etc/machine-id /var/lib/dbus/machine-id
303 }
304 make_repo_packages() {    
305     local  _pkg  _pkglist=($("${script_path}/tools/pkglist-repo.sh" -a "x86_64" -c "${channels_dir}/${channel_name}" -k "${codename}" -l "${locale_name}" $(if [[ "${bootsplash}" = true ]]; then echo -n "-b"; fi) ))
306     # Create a list of packages to be finally installed as packages.list directly under the working directory.
307     echo -e "# The list of packages that is installed in live cd.\n#\n\n" > "${work_dir}/packages.list"
308     # Install packages on airootfs
309     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
310     run_cmd dnf -y --nogpgcheck -c /dnf_conf install ${_pkglist[*]}
311 }
312 make_dnf_packages() {
313     
314     #local  _pkg  _pkglist=($("${script_path}/tools/pkglist.sh" -a "x86_64" -k "${kernel}" -c "${channel_dir}" -l "${locale_name}" $(if [[ "${boot_splash}" = true ]]; then echo -n "-b"; fi) ))
315     local  _pkg  _pkglist=($("${script_path}/tools/pkglist.sh" -a "x86_64" -c "${channels_dir}/${channel_name}" -l "${locale_name}" $(if [[ "${bootsplash}" = true ]]; then echo -n "-b"; fi) ))
316     # Create a list of packages to be finally installed as packages.list directly under the working directory.
317     echo -e "# The list of packages that is installed in live cd.\n#\n\n" > "${work_dir}/packages.list"
318     for _pkg in ${_pkglist[@]}; do
319         echo ${_pkg} >> "${work_dir}/packages.list"
320     done
321
322     # Install packages on airootfs
323     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
324     run_cmd dnf -y --nogpgcheck -c /dnf_conf install ${_pkglist[*]}
325 }
326
327 make_cp_airootfs() {
328     local _copy_airootfs
329
330     _copy_airootfs() {
331         local _dir="${1%/}"
332         if [[ -d "${_dir}" ]]; then
333             cp -af "${_dir}"/* "${work_dir}/airootfs"
334         fi
335     }
336     _copy_airootfs "${channels_dir}/share/airootfs"
337     _copy_airootfs "${channels_dir}/share/airootfs.${locale_name}"
338     _copy_airootfs "${channels_dir}/${channel_name}/airootfs"
339     _copy_airootfs "${channels_dir}/${channel_name}/airootfs.${locale_name}"
340 }
341
342 make_config() {
343     # customize_airootfs options
344     # -b                        : Enable boot splash.
345     # -d                        : Enable debug mode.
346     # -g <locale_gen_name>      : Set locale-gen.
347     # -i <inst_dir>             : Set install dir
348     # -k <kernel config line>   : Set kernel name.
349     # -o <os name>              : Set os name.
350     # -p <password>             : Set password.
351     # -s <shell>                : Set user shell.
352     # -t                        : Set plymouth theme.
353     # -u <username>             : Set live user name.
354     # -x                        : Enable bash debug mode.
355     # -z <locale_time>          : Set the time zone.
356     # -l <locale_name>          : Set language.
357     #
358     # -j is obsolete in AlterISO3 and cannot be used.
359     # -k changed in AlterISO3 from passing kernel name to passing kernel configuration.
360     local _airootfs_script_options _run_script
361     _airootfs_script_options="-p ${liveuser_password} -u ${liveuser_name} -o ${os_name} -s ${liveuser_shell} -a ${arch} -g ${locale_gen_name} -l ${locale_name} -z ${locale_time} "
362     if [[ ${bootsplash} == true ]]; then
363         _airootfs_script_options="${_airootfs_script_options} -b"
364     fi
365     _run_script() {
366         local _file
367         for _file in ${@}; do
368             if [[ -f "${work_dir}/airootfs${_file}" ]]; then run_cmd "${_file}" ${_airootfs_script_options}; fi
369             if [[ -f "${work_dir}/airootfs${_file}" ]]; then chmod 755 "${work_dir}/airootfs${_file}"; fi
370         done
371     }
372
373     _run_script "/root/customize_airootfs.sh" "/root/customize_airootfs_${channel_name}.sh"
374 }
375
376 make_clean() {
377     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
378     run_cmd dnf -c /dnf_conf -y remove $(run_cmd dnf -c /dnf_conf repoquery --installonly --latest-limit=-1 -q)
379 }
380
381 make_squashfs() {
382     # prepare
383     remove "${bootfiles_dir}"
384     if [[ -d "${work_dir}/airootfs/dnf_cache" ]]; then
385         rm -rf "${work_dir}/airootfs/dnf_cache"
386     fi
387     mkdir -p "${bootfiles_dir}"/{grub,LiveOS,boot,isolinux}
388     #generate initrd
389     _msg_info "make initrd..."
390     run_cmd dracut --xz --add "dmsquash-live convertfs pollcdrom" --no-hostonly --no-early-microcode /boot/initrd0 `run_cmd ls /lib/modules`
391     cp ${work_dir}/airootfs/boot/vmlinuz-$(run_cmd ls /lib/modules) ${bootfiles_dir}/boot/vmlinuz
392     mv ${work_dir}/airootfs/boot/initrd0 ${bootfiles_dir}/boot/initrd
393     #cp isolinux
394     cp "${nfb_dir}"/isolinux/* "${bootfiles_dir}/isolinux/"
395     # make squashfs
396     remove "${work_dir}/airootfs/boot"
397     mkdir "${work_dir}/airootfs/boot"
398     cp ${bootfiles_dir}/boot/vmlinuz ${work_dir}/airootfs/boot/vmlinuz-$(run_cmd ls /lib/modules)
399     kernelkun=$(run_cmd ls /lib/modules)
400     echo -e "\nkernel-install add ${kernelkun} /boot/vmlinuz-${kernelkun}" >> ${work_dir}/airootfs/usr/share/calamares/final-process
401     umount "${work_dir}/airootfs"
402     _msg_info "e2fsck..."
403     e2fsck -f "${work_dir}/squashfsroot/LiveOS/rootfs.img"
404     _msg_info "Minimize rootfs..."
405     resize2fs -M "${work_dir}/squashfsroot/LiveOS/rootfs.img"
406     _msg_info "Compress rootfs.."
407     mksquashfs "${work_dir}/squashfsroot/" "${bootfiles_dir}/LiveOS/squashfs.img" -noappend -no-recovery -comp zstd -Xcompression-level 19 -b 1048576
408     _msg_info "Deleting block image..."
409     rm -rf "${work_dir}/squashfsroot/LiveOS/rootfs.img"
410 }
411
412 make_nfb() {
413     touch "${bootfiles_dir}/fedora_lfbs"
414     # isolinux setup
415     sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/isolinux.cfg" | sed "s|%CD_LABEL%|${iso_label}|g"  > "${bootfiles_dir}/isolinux/isolinux.cfg"
416     #grub
417     if [[ ${bootsplash} = true ]]; then
418         sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/grub.cfg" | sed "s|%CD_LABEL%|${iso_label}|g" | sed "s|selinux=0|selinux=0 quiet splash|g" > "${bootfiles_dir}/grub/grub.cfg"
419     else
420         sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/grub.cfg" | sed "s|%CD_LABEL%|${iso_label}|g" > "${bootfiles_dir}/grub/grub.cfg"
421     fi
422     sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/grub.cfg" | sed "s|%CD_LABEL%|${iso_label}|g" | sed "s|selinux=0|selinux=0 quiet splash|g" > "${bootfiles_dir}/grub/grub.cfg"
423 }
424 make_efi() {
425     # UEFI 32bit (ia32)
426     ${grub2_standalone_cmd} \
427         --format=i386-efi \
428         --output="${bootfiles_dir}/grub/bootia32.efi" \
429         --locales="" \
430         --fonts="" \
431         "boot/grub/grub.cfg=${bootfiles_dir}/grub/grub.cfg"
432     
433     # UEFI 64bit (x64)
434     ${grub2_standalone_cmd} \
435         --format=x86_64-efi \
436         --output="${bootfiles_dir}/grub/bootx64.efi" \
437         --locales="" \
438         --fonts="" \
439         "boot/grub/grub.cfg=${bootfiles_dir}/grub/grub.cfg"
440
441     # create efiboot.img
442     truncate -s 200M "${bootfiles_dir}/grub/efiboot.img"
443     mkfs.fat -F 16 -f 1 -r 112 "${bootfiles_dir}/grub/efiboot.img"
444     mkdir "${bootfiles_dir}/mnt"
445     mount "${bootfiles_dir}/grub/efiboot.img" "${bootfiles_dir}/mnt"
446     mkdir -p "${bootfiles_dir}/mnt/efi/boot"
447     cp "${bootfiles_dir}/grub/bootia32.efi" "${bootfiles_dir}/mnt/efi/boot"
448     cp "${bootfiles_dir}/grub/bootx64.efi" "${bootfiles_dir}/mnt/efi/boot"
449     umount -d "${bootfiles_dir}/mnt"
450     remove "${bootfiles_dir}/mnt"
451 }
452 make_iso() {
453     cd "${bootfiles_dir}"
454
455     # create checksum (using at booting)
456     bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)"
457
458     # create iso
459     xorriso \
460         -as mkisofs \
461         -iso-level 3 \
462         -full-iso9660-filenames \
463         -volid "${iso_label}" \
464         -appid "${iso_application}" \
465         -publisher "${iso_publisher}" \
466         -preparer "prepared by LFBS" \
467         -b isolinux/isolinux.bin \
468             -no-emul-boot \
469             -boot-load-size 4 \
470             -boot-info-table \
471         -eltorito-alt-boot \
472             -eltorito-platform efi \
473             -eltorito-boot EFI/efiboot.img \
474             -no-emul-boot \
475         -isohybrid-mbr "${bootfiles_dir}/isolinux/isohdpfx.bin" \
476         -isohybrid-gpt-basdat \
477         -eltorito-catalog isolinux/boot.cat \
478         -output "${out_dir}/${iso_filename}" \
479         -graft-points \
480             "." \
481             "/isolinux/isolinux.bin=isolinux/isolinux.bin" \
482             "/EFI/efiboot.img=grub/efiboot.img"
483     
484     cd - > /dev/null
485 }
486
487 make_checksum() {
488     cd "${out_dir}"
489     _msg_info "Creating md5 checksum ..."
490     md5sum "${iso_filename}" > "${iso_filename}.md5"
491
492     _msg_info "Creating sha256 checksum ..."
493     sha256sum "${iso_filename}" > "${iso_filename}.sha256"
494     cd - > /dev/null 2>&1
495     umount_chroot_airootfs
496 }
497
498 # 引数解析 参考記事:https://0e0.pw/ci83 https://0e0.pw/VJlg
499 _opt_short="w:l:o:hba:-:m:c:dx"
500 _opt_long="help,arch:,codename:,debug,help,lang,mirror:,out:,work,cache-only,bootsplash,bash-debug"
501 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
502
503 if [[ ${?} != 0 ]]; then
504     exit 1
505 fi
506
507 eval set -- "${OPT}"
508
509 while :; do
510     case ${1} in
511         -a | --arch)
512             arch="${2}"
513             shift 2
514             ;;
515         -b | --bootsplash)
516             bootsplash=true
517             shift 1
518             ;;
519         -c | --cache)
520             cache_dir="${2}"
521             shift 2
522             ;;
523         -d | --debug)
524             debug=true
525             shift 1
526             ;;
527         -h | --help)
528             _usage
529             exit 0
530             ;;
531         -m | --mirror)
532             mirror="${2}"
533             shift 2
534             ;;
535         -l | --lang)
536             locale_name="${2}"
537             shift 2
538             ;;
539         -o | --out)
540             out_dir="${2}"
541             shift 2
542             ;;
543         -w | --work)
544             work_dir="${2}"
545             shift 2
546             ;;
547         --cache-only)
548             cache_only=true
549             shift 1
550             ;;
551         -x | --bash-debug)
552             set -xv
553             shift 1
554             ;;
555         --)
556             shift
557             break
558             ;;
559         *)
560             _msg_error "Invalid argument '${1}'"
561             _usage 1
562             ;;
563     esac
564 done
565 if [[ -f "/etc/arch-release" ]]; then
566     grub2_standalone_cmd=grub-mkstandalone
567 fi
568 bootfiles_dir="${work_dir}/bootfiles"
569 trap 'umount_chroot_airootfs' 0 2 15
570
571 if [[ -n "${1}" ]]; then
572     channel_name="${1}"
573     if [[ "${channel_name}" = "umount" ]]; then
574         umount_chroot_airootfs
575         exit 0
576     fi
577     if [[ "${channel_name}" = "clean" ]]; then
578         umount_chroot_airootfs
579         _msg_info "deleting work dir..."
580         remove "${work_dir}"
581         exit 0
582     fi
583     check_channel() {
584         local channel_list
585         local i
586         channel_list=()
587         
588         for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
589             if [[ -n "$(ls "${channels_dir}/${_channel}")" ]] && [[ ! "${_channel}" = "share" ]]; then
590                 channel_list+=( "${_channel}" )
591             fi
592         done
593
594         for i in ${channel_list[@]}; do
595             if [[ "${i}" = "${channel_name}" ]]; then
596                 echo -n "true"
597                 return 0
598             fi
599         done
600
601         echo -n "false"
602         return 1
603     }
604
605     if [[ "$(check_channel ${channel_name})" = false ]]; then
606         _msg_error "Invalid channel ${channel_name}"
607         exit 1
608     fi
609 fi
610 iso_filename="${iso_name}-${codename}-${channel_name}-${locale_name}-$(date +%Y.%m.%d)-${arch}.iso"
611 umount_chroot_airootfs
612 if [[ -d "${work_dir}" ]]; then
613     _msg_info "deleting work dir..."
614     remove "${work_dir}"
615 fi
616
617 prepare_build
618 parse_files
619 run_once make_basefs
620 run_once make_systemd
621 run_once make_repo_packages
622 run_once make_dnf_packages
623 run_once make_cp_airootfs
624 run_once make_config
625 run_once make_clean
626 run_once make_squashfs
627 run_once make_nfb
628 run_once make_efi
629 run_once make_iso
630 run_once make_checksum