Install the filesystem first, it helps...
[rpmbased-dist-chroot.git] / rpmbased-dist-chroot.sh
index 5aaf4eaef76cb4e11afda41fbdd6610f7e265bb4..d95310743d15605499dfab95c3f72ca6b7c2a3a2 100755 (executable)
 
 RPMArchives=/media/cdrom/Fedora/RPMS
 InstallRoot=/mnt/temp/fedora
-installpackages="bash coreutils yum"
+installpackages="filesystem basesystem coreutils yum redhat-release"
 
 ourcachedirectory=$(mktemp -d)
 
 architecture=$(uname -m)
 export ARCH=$architecture
 
+case $architecture in
+       x86_64)
+               architecture="x86_64,i686,i586,i486,i386"
+               ;;
+       i686)
+               architecture="i686,i586,i486,i386"
+               ;;
+       i586)
+               architecture="i586,i486,i386"
+               ;;
+       i486)
+               architecture="i486,i386"
+               ;;
+esac
+
 function displayHelp() {
 cat <<END
 Usage: $0 [options]
@@ -43,9 +58,25 @@ END
        exit $1
 }
 
+function startswithmm() {
+       if [ "${1##--*}" == "" ]; then
+               return 0
+       else
+               return 1
+       fi
+}
+
+function containsequals() {
+       if [ "${1//*=*}" == "" ]; then
+               return 0
+       else
+               return 1
+       fi
+}
+
 argcommand=""
 for option in $@; do
-       if [[ ! $option =~ ^-- ]]; then
+       if ( ! startswithmm $option ); then
                if [ "x$argcommand" == "xinstall-root" ]; then
                        InstallRoot=$option
                elif [ "x$argcommand" == "xrpm-archives" ]; then
@@ -58,7 +89,7 @@ for option in $@; do
                        fi
                fi
        else
-               if [[ $option =~ [=] ]]; then
+               if ( containsequals $option ); then
                        argcommand=${option%%=*}
                        argcommand=${argcommand##--}
                        option=${option##*=}
@@ -98,9 +129,11 @@ echo "InstallRoot     : $InstallRoot"
 function buildcache() {
        cd $RPMArchives
 
-       for file in *.{noarch,$architecture}.rpm; do
-               rpm -qpl $file | sed 's#^#'$file':#' >> $ourcachedirectory/files-cache
-               rpm -qp --provides $file | cut -d " " -f 1 | sed 's#^#'$file':#' >> $ourcachedirectory/package-cache
+       for arch in noarch $(echo $architecture | sed -e 's/,/\n/g'); do
+               for file in *.$arch.rpm; do
+                       rpm -qpl $file | sed 's#^#'$file':#' >> $ourcachedirectory/files-cache
+                       rpm -qp --provides $file | cut -d " " -f 1 | sed 's#^#'$file':#' >> $ourcachedirectory/package-cache
+               done
        done
 }
 
@@ -188,8 +221,10 @@ for package in $installpackages; do
                
                cd ${RPMArchives} && rpm -r ${InstallRoot} --ignorearch --install $(cat $ourcachedirectory/build-packagelist | cut -d ' ' -f 1)
                if ( ! grep " $package\$" $ourcachedirectory/build-packagelist > /dev/null 2>/dev/null ); then
-                       echo rpm -r ${InstallRoot} --ignorearch --install $(findrpm $package) >> $ourcachedirectory/install-log
-                       cd ${RPMArchives} && rpm -r ${InstallRoot} --ignorearch --install $(findrpm $package)
+                       packages="$(findrpm $package)"
+                       echo rpm -r ${InstallRoot} --ignorearch --install "${packages}" >> $ourcachedirectory/install-log
+                       echo "${packages}" >> $ourcachedirectory/packages-installed
+                       cd ${RPMArchives} && rpm -r ${InstallRoot} --ignorearch --install ${packages}
                fi
        else
                echo " Failed to find the RPM providing $package - skipping"
@@ -198,7 +233,9 @@ done
 
 read -p "Remove cache directory ($ourcachedirectory)? [Yn]: " cleanup
 
-if [[ $cleanup =~ ^[Nn] ]]; then
+cleanup=${cleanup:0:1}
+
+if [ "$cleanup" == "N" ] || [ "$cleanup" == "n" ] ; then
        echo leaving logs in $ourcachedirectory
 else
        echo removing logs directory