From fc8198fff8b634172b48c7dab087da4eb3a5e754 Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Tue, 27 Mar 2012 14:04:44 +0000 Subject: Rename tbdiff-switch to tb-switch. --- Makefile.am | 2 +- configure.ac | 2 +- tb-switch/Makefile.am | 20 +++++++++++ tb-switch/tb-switch | 83 +++++++++++++++++++++++++++++++++++++++++++++ tbdiff-switch/Makefile.am | 20 ----------- tbdiff-switch/tbdiff-switch | 83 --------------------------------------------- 6 files changed, 105 insertions(+), 105 deletions(-) create mode 100644 tb-switch/Makefile.am create mode 100755 tb-switch/tb-switch delete mode 100644 tbdiff-switch/Makefile.am delete mode 100755 tbdiff-switch/tbdiff-switch diff --git a/Makefile.am b/Makefile.am index 8f68b1f..8c301ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,7 @@ SUBDIRS = \ tbdiff \ tbdiff-create \ tbdiff-deploy \ - tbdiff-switch \ + tb-switch \ tb-update \ tests diff --git a/configure.ac b/configure.ac index ad86cbf..e0ba901 100644 --- a/configure.ac +++ b/configure.ac @@ -119,7 +119,7 @@ tbdiff/Makefile tbdiff/tbdiff-1.pc tbdiff-create/Makefile tbdiff-deploy/Makefile -tbdiff-switch/Makefile +tb-switch/Makefile tb-update/Makefile tests/Makefile ]) diff --git a/tb-switch/Makefile.am b/tb-switch/Makefile.am new file mode 100644 index 0000000..e094e78 --- /dev/null +++ b/tb-switch/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-switch diff --git a/tb-switch/tb-switch b/tb-switch/tb-switch new file mode 100755 index 0000000..79568d5 --- /dev/null +++ b/tb-switch/tb-switch @@ -0,0 +1,83 @@ +#!/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" +target_subvolume="$2" + +# print usage information if not all parameters are provided +if [ -z "$device" ] || + [ -z "$target_subvolume" ] +then + echo "Usage: $0 " >&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 target subvolume exists +if [ ! -e "$target_subvolume" ]; then + echo "Target subvolume \"$target_subvolume\" does not yet exist" >&2 + exit 1 +fi + +# delete the target subvolume's -run snapshot if it exists +if [ -e "$target_subvolume-run" ]; then + echo "Deleting existing snapshot \"$target_subvolume-run\"" + btrfs subvolume delete "$target_subvolume-run" +fi + +echo "Creating snapshot \"$target_subvolume-run\" from \"$target_subvolume\"" + +# create a a new -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-switch/Makefile.am b/tbdiff-switch/Makefile.am deleted file mode 100644 index 596172e..0000000 --- a/tbdiff-switch/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-switch diff --git a/tbdiff-switch/tbdiff-switch b/tbdiff-switch/tbdiff-switch deleted file mode 100755 index b076354..0000000 --- a/tbdiff-switch/tbdiff-switch +++ /dev/null @@ -1,83 +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" -target_subvolume="$2" - -# print usage information if not all parameters are provided -if [ -z "$device" ] || - [ -z "$target_subvolume" ] -then - echo "Usage: $0 " >&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 target subvolume exists -if [ ! -e "$target_subvolume" ]; then - echo "Target subvolume \"$target_subvolume\" does not yet exist" >&2 - exit 1 -fi - -# delete the target subvolume's -run snapshot if it exists -if [ -e "$target_subvolume-run" ]; then - echo "Deleting existing snapshot \"$target_subvolume-run\"" - btrfs subvolume delete "$target_subvolume-run" -fi - -echo "Creating snapshot \"$target_subvolume-run\" from \"$target_subvolume\"" - -# create a a new -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