Link to curl and download yum files automatically.
authorKristian H?gsberg <krh@redhat.com>
Mon Nov 05 19:06:52 2007 -0500 (2007-11-05)
changeset 71befb5208c022
parent 70 e94d16f789e5
child 72 4fddfa5f29fa
Link to curl and download yum files automatically.
Makefile
TODO
import-rpm.sh
main.c
     1.1 --- a/Makefile	Sun Nov 04 01:11:53 2007 -0400
     1.2 +++ b/Makefile	Mon Nov 05 19:06:52 2007 -0500
     1.3 @@ -1,13 +1,7 @@
     1.4  CFLAGS = -Wall -g -O2
     1.5 -LDLIBS = -lexpat -lz -g -lrpm
     1.6 +LDLIBS = -lexpat -lz -g -lrpm -lcurl
     1.7  
     1.8  razor : razor.o import.o sha1.o main.o
     1.9  
    1.10 -import : razor primary.xml.gz
    1.11 -	zcat primary.xml.gz | ./razor import-yum
    1.12 -
    1.13 -primary.xml.gz :
    1.14 -	wget http://download.fedora.redhat.com/pub/fedora/linux/development/i386/os/repodata/primary.xml.gz
    1.15 -
    1.16  clean :
    1.17  	rm -f *.o razor
     2.1 --- a/TODO	Sun Nov 04 01:11:53 2007 -0400
     2.2 +++ b/TODO	Mon Nov 05 19:06:52 2007 -0500
     2.3 @@ -12,8 +12,6 @@
     2.4  
     2.5  - merge file lists when merging package sets
     2.6  
     2.7 -- import filelist.xml.gz too in yum importer
     2.8 -
     2.9  - download (libcurl?)
    2.10  
    2.11  - figure out how to canonically represent empty string... ~0?
    2.12 @@ -88,3 +86,6 @@
    2.13    maybe the effective set is the on-disk representation and the
    2.14    overlay can be computed when needed, we just keep a link back to the
    2.15    base.
    2.16 +
    2.17 +- incremental rawhide repo updates? instead of downloading 10MB zipped
    2.18 +  repo every time, download a diff repo?
     3.1 --- a/import-rpm.sh	Sun Nov 04 01:11:53 2007 -0400
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,36 +0,0 @@
     3.4 -#!/bin/sh
     3.5 -
     3.6 -import_rpm() {
     3.7 -    echo "<package name=\"$1\" version=\"$2\" build=\"$3\">"
     3.8 -    echo "  <properties>"
     3.9 -
    3.10 -    rpm -q --provides $p | sort -u | while read name ignore version; do
    3.11 -	if test -z $version; then
    3.12 -	    echo "    <provides name=\"$name\"/>"
    3.13 -	else
    3.14 -	    echo "    <provides name=\"$name\" version=\"$version\"/>"
    3.15 -	fi
    3.16 -    done
    3.17 -
    3.18 -    rpm -q --requires $p | sort -u | while read name ignore version; do
    3.19 -	if test -z $version; then
    3.20 -	    echo "    <requires name=\"$name\"/>"
    3.21 -	else
    3.22 -	    echo "    <requires name=\"$name\" version=\"$version\"/>"
    3.23 -	fi
    3.24 -    done
    3.25 -
    3.26 -    echo "  </properties>"
    3.27 -    echo "</package>"
    3.28 -}
    3.29 -
    3.30 -mkdir -p pkgs
    3.31 -rpm -qa | while read p; do
    3.32 -    name=${p%-*-*}
    3.33 -    vr=${p#$name-}
    3.34 -    version=${vr%-*}
    3.35 -    release=${vr#*-}
    3.36 -
    3.37 -    echo $name - $version - $release
    3.38 -    import_rpm $name $version $release > pkgs/$name.rzr
    3.39 -done
     4.1 --- a/main.c	Sun Nov 04 01:11:53 2007 -0400
     4.2 +++ b/main.c	Mon Nov 05 19:06:52 2007 -0500
     4.3 @@ -4,6 +4,7 @@
     4.4  #include <string.h>
     4.5  #include <unistd.h>
     4.6  
     4.7 +#include <curl/curl.h>
     4.8  #include "razor.h"
     4.9  
    4.10  static const char *repo_filename = "system.repo";
    4.11 @@ -138,10 +139,35 @@
    4.12  	return 0;
    4.13  }
    4.14  
    4.15 +#define REPO_URL "http://download.fedora.redhat.com" \
    4.16 +	"/pub/fedora/linux/development/i386/os/repodata"
    4.17 +
    4.18  static int
    4.19  command_import_yum(int argc, const char *argv[])
    4.20  {
    4.21  	struct razor_set *set;
    4.22 +	CURL *curl;
    4.23 +	CURLcode res;
    4.24 +	FILE *fp;
    4.25 +
    4.26 +	curl = curl_easy_init();
    4.27 +	if (curl == NULL)
    4.28 +		return 1;
    4.29 +
    4.30 +	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
    4.31 +	fp = fopen("primary.xml.gz", "w");
    4.32 +	curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    4.33 +	curl_easy_setopt(curl, CURLOPT_URL, REPO_URL "/primary.xml.gz");
    4.34 +	res = curl_easy_perform(curl);
    4.35 +	fclose(fp);
    4.36 +
    4.37 +	fp = fopen("filelists.xml.gz", "w");
    4.38 +	curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    4.39 +	curl_easy_setopt(curl, CURLOPT_URL, REPO_URL "/filelists.xml.gz");
    4.40 +	res = curl_easy_perform(curl);
    4.41 +	fclose(fp);
    4.42 +
    4.43 +	curl_easy_cleanup(curl);
    4.44  
    4.45  	set = razor_set_create_from_yum();
    4.46  	if (set == NULL)