summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-03-23 11:10:42 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-03-23 13:19:36 +0000
commit81771871c53d24a084b54d116085028329312cf7 (patch)
treef4a66c127d8e50fcb20ad066bca2ba0332b6ebba
parent837f58bdadda09a13b062929d6b5d448bdb5cabe (diff)
downloadtbdiff-81771871c53d24a084b54d116085028329312cf7.tar.gz
Add new tbdiff-update command to apply a patch to a system.
This command is written in bash and takes four parameters: * a device with a btrfs file system to mount * the source subvolume name * the target subvolume name * the path to a patch file or stream It then creates the target subvolume as a snapshot of the source subvolume, applies the patch in there, then creates a <target>-run snapshot and copies the boot files (vmlinuz, extlinux.conf) to the root file system. Lastly, it adjusts extlinux.conf to point to the -run snapshot.
-rw-r--r--Makefile.am1
-rw-r--r--configure.ac3
-rw-r--r--tbdiff-update/Makefile.am20
-rwxr-xr-xtbdiff-update/tbdiff-update111
4 files changed, 134 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 2560896..e26010b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,6 +19,7 @@ SUBDIRS = \
tbdiff \
tbdiff-create \
tbdiff-deploy \
+ tbdiff-update \
tests
.PHONY: ChangeLog
diff --git a/configure.ac b/configure.ac
index 8c68def..320cf86 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,7 +106,7 @@ dnl AC_CHECK_FUNCS([])
dnl ************************************
dnl *** Check for required libraries ***
dnl ************************************
-dnl AC_CHECK_LIBS([])
+AC_CHECK_LIB([attr], [lsetxattr])
dnl ***********************************
dnl *** Check for required packages ***
@@ -119,6 +119,7 @@ tbdiff/Makefile
tbdiff/tbdiff-1.pc
tbdiff-create/Makefile
tbdiff-deploy/Makefile
+tbdiff-update/Makefile
tests/Makefile
])
diff --git a/tbdiff-update/Makefile.am b/tbdiff-update/Makefile.am
new file mode 100644
index 0000000..bddbb13
--- /dev/null
+++ b/tbdiff-update/Makefile.am
@@ -0,0 +1,20 @@
+# vi:set ts=8 sw=8 noet ai nocindent:
+# -
+# Copyright (c) 2011-2012 Codethink Ltd.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License Version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# vi:set ts=8 sw=8 noet ai nocindent:
+
+bin_SCRIPTS = \
+ tbdiff-update
diff --git a/tbdiff-update/tbdiff-update b/tbdiff-update/tbdiff-update
new file mode 100755
index 0000000..40ce11c
--- /dev/null
+++ b/tbdiff-update/tbdiff-update
@@ -0,0 +1,111 @@
+#!/bin/sh
+#
+# Copyright (c) 2011-2012 Codethink Ltd.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License Version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# vi:set ts=8 sw=8 noet ai nocindent:
+
+set -e
+set -x
+
+# read input parameters
+device="$1"
+source_subvolume="$2"
+target_subvolume="$3"
+patch_file="$4"
+
+# print usage information if not all parameters are provided
+if [ -z "$device" ] ||
+ [ -z "$source_subvolume" ] ||
+ [ -z "$target_subvolume" ] ||
+ [ -z "$patch_file" ]
+then
+ echo "Usage: $0 <device> <source subvolume> <target subvolume> <patch file>" >&2
+ exit 1
+fi
+
+if [ ! -f "$patch_file" ]; then
+ echo "Patch file \"$patch_file\" does not exist" >&2
+ exit 1
+fi
+
+# mount the root btrfs file system
+rootfs="$(mktemp -d)"
+mount -t btrfs "$device" "$rootfs"
+trap "cd /; umount $rootfs; rm -rf $rootfs" ERR EXIT SIGINT SIGTERM
+
+# switch into the root file system
+cd "$rootfs"
+
+# verify that the source subvolume exists
+if [ ! -e "$source_subvolume" ]; then
+ echo "Source subvolume \"$source_subvolume\" does not exist in $device" >&2
+ exit 1
+fi
+
+# verify that the source subvolume is a directory
+if [ ! -d "$source_subvolume" ]; then
+ echo "Source subvolume \"$source_subvolume\" is not a directory" >&2
+ exit 1
+fi
+
+# verify that the target subvolume does not yet exist
+if [ -e "$target_subvolume" ]; then
+ echo "Target subvolume \"$target_subvolume\" already exists" >&2
+ exit 1
+fi
+
+# verify that the target subvolume's -run snapshot does not yet exist
+if [ -e "$target_subvolume-run" ]; then
+ echo "Target subvolume's \"$target_subvolume-run\" snapshot already exists" >&2
+ exit 1
+fi
+
+echo "Creating snapshot \"$target_subvolume\" from \"$source_subvolume\""
+
+# create a snapshot for the target subvolume
+if ! btrfs subvolume snapshot "$source_subvolume" "$target_subvolume"; then
+ echo "Failed to create the target subvolume \"$target_subvolume\"" >&2
+ exit 1
+fi
+
+# switch to the target subvolume
+cd "$target_subvolume"
+
+echo "Applying the patch \"$patch_file\" to \"$target_subvolume\""
+
+# apply the patch to this subvolume
+tbdiff-deploy "$patch_file"
+
+# leave the subvolume
+cd "$rootfs"
+
+echo "Creating snapshot \"$target_subvolume-run\" from \"$target_subvolume\""
+
+# create a -run snapshot for the target subvolume
+btrfs subvolume snapshot "$target_subvolume" "$target_subvolume-run"
+
+echo "Copying boot files to the root file system"
+
+# copy boot files to the root file system
+cp "$target_subvolume/boot/vmlinuz" "boot/vmlinuz"
+cp "$target_subvolume/boot/System.map" "boot/System.map"
+cp "$target_subvolume/extlinux.conf" "extlinux.conf"
+
+echo "Configuring extlinux to boot from \"$target_subvolume-run\""
+
+sed -i -e "s,factory-run,$target_subvolume-run,g" "extlinux.conf"
+
+# leave the root file system
+cd /