3 # (C) Copyright 2009 Red Hat Inc.
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.
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.
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.
19 # Written by Richard W.M. Jones <rjones@redhat.com>
25 --long groupinstall:,group-install:,help,install:,noclean,no-clean,proxy:,updates: \
26 -n febootstrap -- "$@"`
28 echo "febootstrap: problem parsing the command line arguments"
41 echo "Usage: febootstrap [--options] REPO TARGET [MIRROR]"
42 echo "Please read febootstrap(8) man page for more information."
50 --groupinstall|--group-install)
69 echo "Internal error!"
74 if [ $# -lt 2 -o $# -gt 3 ]; then
83 # Architecture is currently always the same as the current arch. We
84 # cannot do --foreign builds. See discussion in the manpage.
90 # Create a temporary directory, make sure it gets cleaned up at the end.
95 rm -rf "$tmpdir" && exit $status
97 trap remove_tmpdir EXIT
99 # Create the temporary repository configuration. The name of the
100 # repository is always 'febootstrap'.
101 cat > $tmpdir/febootstrap.repo <<__EOF__
103 name=febootstrap $repo $arch
104 failovermethod=priority
110 # "Mirror" parameter is a bit misnamed, but it means a local mirror,
111 # instead of the public Fedora mirrors.
112 if [ -n "$mirror" ]; then
113 echo "baseurl=$mirror" >> "$tmpdir"/febootstrap.repo
115 echo "mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=$repo&arch=$arch" >> "$tmpdir"/febootstrap.repo
118 # Add the updates repository if asked.
123 cat >> $tmpdir/febootstrap.repo <<EOF
125 [febootstrap-updates]
126 name=febootstrap updates $arch
127 failovermethod=priority
135 cat >> $tmpdir/febootstrap.repo <<EOF
137 [febootstrap-updates]
138 name=febootstrap $updates $arch
139 failovermethod=priority
143 mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=$updates&arch=$arch
148 # Create the target filesystem.
152 # Target must be an absolute path.
153 target=$(cd "$target" > /dev/null; pwd)
155 # This is necessary to keep yum happy. It's not clear why yum can't
156 # just create this file itself.
157 mkdir -p "$target"/var/cache/yum/febootstrap/packages
159 # NB: REQUIRED for useradd/groupadd to run properly.
161 # However this causes 'filesystem' RPM install to give the
162 # following error. Not sure how serious the error is:
163 # error: unpacking of archive failed on file /proc: cpio: utime
164 export FAKECHROOT_EXCLUDE_PATH=/proc
166 # Substitute some statically-linked commands. This is only supported
167 # in fakechroot > 2.9. For previous versions of fakechroot it is
169 export FAKECHROOT_CMD_SUBST=/sbin/ldconfig=/bin/true:/usr/sbin/glibc_post_upgrade.i686=/bin/true:/usr/sbin/glibc_post_upgrade.x86_64=/bin/true:/usr/sbin/build-locale-archive=/bin/true:/usr/sbin/libgcc_post_upgrade=/bin/true
171 # Make the device nodes inside the fake chroot.
172 # (Copied from mock/backend.py) Why isn't there a base package which
184 mknod null c 1 3; chmod 0666 null
185 mknod full c 1 7; chmod 0666 full
186 mknod zero c 1 5; chmod 0666 zero
187 mknod random c 1 8; chmod 0666 random
188 mknod urandom c 1 9; chmod 0444 urandom
189 mknod tty c 5 0; chmod 0666 tty
190 mknod console c 5 1; chmod 0600 console
191 mknod ptmx c 5 2; chmod 0666 ptmx
192 ln -sf /proc/self/fd/0 stdin
193 ln -sf /proc/self/fd/1 stdout
194 ln -sf /proc/self/fd/2 stderr
197 export -f make_device_nodes
200 if [ $(id -u) -ne 0 ]; then
201 fakeroot -s "$target"/fakeroot.log \
211 -y -c "$tmpdir"/febootstrap.repo \
212 --disablerepo=* --enablerepo=febootstrap \
213 --noplugins --nogpgcheck \
214 --installroot="$target" \
220 if [ $(id -u) -ne 0 ]; then
221 # Bash doesn't support exporting array variables, hence this
222 # tortuous workaround.
223 fakeroot -i "$target"/fakeroot.log -s "$target"/fakeroot.log \
225 bash -c 'run_yum "$@"' run_yum "${packages[@]}"
227 run_yum "${packages[@]}"
230 # Clean up the yum repository.
231 if [ "$clean" = "yes" ]; then
232 rm -rf "$target"/var/cache/yum/febootstrap