@@ -74,6 +74,9 @@ getclm() { cut -d " " -f "${1}"; }
7474# 指定されたぶんの半角空白文字を出力します
7575echo_blank (){ yes " " 2> /dev/null | head -n " ${1} " | tr -d " \n" ; }
7676
77+ # cpコマンドのラッパー
78+ _cp (){ cp -af --no-preserve=ownership,mode -- " ${@ } " ; }
79+
7780_usage () {
7881 cat " ${script_path} /docs/build.sh/help.1"
7982 local blank=" 29" _arch _dirname _type _output _first
@@ -379,6 +382,7 @@ prepare_build() {
379382 for_module load_config " ${module_dir} /{}/config.any" " ${module_dir} /{}/config.${arch} "
380383 msg_debug " Loaded modules: ${modules[*]} "
381384 ! printf " %s\n" " ${modules[@]} " | grep -x " share" > /dev/null 2>&1 && msg_warn " The share module is not loaded."
385+ ! printf " %s\n" " ${modules[@]} " | grep -x " base" > /dev/null 2>&1 && msg_error " The base module is not loaded." 1
382386
383387 # Set kernel
384388 [[ " ${customized_kernel} " = false ]] && kernel=" ${defaultkernel} "
@@ -424,7 +428,7 @@ prepare_build() {
424428 mkdir -p " $( dirname " ${logging} " ) " && touch " ${logging} "
425429 msg_warn " Re-run sudo ${0} ${ARGUMENT[*]} --nodepend --nolog --nocolor --rerun 2>&1 | tee ${logging} "
426430 sudo " ${0} " " ${ARGUMENT[@]} " --nolog --nocolor --nodepend --rerun 2>&1 | tee " ${logging} "
427- exit " ${? } "
431+ exit " ${PIPESTATUS[0] } "
428432 fi
429433
430434 # Set argument of pkglist.sh
@@ -438,7 +442,7 @@ prepare_build() {
438442
439443 # Set argument of aur.sh and pkgbuild.sh
440444 [[ " ${bash_debug} " = true ]] && makepkg_script_args+=(" -x" )
441- [[ " ${pacman_debug} " = true ]] && makepkg_script_args+=(" -d " )
445+ [[ " ${pacman_debug} " = true ]] && makepkg_script_args+=(" -c " )
442446
443447 return 0
444448}
@@ -502,7 +506,7 @@ make_packages_repo() {
502506 if printf " %s\n" " ${repopkgs[@]} " | grep -qx " ${_pkg} " ; then
503507 _pkglist_install+=(" ${_pkg} " )
504508 else
505- msg_info " ${_pkg} was not found. Install it with yay from AUR"
509+ msg_info " ${_pkg} was not found. Install it from AUR"
506510 norepopkg+=(" ${_pkg} " )
507511 fi
508512 done
@@ -521,17 +525,23 @@ make_packages_repo() {
521525make_packages_aur () {
522526 readarray -t _pkglist_aur < <( " ${tools_dir} /pkglist.sh" --aur " ${pkglist_args[@]} " )
523527 _pkglist_aur=(" ${_pkglist_aur[@]} " " ${norepopkg[@]} " )
528+ _aursh_args=(
529+ " -a" " ${aur_helper_command} " -e " ${aur_helper_package} "
530+ " -d" " $( printf " %s\n" " ${aur_helper_depends[@]} " | tr " \n" " ," ) "
531+ " -p" " $( printf " %s\n" " ${_pkglist_aur[@]} " | tr " \n" " ," ) "
532+ " ${makepkg_script_args[@]} " -- " ${aur_helper_args[@]} "
533+ )
524534
525535 # Create a list of packages to be finally installed as packages.list directly under the working directory.
526536 echo -e " \n# AUR packages.\n#\n" >> " ${build_dir} /packages.list"
527537 printf " %s\n" " ${_pkglist_aur[@]} " >> " ${build_dir} /packages.list"
528538
529- # prepare for yay
530- cp -rf --preserve=mode " ${script_path} /system/aur.sh" " ${airootfs_dir} /root/aur.sh"
531- _pacstrap --asdeps --needed " go " # --asdepsをつけているのでaur.shで削除される --neededをつけているので明示的にインストールされている場合削除されない
539+ # prepare for aur helper
540+ _cp " ${script_path} /system/aur.sh" " ${airootfs_dir} /root/aur.sh"
541+ _pacstrap --asdeps --needed " ${aur_helper_depend[@]} "
532542
533543 # Run aur script
534- _run_with_pacmanconf _chroot_run " bash" " /root/aur.sh" " ${makepkg_script_args[@]} " " ${_pkglist_aur [@]}"
544+ _run_with_pacmanconf _chroot_run " bash" " /root/aur.sh" " ${_aursh_args [@]} "
535545
536546 # Remove script
537547 remove " ${airootfs_dir} /root/aur.sh"
@@ -548,11 +558,11 @@ make_pkgbuild() {
548558 mkdir -p " ${airootfs_dir} /pkgbuilds/"
549559 for _dir in $( find " ${_pkgbuild_dirs[@]} " -type f -name " PKGBUILD" -print0 2> /dev/null | xargs -0 -I{} realpath {} | xargs -I{} dirname {}) ; do
550560 msg_info " Find $( basename " ${_dir} " ) "
551- cp -r " ${_dir} " " ${airootfs_dir} /pkgbuilds/"
561+ _cp " ${_dir} " " ${airootfs_dir} /pkgbuilds/"
552562 done
553563
554564 # copy buold script
555- cp -rf --preserve=mode " ${script_path} /system/pkgbuild.sh" " ${airootfs_dir} /root/pkgbuild.sh"
565+ _cp " ${script_path} /system/pkgbuild.sh" " ${airootfs_dir} /root/pkgbuild.sh"
556566
557567 # Run build script
558568 _run_with_pacmanconf _chroot_run " bash" " /root/pkgbuild.sh" " ${makepkg_script_args[@]} " " /pkgbuilds"
@@ -574,15 +584,15 @@ make_customize_airootfs() {
574584 for _airootfs in " ${_airootfs_list[@]} " ; do
575585 if [[ -d " ${_airootfs} " ]]; then
576586 msg_debug " Copying airootfs ${_airootfs} ..."
577- cp -af " ${_airootfs} " /* " ${airootfs_dir} "
587+ _cp " ${_airootfs} " /* " ${airootfs_dir} "
578588 fi
579589 done
580590
581591 # Replace /etc/mkinitcpio.conf if Plymouth is enabled.
582592 if [[ " ${boot_splash} " = true ]]; then
583- cp -f " ${script_path} /mkinitcpio/mkinitcpio-plymouth.conf" " ${airootfs_dir} /etc/mkinitcpio.conf"
593+ install -m 0644 -- " ${script_path} /mkinitcpio/mkinitcpio-plymouth.conf" " ${airootfs_dir} /etc/mkinitcpio.conf"
584594 else
585- cp -f " ${script_path} /mkinitcpio/mkinitcpio.conf" " ${airootfs_dir} /etc/mkinitcpio.conf"
595+ install -m 0644 -- " ${script_path} /mkinitcpio/mkinitcpio.conf" " ${airootfs_dir} /etc/mkinitcpio.conf"
586596 fi
587597
588598 # customize_airootfs options
@@ -646,15 +656,15 @@ make_setup_mkinitcpio() {
646656 mkdir -p " ${airootfs_dir} /etc/initcpio/hooks" " ${airootfs_dir} /etc/initcpio/install"
647657
648658 for _hook in " archiso" " archiso_shutdown" " archiso_pxe_common" " archiso_pxe_nbd" " archiso_pxe_http" " archiso_pxe_nfs" " archiso_loop_mnt" ; do
649- cp " ${script_path} /system/initcpio/hooks/${_hook} " " ${airootfs_dir} /etc/initcpio/hooks"
650- cp " ${script_path} /system/initcpio/install/${_hook} " " ${airootfs_dir} /etc/initcpio/install"
659+ install -m 0644 -- " ${script_path} /system/initcpio/hooks/${_hook} " " ${airootfs_dir} /etc/initcpio/hooks"
660+ install -m 0644 -- " ${script_path} /system/initcpio/install/${_hook} " " ${airootfs_dir} /etc/initcpio/install"
651661 done
652662
653663 sed -i " s|%COWSPACE%|${cowspace} |g" " ${airootfs_dir} /etc/initcpio/hooks/archiso"
654664 sed -i " s|/usr/lib/initcpio/|/etc/initcpio/|g" " ${airootfs_dir} /etc/initcpio/install/archiso_shutdown"
655- cp " ${script_path} /system/initcpio/install/archiso_kms" " ${airootfs_dir} /etc/initcpio/install"
656- cp " ${script_path} /system/initcpio/script/archiso_shutdown" " ${airootfs_dir} /etc/initcpio"
657- cp " ${script_path} /mkinitcpio/mkinitcpio-archiso.conf" " ${airootfs_dir} /etc/mkinitcpio-archiso.conf"
665+ install -m 0644 -- " ${script_path} /system/initcpio/install/archiso_kms" " ${airootfs_dir} /etc/initcpio/install"
666+ install -m 0755 -- " ${script_path} /system/initcpio/script/archiso_shutdown" " ${airootfs_dir} /etc/initcpio"
667+ install -m 0644 -- " ${script_path} /mkinitcpio/mkinitcpio-archiso.conf" " ${airootfs_dir} /etc/mkinitcpio-archiso.conf"
658668 [[ " ${boot_splash} " = true ]] && cp " ${script_path} /mkinitcpio/mkinitcpio-archiso-plymouth.conf" " ${airootfs_dir} /etc/mkinitcpio-archiso.conf"
659669
660670 if [[ " ${gpg_key} " ]]; then
@@ -672,8 +682,8 @@ make_setup_mkinitcpio() {
672682# Prepare kernel/initramfs ${install_dir}/boot/
673683make_boot () {
674684 mkdir -p " ${isofs_dir} /${install_dir} /boot/${arch} "
675- cp " ${airootfs_dir} /boot/archiso.img" " ${isofs_dir} /${install_dir} /boot/${arch} /archiso.img"
676- cp " ${airootfs_dir} /boot/${kernel_filename} " " ${isofs_dir} /${install_dir} /boot/${arch} /${kernel_filename} "
685+ install -m 0644 -- " ${airootfs_dir} /boot/archiso.img" " ${isofs_dir} /${install_dir} /boot/${arch} /archiso.img"
686+ install -m 0644 -- " ${airootfs_dir} /boot/${kernel_filename} " " ${isofs_dir} /${install_dir} /boot/${arch} /${kernel_filename} "
677687
678688 return 0
679689}
@@ -710,7 +720,7 @@ make_syslinux() {
710720
711721 # 一時ディレクトリに設定ファイルをコピー
712722 mkdir -p " ${build_dir} /syslinux/"
713- cp -a " ${script_path} /syslinux/" * " ${build_dir} /syslinux/"
723+ _cp " ${script_path} /syslinux/" * " ${build_dir} /syslinux/"
714724 [[ -d " ${channel_dir} /syslinux" ]] && [[ " ${customized_syslinux} " = true ]] && cp -af " ${channel_dir} /syslinux" * " ${build_dir} /syslinux/"
715725
716726 # copy all syslinux config to work dir
@@ -734,8 +744,8 @@ make_syslinux() {
734744 done
735745
736746 # Set syslinux wallpaper
737- cp " ${script_path} /syslinux/splash.png" " ${isofs_dir} /syslinux"
738- [[ -f " ${channel_dir} /splash.png" ]] && cp -f " ${channel_dir} /splash.png" " ${isofs_dir} /syslinux"
747+ install -m 0644 -- " ${script_path} /syslinux/splash.png" " ${isofs_dir} /syslinux/ "
748+ [[ -f " ${channel_dir} /splash.png" ]] && install -m 0644 -- " ${channel_dir} /splash.png" " ${isofs_dir} /syslinux"
739749
740750 # remove config
741751 local _remove_config
@@ -748,9 +758,9 @@ make_syslinux() {
748758 [[ " ${memtest86} " = false ]] && _remove_config memtest86.cfg
749759
750760 # copy files
751- cp " ${airootfs_dir} /usr/lib/syslinux/bios/" * .c32 " ${isofs_dir} /syslinux"
752- cp " ${airootfs_dir} /usr/lib/syslinux/bios/lpxelinux.0" " ${isofs_dir} /syslinux"
753- cp " ${airootfs_dir} /usr/lib/syslinux/bios/memdisk" " ${isofs_dir} /syslinux"
761+ install -m 0644 -- " ${airootfs_dir} /usr/lib/syslinux/bios/" * .c32 " ${isofs_dir} /syslinux/ "
762+ install -m 0644 -- " ${airootfs_dir} /usr/lib/syslinux/bios/lpxelinux.0" " ${isofs_dir} /syslinux/ "
763+ install -m 0644 -- " ${airootfs_dir} /usr/lib/syslinux/bios/memdisk" " ${isofs_dir} /syslinux/ "
754764
755765
756766 if [[ -e " ${isofs_dir} /syslinux/hdt.c32" ]]; then
@@ -786,8 +796,8 @@ make_efi() {
786796 install -d -m 0755 -- " ${isofs_dir} /loader/entries"
787797 sed " s|%ARCH%|${arch} |g;" " ${script_path} /efiboot/${_use_config_name} /loader.conf" > " ${isofs_dir} /loader/loader.conf"
788798
789- readarray -t _efi_config_list < <( find " ${script_path} /efiboot/${_use_config_name} /" -mindepth 1 -maxdepth 1 -type f -name " archiso-usb*.conf" -printf " %f\n" | grep -v " rescue" )
790- [[ " ${norescue_entry} " = false ]] && readarray -t _efi_config_list < <( find " ${script_path} /efiboot/${_use_config_name} /" -mindepth 1 -maxdepth 1 -type f -name " archiso-usb*.conf" -printf " %f\n" )
799+ readarray -t _efi_config_list < <( find " ${script_path} /efiboot/${_use_config_name} /" -mindepth 1 -maxdepth 1 -type f -name " *- archiso-usb*.conf" -printf " %f\n" | grep -v " rescue" )
800+ [[ " ${norescue_entry} " = false ]] && readarray -t _efi_config_list < <( find " ${script_path} /efiboot/${_use_config_name} /" -mindepth 1 -maxdepth 1 -type f -name " *- archiso-usb*.conf" -printf " %f\n" )
791801
792802 for _efi_config in " ${_efi_config_list[@]} " ; do
793803 sed " s|%ARCHISO_LABEL%|${iso_label} |g;
@@ -825,26 +835,26 @@ make_efiboot() {
825835 mount " ${build_dir} /efiboot.img" " ${build_dir} /efiboot"
826836
827837 mkdir -p " ${build_dir} /efiboot/EFI/alteriso/${arch} " " ${build_dir} /efiboot/EFI/boot" " ${build_dir} /efiboot/loader/entries"
828- cp " ${isofs_dir} /${install_dir} /boot/${arch} /${kernel_filename} " " ${build_dir} /efiboot/EFI/alteriso/${arch} /${kernel_filename} .efi"
829- cp " ${isofs_dir} /${install_dir} /boot/${arch} /archiso.img" " ${build_dir} /efiboot/EFI/alteriso/${arch} /archiso.img"
838+ _cp " ${isofs_dir} /${install_dir} /boot/${arch} /${kernel_filename} " " ${build_dir} /efiboot/EFI/alteriso/${arch} /${kernel_filename} .efi"
839+ _cp " ${isofs_dir} /${install_dir} /boot/${arch} /archiso.img" " ${build_dir} /efiboot/EFI/alteriso/${arch} /archiso.img"
830840
831841 local _ucode_image _efi_config _use_config_name=" nosplash" _bootfile
832842 for _ucode_image in " ${airootfs_dir} /boot/" {intel-uc.img,intel-ucode.img,amd-uc.img,amd-ucode.img,early_ucode.cpio,microcode.cpio}; do
833- [[ -e " ${_ucode_image} " ]] && cp " ${_ucode_image} " " ${build_dir} /efiboot/EFI/alteriso/"
843+ [[ -e " ${_ucode_image} " ]] && _cp " ${_ucode_image} " " ${build_dir} /efiboot/EFI/alteriso/"
834844 done
835845
836- cp " ${airootfs_dir} /usr/share/efitools/efi/HashTool.efi" " ${build_dir} /efiboot/EFI/boot/"
846+ _cp " ${airootfs_dir} /usr/share/efitools/efi/HashTool.efi" " ${build_dir} /efiboot/EFI/boot/"
837847
838848 _bootfile=" $( basename " $( ls " ${airootfs_dir} /usr/lib/systemd/boot/efi/systemd-boot" * " .efi" ) " ) "
839- cp " ${airootfs_dir} /usr/lib/systemd/boot/efi/${_bootfile} " " ${build_dir} /efiboot/EFI/boot/${_bootfile# systemd-} "
849+ _cp " ${airootfs_dir} /usr/lib/systemd/boot/efi/${_bootfile} " " ${build_dir} /efiboot/EFI/boot/${_bootfile# systemd-} "
840850
841851 [[ " ${boot_splash} " = true ]] && _use_config_name=" splash"
842852 sed " s|%ARCH%|${arch} |g;" " ${script_path} /efiboot/${_use_config_name} /loader.conf" > " ${build_dir} /efiboot/loader/loader.conf"
843853
844854 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/"
845855
846- readarray -t _efi_config_list < <( find " ${script_path} /efiboot/${_use_config_name} /" -mindepth 1 -maxdepth 1 -type f -name " archiso-cd*.conf" -printf " %f\n" | grep -v " rescue" )
847- [[ " ${norescue_entry} " = false ]] && readarray -t _efi_config_list < <( find " ${script_path} /efiboot/${_use_config_name} /" -mindepth 1 -maxdepth 1 -type f -name " archiso-cd*.conf" -printf " %f\n" )
856+ readarray -t _efi_config_list < <( find " ${script_path} /efiboot/${_use_config_name} /" -mindepth 1 -maxdepth 1 -type f -name " *- archiso-cd*.conf" -printf " %f\n" | grep -v " rescue" )
857+ [[ " ${norescue_entry} " = false ]] && readarray -t _efi_config_list < <( find " ${script_path} /efiboot/${_use_config_name} /" -mindepth 1 -maxdepth 1 -type f -name " *- archiso-cd*.conf" -printf " %f\n" )
848858
849859 for _efi_config in " ${_efi_config_list[@]} " ; do
850860 sed " s|%ARCHISO_LABEL%|${iso_label} |g;
0 commit comments