summaryrefslogtreecommitdiff
path: root/imgpkg/common.sh.in
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-03-18 16:42:03 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-03-20 16:33:34 +0000
commitfcf5150e927147bbce338a61101ccbb3d760f07c (patch)
tree371099eaffd417f61878f0c756a50964c35ba2b6 /imgpkg/common.sh.in
parent31aadea7e49617a783f924fe373e642c88157a2b (diff)
downloaddefinitions-fcf5150e927147bbce338a61101ccbb3d760f07c.tar.gz
Add write extension for making a package that allows deferred instansiationbaserock/richardmaw/S10721-img-pkg
This is a write extension for making a package that can be used to install the produced system. Ideally we'd instead have Baserock everywhere to do the deployment, but we need to support this workflow until that is possible. It gets configured with a script templates that get filled in with the paths to the rootfs tarball as @@ROOTFS_TAR_PATH@@, script directory as @@SCRIPT_DIR@@ and copied boot-files as @@IMAGE_DIR@@. Scripts to include are specified as a relative path to your morphologies repository, separated by : characters in the INCLUDE_SCRIPTS variable. If another separator is convenient, it can be specified in the INCLUDE_SCRIPTS_SEPARATOR variable, which has the same semantics as the shell IFS variable. Other files needed to create the disk image, such as bootloader image files can be specified in BOOTLOADER_BLOBS, relative to the root of the rootfs, separated with similar rules to INCLUDE_SCRIPTS. The name of the rootfs tarball, the scripts subdirectory and the bootloader blobs subdirectory can be changed with the ROOTFS_TAR, SCRIPT_SUBDIR and IMAGE_SUBDIR variables, but the default should be sufficient. The compression of the rootfs tarball, and the package tarball can be specified by specifying a shell command that reads the uncompressed tarball from stdin and writes to stdout in the ROOTFS_COMPRESS and OUTPUT_COMPRESS variables.
Diffstat (limited to 'imgpkg/common.sh.in')
-rw-r--r--imgpkg/common.sh.in71
1 files changed, 71 insertions, 0 deletions
diff --git a/imgpkg/common.sh.in b/imgpkg/common.sh.in
new file mode 100644
index 00000000..08473a6b
--- /dev/null
+++ b/imgpkg/common.sh.in
@@ -0,0 +1,71 @@
+#!/bin/false
+
+status(){
+ echo "$@"
+}
+
+info(){
+ echo "$@" >&2
+}
+
+warn(){
+ echo "$@" >&2
+}
+
+extract_rootfs(){
+ tar -C "$1" -xf @@ROOTFS_TAR_PATH@@ .
+}
+
+make_disk_image(){
+ truncate --size "$1" "$2"
+}
+
+format_disk(){
+ local disk="$1"
+ mkfs.ext4 -F -L rootfs "$disk"
+}
+
+install_fs_config(){
+ local mountpoint="$1"
+ local rootdisk="${2-/dev/vda}"
+ cat >>"$mountpoint/etc/fstab" <<EOF
+$rootdisk / ext4 rw,errors=remount-ro 0 0
+EOF
+ install -D -m 644 /proc/self/fd/0 "$mountpoint/boot/extlinux.conf" <<EOF
+DEFAULT baserock
+LABEL baserock
+SAY Booting Baserock
+LINUX /boot/vmlinuz
+APPEND root=$rootdisk
+EOF
+}
+
+install_bootloader(){
+ local disk="$1"
+ local mountpoint="$2"
+ dd if=@@IMAGE_DIR@@/mbr.bin conv=notrunc bs=440 count=1 of="$disk"
+ extlinux --install "$mountpoint/boot"
+}
+
+loop_file(){
+ losetup --show --find "$1"
+}
+unloop_file(){
+ #losetup --detach "$1"
+ # unlooping handled by umount -d, for busybox compatibility
+ true
+}
+
+temp_mount(){
+ local mp="$(mktemp -d)"
+ if ! mount "$@" "$mp"; then
+ rmdir "$mp"
+ return 1
+ fi
+ echo "$mp"
+}
+untemp_mount(){
+ # Unmount and detach in one step for busybox compatibility
+ umount -d "$1"
+ rmdir "$1"
+}