From 54d222fc53cdc96fec8ac156e9d3e41d520e0bcd Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Tue, 27 Mar 2012 14:00:21 +0000 Subject: Rename tbdiff-update to tb-update. --- Makefile.am | 2 +- configure.ac | 2 +- tb-update/Makefile.am | 20 +++++++ tb-update/tb-update | 123 ++++++++++++++++++++++++++++++++++++++++++++ tbdiff-update/Makefile.am | 20 ------- tbdiff-update/tbdiff-update | 123 -------------------------------------------- 6 files changed, 145 insertions(+), 145 deletions(-) create mode 100644 tb-update/Makefile.am create mode 100755 tb-update/tb-update delete mode 100644 tbdiff-update/Makefile.am delete mode 100755 tbdiff-update/tbdiff-update diff --git a/Makefile.am b/Makefile.am index d3fc717..8f68b1f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,7 +20,7 @@ SUBDIRS = \ tbdiff-create \ tbdiff-deploy \ tbdiff-switch \ - tbdiff-update \ + tb-update \ tests .PHONY: ChangeLog diff --git a/configure.ac b/configure.ac index 6ee08fe..ad86cbf 100644 --- a/configure.ac +++ b/configure.ac @@ -120,7 +120,7 @@ tbdiff/tbdiff-1.pc tbdiff-create/Makefile tbdiff-deploy/Makefile tbdiff-switch/Makefile -tbdiff-update/Makefile +tb-update/Makefile tests/Makefile ]) diff --git a/tb-update/Makefile.am b/tb-update/Makefile.am new file mode 100644 index 0000000..3a2f60b --- /dev/null +++ b/tb-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 = \ + tb-update diff --git a/tb-update/tb-update b/tb-update/tb-update new file mode 100755 index 0000000..67a4637 --- /dev/null +++ b/tb-update/tb-update @@ -0,0 +1,123 @@ +#!/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 " >&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="$(busybox mktemp -d)" +mount -t btrfs "$device" "$rootfs" +trap "cd /; umount $rootfs && busybox rm -rf $rootfs" 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 +busybox cp "$target_subvolume/boot/vmlinuz" "boot/vmlinuz" +busybox cp "$target_subvolume/boot/System.map" "boot/System.map" +busybox cp "$target_subvolume/extlinux.conf" "extlinux.conf" + +echo "Configuring extlinux to boot from \"$target_subvolume-run\"" + +busybox sed -i -e "s,factory-run,$target_subvolume-run,g" "extlinux.conf" + +# clear the traps +trap - EXIT SIGINT SIGTERM + +# leave the root file system +cd / + +# unmount the root file system +umount "$rootfs" + +# remove the temporary directory +busybox rm -rf "$rootfs" + +# reboot the system +busybox reboot diff --git a/tbdiff-update/Makefile.am b/tbdiff-update/Makefile.am deleted file mode 100644 index bddbb13..0000000 --- a/tbdiff-update/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -# 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 deleted file mode 100755 index 1014a3c..0000000 --- a/tbdiff-update/tbdiff-update +++ /dev/null @@ -1,123 +0,0 @@ -#!/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 " >&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="$(busybox mktemp -d)" -mount -t btrfs "$device" "$rootfs" -trap "cd /; umount $rootfs && busybox rm -rf $rootfs" 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 -busybox cp "$target_subvolume/boot/vmlinuz" "boot/vmlinuz" -busybox cp "$target_subvolume/boot/System.map" "boot/System.map" -busybox cp "$target_subvolume/extlinux.conf" "extlinux.conf" - -echo "Configuring extlinux to boot from \"$target_subvolume-run\"" - -busybox sed -i -e "s,factory-run,$target_subvolume-run,g" "extlinux.conf" - -# clear the traps -trap EXIT SIGINT SIGTERM - -# leave the root file system -cd / - -# unmount the root file system -umount "$rootfs" - -# remove the temporary directory -rm -rf "$rootfs" - -# reboot the system -busybox reboot -- cgit v1.2.1