OSDN Git Service

fixed bind
[alterlinux/LFBS.git] / lfbs
diff --git a/lfbs b/lfbs
index ab3fa72..1a0a650 100755 (executable)
--- a/lfbs
+++ b/lfbs
@@ -18,13 +18,14 @@ script_path=$(readlink -f "${0%/*}")
 work_dir="${script_path}/work"
 channels_dir="${script_path}/channels"
 nfb_dir="${script_path}/nfb"
-codename="32"
-os_name="Fedora"
+codename="33"
+os_name="SereneLinux"
 iso_name="Fedora"
 language="ja_JP.UTF-8"
-channel_name="lxde"
-
-arch=x86_64
+channel_name="serene"
+cache_dir="${script_path}/cache"
+bootsplash=false
+arch="x86_64"
 
 out_dir="${script_path}/out"
 iso_label="${os_name}_${codename}_${arch}"
@@ -32,8 +33,8 @@ iso_publisher='Fascode Network <https://fascode.net>'
 iso_application="${os_name} Live/Rescue CD"
 iso_version="${codename}-$(date +%Y.%m.%d)"
 iso_filename="${iso_name}-${iso_version}-${arch}.iso"
-liveuser_name=fedora
-liveuser_password=fedora
+liveuser_name="fedora"
+liveuser_password="fedora"
 liveuser_shell="/usr/bin/zsh"
 
 #-- language config --#
@@ -48,7 +49,7 @@ locale_fullname="global"
 
 debug=false
 cache_only=false
-
+grub2_standalone_cmd=grub2-mkstandalone
 
 start_time="$(date +%s)"
 
@@ -141,16 +142,17 @@ run_once() {
 run_cmd() {
     local mount
 
-    for mount in "dev" "dev/pts" "proc" "sys" "etc/resolv.conf"; do
+    for mount in "dev" "dev/pts" "proc" "sys" "run/systemd/resolve/stub-resolv.conf"; do
     #for mount in "dev" "dev/pts" "proc" "sys" ; do
-        if [[ "${mount}" == "etc/resolv.conf" ]]; then
-            cp /etc/resolv.conf "${work_dir}/airootfs/${mount}"
+        if [[ "${mount}" == "run/systemd/resolve/stub-resolv.conf" ]]; then
+            # cp /etc/resolv.conf "${work_dir}/airootfs/run${mount}"
+            mount --bind /etc/resolv.conf "${work_dir}/airootfs/run/systemd/resolve/stub-resolv.conf"
         else
             mount --bind /${mount} "${work_dir}/airootfs/${mount}"
         fi
     done
     
-    chroot "${work_dir}/airootfs" "${@}"
+    unshare --fork --pid chroot "${work_dir}/airootfs" "${@}"
 
     for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
         if [[ ! "${mount}" == "${work_dir}/airootfs" ]]; then
@@ -159,8 +161,9 @@ run_cmd() {
     done
 }
 
-_dnf_install() {
-    run_cmd dnf install -y ${@}
+_dnf_install() {    
+    mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
+    run_cmd dnf -c /dnf_conf install -y ${@}
 }
 
 # rm helper
@@ -192,8 +195,7 @@ _usage () {
     echo
     echo "    -a | --arch <str>      Set architecture"
     echo "                           Default: ${arch}"
-    echo "    -c | --codename <str>  Set ubuntu codename"
-    echo "                           Default: ${codename}"
+    echo "    -b | --bootsplash      Enable Plymouth"
     echo "    -l | --lang <lang>     Specifies the default language for the live environment"
     echo "                           Default: ${locale_name}"
     echo "    -m | --mirror <url>    Set apt mirror server."
@@ -202,6 +204,8 @@ _usage () {
     echo "                           Default: ${out_dir}"
     echo "    -w | --work <work_dir> Set the working directory"
     echo "                           Default: ${work_dir}"
+    echo "    -c | --cache <cache_dir> Set the cache directory"
+    echo "                           Default: ${cache_dir}"
     echo
     echo "    -d | --debug           "
     echo "    -h | --help            This help message and exit"
@@ -251,18 +255,27 @@ _usage () {
 }
 
 dnfstrap() {
-    dnf --installroot="${work_dir}/airootfs" $(${script_path}/system/repository-json-parser.py ${script_path}/system/repository.json) install ${@} -y
+    if [[ ! -d "${cache_dir}" ]]; then
+        mkdir -p "${cache_dir}"
+    fi
+    cp -rf "${script_path}/system/dnfconf.conf" "${work_dir}/airootfs/dnf_conf"
+    if [[ ! -d "${work_dir}/airootfs/dnf_cache" ]]; then
+        mkdir -p "${work_dir}/airootfs/dnf_cache"
+    fi
+    mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
+    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
+    umount -fl "${work_dir}/airootfs/dnf_cache"
 }
 
-
 make_basefs() {
     _msg_info "Installing Fedora to '${work_dir}/airootfs'..."
-    dnfstrap @Core
+    dnfstrap @Core yamad-repo 
     _msg_info "${codename} installed successfully!"
     
     echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' > "${work_dir}/airootfs/etc/bash.bashrc"
-    run_cmd dnf update -y
-    run_cmd dnf -y remove $(run_cmd dnf repoquery --installonly --latest-limit=-1 -q)
+    mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
+    run_cmd dnf -c /dnf_conf update -y
+    run_cmd dnf -c /dnf_conf -y remove $(run_cmd dnf -c /dnf_conf repoquery --installonly --latest-limit=-1 -q)
     # run_cmd apt-get upgrade
 }
 
@@ -286,7 +299,7 @@ parse_files() {
     _locale_line_number="$(_get_locale_line_number)"
 
     # 不正なロケール名なら終了する
-    [[ "${_locale_line_number}" == "failed" ]] && msg_error "${locale_name} is not a valid language." "1"
+    [[ "${_locale_line_number}" == "failed" ]] && _msg_error "${locale_name} is not a valid language." "1"
 
     # ロケール設定ファイルから該当の行を抽出
     _locale_config_line=($(cat "${_locale_config_file}" | grep -h -v ^'#' | grep -v ^$ | head -n "${_locale_line_number}" | tail -n 1))
@@ -313,7 +326,7 @@ prepare_build() {
         mkdir -p "${work_dir}/squashfsroot/LiveOS/"
         mkdir -p "${work_dir}/airootfs/"
         _msg_info "Make rootfs image..."
-        truncate -s 5G "${work_dir}/squashfsroot/LiveOS/rootfs.img"
+        truncate -s 6G "${work_dir}/squashfsroot/LiveOS/rootfs.img"
         _msg_info "Format rootfs image..."
         mkfs.ext4 -F "${work_dir}/squashfsroot/LiveOS/rootfs.img"
     fi    
@@ -331,6 +344,27 @@ make_systemd() {
     fi
     run_cmd ln -sf /etc/machine-id /var/lib/dbus/machine-id
 }
+make_repo_packages() {
+    remove "${work_dir}/airootfs/dnfrepopkglist"
+    #_apt_install initramfs-tools
+    # run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --yes'
+
+    if [[ -f "${channels_dir}/share/add_repo.${arch}" ]]; then
+        grep -h -v ^'#' "${channels_dir}/share/add_repo.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfrepopkglist"
+    fi
+
+    if [[ -f "${channels_dir}/${channel_name}/add_repo.${arch}" ]]; then
+        grep -h -v ^'#' "${channels_dir}/${channel_name}/add_repo.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfrepopkglist"
+    fi
+
+    if [[ -s "${work_dir}/airootfs/dnfrepopkglist" ]]; then
+        mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
+        sed -i -e "s|\${codename}|${codename}|g" "${work_dir}/airootfs/dnfrepopkglist"
+        run_cmd env -i bash -c 'dnf -y --nogpgcheck -c /dnf_conf install $(echo $(<dnfrepopkglist))'
+    fi
+
+    remove "${work_dir}/airootfs/dnfrepopkglist"
+}
 make_dnf_packages() {
     remove "${work_dir}/airootfs/dnfpkglist"
     #_apt_install initramfs-tools
@@ -350,9 +384,18 @@ make_dnf_packages() {
     if [[ -f "${channels_dir}/${channel_name}/packages-${locale_name}.${arch}" ]]; then
         grep -h -v ^'#' "${channels_dir}/${channel_name}/packages-${locale_name}.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
     fi
-
+    if [[ ${bootsplash} == true ]]; then
+        if [[ -f "${channels_dir}/share/packages_plymouth.${arch}" ]]; then
+            grep -h -v ^'#' "${channels_dir}/share/packages_plymouth.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
+        fi
+        
+        if [[ -f "${channels_dir}/${channel_name}/packages_plymouth.${arch}" ]]; then
+            grep -h -v ^'#' "${channels_dir}/${channel_name}/packages_plymouth.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
+        fi
+    fi
     if [[ -s "${work_dir}/airootfs/dnfpkglist" ]]; then
-        run_cmd env -i bash -c 'dnf -y --nogpgcheck install $(echo $(<dnfpkglist))'
+        mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
+        run_cmd env -i bash -c 'dnf -y --nogpgcheck -c /dnf_conf install $(echo $(<dnfpkglist))'
     fi
 
     remove "${work_dir}/airootfs/dnfpkglist"
@@ -374,7 +417,6 @@ make_cp_airootfs() {
 }
 
 make_config() {
-
     # customize_airootfs options
     # -b                        : Enable boot splash.
     # -d                        : Enable debug mode.
@@ -395,46 +437,52 @@ make_config() {
     # -k changed in AlterISO3 from passing kernel name to passing kernel configuration.
     local _airootfs_script_options _run_script
     _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} "
-
+    if [[ ${bootsplash} == true ]]; then
+        _airootfs_script_options="${_airootfs_script_options} -b"
+    fi
     _run_script() {
         local _file
         for _file in ${@}; do
-            chmod 755 "${_file}"
-            if [[ -f "${_file}" ]]; then run_cmd "${_file}" ${_airootfs_script_options}; fi
+            if [[ -f "${work_dir}/airootfs${_file}" ]]; then run_cmd "${_file}" ${_airootfs_script_options}; fi
+            if [[ -f "${work_dir}/airootfs${_file}" ]]; then chmod 755 "${work_dir}/airootfs${_file}"; fi
         done
     }
 
     _run_script "/root/customize_airootfs.sh" "/root/customize_airootfs_${channel_name}.sh"
-
-    run_cmd ln -sf /usr/share/zoneinfo/${locale_time} /etc/localtime
-    echo "LANG=${locale_gen_name}" > "${work_dir}/airootfs/etc/locale.conf"
-    run_cmd truncate -s 0 /etc/machine-id
-    run_cmd passwd -u -f root
 }
 
 make_clean() {
-    run_cmd dnf -y remove $(run_cmd dnf repoquery --installonly --latest-limit=-1 -q)
-    run_cmd dnf clean all
+    mount --bind "${cache_dir}" "${work_dir}/airootfs/dnf_cache"
+    run_cmd dnf -c /dnf_conf -y remove $(run_cmd dnf -c /dnf_conf repoquery --installonly --latest-limit=-1 -q)
 }
 
 make_squashfs() {
     # prepare
-    [[ -d "${bootfiles_dir}" ]] && rm -r "${bootfiles_dir}"
+    remove "${bootfiles_dir}"
+    if [[ -d "${work_dir}/airootfs/dnf_cache" ]]; then
+        rm -rf "${work_dir}/airootfs/dnf_cache"
+    fi
     mkdir -p "${bootfiles_dir}"/{grub,LiveOS,boot,isolinux}
     #generate initrd
     _msg_info "make initrd..."
-    run_cmd dracut --xz --add "dmsquash-live convertfs pollcdrom" --omit plymouth --no-hostonly --no-early-microcode /boot/initrd0 `run_cmd ls /lib/modules`
+    run_cmd dracut --xz --add "dmsquash-live convertfs pollcdrom" --no-hostonly --no-early-microcode /boot/initrd0 `run_cmd ls /lib/modules`
     cp ${work_dir}/airootfs/boot/vmlinuz-$(run_cmd ls /lib/modules) ${bootfiles_dir}/boot/vmlinuz
     mv ${work_dir}/airootfs/boot/initrd0 ${bootfiles_dir}/boot/initrd
     #cp isolinux
     cp "${nfb_dir}"/isolinux/* "${bootfiles_dir}/isolinux/"
     # make squashfs
-    rm -rf "${work_dir}/airootfs/boot"
+    remove "${work_dir}/airootfs/boot"
+    mkdir "${work_dir}/airootfs/boot"
+    cp ${bootfiles_dir}/boot/vmlinuz ${work_dir}/airootfs/boot/vmlinuz-$(run_cmd ls /lib/modules)
+    kernelkun=$(run_cmd ls /lib/modules)
+    echo -e "\nkernel-install add ${kernelkun} /boot/vmlinuz-${kernelkun}" >> ${work_dir}/airootfs/usr/share/calamares/final-process
     umount "${work_dir}/airootfs"
     _msg_info "Minimize rootfs..."
     resize2fs -M "${work_dir}/squashfsroot/LiveOS/rootfs.img"
     _msg_info "Compress rootfs.."
-    mksquashfs "${work_dir}/squashfsroot/" "${bootfiles_dir}/LiveOS/squashfs.img"
+    mksquashfs "${work_dir}/squashfsroot/" "${bootfiles_dir}/LiveOS/squashfs.img" -noappend -no-recovery -comp zstd -Xcompression-level 19 -b 1048576
+    _msg_info "Deleting block image..."
+    rm -rf "${work_dir}/squashfsroot/LiveOS/rootfs.img"
 }
 
 make_nfb() {
@@ -442,11 +490,16 @@ make_nfb() {
     # isolinux setup
     sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/isolinux.cfg" | sed "s|%CD_LABEL%|${iso_label}|g"  > "${bootfiles_dir}/isolinux/isolinux.cfg"
     #grub
-    sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/grub.cfg" | sed "s|%CD_LABEL%|${iso_label}|g" > "${bootfiles_dir}/grub/grub.cfg"
+    if [[ ${bootsplash} = true ]]; then
+        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"
+    else
+        sed "s|%OS_NAME%|${os_name}|g" "${nfb_dir}/grub.cfg" | sed "s|%CD_LABEL%|${iso_label}|g" > "${bootfiles_dir}/grub/grub.cfg"
+    fi
+    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"
 }
 make_efi() {
     # UEFI 32bit (ia32)
-    grub-mkstandalone \
+    ${grub2_standalone_cmd} \
         --format=i386-efi \
         --output="${bootfiles_dir}/grub/bootia32.efi" \
         --locales="" \
@@ -454,7 +507,7 @@ make_efi() {
         "boot/grub/grub.cfg=${bootfiles_dir}/grub/grub.cfg"
     
     # UEFI 64bit (x64)
-    grub-mkstandalone \
+    ${grub2_standalone_cmd} \
         --format=x86_64-efi \
         --output="${bootfiles_dir}/grub/bootx64.efi" \
         --locales="" \
@@ -470,7 +523,7 @@ make_efi() {
     cp "${bootfiles_dir}/grub/bootia32.efi" "${bootfiles_dir}/mnt/efi/boot"
     cp "${bootfiles_dir}/grub/bootx64.efi" "${bootfiles_dir}/mnt/efi/boot"
     umount -d "${bootfiles_dir}/mnt"
-    rm -r "${bootfiles_dir}/mnt"
+    remove "${bootfiles_dir}/mnt"
 }
 make_iso() {
     cd "${bootfiles_dir}"
@@ -521,8 +574,8 @@ make_checksum() {
 # 引数解析()
 # 参考記事:https://0e0.pw/ci83 https://0e0.pw/VJlg
 
-_opt_short="w:l:o:ha:-:m:c:d"
-_opt_long="help,arch:,codename:,debug,help,lang,mirror:,out:,work,cache-only"
+_opt_short="w:l:o:hba:-:m:c:d"
+_opt_long="help,arch:,codename:,debug,help,lang,mirror:,out:,work,cache-only,bootsplash"
 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
 
 if [[ ${?} != 0 ]]; then
@@ -537,8 +590,12 @@ while :; do
             arch="${2}"
             shift 2
             ;;
-        -c | --codename)
-            codename="${2}"
+        -b | --bootsplash)
+            bootsplash=true
+            shift 1
+            ;;
+        -c | --cache)
+            cache_dir="${2}"
             shift 2
             ;;
         -d | --debug)
@@ -579,9 +636,11 @@ while :; do
             ;;
     esac
 done
-
+if [[ -f /etc/arch-release ]]; then
+    grub2_standalone_cmd=grub-mkstandalone
+fi
 bootfiles_dir="${work_dir}/bootfiles"
-trap  umount_chroot 0 2 15
+trap  umount_chroot_airootfs 0 2 15
 
 if [[ -n "${1}" ]]; then
     channel_name="${1}"
@@ -592,7 +651,7 @@ if [[ -n "${1}" ]]; then
     if [[ "${channel_name}" = "clean" ]]; then
         umount_chroot_airootfs
         _msg_info "deleting work dir..."
-        rm -rf "${work_dir}"
+        remove "${work_dir}"
         exit 0
     fi
     check_channel() {
@@ -626,12 +685,14 @@ iso_filename="${iso_name}-${codename}-${channel_name}-${locale_name}-$(date +%Y.
 umount_chroot_airootfs
 if [[ -d "${work_dir}" ]]; then
     _msg_info "deleting work dir..."
-    rm -rf "${work_dir}"
+    remove "${work_dir}"
 fi
+
 prepare_build
 parse_files
 run_once make_basefs
 run_once make_systemd
+run_once make_repo_packages
 run_once make_dnf_packages
 run_once make_cp_airootfs
 run_once make_config