Stop febootstrap-run from accepting -g and -i options in error.
[febootstrap.git] / febootstrap-run.sh
1 #!/bin/bash -
2 # febootstrap-run
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 help,ro \
26         -n febootstrap-run -- "$@"`
27 if [ $? != 0 ]; then
28     echo "febootstrap-run: problem parsing the command line arguments"
29     exit 1
30 fi
31 eval set -- "$TEMP"
32
33 readonly=no
34
35 usage ()
36 {
37     echo "Usage: febootstrap-run [--options] DIR [CMD]"
38     echo "Please read febootstrap-run(8) man page for more information."
39 }
40
41 while true; do
42     case "$1" in
43         --ro)
44             readonly=yes
45             shift;;
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 [ $# -lt 1 ]; then
59     usage
60     exit 1
61 fi
62
63 target="$1"
64 shift
65
66 if [ ! -f "$target"/fakeroot.log ]; then
67     echo "febootstrap-run: $target: not a root filesystem"
68     exit 1
69 fi
70
71 if [ "$readonly" = "no" ]; then
72     fakeroot -i "$target"/fakeroot.log -s "$target"/fakeroot.log \
73         fakechroot -s \
74         chroot "$target" "$@"
75 else
76     fakeroot -i "$target"/fakeroot.log \
77         fakechroot -s \
78         chroot "$target" "$@"
79 fi