summaryrefslogtreecommitdiff
path: root/tools/boot/questing/common.sh
blob: 264334d58fe5886693675175cb5dcc1bd2a9da9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# encode the right CD kernel parameteres, for every project
default_kernel_params() {
    case $PROJECT in
        ubuntu|edubuntu|ubuntustudio|ubuntu-budgie|kubuntu|lubuntu|ubuntu-unity|ubuntucinnamon|xubuntu|ubuntu-mate)
            KERNEL_PARAMS="${KERNEL_PARAMS:+$KERNEL_PARAMS } --- quiet splash"
            ;;
        ubuntukylin)
            KERNEL_PARAMS="${KERNEL_PARAMS:+$KERNEL_PARAMS }file=/cdrom/preseed/ubuntu.seed locale=zh_CN keyboard-configuration/layoutcode?=cn quiet splash --- "
            ;;
        ubuntu-server)
            KERNEL_PARAMS="${KERNEL_PARAMS:+$KERNEL_PARAMS } ---"
            ;;
    esac
}

HUMANPROJECT="$(echo "$CAPPROJECT" | sed 's/-/ /g')"

# download and extract a package
download_and_extract_package() {
    local package_name=$1
    local target_dir=$2

    mkdir -p $target_dir
    $BASEDIR/tools/apt-selection download $package_name
    dpkg --fsys-tarfile $package_name*.deb | tar xf - -C $target_dir
}

# copy common files for GRUB (e.g. unicode font) to boot tree
copy_grub_common_files_to_boot_tree() {
    local grub_dir=$1
    local boot_tree=$2

    mkdir -p $boot_tree/boot/grub/fonts
    cp $grub_dir/usr/share/grub/unicode.pf2 $boot_tree/boot/grub/fonts/unicode.pf2
}

# copy signed shim and GRUB to boot tree
# NOTE: we are using the non-NX shim here for now, in future the default should be updated here
copy_signed_shim_grub_to_boot_tree() {
    local shim_dir=$1
    local grub_dir=$2
    local efi_suffix=$3
    local grub_target=$4
    local boot_tree=$5

    mkdir -p $boot_tree/EFI/boot
    cp $shim_dir/usr/lib/shim/shim$efi_suffix.efi.signed.latest $boot_tree/EFI/boot/boot$efi_suffix.efi
    cp $shim_dir/usr/lib/shim/mm$efi_suffix.efi $boot_tree/EFI/boot/mm$efi_suffix.efi
    cp $grub_dir/usr/lib/grub/$grub_target-efi-signed/gcd$efi_suffix.efi.signed $boot_tree/EFI/boot/grub$efi_suffix.efi

    mkdir -p $boot_tree/boot/grub/$grub_target-efi
    cp -r $grub_dir/usr/lib/grub/$grub_target-efi/*.mod $boot_tree/boot/grub/$grub_target-efi
    cp -r $grub_dir/usr/lib/grub/$grub_target-efi/*.lst $boot_tree/boot/grub/$grub_target-efi
}

# copy unsigned monolithic GRUB to boot tree
copy_unsigned_monolithic_grub_to_boot_tree() {
    local grub_dir=$1
    local efi_suffix=$2
    local grub_target=$3
    local boot_tree=$4

    mkdir -p $boot_tree/EFI/boot
    cp $grub_dir/usr/lib/grub/$grub_target-efi/monolithic/gcd$efi_suffix.efi $boot_tree/EFI/boot/boot$efi_suffix.efi

    mkdir -p $boot_tree/boot/grub/$grub_target-efi
    cp -r $grub_dir/usr/lib/grub/$grub_target-efi/*.mod $boot_tree/boot/grub/$grub_target-efi
    cp -r $grub_dir/usr/lib/grub/$grub_target-efi/*.lst $boot_tree/boot/grub/$grub_target-efi
}

# create an ESP image for insertion into the El-Torito catalog
# NOTE: this needs dosfstools and mtools installed
create_eltorito_esp_image() {
    local boot_tree=$1
    local target_file=$2

    mkfs.msdos -n ESP -C -v $target_file \
        $(( $(du -s --apparent-size --block-size=1024 $boot_tree/EFI/ | cut -f 1 ) + 1024))
    mcopy -s -i $target_file $boot_tree/EFI ::/.;
}