X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=febootstrap.sh;h=6700a9b1fdddfd70308010359cfd1603bca4e2be;hb=4cf4be3e7699a98ddd4233fafa1a74c5f52fe1e2;hp=908d47e09157427047497023313af5679c64478d;hpb=9e86010ce13b72921b4887b235d209adc6d263b7;p=febootstrap.git diff --git a/febootstrap.sh b/febootstrap.sh index 908d47e..6700a9b 100755 --- a/febootstrap.sh +++ b/febootstrap.sh @@ -1,4 +1,4 @@ -#!/bin/sh - +#!/bin/bash - # febootstrap # (C) Copyright 2009 Red Hat Inc. # @@ -18,3 +18,109 @@ # # Written by Richard W.M. Jones +TEMP=`getopt \ + -o g:i: \ + --long groupinstall:,group-install:,help,install: \ + -n febootstrap -- "$@"` +if [ $? != 0 ]; then + echo "febootstrap: problem parsing the command line arguments" + exit 1 +fi +eval set -- "$TEMP" + +declare -a packages +packages[0]="@Core" +i=0 + +usage () +{ + echo "Usage: febootstrap [--options] REPO TARGET [MIRROR]" + echo "Please read febootstrap(8) man page for more information." +} + +while true; do + case "$1" in + -i|--install) + packages[i++]="$2" + shift 2;; + --groupinstall|--group-install) + packages[i++]="@$2" + shift 2;; + --help) + usage + exit 0;; + --) + shift + break;; + *) + echo "Internal error!" + exit 1;; + esac +done + +if [ $# -lt 2 -o $# -gt 3 ]; then + usage + exit 1 +fi + +repo="$1" +target="$2" +mirror="$3" + +# Architecture is currently always the same as the current arch. We +# cannot do --foreign builds. See discussion in the manpage. +arch=$(arch) + +# Create a temporary directory, make sure it gets cleaned up at the end. +tmpdir=$(mktemp -d) +remove_tmpdir () +{ + status=$? + rm -rf "$tmpdir" && exit $status +} +trap remove_tmpdir EXIT + +# Create the temporary repository configuration. The name of the +# repository is always 'febootstrap'. +cat > $tmpdir/febootstrap.repo <<__EOF__ +[febootstrap] +name=febootstrap $repo $arch +failovermethod=priority +enabled=1 +gpgcheck=0 +__EOF__ + +# "Mirror" parameter is a bit misnamed, but it means a local mirror, +# instead of the public Fedora mirrors. +if [ -n "$mirror" ]; then + echo "baseurl=$mirror" >> "$tmpdir"/febootstrap.repo +else + echo "mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=$repo&arch=$arch" >> "$tmpdir"/febootstrap.repo +fi + +# Create the target filesystem. +rm -rf "$target" +mkdir "$target" + +# This is necessary to keep yum happy. It's not clear why yum can't +# just create this file itself. +mkdir -p "$target"/var/cache/yum/febootstrap/packages + +yumargs="-y --disablerepo=* --enablerepo=febootstrap --noplugins --nogpgcheck" + +# If we are root, then we don't need to run fakeroot and fakechroot. +if [ $(id -u) -eq 0 ]; then + yum \ + -c "$tmpdir"/febootstrap.repo \ + $yumargs \ + --installroot="$target" \ + install "${packages[@]}" +else + fakeroot -s "$target"/fakeroot.log \ + fakechroot -s \ + yum \ + -c "$tmpdir"/febootstrap.repo \ + $yumargs \ + --installroot="$target" \ + install "${packages[@]}" +fi