summaryrefslogtreecommitdiff
path: root/extensions/image-package-example/disk-install.sh.in
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2015-06-02 14:01:55 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2015-06-02 14:01:55 +0000
commitc6abc426b5857f9b1edd9c72e3094c1e2df8a7bf (patch)
treeeff61e6fe9bb3adcf254c4e86eebca7190c65cce /extensions/image-package-example/disk-install.sh.in
parent4f43fdd08770c113f7443fecbda43d4316091d4b (diff)
parent02faf51e91a8c55adfbb6d953bca354ab99bf261 (diff)
downloaddefinitions-c6abc426b5857f9b1edd9c72e3094c1e2df8a7bf.tar.gz
Merge branch 'baserock/adamcoldrick/all-exts-in-definitions-v2'
Reviewed-by: Richard Maw <richard.maw@codethink.co.uk>
Diffstat (limited to 'extensions/image-package-example/disk-install.sh.in')
-rw-r--r--extensions/image-package-example/disk-install.sh.in51
1 files changed, 51 insertions, 0 deletions
diff --git a/extensions/image-package-example/disk-install.sh.in b/extensions/image-package-example/disk-install.sh.in
new file mode 100644
index 00000000..bc8e0e67
--- /dev/null
+++ b/extensions/image-package-example/disk-install.sh.in
@@ -0,0 +1,51 @@
+#!/bin/sh
+# Script for writing the system to an existing disk.
+# This formats the disk, extracts the rootfs to it, installs the
+# bootloader, and ensures there's appropriate configuration for the
+# bootloader, kernel and userland to agree what the rootfs is.
+
+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"
+)