summaryrefslogtreecommitdiff
path: root/imgpkg/disk-install.sh.in
blob: 60b3f4659a89144126eca35baf44685b35c305e9 (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
#!/bin/sh

set -eu

usage(){
    cat <<EOF
usage: $0 DISK [TARGET_DISK]

DISK:        Where the disk appears on your development machine
TARGET_DISK: What the disk will appear as on the target machine
EOF
}

. @@SCRIPT_DIR@@/common.sh

if [ "$#" -lt 1 -o "$#" -gt 2 ]; then
    usage
    exit 1
fi

DISK="$1"
TARGET_DISK="${1-/dev/sda}"

status Formatting "$DISK" as ext4
format_disk "$DISK"
(
    info Mounting "$DISK"
    MP="$(temp_mount -t ext4 "$DISK")"
    info Mounted "$DISK" to "$MP"
    set +e
    (
        set -e
        info Copying rootfs onto disk
        extract_rootfs "$MP"
        info Configuring disk paths
        install_fs_config "$MP" "$TARGET_DISK"
        info Installing bootloader
        install_bootloader "$DISK" "$MP"
    )
    ret="$?"
    if [ "$ret" != 0 ]; then
        warn Filling rootfs failed with "$ret"
    fi
    info Unmounting "$DISK" from "$MP" and removing "$MP"
    untemp_mount "$MP"
    exit "$ret"
)