Add febootstrap-to-initramfs --files option, version 2.2
[febootstrap.git] / febootstrap-to-initramfs.sh
1 #!/bin/bash -
2 # febootstrap-to-initramfs
3 # (C) Copyright 2009 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # Written by Richard W.M. Jones <rjones@redhat.com>
20
21 unset CDPATH
22
23 TEMP=`getopt \
24         -o '' \
25         --long files:,help \
26         -n febootstrap-to-initramfs -- "$@"`
27 if [ $? != 0 ]; then
28     echo "febootstrap-to-initramfs: problem parsing the command line arguments"
29     exit 1
30 fi
31 eval set -- "$TEMP"
32
33 files=
34
35 usage ()
36 {
37     echo "Usage: febootstrap-to-initramfs [--files=filelist] DIR"
38     echo "Please read febootstrap-to-initramfs(8) man page for more information."
39 }
40
41 while true; do
42     case "$1" in
43         --files)
44             files=$2
45             shift 2;;
46         --help)
47             usage
48             exit 0;;
49         --)
50             shift
51             break;;
52         *)
53             echo "Internal error!"
54             exit 1;;
55     esac
56 done
57
58 if [ $# -ne 1 ]; then
59     usage
60     exit 1
61 fi
62
63 cd "$1" > /dev/null
64
65 if [ ! -f fakeroot.log -a $(id -u) -ne 0 ]; then
66     echo "no fakeroot.log and not running as root"
67     exit 1
68 fi
69
70 set -e
71
72 if [ -f fakeroot.log ]; then
73     if [ -z "$files" ]; then
74         fakeroot -i fakeroot.log \
75         sh -c 'find -not -name fakeroot.log -a -print0 | cpio -o -0 -H newc | gzip --best'
76     else
77         fakeroot -i fakeroot.log \
78         sh -c 'cpio -o -H newc | gzip --best' < $files
79     fi
80 else
81     if [ -z "$files" ]; then
82         find -not -name fakeroot.log -a -print0 | cpio -o -0 -H newc | gzip --best
83     else
84         cpio -o -H newc < $files | gzip --best
85     fi
86 fi