OSDN Git Service

[fix] : Fixing issues with variable quoting and arrays (archiso 45)
authorhayao <shun819.mail@gmail.com>
Wed, 29 Jul 2020 08:55:19 +0000 (17:55 +0900)
committerhayao <shun819.mail@gmail.com>
Wed, 29 Jul 2020 08:55:19 +0000 (17:55 +0900)
archiso/mkarchiso:
Calls to _pacman() need to be done with multiple parameters (e.g. array) instead of one string, as string splitting is
not done in that function anymore.
Turning _iso_efi_boot_args from string into an array to have an easier time of passing it to xorriso.
Calling xorriso within the if statements instead of providing -quiet via variable.
Fixing command_install() to provide packages separately to _pacman()

configs/releng/build.sh:
Replacing all newlines when retrieving the packages from packages.x86_64 with spaces so they will be properly provided
to "mkarchiso install".

build.sh
system/mkalteriso.sh

index 4c2ae78..509ebca 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -239,7 +239,7 @@ _usage () {
     for list in ${script_path}/system/kernel_list-* ; do
         echo " ${list#${script_path}/system/kernel_list-}:"
         echo -n "    "
-        for kernel in $(grep -h -v ^'#' ${list}); do
+        for kernel in $(grep -h -v ^'#' ${list} | sed ':a;N;$!ba;s/\n/ /g'); do
             echo -n "${kernel} "
         done
         echo
@@ -705,7 +705,7 @@ make_packages() {
         # Read the file and remove comments starting with # and add it to the list of packages to install.
         for _file in ${_loadfilelist[@]}; do
             _msg_debug "Loaded package file ${_file}"
-            pkglist=( ${pkglist[@]} "$(grep -h -v ^'#' ${_file})" )
+            pkglist=( ${pkglist[@]} "$(grep -h -v ^'#' ${_file} | sed ':a;N;$!ba;s/\n/ /g')" )
         done
         if [[ ${debug} = true ]]; then
             sleep 3
@@ -714,7 +714,7 @@ make_packages() {
         # Exclude packages from the share exclusion list
         excludefile="${script_path}/channels/share/packages.${arch}/exclude"
         if [[ -f "${excludefile}" ]]; then
-            excludelist=( $(grep -h -v ^'#' "${excludefile}") )
+            excludelist=( $(grep -h -v ^'#' "${excludefile}" | sed ':a;N;$!ba;s/\n/ /g') )
 
             # 現在のpkglistをコピーする
             _pkglist=(${pkglist[@]})
@@ -735,7 +735,7 @@ make_packages() {
         # Exclude packages from the exclusion list for each channel
         excludefile="${script_path}/channels/${channel_name}/packages.${arch}/exclude"
         if [[ -f "${excludefile}" ]]; then
-            excludelist=( $(grep -h -v ^'#' "${excludefile}") )
+            excludelist=( $(grep -h -v ^'#' "${excludefile}" | sed ':a;N;$!ba;s/\n/ /g') )
         
             # 現在のpkglistをコピーする
             _pkglist=(${pkglist[@]})
@@ -1192,7 +1192,7 @@ while :; do
             shift 1
             ;;
         -k | --kernel)
-            if [[ -n $(cat ${script_path}/system/kernel_list-${arch} | grep -h -v ^'#' | grep -x "${2}") ]]; then
+            if [[ -n $(cat ${script_path}/system/kernel_list-${arch} | grep -h -v ^'#' | sed ':a;N;$!ba;s/\n/ /g' | grep -x "${2}") ]]; then
                 kernel="${2}"
             else
                 _msg_error "Invalid kernel ${2}" "1"
@@ -1377,13 +1377,13 @@ fi
 # Check architecture and kernel for each channel
 if [[ ! "${channel_name}" = "rebuild" ]] && [[ ! "${channel_name}" = "clean" ]]; then
     # architecture
-    if [[ -z $(cat "${script_path}/channels/${channel_name}/architecture" | grep -h -v ^'#' | grep -x "${arch}") ]]; then
+    if [[ -z $(cat "${script_path}/channels/${channel_name}/architecture" | grep -h -v ^'#' | sed ':a;N;$!ba;s/\n/ /g' | grep -x "${arch}") ]]; then
         _msg_error "${channel_name} channel does not support current architecture (${arch})." "1"
     fi
 
     # kernel
     if [[ -f "${script_path}/channels/${channel_name}/kernel_list-${arch}" ]]; then
-        if [[ -z $(cat "${script_path}/channels/${channel_name}/kernel_list-${arch}" | grep -h -v ^'#' | grep -x "${kernel}") ]]; then
+        if [[ -z $(cat "${script_path}/channels/${channel_name}/kernel_list-${arch}" | grep -h -v ^'#' | sed ':a;N;$!ba;s/\n/ /g' | grep -x "${kernel}") ]]; then
             _msg_error "This kernel is currently not supported on this channel." "1"
         fi
     fi
index 3bddc29..74b4a50 100755 (executable)
@@ -57,10 +57,8 @@ cdback() {
 
 _chroot_init() {
     mkdir -p ${work_dir}/airootfs
-    
-    #_pacman "base base-devel syslinux" <- old code
 
-    _pacman "base syslinux"
+    _pacman base syslinux
 }
 
 _chroot_run() {
@@ -308,7 +306,7 @@ command_pkglist () {
 
 # Create an ISO9660 filesystem from "iso" directory.
 command_iso () {
-    local _iso_efi_boot_args=""
+    local _iso_efi_boot_args=()
 
     if [[ ! -f "${work_dir}/iso/isolinux/isolinux.bin" ]]; then
          _msg_error "The file '${work_dir}/iso/isolinux/isolinux.bin' does not exist." 1
@@ -319,10 +317,12 @@ command_iso () {
 
     # If exists, add an EFI "El Torito" boot image (FAT filesystem) to ISO-9660 image.
     if [[ -f "${work_dir}/iso/EFI/archiso/efiboot.img" ]]; then
-        _iso_efi_boot_args="-eltorito-alt-boot
-                            -e EFI/archiso/efiboot.img
-                            -no-emul-boot
-                            -isohybrid-gpt-basdat"
+        _iso_efi_boot_args+=(
+            '-eltorito-alt-boot'
+            '-e' 'EFI/archiso/efiboot.img'
+            '-no-emul-boot'
+            '-isohybrid-gpt-basdat'
+        )
     fi
 
     _show_config iso
@@ -330,23 +330,39 @@ command_iso () {
     mkdir -p "${out_dir}"
     _msg_info "Creating ISO image..."
     local _qflag=""
-    if [[ ${quiet} == "y" ]]; then
-        _qflag="-quiet"
+    if [[ "${quiet}" == "y" ]]; then
+        xorriso -as mkisofs -quiet \
+            -iso-level 3 \
+            -full-iso9660-filenames \
+            -volid "${iso_label}" \
+            -appid "${iso_application}" \
+            -publisher "${iso_publisher}" \
+            -preparer "prepared by mkarchiso" \
+            -eltorito-boot isolinux/isolinux.bin \
+            -eltorito-catalog isolinux/boot.cat \
+            -no-emul-boot -boot-load-size 4 -boot-info-table \
+            -isohybrid-mbr "${work_dir}/iso/isolinux/isohdpfx.bin" \
+            "${_iso_efi_boot_args[@]}" \
+            -output "${out_dir}/${img_name}" \
+            "${work_dir}/iso/"
+    else
+        xorriso -as mkisofs \
+            -iso-level 3 \
+            -full-iso9660-filenames \
+            -volid "${iso_label}" \
+            -appid "${iso_application}" \
+            -publisher "${iso_publisher}" \
+            -preparer "prepared by mkarchiso" \
+            -eltorito-boot isolinux/isolinux.bin \
+            -eltorito-catalog isolinux/boot.cat \
+            -no-emul-boot -boot-load-size 4 -boot-info-table \
+            -isohybrid-mbr "${work_dir}/iso/isolinux/isohdpfx.bin" \
+            "${_iso_efi_boot_args[@]}" \
+            -output "${out_dir}/${img_name}" \
+            "${work_dir}/iso/"
     fi
-    xorriso -as mkisofs ${_qflag} \
-        -iso-level 3 \
-        -full-iso9660-filenames \
-        -volid "${iso_label}" \
-        -appid "${iso_application}" \
-        -publisher "${iso_publisher}" \
-        -preparer "prepared by mkalteriso" \
-        -eltorito-boot isolinux/isolinux.bin \
-        -eltorito-catalog isolinux/boot.cat \
-        -no-emul-boot -boot-load-size 4 -boot-info-table \
-        -isohybrid-mbr ${work_dir}/iso/isolinux/isohdpfx.bin \
-        ${_iso_efi_boot_args} \
-        -output "${out_dir}/${img_name}" \
-        "${work_dir}/iso/"
+
+    
     _mkisochecksum
     _msg_info "Done! | $(ls -sh ${out_dir}/${img_name})"
 }
@@ -374,17 +390,14 @@ command_install () {
         _msg_error "Pacman config file '${pacman_conf}' does not exist" 1
     fi
 
-    #trim spaces
-    pkg_list="$(echo ${pkg_list})"
-
-    if [[ -z ${pkg_list} ]]; then
+    if [[ "${#pkg_list[@]}" -eq 0 ]]; then
         _msg_error "Packages must be specified" 0
         _usage 1
     fi
 
     _show_config install
 
-    _pacman "${pkg_list}"
+    _pacman "${pkg_list[@]}"
 }
 
 command_init() {
@@ -406,6 +419,10 @@ umask 0022
 while getopts 'a:p:r:C:L:P:A:D:w:o:s:c:g:t:vhx' arg; do
     case "${arg}" in
         a) arch="${OPTARG}" ;;
+        p)
+            read -r -a opt_pkg_list <<< "${OPTARG}"
+            pkg_list+=("${opt_pkg_list[@]}")
+            ;;
         p) pkg_list="${pkg_list} ${OPTARG}" ;;
         r) run_cmd="${OPTARG}" ;;
         C) pacman_conf="${OPTARG}" ;;