Merging casper 1.129.
[live-boot-grml.git] / bin / live-new-uuid
1 #!/bin/sh
2 # -*- coding: utf-8 -*-
3 #
4 # «casper-new-uuid» - Creates and injects new UUIDs for casper disks
5 #
6 # Create new UUIDs for disks to prevent conflicts and booting the wrong casper
7 # directory.  Particularly useful in creating recovery disks that need to be
8 # able to also work with recovery partitioning schemes.
9 #
10 # Copyright (C) 2008, Dell Inc.
11 #
12 # Author:
13 #  - Mario Limonciello <Mario_Limonciello@Dell.com>
14 #
15 # This script is free software; you can redistribute it and/or modify it under
16 # the terms of the GNU General Public License as published by the Free
17 # Software Foundation; either version 2 of the License, or at your option)
18 # any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License along
26 # with this application; if not, write to the Free Software Foundation, Inc., 51
27 # Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 ##################################################################################
29
30 set -e
31
32 help() {
33  echo
34  echo "USAGE: $0 initrd.gz <path-to-new-initrd.gz> <path-to-new-casper-uuid> "
35  echo
36  echo "initrd.gz is the absolute path to the original gzipped initramfs"
37  echo "<path-to-new-initrd.gz> is the destination directory for the new gzipped initramfs"
38  echo "<path-to-new-casper-uuid> is the destination directory for the new casper-uuid-TYPE "
39  echo
40  echo "if either path is absent, they will end up in the current directory "
41  echo "TYPE is determined by an already existing casper-uuid-* or by 'uname -s'"
42 }
43
44 if [ "$#" = "0" ] || [ "x$1" = x-h ] || [ "x$1" = x--help ]; then
45         help
46         exit 3
47 fi
48
49 CWD=`pwd`
50 TEMPDIR=`mktemp -d /tmp/uuid-XXXXXX`
51 TYPE=`uname -r | cut -d '-' -f 3`
52
53 if [ -z "$2" ] || [ ! -d "$2" ] || [ "$2" = "." ]; then
54         GZIPDIR="$CWD"
55 else
56         GZIPDIR="$2"
57 fi
58
59 if [ -z "$3" ] || [ ! -d "$3" ] || [ "$3" = "." ]; then
60         CASPERDIR="$CWD"
61 else
62         CASPERDIR="$3"
63 fi
64
65 cd "$TEMPDIR"
66 zcat "$1" | cpio -id
67 uuidgen -r > conf/uuid.conf
68 find . | cpio --quiet --dereference -o -H newc | gzip > "$GZIPDIR/initrd.gz"
69 if [ "$(ls "$CASPERDIR/casper-uuid"-* >/dev/null 2>&1 | wc -l)" = 1 ]; then
70     cp conf/uuid.conf "$CASPERDIR/casper-uuid"-*
71 else
72     cp conf/uuid.conf "$CASPERDIR/casper-uuid-$TYPE"
73 fi
74 cd "$CWD"
75 rm -rf "$TEMPDIR"