OSDN Git Service

added fusion
[alterlinux/LFBS.git] / lfbs
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="32"
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             echo "[$(date -d @${_time} +%H:%M.%S)]$("${script_path}/echo_color" -t 6 "[LFBS Core]")"
65         elif [[ "${_time}" -ge 60 ]]; then
66             echo "[00:$(date -d @${_time} +%M.%S)]$("${script_path}/echo_color" -t 6 "[LFBS Core]")"
67         else
68             echo "[00:00.$(date -d @${_time} +%S)] $("${script_path}/echo_color" -t 6 "[LFBS Core]")"
69         fi
70     else
71         "${script_path}/echo_color" -t 6 "[LFBS Core]"
72     fi
73 }
74
75 # Show an INFO message
76 # _msg_info <message>
77 _msg_info() {
78     local _msg
79     _msg="${@}"
80     echo "$(_msg_common)  $("${script_path}/echo_color" -t 2 "Info:") ${_msg}"
81 }
82
83 # Show an debug message
84 # _msg_debug <message>
85 _msg_debug() {
86     if [[ "${debug}" = true ]]; then
87         local _msg
88         _msg="${@}"
89         echo "$(_msg_common)  $("${script_path}/echo_color" -t 3 "Debug:") ${_msg}"
90     fi
91 }
92
93 # Show an ERROR message then exit with status
94 # _msg_error <message> <exit code>
95 _msg_error() {
96     local _msg
97     local _error
98     _msg="${1}"
99     _error=${2}
100     echo "$(_msg_common)  $("${script_path}/echo_color" -t 1 "Error:") ${_msg}"
101
102     if [[ ! ${_error} = 0 ]]; then
103         exit ${_error}
104     fi
105 }
106
107 # Unmount chroot dir
108 umount_chroot () {
109     local mount
110
111     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
112         if [[ ! "${mount}" == "${work_dir}/airootfs" ]]; then
113             _msg_info "Unmounting ${mount}"
114             umount -fl "${mount}"
115         fi
116     done
117 }
118
119 # Unmount chroot dir and airootfs
120 umount_chroot_airootfs () {
121     local mount
122
123     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
124         _msg_info "Unmounting ${mount}"
125         umount -fl "${mount}"
126     done
127 }
128 # Helper function to run make_*() only one time.
129 run_once() {
130     local name
131     umount_chroot
132     name="$1"
133
134     if [[ ! -e "${work_dir}/build.${name}" ]]; then
135         _msg_info "$(echo $name | sed "s@_@ @g") is starting."
136         "${1}"
137         _msg_info "$(echo $name | sed "s@_@ @g") was done!"
138         touch "${work_dir}/build.${name}"
139     fi
140 }
141
142 run_cmd() {
143     local mount
144
145     for mount in "dev" "dev/pts" "proc" "sys" "etc/resolv.conf"; do
146     #for mount in "dev" "dev/pts" "proc" "sys" ; do
147         if [[ "${mount}" == "etc/resolv.conf" ]]; then
148             cp /etc/resolv.conf "${work_dir}/airootfs/${mount}"
149         else
150             mount --bind /${mount} "${work_dir}/airootfs/${mount}"
151         fi
152     done
153     
154     unshare --fork --pid chroot "${work_dir}/airootfs" "${@}"
155
156     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
157         if [[ ! "${mount}" == "${work_dir}/airootfs" ]]; then
158             umount -fl "${mount}"
159         fi
160     done
161 }
162
163 _dnf_install() {    
164     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
165     run_cmd dnf -c /dnf_conf install -y ${@}
166 }
167
168 # rm helper
169 # Delete the file if it exists.
170 # For directories, rm -rf is used.
171 # If the file does not exist, skip it.
172 # remove <file> <file> ...
173 remove() {
174     local _list
175     local _file
176     _list=($(echo "$@"))
177
178     for _file in "${_list[@]}"; do
179         _msg_debug "Removeing ${_file}"
180
181         if [[ -f ${_file} ]]; then
182             rm -f "${_file}"
183         elif [[ -d ${_file} ]]; then
184             rm -rf "${_file}"
185         fi
186     done
187 }
188
189 # Show help
190 _usage () {
191     echo "usage ${0} [options] [channel]"
192     echo
193     echo " General options:"
194     echo
195     echo "    -a | --arch <str>      Set architecture"
196     echo "                           Default: ${arch}"
197     echo "    -b | --bootsplash      Enable Plymouth"
198     echo "    -l | --lang <lang>     Specifies the default language for the live environment"
199     echo "                           Default: ${locale_name}"
200     echo "    -m | --mirror <url>    Set apt mirror server."
201     echo "                           Default: ${mirror}"
202     echo "    -o | --out <out_dir>   Set the output directory"
203     echo "                           Default: ${out_dir}"
204     echo "    -w | --work <work_dir> Set the working directory"
205     echo "                           Default: ${work_dir}"
206     echo "    -c | --cache <cache_dir> Set the cache directory"
207     echo "                           Default: ${cache_dir}"
208     echo
209     echo "    -d | --debug           "
210     echo "    -h | --help            This help message and exit"
211     echo
212     echo "You can switch between installed packages, files included in images, etc. by channel."
213     echo
214     echo " Language for each architecture:"
215     for _list in ${script_path}/system/locale-* ; do
216         _arch="${_list#${script_path}/system/locale-}"
217         echo -n "    ${_arch}"
218         for i in $( seq 1 $(( ${blank} - 4 - ${#_arch} )) ); do
219             echo -ne " "
220         done
221         _locale_name_list=$(cat ${_list} | grep -h -v ^'#' | awk '{print $1}')
222         for _lang in ${_locale_name_list[@]};do
223             echo -n "${_lang} "
224         done
225         echo
226     done
227     echo " Channel:"
228     
229     local _channel
230     local channel_list
231     local description
232
233     for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
234         if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
235             channel_list+=( "${_channel}" )
236         fi
237     done
238
239     for _channel in ${channel_list[@]}; do
240         if [[ -f "${channels_dir}/${_channel}/description.txt" ]]; then
241             description=$(cat "${channels_dir}/${_channel}/description.txt")
242         else
243             description="This channel does not have a description.txt."
244         fi
245
246         echo -ne "    ${_channel}"
247
248         for i in $( seq 1 $(( 23 - ${#_channel} )) ); do
249             echo -ne " "
250         done
251         
252         echo -ne "${description}\n"
253     done
254 }
255
256 dnfstrap() {
257     if [[ ! -d "${cache_dir}" ]]; then
258         mkdir -p "${cache_dir}"
259     fi
260     cp -rf "${script_path}/system/dnfconf.conf" "${work_dir}/airootfs/dnf_conf"
261     if [[ ! -d "${work_dir}/airootfs/dnf_cache" ]]; then
262         mkdir -p "${work_dir}/airootfs/dnf_cache"
263     fi
264     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
265     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
266     umount -fl "${work_dir}/airootfs/dnf_cache"
267 }
268
269 make_basefs() {
270     _msg_info "Installing Fedora to '${work_dir}/airootfs'..."
271     dnfstrap @Core yamad-repo 
272     _msg_info "${codename} installed successfully!"
273     
274     echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' > "${work_dir}/airootfs/etc/bash.bashrc"
275     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
276     run_cmd dnf -c /dnf_conf update -y
277     run_cmd dnf -c /dnf_conf -y remove $(run_cmd dnf -c /dnf_conf repoquery --installonly --latest-limit=-1 -q)
278     # run_cmd apt-get upgrade
279 }
280
281
282 # Parse files
283 parse_files() {
284     #-- ロケールを解析、設定 --#
285     local _get_locale_line_number _locale_config_file _locale_name_list _locale_line_number _locale_config_line
286
287     # 選択されたロケールの設定が描かれた行番号を取得
288     _locale_config_file="${script_path}/system/locale-${arch}"
289     _locale_name_list=($(cat "${_locale_config_file}" | grep -h -v ^'#' | awk '{print $1}'))
290     _get_locale_line_number() {
291         local _lang _count=0
292         for _lang in ${_locale_name_list[@]}; do
293             _count=$(( _count + 1 ))
294             if [[ "${_lang}" == "${locale_name}" ]]; then echo "${_count}"; return 0; fi
295         done
296         echo -n "failed"
297     }
298     _locale_line_number="$(_get_locale_line_number)"
299
300     # 不正なロケール名なら終了する
301     [[ "${_locale_line_number}" == "failed" ]] && _msg_error "${locale_name} is not a valid language." "1"
302
303     # ロケール設定ファイルから該当の行を抽出
304     _locale_config_line=($(cat "${_locale_config_file}" | grep -h -v ^'#' | grep -v ^$ | head -n "${_locale_line_number}" | tail -n 1))
305
306     # 抽出された行に書かれた設定をそれぞれの変数に代入
307     # ここで定義された変数のみがグローバル変数
308     locale_name="${_locale_config_line[0]}"
309     locale_gen_name="${_locale_config_line[1]}"
310     locale_version="${_locale_config_line[2]}"
311     locale_time="${_locale_config_line[3]}"
312     locale_fullname="${_locale_config_line[4]}"
313 }
314
315 prepare_build() {
316     if [[ ${EUID} -ne 0 ]]; then
317         _msg_error "This script must be run as root." 1
318     fi
319     umount_chroot_airootfs
320     # Check codename
321     if [[ -z "$(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename})" ]]; then
322         _msg_error "This codename (${channel_name}) is not supported on this channel (${codename})."
323     fi
324     if [[ ! -d "${work_dir}/squashfsroot/LiveOS/" ]]; then
325         mkdir -p "${work_dir}/squashfsroot/LiveOS/"
326         mkdir -p "${work_dir}/airootfs/"
327         _msg_info "Make rootfs image..."
328         truncate -s 6G "${work_dir}/squashfsroot/LiveOS/rootfs.img"
329         _msg_info "Format rootfs image..."
330         mkfs.ext4 -F "${work_dir}/squashfsroot/LiveOS/rootfs.img"
331     fi    
332     mkdir -p "${out_dir}"
333     _msg_info "Mount rootfs image..."
334     mount -o loop,rw,sync "${work_dir}/squashfsroot/LiveOS/rootfs.img" "${work_dir}/airootfs"
335
336 }
337
338 make_systemd() {
339     _dnf_install dbus-tools
340     run_cmd dbus-uuidgen --ensure=/etc/machine-id
341     if [[ ! -d "${work_dir}/airootfs/var/lib/dbus" ]]; then
342         run_cmd mkdir /var/lib/dbus
343     fi
344     run_cmd ln -sf /etc/machine-id /var/lib/dbus/machine-id
345 }
346 make_repo_packages() {
347     remove "${work_dir}/airootfs/dnfrepopkglist"
348     #_apt_install initramfs-tools
349     # run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --yes'
350
351     if [[ -f "${channels_dir}/share/add_repo.${arch}" ]]; then
352         grep -h -v ^'#' "${channels_dir}/share/add_repo.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfrepopkglist"
353     fi
354
355     if [[ -f "${channels_dir}/${channel_name}/add_repo.${arch}" ]]; then
356         grep -h -v ^'#' "${channels_dir}/${channel_name}/add_repo.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfrepopkglist"
357     fi
358
359     if [[ -s "${work_dir}/airootfs/dnfrepopkglist" ]]; then
360         mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
361         sed -i -e "s|\${codename}|${codename}|g" "${work_dir}/airootfs/dnfrepopkglist"
362         run_cmd env -i bash -c 'dnf -y --nogpgcheck -c /dnf_conf install $(echo $(<dnfrepopkglist))'
363     fi
364
365     remove "${work_dir}/airootfs/dnfrepopkglist"
366 }
367 make_dnf_packages() {
368     remove "${work_dir}/airootfs/dnfpkglist"
369     #_apt_install initramfs-tools
370     # run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --yes'
371
372     if [[ -f "${channels_dir}/share/packages.${arch}" ]]; then
373         grep -h -v ^'#' "${channels_dir}/share/packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
374     fi
375     if [[ -f "${channels_dir}/share/packages-${locale_name}.${arch}" ]]; then
376         grep -h -v ^'#' "${channels_dir}/share/packages-${locale_name}.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
377     fi
378
379     if [[ -f "${channels_dir}/${channel_name}/packages.${arch}" ]]; then
380         grep -h -v ^'#' "${channels_dir}/${channel_name}/packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
381     fi
382
383     if [[ -f "${channels_dir}/${channel_name}/packages-${locale_name}.${arch}" ]]; then
384         grep -h -v ^'#' "${channels_dir}/${channel_name}/packages-${locale_name}.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
385     fi
386     if [[ ${bootsplash} == true ]]; then
387         if [[ -f "${channels_dir}/share/packages_plymouth.${arch}" ]]; then
388             grep -h -v ^'#' "${channels_dir}/share/packages_plymouth.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
389         fi
390         
391         if [[ -f "${channels_dir}/${channel_name}/packages_plymouth.${arch}" ]]; then
392             grep -h -v ^'#' "${channels_dir}/${channel_name}/packages_plymouth.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
393         fi
394     fi
395     if [[ -s "${work_dir}/airootfs/dnfpkglist" ]]; then
396         mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
397         run_cmd env -i bash -c 'dnf -y --nogpgcheck -c /dnf_conf install $(echo $(<dnfpkglist))'
398     fi
399
400     remove "${work_dir}/airootfs/dnfpkglist"
401 }
402
403 make_cp_airootfs() {
404     local _copy_airootfs
405
406     _copy_airootfs() {
407         local _dir="${1%/}"
408         if [[ -d "${_dir}" ]]; then
409             cp -af "${_dir}"/* "${work_dir}/airootfs"
410         fi
411     }
412     _copy_airootfs "${channels_dir}/share/airootfs"
413     _copy_airootfs "${channels_dir}/share/airootfs.${locale_name}"
414     _copy_airootfs "${channels_dir}/${channel_name}/airootfs"
415     _copy_airootfs "${channels_dir}/${channel_name}/airootfs.${locale_name}"
416 }
417
418 make_config() {
419     # customize_airootfs options
420     # -b                        : Enable boot splash.
421     # -d                        : Enable debug mode.
422     # -g <locale_gen_name>      : Set locale-gen.
423     # -i <inst_dir>             : Set install dir
424     # -k <kernel config line>   : Set kernel name.
425     # -o <os name>              : Set os name.
426     # -p <password>             : Set password.
427     # -s <shell>                : Set user shell.
428     # -t                        : Set plymouth theme.
429     # -u <username>             : Set live user name.
430     # -x                        : Enable bash debug mode.
431     # -r                        : Enable rebuild.
432     # -z <locale_time>          : Set the time zone.
433     # -l <locale_name>          : Set language.
434     #
435     # -j is obsolete in AlterISO3 and cannot be used.
436     # -k changed in AlterISO3 from passing kernel name to passing kernel configuration.
437     local _airootfs_script_options _run_script
438     _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} "
439     if [[ ${bootsplash} == true ]]; then
440         _airootfs_script_options="${_airootfs_script_options} -b"
441     fi
442     _run_script() {
443         local _file
444         for _file in ${@}; do
445             if [[ -f "${work_dir}/airootfs${_file}" ]]; then run_cmd "${_file}" ${_airootfs_script_options}; fi
446             if [[ -f "${work_dir}/airootfs${_file}" ]]; then chmod 755 "${work_dir}/airootfs${_file}"; fi
447         done
448     }
449
450     _run_script "/root/customize_airootfs.sh" "/root/customize_airootfs_${channel_name}.sh"
451 }
452
453 make_clean() {
454     mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
455     run_cmd dnf -c /dnf_conf -y remove $(run_cmd dnf -c /dnf_conf repoquery --installonly --latest-limit=-1 -q)
456 }
457
458 make_squashfs() {
459     # prepare
460     remove "${bootfiles_dir}"
461     if [[ -d "${work_dir}/airootfs/dnf_cache" ]]; then
462         rm -rf "${work_dir}/airootfs/dnf_cache"
463     fi
464     mkdir -p "${bootfiles_dir}"/{grub,LiveOS,boot,isolinux}
465     #generate initrd
466     _msg_info "make initrd..."
467     run_cmd dracut --xz --add "dmsquash-live convertfs pollcdrom" --no-hostonly --no-early-microcode /boot/initrd0 `run_cmd ls /lib/modules`
468     cp ${work_dir}/airootfs/boot/vmlinuz-$(run_cmd ls /lib/modules) ${bootfiles_dir}/boot/vmlinuz
469     mv ${work_dir}/airootfs/boot/initrd0 ${bootfiles_dir}/boot/initrd
470     #cp isolinux
471     cp "${nfb_dir}"/isolinux/* "${bootfiles_dir}/isolinux/"
472     # make squashfs
473     remove "${work_dir}/airootfs/boot"
474     mkdir "${work_dir}/airootfs/boot"
475     cp ${bootfiles_dir}/boot/vmlinuz ${work_dir}/airootfs/boot/vmlinuz-$(run_cmd ls /lib/modules)
476     kernelkun=$(run_cmd ls /lib/modules)
477     echo -e "\nkernel-install add ${kernelkun} /boot/vmlinuz-${kernelkun}" >> ${work_dir}/airootfs/usr/share/calamares/final-process
478     umount "${work_dir}/airootfs"
479     _msg_info "Minimize rootfs..."
480     resize2fs -M "${work_dir}/squashfsroot/LiveOS/rootfs.img"
481     _msg_info "Compress rootfs.."
482     mksquashfs "${work_dir}/squashfsroot/" "${bootfiles_dir}/LiveOS/squashfs.img" -noappend -no-recovery -comp zstd -Xcompression-level 19 -b 1048576
483     _msg_info "Deleting block image..."
484     rm -rf "${work_dir}/squashfsroot/LiveOS/rootfs.img"
485 }
486
487 make_nfb() {
488     touch "${bootfiles_dir}/fedora_lfbs"
489     # isolinux setup
490     sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/isolinux.cfg" | sed "s|%CD_LABEL%|${iso_label}|g"  > "${bootfiles_dir}/isolinux/isolinux.cfg"
491     #grub
492     if [[ ${bootsplash} = true ]]; then
493         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"
494     else
495         sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/grub.cfg" | sed "s|%CD_LABEL%|${iso_label}|g" > "${bootfiles_dir}/grub/grub.cfg"
496     fi
497     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"
498 }
499 make_efi() {
500     # UEFI 32bit (ia32)
501     ${grub2_standalone_cmd} \
502         --format=i386-efi \
503         --output="${bootfiles_dir}/grub/bootia32.efi" \
504         --locales="" \
505         --fonts="" \
506         "boot/grub/grub.cfg=${bootfiles_dir}/grub/grub.cfg"
507     
508     # UEFI 64bit (x64)
509     ${grub2_standalone_cmd} \
510         --format=x86_64-efi \
511         --output="${bootfiles_dir}/grub/bootx64.efi" \
512         --locales="" \
513         --fonts="" \
514         "boot/grub/grub.cfg=${bootfiles_dir}/grub/grub.cfg"
515
516     # create efiboot.img
517     truncate -s 200M "${bootfiles_dir}/grub/efiboot.img"
518     mkfs.fat -F 16 -f 1 -r 112 "${bootfiles_dir}/grub/efiboot.img"
519     mkdir "${bootfiles_dir}/mnt"
520     mount "${bootfiles_dir}/grub/efiboot.img" "${bootfiles_dir}/mnt"
521     mkdir -p "${bootfiles_dir}/mnt/efi/boot"
522     cp "${bootfiles_dir}/grub/bootia32.efi" "${bootfiles_dir}/mnt/efi/boot"
523     cp "${bootfiles_dir}/grub/bootx64.efi" "${bootfiles_dir}/mnt/efi/boot"
524     umount -d "${bootfiles_dir}/mnt"
525     remove "${bootfiles_dir}/mnt"
526 }
527 make_iso() {
528     cd "${bootfiles_dir}"
529
530     # create checksum (using at booting)
531     bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)"
532
533     # create iso
534     xorriso \
535         -as mkisofs \
536         -iso-level 3 \
537         -full-iso9660-filenames \
538         -volid "${iso_label}" \
539         -appid "${iso_application}" \
540         -publisher "${iso_publisher}" \
541         -preparer "prepared by LFBS" \
542         -b isolinux/isolinux.bin \
543             -no-emul-boot \
544             -boot-load-size 4 \
545             -boot-info-table \
546         -eltorito-alt-boot \
547             -eltorito-platform efi \
548             -eltorito-boot EFI/efiboot.img \
549             -no-emul-boot \
550         -isohybrid-mbr "${bootfiles_dir}/isolinux/isohdpfx.bin" \
551         -isohybrid-gpt-basdat \
552         -eltorito-catalog isolinux/boot.cat \
553         -output "${out_dir}/${iso_filename}" \
554         -graft-points \
555             "." \
556             "/isolinux/isolinux.bin=isolinux/isolinux.bin" \
557             "/EFI/efiboot.img=grub/efiboot.img"
558     
559     cd - > /dev/null
560 }
561
562 make_checksum() {
563     cd "${out_dir}"
564     _msg_info "Creating md5 checksum ..."
565     md5sum "${iso_filename}" > "${iso_filename}.md5"
566
567     _msg_info "Creating sha256 checksum ..."
568     sha256sum "${iso_filename}" > "${iso_filename}.sha256"
569     cd - > /dev/null 2>&1
570     umount_chroot_airootfs
571 }
572
573 # 引数解析()
574 # 参考記事:https://0e0.pw/ci83 https://0e0.pw/VJlg
575
576 _opt_short="w:l:o:hba:-:m:c:d"
577 _opt_long="help,arch:,codename:,debug,help,lang,mirror:,out:,work,cache-only,bootsplash"
578 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
579
580 if [[ ${?} != 0 ]]; then
581     exit 1
582 fi
583
584 eval set -- "${OPT}"
585
586 while :; do
587     case ${1} in
588         -a | --arch)
589             arch="${2}"
590             shift 2
591             ;;
592         -b | --bootsplash)
593             bootsplash=true
594             shift 1
595             ;;
596         -c | --cache)
597             cache_dir="${2}"
598             shift 2
599             ;;
600         -d | --debug)
601             debug=true
602             shift 1
603             ;;
604         -h | --help)
605             _usage
606             exit 0
607             ;;
608         -m | --mirror)
609             mirror="${2}"
610             shift 2
611             ;;
612         -l | --lang)
613             locale_name="${2}"
614             shift 2
615             ;;
616         -o | --out)
617             out_dir="${2}"
618             shift 2
619             ;;
620         -w | --work)
621             work_dir="${2}"
622             shift 2
623             ;;
624         --cache-only)
625             cache_only=true
626             shift 1
627             ;;
628         --)
629             shift
630             break
631             ;;
632         *)
633             _msg_error "Invalid argument '${1}'"
634             _usage 1
635             ;;
636     esac
637 done
638 if [[ -f /etc/arch-release ]]; then
639     grub2_standalone_cmd=grub-mkstandalone
640 fi
641 bootfiles_dir="${work_dir}/bootfiles"
642 trap  umount_chroot_airootfs 0 2 15
643
644 if [[ -n "${1}" ]]; then
645     channel_name="${1}"
646     if [[ "${channel_name}" = "umount" ]]; then
647         umount_chroot_airootfs
648         exit 0
649     fi
650     if [[ "${channel_name}" = "clean" ]]; then
651         umount_chroot_airootfs
652         _msg_info "deleting work dir..."
653         remove "${work_dir}"
654         exit 0
655     fi
656     check_channel() {
657         local channel_list
658         local i
659         channel_list=()
660         
661         for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
662             if [[ -n "$(ls "${channels_dir}/${_channel}")" ]] && [[ ! "${_channel}" = "share" ]]; then
663                 channel_list+=( "${_channel}" )
664             fi
665         done
666
667         for i in ${channel_list[@]}; do
668             if [[ "${i}" = "${channel_name}" ]]; then
669                 echo -n "true"
670                 return 0
671             fi
672         done
673
674         echo -n "false"
675         return 1
676     }
677
678     if [[ "$(check_channel ${channel_name})" = false ]]; then
679         _msg_error "Invalid channel ${channel_name}"
680         exit 1
681     fi
682 fi
683 iso_filename="${iso_name}-${codename}-${channel_name}-${locale_name}-$(date +%Y.%m.%d)-${arch}.iso"
684 umount_chroot_airootfs
685 if [[ -d "${work_dir}" ]]; then
686     _msg_info "deleting work dir..."
687     remove "${work_dir}"
688 fi
689
690 prepare_build
691 parse_files
692 run_once make_basefs
693 run_once make_systemd
694 run_once make_repo_packages
695 run_once make_dnf_packages
696 run_once make_cp_airootfs
697 run_once make_config
698 run_once make_clean
699 run_once make_squashfs
700 run_once make_nfb
701 run_once make_efi
702 run_once make_iso
703 run_once make_checksum