Support lvm devices for live-media.
[live-boot-grml.git] / bin / live-new-uuid
1 #!/bin/sh
2 # -*- coding: utf-8 -*-
3 #
4 # «live-new-uuid» - Creates and injects new UUIDs for live disks
5 #
6 # Create new UUIDs for disks to prevent conflicts and booting the wrong live
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.{l,g}z <path-to-new-initrd> <path-to-new-live-uuid> "
35  echo
36  echo "initrd.{l,g}z is the absolute path to the original gzipped or lzmaed initramfs"
37  echo "<path-to-new-initrd> is the destination directory for the new compressed initramfs"
38  echo "<path-to-new-live-uuid> is the destination directory for the new live-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 live-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 echo "$1" | grep ".lz$" >/dev/null; then
54         COMPRESSOR="lzma"
55         SUFFIX=".lz"
56 elif echo "$1" | grep ".gz$" >/dev/null; then
57         COMPRESSOR="gzip"
58         SUFFIX=".gz"
59 else
60         echo "Unsupported archive type."
61         exit 2
62 fi
63
64 if [ -z "$2" ] || [ ! -d "$2" ] || [ "$2" = "." ]; then
65         COMPRESS_DIR="$CWD"
66 else
67         COMPRESS_DIR="$2"
68 fi
69
70 if [ -z "$3" ] || [ ! -d "$3" ] || [ "$3" = "." ]; then
71         LIVEDIR="$CWD"
72 else
73         LIVEDIR="$3"
74 fi
75
76 cd "$TEMPDIR"
77 $COMPRESSOR -cd "$1" -S "$SUFFIX" | cpio -id
78 uuidgen -r > conf/uuid.conf
79 find . | cpio --quiet --dereference -o -H newc | $COMPRESSOR -9c > "$COMPRESS_DIR/initrd$SUFFIX"
80 if [ "$(ls "$LIVEDIR/live-uuid"-* >/dev/null 2>&1 | wc -l)" = 1 ]; then
81         cp conf/uuid.conf "$LIVEDIR/live-uuid"-*
82 else
83         cp conf/uuid.conf "$LIVEDIR/live-uuid-$TYPE"
84 fi
85 cd "$CWD"
86 rm -rf "$TEMPDIR"