OSDN Git Service

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