summaryrefslogtreecommitdiffstats
path: root/febootstrap.sh
diff options
context:
space:
mode:
authorrjones <rjones>2009-03-19 16:57:35 +0000
committerrjones <rjones>2009-03-19 16:57:35 +0000
commit4cf4be3e7699a98ddd4233fafa1a74c5f52fe1e2 (patch)
treeb8e7fa048754a5737e211c691e42944a895b7589 /febootstrap.sh
parent9e86010ce13b72921b4887b235d209adc6d263b7 (diff)
downloadfebootstrap-4cf4be3e7699a98ddd4233fafa1a74c5f52fe1e2.tar.gz
febootstrap-4cf4be3e7699a98ddd4233fafa1a74c5f52fe1e2.tar.xz
febootstrap-4cf4be3e7699a98ddd4233fafa1a74c5f52fe1e2.zip
First version of the script, working.
Diffstat (limited to 'febootstrap.sh')
-rwxr-xr-xfebootstrap.sh108
1 files changed, 107 insertions, 1 deletions
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 <rjones@redhat.com>
+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