#!/bin/bash

set -e

new_sysroot_path=$(get_value new-root)
echo "---------------<20 setup-chroot new_sysroot_path> >>>>>>>>>>>>>>>>>>>>>> $new_sysroot_path"
do_mountfs() {
    # mkdir -p /target/{dev,run,dev/pts,proc,sys}
    mount --bind /dev $new_sysroot_path/dev
    mount --bind /run $new_sysroot_path/run
    mount -vt devpts devpts $new_sysroot_path/dev/pts -o gid=5,mode=620
    mount -vt proc proc $new_sysroot_path/proc
    mount -vt sysfs sysfs $new_sysroot_path/sys
}

do_mount_cdrom() {
    mkdir -p $new_sysroot_path/cdrom
    mount --bind /cdrom $new_sysroot_path/cdrom
}

do_mountfs

do_mount_cdrom

if [[ "${is_efi}" == "true" ]]; then
    mount -t efivarfs none $new_sysroot_path/sys/firmware/efi/efivars || echo "mount -t efivarfs none $new_sysroot_path/sys/firmware/efi/efivars faild"
fi
