3 # rpmbased-dist-chroot.sh - builds a simple chroot from a directory of .rpms
4 # best to feed it the RPMS directory of a particular
5 # distribution. Has been tested with FC4.
6 # Copyright (C) 2004 Brett Parker <iDunno@sommitrealweird.co.uk>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 RPMArchives=/media/cdrom/Fedora/RPMS
25 InstallRoot=/mnt/temp/fedora
26 installpackages="bash coreutils yum"
28 ourcachedirectory=$(mktemp -d)
30 architecture=$(uname -m)
31 export ARCH=$architecture
33 function buildcache() {
36 for file in *.{noarch,$architecture}.rpm; do
37 rpm -qpl $file | sed 's#^#'$file':#' >> $ourcachedirectory/fedora-files-cache
38 rpm -qp --provides $file | cut -d " " -f 1 | sed 's#^#'$file':#' >> $ourcachedirectory/fedora-package-cache
49 escapename=$(echo $name | sed -e 's#\+#\\+#g; s#\.#\\.#g; s#(#\\(#g; s#)#\\)#g;')
51 if [ ${name:0:1} == "/" ]; then
52 grep -E "^.*:$escapename\$" $ourcachedirectory/fedora-files-cache | cut -d ":" -f 1 | head -n 1
54 grep -E "^.*:$escapename\$" $ourcachedirectory/fedora-package-cache | cut -d ":" -f 1 | head -n 1
58 function getdependencies() {
62 rpm -qp --requires ${RPMArchives}/$filename | grep -v '^.*('$name')' | cut -d " " -f 1 | sort | uniq | grep -Ev '^[ ]*$' | while read line; do
63 if [ ! -z $line ]; then
64 fname=$(findrpm $line)
65 packagename=$(getpackagename $fname)
66 if [ ! -z $name ] && [ ! -z $packagename ]; then
67 if ( ! grep '^'$fname' ' $ourcachedirectory/buildfedora-packagelist > /dev/null ) && ( ! rpm -r ${InstallRoot} -qv $packagename > /dev/null ); then
68 echo $fname $packagename >> $ourcachedirectory/buildfedora-packagelist
69 getdependencies $fname $packagename
76 function getpackagename() {
78 if [ ! -z $filename ]; then
79 rpm -qp --queryformat "%{NAME}\n" ${RPMArchives}/$filename
89 cp /etc/resolv.conf etc/
90 mknod -m 666 dev/null c 1 3
95 rpm -r ${InstallRoot} --initdb
97 # install setup and filesystem
100 echo $(findrpm filesystem)
102 rpm -r ${InstallRoot} --ignorearch --install ${RPMArchives}/$(findrpm setup)
103 echo rpm -r ${InstallRoot} --ignorearch --install ${RPMArchives}/$(findrpm setup) >> $ourcachedirectory/install-log
104 rpm -r ${InstallRoot} --ignorearch --install ${RPMArchives}/$(findrpm filesystem)
105 echo rpm -r ${InstallRoot} --ignorearch --install ${RPMArchives}/$(findrpm filesystem) >> $ourcachedirectory/install-log
107 for package in $installpackages; do
108 rm -f ~/.buildfedora-packagelist
109 touch ~/.buildfedora-packagelist
111 echo "Installing packages required for $package"
113 getdependencies $(findrpm $package) $package
115 echo rpm -r ${InstallRoot} --ignorearch --install $(cat ~/.buildfedora-packagelist | cut -d ' ' -f 1) >> ~/.fedora-install-log
117 cd ${RPMArchives} && rpm -r ${InstallRoot} --ignorearch --install $(cat ~/.buildfedora-packagelist | cut -d ' ' -f 1)
118 if ( ! grep " $package\$" ~/.buildfedora-packagelist > /dev/null 2>/dev/null ); then
119 echo rpm -r ${InstallRoot} --ignorearch --install $(findrpm $package) >> $ourcachedirectory/install-log
120 cd ${RPMArchives} && rpm -r ${InstallRoot} --ignorearch --install $(findrpm $package)
124 read -p "Remove cache directory ($ourcachedirectory)? [Yn]: " cleanup
126 if [[ $cleanup =~ ^[Nn] ]]; then
127 echo leaving logs in $ourcachedirectory
129 echo removing logs directory
130 rm -r $ourcachedirectory