@@ -24,6 +24,7 @@ customized_password=false
2424customized_kernel=false
2525customized_logpath=false
2626pkglist_args=()
27+ modules=()
2728DEFAULT_ARGUMENT=" "
2829alteriso_version=" 3.1"
2930
4243
4344umask 0022
4445
46+ # Message common function
47+ # msg_common [type] [-n] [string]
48+ msg_common (){
49+ local _msg_opts=(" -a" " build.sh" ) _type=" ${1} "
50+ shift 1
51+ [[ " ${1} " = " -n" ]] && _msg_opts+=(" -o" " -n" ) && shift 1
52+ [[ " ${msgdebug} " = true ]] && _msg_opts+=(" -x" )
53+ [[ " ${nocolor} " = true ]] && _msg_opts+=(" -n" )
54+ _msg_opts+=(" ${_type} " " ${@ } " )
55+ " ${tools_dir} /msg.sh" " ${_msg_opts[@]} "
56+ }
57+
4558# Show an INFO message
4659# ${1}: message string
4760msg_info () {
48- local _msg_opts=" -a build.sh"
49- if [[ " ${1} " = " -n" ]]; then
50- _msg_opts=" ${_msg_opts} -o -n"
51- shift 1
52- fi
53- [[ " ${msgdebug} " = true ]] && _msg_opts=" ${_msg_opts} -x"
54- [[ " ${nocolor} " = true ]] && _msg_opts=" ${_msg_opts} -n"
55- " ${tools_dir} /msg.sh" ${_msg_opts} info " ${1} "
61+ msg_common info " ${@ } "
5662}
5763
5864# Show an Warning message
5965# ${1}: message string
6066msg_warn () {
61- local _msg_opts=" -a build.sh"
62- if [[ " ${1} " = " -n" ]]; then
63- _msg_opts=" ${_msg_opts} -o -n"
64- shift 1
65- fi
66- [[ " ${msgdebug} " = true ]] && _msg_opts=" ${_msg_opts} -x"
67- [[ " ${nocolor} " = true ]] && _msg_opts=" ${_msg_opts} -n"
68- " ${tools_dir} /msg.sh" ${_msg_opts} warn " ${1} "
67+ msg_common warn " ${@ } "
6968}
7069
7170# Show an debug message
7271# ${1}: message string
7372msg_debug () {
7473 if [[ " ${debug} " = true ]]; then
75- local _msg_opts=" -a build.sh"
76- if [[ " ${1} " = " -n" ]]; then
77- _msg_opts=" ${_msg_opts} -o -n"
78- shift 1
79- fi
80- [[ " ${msgdebug} " = true ]] && _msg_opts=" ${_msg_opts} -x"
81- [[ " ${nocolor} " = true ]] && _msg_opts=" ${_msg_opts} -n"
82- " ${tools_dir} /msg.sh" ${_msg_opts} debug " ${1} "
74+ msg_common debug " ${@ } "
8375 fi
8476}
8577
8678# Show an ERROR message then exit with status
8779# ${1}: message string
8880# ${2}: exit code number (with 0 does not exit)
8981msg_error () {
90- local _msg_opts=" -a build.sh"
91- if [[ " ${1} " = " -n" ]]; then
92- _msg_opts=" ${_msg_opts} -o -n"
93- shift 1
94- fi
95- [[ " ${msgdebug} " = true ]] && _msg_opts=" ${_msg_opts} -x"
96- [[ " ${nocolor} " = true ]] && _msg_opts=" ${_msg_opts} -n"
97- " ${tools_dir} /msg.sh" ${_msg_opts} error " ${1} "
82+ msg_common error " ${1} "
9883 if [[ -n " ${2:- } " ]]; then
99- exit ${2}
84+ exit " ${2} "
10085 fi
10186}
10287
@@ -194,16 +179,15 @@ _umount() { if mountpoint -q "${1}"; then umount -lf "${1}"; fi; }
194179# Mount helper Usage: _mount <source> <target>
195180_mount () { if ! mountpoint -q " ${2} " && [[ -f " ${1} " ]] && [[ -d " ${2} " ]]; then mount " ${1} " " ${2} " ; fi ; }
196181
197- # Unmount chroot dir
198- umount_chroot () {
182+ # Unmount work dir
183+ umount_work () {
199184 local _mount
200185 if [[ ! -v " build_dir" ]] || [[ " ${build_dir} " = " " ]]; then
201186 msg_error " Exception error about working directory" 1
202187 fi
203- if [[ ! -d " ${build_dir} " ]]; then
204- return 0
205- fi
206- for _mount in $( cat " /proc/mounts" | getclm 2 | grep " $( realpath -s ${build_dir} ) " | tac | grep -xv " $( realpath -s ${build_dir} ) /${arch} /airootfs" ) ; do
188+ [[ ! -d " ${build_dir} " ]] && return 0
189+ # for _mount in $(cat "/proc/mounts" | getclm 2 | grep "$(realpath -s ${build_dir})" | tac | grep -xv "$(realpath -s ${airootfs_dir})"); do
190+ for _mount in $( find " ${build_dir} " -mindepth 1 -type d -printf " %p\0" | xargs -0 -I{} bash -c " mountpoint -q {} && echo {}" | tac) ; do
207191 if echo " ${_mount} " | grep " ${work_dir} " > /dev/null 2>&1 || echo " ${_mount} " | grep " ${script_path} " > /dev/null 2>&1 || echo " ${_mount} " | grep " ${out_dir} " > /dev/null 2>&1 ; then
208192 msg_info " Unmounting ${_mount} "
209193 _umount " ${_mount} " 2> /dev/null
@@ -213,30 +197,22 @@ umount_chroot () {
213197 done
214198}
215199
216- # Mount airootfs on "${build_dir}/${arch}/airootfs "
200+ # Mount airootfs on "${airootfs_dir} "
217201mount_airootfs () {
218202 mkdir -p " ${airootfs_dir} "
219203 _mount " ${airootfs_dir} .img" " ${airootfs_dir} "
220204}
221205
222- umount_airootfs () {
223- if [[ -v airootfs_dir ]]; then _umount " ${airootfs_dir} " ; fi
224- }
225-
226- umount_chroot_advance () {
227- umount_chroot
228- umount_airootfs
229- }
230206
231207# Helper function to run make_*() only one time.
232208run_once () {
233209 set -eu
234- if [[ ! -e " ${lockfile_dir} /build.${1} _ ${arch} " ]]; then
210+ if [[ ! -e " ${lockfile_dir} /build.${1} " ]]; then
235211 msg_debug " Running ${1} ..."
236212 mount_airootfs
237- " ${1 } "
238- mkdir -p " ${lockfile_dir} " ; touch " ${lockfile_dir} /build.${1} _ ${arch} "
239- umount_chroot_advance
213+ eval " ${@ } "
214+ mkdir -p " ${lockfile_dir} " ; touch " ${lockfile_dir} /build.${1} "
215+ umount_work
240216 else
241217 msg_debug " Skipped because ${1} has already been executed."
242218 fi
@@ -252,7 +228,7 @@ remove() {
252228# 強制終了時にアンマウント
253229umount_trap () {
254230 local _status=" ${?} "
255- umount_chroot_advance
231+ umount_work
256232 msg_error " It was killed by the user.\nThe process may not have completed successfully."
257233 exit " ${_status} "
258234}
@@ -283,14 +259,14 @@ for_module(){
283259# pacstrapを実行
284260_pacstrap (){
285261 msg_info " Installing packages to ${airootfs_dir} /'..."
286- pacstrap -C " ${build_dir} /pacman- ${arch} .conf" -c -G -M -- " ${airootfs_dir} " " ${@ } "
262+ pacstrap -C " ${build_dir} /pacman.conf" -c -G -M -- " ${airootfs_dir} " " ${@ } "
287263 msg_info " Packages installed successfully!"
288264}
289265
290266# chroot環境でpacmanコマンドを実行
291267# /etc/alteriso-pacman.confを準備してコマンドを実行します
292268_run_with_pacmanconf (){
293- sed " s|^CacheDir =|#CacheDir =|g" " ${build_dir} /pacman- ${arch} .conf" > " ${airootfs_dir} /etc/alteriso-pacman.conf"
269+ sed " s|^CacheDir =|#CacheDir =|g" " ${build_dir} /pacman.conf" > " ${airootfs_dir} /etc/alteriso-pacman.conf"
294270 " ${@ } "
295271 remove " ${airootfs_dir} /etc/alteriso-pacman.conf"
296272}
@@ -306,17 +282,25 @@ _cleanup_common () {
306282
307283 # Delete pacman database sync cache files (*.tar.gz)
308284 [[ -d " ${airootfs_dir} /var/lib/pacman" ]] && find " ${airootfs_dir} /var/lib/pacman" -maxdepth 1 -type f -delete
285+
309286 # Delete pacman database sync cache
310287 [[ -d " ${airootfs_dir} /var/lib/pacman/sync" ]] && find " ${airootfs_dir} /var/lib/pacman/sync" -delete
288+
311289 # Delete pacman package cache
312290 [[ -d " ${airootfs_dir} /var/cache/pacman/pkg" ]] && find " ${airootfs_dir} /var/cache/pacman/pkg" -type f -delete
291+
313292 # Delete all log files, keeps empty dirs.
314293 [[ -d " ${airootfs_dir} /var/log" ]] && find " ${airootfs_dir} /var/log" -type f -delete
294+
315295 # Delete all temporary files and dirs
316296 [[ -d " ${airootfs_dir} /var/tmp" ]] && find " ${airootfs_dir} /var/tmp" -mindepth 1 -delete
297+
317298 # Delete package pacman related files.
318299 find " ${build_dir} " \( -name ' *.pacnew' -o -name ' *.pacsave' -o -name ' *.pacorig' \) -delete
319300
301+ # Delete all cache file
302+ [[ -d " ${airootfs_dir} /var/cache" ]] && find " ${airootfs_dir} /var/cache" -mindepth 1 -delete
303+
320304 # Create an empty /etc/machine-id
321305 printf ' ' > " ${airootfs_dir} /etc/machine-id"
322306
@@ -526,8 +510,8 @@ prepare_build() {
526510 logging=" ${out_dir} /${iso_filename% .iso} .log"
527511 fi
528512 mkdir -p " $( dirname " ${logging} " ) " ; touch " ${logging} "
529- msg_warn " Re-run sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT[*]} --nolog 2>&1 | tee ${logging} "
530- sudo ${0} ${DEFAULT_ARGUMENT} " ${ARGUMENT[@]} " --nolog 2>&1 | tee " ${logging} "
513+ msg_warn " Re-run sudo ${0} ${DEFAULT_ARGUMENT} ${ARGUMENT[*]} --nodepend -- nolog 2>&1 | tee ${logging} "
514+ sudo ${0} ${DEFAULT_ARGUMENT} " ${ARGUMENT[@]} " --nolog --nodepend 2>&1 | tee " ${logging} "
531515 exit " ${?} "
532516 else
533517 unset DEFAULT_ARGUMENT ARGUMENT
@@ -539,10 +523,7 @@ prepare_build() {
539523 if [[ " ${debug} " = true ]]; then pkglist_args+=(" -d" ); fi
540524 if [[ " ${memtest86} " = true ]]; then pkglist_args+=(" -m" ); fi
541525 if (( "${# additional_exclude_pkg[@]} " >= 1 )) ; then pkglist_args+=(" -e" " ${additional_exclude_pkg[*]} " ); fi
542- pkglist_args+=(" ${modules[*]} " )
543-
544- # Unmount
545- umount_chroot
526+ pkglist_args+=(" ${modules[@]} " )
546527}
547528
548529
@@ -559,7 +540,7 @@ make_pacman_conf() {
559540 done
560541
561542 msg_debug " Use ${build_pacman_conf} "
562- sed -r " s|^#?\\ s*CacheDir.+|CacheDir = ${cache_dir} |g" " ${build_pacman_conf} " > " ${build_dir} /pacman- ${arch} .conf"
543+ sed -r " s|^#?\\ s*CacheDir.+|CacheDir = ${cache_dir} |g" " ${build_pacman_conf} " > " ${build_dir} /pacman.conf"
563544
564545 if [[ " ${nosigcheck} " = true ]]; then
565546 sed -ir " s|^s*SigLevel.+|SigLevel = Never|g" " ${build_pacman_conf} "
@@ -588,7 +569,7 @@ make_packages_repo() {
588569 local _pkglist=($( " ${tools_dir} /pkglist.sh" " ${pkglist_args[@]} " ) )
589570
590571 # Create a list of packages to be finally installed as packages.list directly under the working directory.
591- echo -e " # The list of packages that is installed in live cd.\n#\n\n " > " ${build_dir} /packages.list"
572+ echo -e " # The list of packages that is installed in live cd.\n#\n" > " ${build_dir} /packages.list"
592573 printf " %s\n" " ${_pkglist[@]} " >> " ${build_dir} /packages.list"
593574
594575 # Install packages on airootfs
@@ -602,7 +583,7 @@ make_packages_aur() {
602583 local _pkglist_aur=($( " ${tools_dir} /pkglist.sh" --aur " ${pkglist_args[@]} " ) )
603584
604585 # Create a list of packages to be finally installed as packages.list directly under the working directory.
605- echo -e " \n\n # AUR packages.\n#\n \n" >> " ${build_dir} /packages.list"
586+ echo -e " \n# AUR packages.\n#\n" >> " ${build_dir} /packages.list"
606587 printf " %s\n" " ${_pkglist_aur[@]} " >> " ${build_dir} /packages.list"
607588
608589 # prepare for yay
@@ -621,12 +602,14 @@ make_pkgbuild() {
621602 for_module ' _pkgbuild_dirs+=("${module_dir}/{}/pkgbuild.any" "${module_dir}/{}/pkgbuild.${arch}")'
622603
623604 # -- PKGBUILDが入ったディレクトリを作業ディレクトリにコピー --#
605+ mkdir -p " ${airootfs_dir} /pkgbuilds/"
624606 for _dir in $( find " ${_pkgbuild_dirs[@]} " -type f -name " PKGBUILD" -print0 2> /dev/null | xargs -0 -I{} realpath {} | xargs -I{} dirname {}) ; do
625- mkdir -p " ${airootfs_dir} /pkgbuilds/ "
607+ msg_info " Find $( basename " ${_dir} " ) "
626608 cp -r " ${_dir} " " ${airootfs_dir} /pkgbuilds/"
627609 done
628610
629611 # -- ビルドスクリプトの実行 --#
612+ # copy buold script
630613 cp -rf --preserve=mode " ${script_path} /system/pkgbuild.sh" " ${airootfs_dir} /root/pkgbuild.sh"
631614
632615 # Run build script
@@ -761,6 +744,7 @@ make_boot_extra() {
761744
762745 for _ucode_image in {intel-uc.img,intel-ucode.img,amd-uc.img,amd-ucode.img,early_ucode.cpio,microcode.cpio}; do
763746 if [[ -e " ${airootfs_dir} /boot/${_ucode_image} " ]]; then
747+ msg_info " Installimg ${_ucode_image} ..."
764748 install -m 0644 -- " ${airootfs_dir} /boot/${_ucode_image} " " ${isofs_dir} /${install_dir} /boot/"
765749 if [[ -e " ${airootfs_dir} /usr/share/licenses/${_ucode_image% .* } /" ]]; then
766750 install -d -m 0755 -- " ${isofs_dir} /${install_dir} /boot/licenses/${_ucode_image% .* } /"
@@ -824,7 +808,7 @@ make_syslinux() {
824808 if [[ " ${memtest86} " = false ]]; then _remove_config memtest86.cfg; fi
825809
826810 # copy files
827- cp " ${build_dir} " / ${arch} /airootfs/ usr/lib/syslinux/bios/* .c32 " ${isofs_dir} /syslinux"
811+ cp " ${airootfs_dir} / usr/lib/syslinux/bios/" * .c32 " ${isofs_dir} /syslinux"
828812 cp " ${airootfs_dir} /usr/lib/syslinux/bios/lpxelinux.0" " ${isofs_dir} /syslinux"
829813 cp " ${airootfs_dir} /usr/lib/syslinux/bios/memdisk" " ${isofs_dir} /syslinux"
830814
@@ -880,20 +864,22 @@ make_efi() {
880864
881865 # edk2-shell based UEFI shell
882866 local _efi_shell_arch
883- for _efi_shell_arch in $( find " ${airootfs_dir} /usr/share/edk2-shell" -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -I{} basename {}) ; do
884- if [[ -f " ${airootfs_dir} /usr/share/edk2-shell/${_efi_shell_arch} /Shell_Full.efi" ]]; then
885- cp " ${airootfs_dir} /usr/share/edk2-shell/${_efi_shell_arch} /Shell_Full.efi" " ${isofs_dir} /EFI/shell_${_efi_shell_arch} .efi"
886- elif [[ -f " ${airootfs_dir} /usr/share/edk2-shell/${_efi_shell_arch} /Shell.efi" ]]; then
887- cp " ${airootfs_dir} /usr/share/edk2-shell/${_efi_shell_arch} /Shell.efi" " ${isofs_dir} /EFI/shell_${_efi_shell_arch} .efi"
888- else
889- continue
890- fi
891- cat - > " ${isofs_dir} /loader/entries/uefi-shell-${_efi_shell_arch} .conf" << EOF
867+ if [[ -d " ${airootfs_dir} /usr/share/edk2-shell" ]]; then
868+ for _efi_shell_arch in $( find " ${airootfs_dir} /usr/share/edk2-shell" -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -I{} basename {}) ; do
869+ if [[ -f " ${airootfs_dir} /usr/share/edk2-shell/${_efi_shell_arch} /Shell_Full.efi" ]]; then
870+ cp " ${airootfs_dir} /usr/share/edk2-shell/${_efi_shell_arch} /Shell_Full.efi" " ${isofs_dir} /EFI/shell_${_efi_shell_arch} .efi"
871+ elif [[ -f " ${airootfs_dir} /usr/share/edk2-shell/${_efi_shell_arch} /Shell.efi" ]]; then
872+ cp " ${airootfs_dir} /usr/share/edk2-shell/${_efi_shell_arch} /Shell.efi" " ${isofs_dir} /EFI/shell_${_efi_shell_arch} .efi"
873+ else
874+ continue
875+ fi
876+ cat - > " ${isofs_dir} /loader/entries/uefi-shell-${_efi_shell_arch} .conf" << EOF
892877title UEFI Shell ${_efi_shell_arch}
893878efi /EFI/shell_${_efi_shell_arch} .efi
894879
895880EOF
896- done
881+ done
882+ fi
897883}
898884
899885# Prepare efiboot.img::/EFI for "El Torito" EFI boot mode
@@ -929,7 +915,8 @@ make_efiboot() {
929915
930916 mkdir -p " ${build_dir} /efiboot/loader/entries"
931917 sed " s|%ARCH%|${arch} |g;" " ${script_path} /efiboot/${_use_config_name} /loader.conf" > " ${build_dir} /efiboot/loader/loader.conf"
932- cp " ${isofs_dir} /loader/entries/uefi-shell" * " ${build_dir} /efiboot/loader/entries/"
918+
919+ find " ${isofs_dir} /loader/entries/" -maxdepth 1 -mindepth 1 -name " uefi-shell*" -type f -printf " %p\0" | xargs -0 -I{} cp {} " ${build_dir} /efiboot/loader/entries/"
933920
934921 local _efi_config _efi_config_list=($( ls " ${script_path} /efiboot/${_use_config_name} /archiso-cd" * " .conf" ) )
935922
@@ -946,7 +933,7 @@ make_efiboot() {
946933 " ${_efi_config} " > " ${build_dir} /efiboot/loader/entries/$( basename " ${_efi_config} " | sed " s|cd|${arch} |g" ) "
947934 done
948935
949- cp " ${isofs_dir} /EFI/shell " * " .efi" " ${build_dir} /efiboot/EFI/"
936+ find " ${isofs_dir} /EFI" -maxdepth 1 -mindepth 1 -name " shell* .efi" -printf " %p\0 " | xargs -0 -I{} cp {} " ${build_dir} /efiboot/EFI/"
950937 umount -d " ${build_dir} /efiboot"
951938}
952939
@@ -1020,7 +1007,7 @@ make_prepare() {
10201007 msg_info " Done!"
10211008 fi
10221009
1023- umount_chroot_advance
1010+ umount_work
10241011
10251012 if [[ " ${cleaning} " = true ]]; then
10261013 remove " ${airootfs_dir} " " ${airootfs_dir} .img"
13051292
13061293# Set dirs
13071294work_dir=" $( realpath " ${work_dir} " ) "
1308- build_dir=" ${work_dir} /build"
1295+ build_dir=" ${work_dir} /build/ ${arch} "
13091296cache_dir=" ${work_dir} /cache/${arch} "
1310- airootfs_dir=" ${build_dir} /${arch} / airootfs"
1297+ airootfs_dir=" ${build_dir} /airootfs"
13111298isofs_dir=" ${build_dir} /iso"
13121299lockfile_dir=" ${build_dir} /lockfile"
13131300
0 commit comments