[Ovirt-devel] [PATCH appliance] make gettree.sh a bit smarter

Alan Pevec apevec at redhat.com
Tue Nov 18 22:54:07 UTC 2008


handle both F9 and F10 trees by using .treeinfo metadata

REPOST with few more fixes

Signed-off-by: Alan Pevec <apevec at redhat.com>
---
 gettree.sh         |   75 ++++++++++++++++++++++++++++++++++++++--------------
 ovirt-appliance.ks |   13 +-------
 2 files changed, 57 insertions(+), 31 deletions(-)

diff --git a/gettree.sh b/gettree.sh
index 67f6cf9..523a40b 100755
--- a/gettree.sh
+++ b/gettree.sh
@@ -5,13 +5,32 @@
 #     e.g. http://download.fedoraproject.org/pub/fedora/linux/releases/9/Fedora/x86_64/os
 #   download minimal Fedora tree: .treeinfo stage2 initrd and kernel
 
+# Requires: wget
+# Requires: python-iniparse
+# Requires: createrepo
+
+# download $destination $URL [$alternative1 ...]
+# attempt to download from a list of URLs until it succeeds
 download() {
-    local f=$1
-    case "$f" in
-        file://*) cp ${f#file://} . ;;
-        *) wget --progress=dot:mega --continue $f ;;
-    esac
-    printf "."
+    local destination=$1
+    shift
+    local files="$@"
+    set +e
+    rc=0
+    for f in $files; do
+        case $f in
+            file://*) cp ${f#file://} "$destination" ;;
+            *) wget --directory-prefix="$destination" \
+                     --progress=dot:mega --continue "$f" ;;
+        esac
+        rc=$?
+        if [ $rc == 0 ]; then
+            printf "."
+            break
+        fi
+    done
+    set -e
+    return $rc
 }
 
 if [[ $# < 2 ]]; then
@@ -24,20 +43,36 @@ fi
 url=$1
 dest=$2
 
-pushd $dest
 printf "Downloading minimal Fedora install tree from $url"
 set -e
-download $url/.treeinfo
-mkdir -p Packages
-cd Packages
-download $url/Packages/basesystem-8.1-1.noarch.rpm
-cd ..
-createrepo .
-mkdir -p images/pxeboot
-cd images
-download $url/images/stage2.img
-cd pxeboot
-download $url/images/pxeboot/initrd.img
-download $url/images/pxeboot/vmlinuz
+download "$dest" $url/.treeinfo
+python -c 'from iniparse.ini import INIConfig
+ini = INIConfig()
+fp = open("'"$dest"'.treeinfo")
+ini.readfp(fp)
+fp.close()
+family = ini.general.family
+version = ini.general.version
+arch = ini.general.arch
+kernel = ini["images-"+arch].kernel
+initrd = ini["images-"+arch].initrd
+stage2 = ini.stage2.mainimage
+print "%s %s %s %s %s %s" % (family, version, arch, kernel, initrd, stage2)' | \
+(
+read os ver arch kernel initrd stage2
+echo $os $ver $arch > "$dest/.treeinfo.ova"
+mkdir -p "$dest/Packages"
+download "$dest/Packages" "$url/Packages/basesystem-8.1-1.noarch.rpm" \
+                          "$url/Packages/basesystem-10.0-1.noarch.rpm"
+createrepo "$dest"
+dir="$dest/$(dirname $stage2)"
+mkdir -p "$dir"
+download "$dir" "$url/$stage2"
+dir="$dest/$(dirname $kernel)"
+mkdir -p "$dir"
+download "$dir" "$url/$kernel"
+dir="$dest/$(dirname $initrd)"
+mkdir -p "$dir"
+download "$dir" "$url/$initrd"
+)
 echo "done"
-popd
diff --git a/ovirt-appliance.ks b/ovirt-appliance.ks
index f9bfcd5..5cb4e1c 100644
--- a/ovirt-appliance.ks
+++ b/ovirt-appliance.ks
@@ -54,18 +54,9 @@ lokkit
   fi
 
   set -e
-  python -c '
-from iniparse.ini import INIConfig
-ini = INIConfig()
-fp = open("tmp/tree/.treeinfo")
-ini.readfp(fp)
-fp.close()
-family = ini.general.family
-version = ini.general.version
-arch = ini.general.arch
-print "%s %s %s" % (family, version, arch)' | ( read os ver arch
+  cat tmp/tree/.treeinfo.ova | ( read os ver arch
       dest=$INSTALL_ROOT/var/www/cobbler/ks_mirror/$os-$ver-$arch
       printf "Importing $os-$ver-$arch ..."
-      cp -a tmp/tree $dest
+      cp -a tmp/tree "$dest"
   )
 %end
-- 
1.5.6.5




More information about the ovirt-devel mailing list