OSDN Git Service

[add] : customize_airootfs.sh
[alterlinux/LUBS.git] / lubs
diff --git a/lubs b/lubs
index d9872d5..ca841a1 100755 (executable)
--- a/lubs
+++ b/lubs
@@ -26,7 +26,7 @@ channels_dir="${script_path}/channels"
 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"
 
@@ -37,12 +37,10 @@ iso_label="${os_name}_${codename}_${arch}"
 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"
 
 channel_name="serene"
 
 username="liveuser"
-password="liveuser"
 usershell="/bin/bash"
 
 debug=false
@@ -223,18 +221,32 @@ _usage () {
 
 prepare_build() {
     if [[ ${EUID} -ne 0 ]]; then
-        _msg_error "This script must be run as root." 1
+        msg_warn "This script must be run as root." >&2
+        msg_warn "Re-run 'sudo ${0} ${@}'"
+        sudo "${0}" ${@}
+        exit "${?}"
     fi
 
     [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
     [[ ! -d "${out_dir}" ]] && mkdir -p "${out_dir}"
     umount_chroot
 
+    # Load channel config
+    local _load_config
+    _load_config() {
+        [[ -f "${1}" ]] && source "${1}"
+    }
+    _load_config "${channels_dir}/${channel_name}/config.any"
+    _load_config "${channels_dir}/${channel_name}/config.${arch}"
+
     # Check codename
     if [[ -z $(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename}) ]]; then
         _msg_error "This codename (${channel_name}) is not supported on this channel (${codename})."
     fi
 
+    # Set iso file name
+    iso_filename="${iso_name}-${iso_version}-${arch}.iso"
+
 }
 
 
@@ -341,25 +353,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'
@@ -378,42 +371,21 @@ make_config() {
     run_cmd truncate -s 0 /etc/machine-id
 }
 
-make_customize_airootfs() {
-    #-- Overwrite airootfs files --#
-    local copy_airootfs
+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`'
+}
 
-    copy_airootfs() {
-        local _dir="${1%/}"
+make_customize_airootfs() {
+    local _run_customize_airootfs_script
 
-        if [[ -d "${_dir}" ]]; then
-            cp -af "${_dir}"/* "${work_dir}/airootfs"
-        fi
+    _run_customize_airootfs_script() {
+        [[ -f "${work_dir}/airootfs${1}" ]] && run_cmd "${1}"
     }
 
-    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"
+    _run_customize_airootfs_script "/root/customize_airootfs.sh"
+    _run_customize_airootfs_script "/root/customize_airootfs_${channel_name}.sh"
 }
 
 make_clean() {
@@ -484,12 +456,12 @@ make_efi() {
         "boot/grub/grub.cfg=${bootfiles_dir}/isolinux/grub.cfg"
 
     # create efiboot.img
-    truncate -s 10M "${bootfiles_dir}/isolinux/efiboot.img"
+    truncate -s 50M "${bootfiles_dir}/isolinux/efiboot.img"
     mkfs.fat -F 16 -f 1 -r 112 "${bootfiles_dir}/isolinux/efiboot.img"
-    mkdir "${bootfiles_dir}/mnt"
     mount "${bootfiles_dir}/isolinux/efiboot.img" "${bootfiles_dir}/mnt"
-    cp "${bootfiles_dir}/isolinux/bootia32.efi" "${bootfiles_dir}/mnt"
-    cp "${bootfiles_dir}/isolinux/bootx64.efi" "${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"
 }
@@ -666,8 +638,8 @@ 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_add_user
 run_once make_customize_airootfs
 run_once make_clean
 run_once make_squashfs