OSDN Git Service

[fix] : efi cp error
[alterlinux/LUBS.git] / lubs
diff --git a/lubs b/lubs
index 44a5156..de6870f 100755 (executable)
--- a/lubs
+++ b/lubs
@@ -1,4 +1,18 @@
 #!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-3.0
+#
+# mk-linux419
+# Twitter: @fascoder_4
+# Email  : m.k419sabuaka@gmail.com
+#
+# Yamada Hayao
+# Twitter: @Hayao0819
+# Email  : hayao@fascode.net
+#
+# (c) 2019-2020 Fascode Network.
+#
+# lubs
+#
 
 set -e
 # set -u
@@ -9,10 +23,10 @@ script_path=$(readlink -f "${0%/*}")
 
 cache_dir="${script_path}/cache"
 channels_dir="${script_path}/channels"
-isolinux_dir="${script_path}/isolinux"
+nfb_dir="${script_path}/nfb"
 
 codename="focal"
-mirror="http://ftp.jaist.ac.jp/pub/Linux/ubuntu/"
+mirror="http://linux.yz.yamagata-u.ac.jp/ubuntu/"
 os_name="Ubuntu"
 iso_name="ubuntu"
 
@@ -28,7 +42,6 @@ iso_filename="${iso_name}-${iso_version}-${arch}.iso"
 channel_name="serene"
 
 username="liveuser"
-password="liveuser"
 usershell="/bin/bash"
 
 debug=false
@@ -102,22 +115,11 @@ umount_chroot () {
 run_once() {
     local name
     umount_chroot
-
-    if [[ "run_bootfiles" == "$1" ]]; then
-        name="$2"
-    else
-        name="$1"
-    fi
+    name="$1"
 
     if [[ ! -e "${work_dir}/build.${name}" ]]; then
         _msg_info "$(echo $name | sed "s@_@ @g") is starting."
-
-        if [[ "run_bootfiles" == "${1}" ]]; then
-            "${1}" "${2}"
-        else
-            "${1}"
-        fi
-
+        "${1}"
         _msg_info "$(echo $name | sed "s@_@ @g") was done!"
         touch "${work_dir}/build.${name}"
     fi
@@ -127,7 +129,11 @@ run_cmd() {
     local mount
 
     for mount in "dev" "dev/pts" "proc" "sys" "run/systemd/resolve/stub-resolv.conf"; do
-        [[ "${mount}" == "run/systemd/resolve/stub-resolv.conf" ]] && mount --bind /etc/resolv.conf "${work_dir}/airootfs/${mount}" || mount --bind /${mount} "${work_dir}/airootfs/${mount}"
+        if [[ "${mount}" == "run/systemd/resolve/stub-resolv.conf" ]]; then
+            mount --bind /etc/resolv.conf "${work_dir}/airootfs/${mount}"
+        else
+            mount --bind /${mount} "${work_dir}/airootfs/${mount}"
+        fi
     done
     
     chroot "${work_dir}/airootfs" "${@}"
@@ -137,12 +143,6 @@ run_cmd() {
     done
 }
 
-run_bootfiles() {
-    cd "${bootfiles_dir}"
-    "$1"
-    cd - > /dev/null
-}
-
 _apt_install() {
     run_cmd apt-get --no-install-recommends --yes install ${@}
 }
@@ -255,7 +255,7 @@ make_basefs() {
         debootstrap_status "Running"
         _msg_info "Installing Ubuntu to '${cache_dir}/${codename}/airootfs'..."
         mkdir -p "${cache_dir}/${codename}/airootfs"
-        debootstrap --arch=${arch} --include=linux-image-generic  --verbose --merged-usr "${codename}" "${cache_dir}/${codename}/airootfs" ${mirror}
+        debootstrap --arch="${arch}" --verbose --merged-usr "${codename}" "${cache_dir}/${codename}/airootfs" "${mirror}"
         _msg_info "${codename} installed successfully!"
         debootstrap_status "Done"
     fi
@@ -280,7 +280,7 @@ make_sourcelist() {
     if [[ -n $(find ${channels_dir}/*/repo -type f) ]]; then
         _apt_install gnupg
 
-        for repo in $(find "${channels_dir}/*/repo" -name '*.list'); do
+        for repo in $(find ${channels_dir}/*/repo -name '*.list'); do
             key="$(dirname ${repo})/$(basename ${repo} | sed "s/list/key/")"
 
             if [[ -f "${key}" ]]; then
@@ -322,6 +322,8 @@ make_systemd() {
 
 make_apt_packages() {
     remove "${work_dir}/airootfs/aptpkglist"
+    _apt_install initramfs-tools
+    run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --yes'
 
     if [[ -f "${channels_dir}/share/packages.${arch}" ]]; then
         grep -h -v ^'#' "${channels_dir}/share/packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/aptpkglist"
@@ -338,25 +340,6 @@ make_apt_packages() {
     remove "${work_dir}/airootfs/aptpkglist"
 }
 
-make_snap_packages() {
-    remove "${work_dir}/airootfs/snappkglist"
-
-    if [[ -f "${channels_dir}/share/snap-packages.${arch}" ]]; then
-        grep -h -v ^'#' "${channels_dir}/share/snap-packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/snappkglist"
-    fi
-
-    if [[ -f "${channels_dir}/${channel_name}/snap-packages.${arch}" ]]; then
-        grep -h -v ^'#' "${channels_dir}/${channel_name}/snap-packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/snappkglist"
-    fi
-
-    if [[ -s "${work_dir}/airootfs/snappkglist" ]]; then
-        _apt_install snapd
-        run_cmd env -i bash -c 'snap install $(echo $(<snappkglist))'
-    fi
-
-    remove "${work_dir}/airootfs/snappkglist"
-}
-
 make_config() {
     # Locales
     run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 LC_ALL=C LANGUAGE=en_US.UTF-8 dpkg-reconfigure locales'
@@ -375,42 +358,10 @@ make_config() {
     run_cmd truncate -s 0 /etc/machine-id
 }
 
-make_customize_airootfs() {
-    #-- Overwrite airootfs files --#
-    local copy_airootfs
-
-    copy_airootfs() {
-        local _dir="${1%/}"
-
-        if [[ -d "${_dir}" ]]; then
-            cp -af "${_dir}"/* "${work_dir}/airootfs"
-        fi
-    }
-
-    copy_airootfs "${channels_dir}/share/airootfs"
-    copy_airootfs "${channels_dir}/${channel_name}/airootfs"
-
-    #-- Run scripts --#
-    local _customize_siript_options
-    _customize_siript_options="-a ${arch} -u '${username}' -p '${password}' -s '${usershell}'"
-
-    #if ${bash_debug}; then
-    #    _customize_siript_options="$_customize_siript_options -x"
-    #elif ${debug}; then
-    if ${debug}; then
-        _customize_siript_options="$_customize_siript_options -d"
-    fi
-
-    # run_customize_script <script path from lubs> <script path in chroot>
-    local run_customize_script
-    run_customize_script() {
-        if [[ -f "${1}" ]]; then
-            chmod 755 "${1}"
-            run_cmd "${2} ${_customize_siript_options}"
-        fi
-    }
-    run_customize_script "${work_dir}/airootfs/root/customize_airootfs.sh" "/root/customize_airootfs.sh"
-    run_customize_script "${work_dir}/airootfs/root/customize_airootfs_${channel_name}.sh"  "/root/customize_airootfs_${channel_name}.sh"
+make_add_user() {
+    sed "s|%USERNAME%|${username}|g;s|%OS_NAME%|${os_name}|g" "${nfb_dir}/casper.conf" > "${work_dir}/airootfs/etc/casper.conf"
+    chmod 755 "${work_dir}"/airootfs/usr/share/initramfs-tools/scripts/casper-bottom/*adduser "${work_dir}"/airootfs/usr/share/initramfs-tools/scripts/casper-bottom/*autologin
+    run_cmd env -i bash -c 'mkinitramfs -o /boot/initrd.img-`uname -r` `uname -r`'
 }
 
 make_clean() {
@@ -421,86 +372,83 @@ make_clean() {
     run_cmd rm -rf "/tmp/* ~/.bash_history"
 }
 
-make_bootfiles() {
-    run_cmd env -i bash -c 'update-initramfs -c -k all'
-    _apt_install memtest86+
+make_squashfs() {
+    # prepare
     [[ -d "${bootfiles_dir}" ]] && rm -r "${bootfiles_dir}"
-    mkdir -p ${bootfiles_dir}/{casper,isolinux,install}
-    cp "${work_dir}/airootfs/boot/vmlinuz" "${bootfiles_dir}/casper/vmlinuz"
-    cp "${work_dir}/airootfs/boot/initrd.img" "${bootfiles_dir}/casper/initrd"
-    cp "${work_dir}/airootfs/boot/memtest86+.bin" "${bootfiles_dir}/install/memtest86+"
-
-    if [[ ! -f "${cache_dir}/memtest86-usb.zip" ]]; then
-        wget -O "${cache_dir}/memtest86-usb.zip" https://www.memtest86.com/downloads/memtest86-usb.zip
-    fi
+    mkdir -p "${bootfiles_dir}"/{casper,isolinux,install}
 
-    (unzip -p "${cache_dir}/memtest86-usb.zip memtest86-usb.img" > "${bootfiles_dir}/install/memtest86")
+    # make squashfs
+    mksquashfs "${work_dir}/airootfs" "${bootfiles_dir}/casper/filesystem.squashfs"
 }
 
-make_grubcfg() {
+make_nfb() {
+    # prepare
     touch "${bootfiles_dir}/ubuntu"
-    cp "${isolinux_dir}/grub.cfg" "${bootfiles_dir}/isolinux/grub.cfg"
-}
+    sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/README.diskdefines" > "${bootfiles_dir}/README.diskdefines"
 
-make_manifest() {
-    run_cmd dpkg-query -W --showformat='${Package} ${Version}\n' | tee ${bootfiles_dir}/casper/filesystem.manifest
+    # casper setup
+    cp "${work_dir}/airootfs/boot/vmlinuz" "${bootfiles_dir}/casper/vmlinuz"
+    cp "${work_dir}/airootfs/boot/initrd.img" "${bootfiles_dir}/casper/initrd"
+    run_cmd dpkg-query -W --showformat='${Package} ${Version}\n' > ${bootfiles_dir}/casper/filesystem.manifest
     cp -v "${bootfiles_dir}/casper/filesystem.manifest" "${bootfiles_dir}/casper/filesystem.manifest-desktop"
-    sed -i '/ubiquity/d' "${bootfiles_dir}/casper/filesystem.manifest-desktop"
-    sed -i '/casper/d' "${bootfiles_dir}/casper/filesystem.manifest-desktop"
-    sed -i '/discover/d' "${bootfiles_dir}/casper/filesystem.manifest-desktop"
-    sed -i '/laptop-detect/d' "${bootfiles_dir}/casper/filesystem.manifest-desktop"
-    sed -i '/os-prober/d' "${bootfiles_dir}/casper/filesystem.manifest-desktop"
-}
+    sed -i '/casper/d;/discover/d;/laptop-detect/d;/os-prober/d;/ubiquity/d' "${bootfiles_dir}/casper/filesystem.manifest-desktop"
+    printf $(du -sx --block-size=1 "${work_dir}/airootfs" | cut -f1) > "${bootfiles_dir}/casper/filesystem.size"
 
-make_squashfs() {
-    mksquashfs "${work_dir}/airootfs" "${bootfiles_dir}/casper/filesystem.squashfs"
-    printf $(du -sx --block-size=1 "${work_dir}/airootfs" | cut -f1) > ${bootfiles_dir}/casper/filesystem.size
-}
+    # isolinux setup
+    cp "${work_dir}"/airootfs/usr/lib/syslinux/modules/bios/*.c32 "${bootfiles_dir}/isolinux/"
+    cp "${work_dir}/airootfs/usr/lib/ISOLINUX/isolinux.bin" "${bootfiles_dir}/isolinux/"
+    cp "${work_dir}/airootfs/usr/lib/ISOLINUX/isohdpfx.bin" "${bootfiles_dir}/isolinux/"
+    sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/grub.cfg" > "${bootfiles_dir}/isolinux/grub.cfg"
+    sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/isolinux.cfg" > "${bootfiles_dir}/isolinux/isolinux.cfg"
 
-make_deifnes() {
-    cp ${isolinux_dir}/README.diskdefines ${bootfiles_dir}/README.diskdefines
-}
+    # memtest86+ setup
+    _apt_install memtest86+
+    cp "${work_dir}/airootfs/boot/memtest86+.bin" "${bootfiles_dir}/install/memtest86+"
 
-make_isolinux() {
-    if [[ "${arch}" = "amd64" ]]; then
-        local _arch="x86_64"
-    else
-        local _arch="${arch}"
+    # memtest86 setup
+    if [[ ! -f "${cache_dir}/memtest86-usb.zip" ]]; then
+        wget -O "${cache_dir}/memtest86-usb.zip" "https://www.memtest86.com/downloads/memtest86-usb.zip"
+        bash -c "(unzip -p ${cache_dir}/memtest86-usb.zip memtest86-usb.img > ${cache_dir}/memtest86)"
     fi
 
+    cp "${cache_dir}/memtest86" "${bootfiles_dir}/install/memtest86"
+}
+
+make_efi() {
+    # UEFI 32bit (ia32)
     grub-mkstandalone \
-        --format=${_arch}-efi \
-        --output=isolinux/bootx64.efi \
+        --format=i386-efi \
+        --output="${bootfiles_dir}/isolinux/bootia32.efi" \
         --locales="" \
         --fonts="" \
-        "boot/grub/grub.cfg=isolinux/grub.cfg"
+        "boot/grub/grub.cfg=${bootfiles_dir}/isolinux/grub.cfg"
     
-    (
-        cd isolinux && \
-        dd if=/dev/zero of=efiboot.img bs=1M count=10 && \
-        sudo mkfs.vfat efiboot.img && \
-        LC_CTYPE=C mmd -i efiboot.img efi efi/boot && \
-        LC_CTYPE=C mcopy -i efiboot.img ./bootx64.efi ::efi/boot/
-    )
-
+    # UEFI 64bit (x64)
     grub-mkstandalone \
-        --format=i386-pc \
-        --output=isolinux/core.img \
-        --install-modules="linux16 linux normal iso9660 biosdisk memdisk search tar ls" \
-        --modules="linux16 linux normal iso9660 biosdisk search" \
+        --format=x86_64-efi \
+        --output="${bootfiles_dir}/isolinux/bootx64.efi" \
         --locales="" \
         --fonts="" \
-        --themes="" \
-        "boot/grub/grub.cfg=isolinux/grub.cfg"
-    
-    cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img > isolinux/bios.img
-}
-
-make_md5sum() {
-    /bin/bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)"
+        "boot/grub/grub.cfg=${bootfiles_dir}/isolinux/grub.cfg"
+
+    # create efiboot.img
+    truncate -s 50M "${bootfiles_dir}/isolinux/efiboot.img"
+    mkfs.fat -F 16 -f 1 -r 112 "${bootfiles_dir}/isolinux/efiboot.img"
+    mount "${bootfiles_dir}/isolinux/efiboot.img" "${bootfiles_dir}/mnt"
+    mkdir -p "${bootfiles_dir}/mnt/efi/boot"
+    cp "${bootfiles_dir}/isolinux/bootia32.efi" "${bootfiles_dir}/mnt/efi/boot/"
+    cp "${bootfiles_dir}/isolinux/bootx64.efi" "${bootfiles_dir}/mnt/efi/boot/"
+    umount -d "${bootfiles_dir}/mnt"
+    rm -r "${bootfiles_dir}/mnt"
 }
 
 make_iso() {
+    cd "${bootfiles_dir}"
+
+    # create checksum (using at booting)
+    bash -c "(find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt)"
+
+    # create iso
     xorriso \
         -as mkisofs \
         -iso-level 3 \
@@ -509,26 +457,28 @@ make_iso() {
         -appid "${iso_application}" \
         -publisher "${iso_publisher}" \
         -preparer "prepared by LUBS" \
-        -eltorito-boot boot/grub/bios.img \
-        -no-emul-boot \
-        -boot-load-size 4 \
-        -boot-info-table \
-        --eltorito-catalog boot/grub/boot.cat \
-        --grub2-boot-info \
-        --grub2-mbr /usr/lib/grub/i386-pc/boot_hybrid.img \
+        -eltorito-boot isolinux/isolinux.bin \
+            -no-emul-boot \
+            -boot-load-size 4 \
+            -boot-info-table \
         -eltorito-alt-boot \
-        -e EFI/efiboot.img \
-        -no-emul-boot \
-        -append_partition 2 0xef isolinux/efiboot.img \
+            -eltorito-platform efi \
+            -eltorito-boot EFI/efiboot.img \
+            -no-emul-boot \
+        -isohybrid-mbr "${bootfiles_dir}/isolinux/isohdpfx.bin" \
+        -isohybrid-gpt-basdat \
+        -eltorito-catalog isolinux/boot.cat \
         -output "${out_dir}/${iso_filename}" \
         -graft-points \
             "." \
-            /boot/grub/bios.img=isolinux/bios.img \
-            /EFI/efiboot.img=isolinux/efiboot.img
+            "/isolinux/isolinux.bin=isolinux/isolinux.bin" \
+            "/EFI/efiboot.img=isolinux/efiboot.img"
+    
+    cd - > /dev/null
 }
 
 make_checksum() {
-    cd ${out_dir}
+    cd "${out_dir}"
     _msg_info "Creating md5 checksum ..."
     md5sum "${iso_filename}" > "${iso_filename}.md5"
 
@@ -664,16 +614,11 @@ run_once make_basefs
 run_once make_sourcelist
 run_once make_systemd
 run_once make_apt_packages
-#run_once make_snap_packages
 run_once make_config
-run_once make_customize_airootfs
+run_once make_add_user
 run_once make_clean
-run_once make_bootfiles
-run_once make_grubcfg
-run_once make_manifest
 run_once make_squashfs
-run_once make_deifnes
-run_once run_bootfiles make_isolinux
-run_once run_bootfiles make_md5sum
-run_once run_bootfiles make_iso
+run_once make_nfb
+run_once make_efi
+run_once make_iso
 run_once make_checksum