1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/.gitignore Thu Jul 09 08:23:50 2009 +0100
1.3 @@ -0,0 +1,18 @@
1.4 +Makefile
1.5 +Makefile.in
1.6 +aclocal.m4
1.7 +config.*
1.8 +config/
1.9 +autom4te.cache/
1.10 +configure
1.11 +libtool
1.12 +plover-*.tar.gz
1.13 +stamp-h1
1.14 +.deps/
1.15 +.libs/
1.16 +*.o
1.17 +*.lo
1.18 +*.la
1.19 +plover/plover.pc
1.20 +setup/resources.rc
1.21 +setup/setup
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/Makefile.am Thu Jul 09 08:23:50 2009 +0100
2.3 @@ -0,0 +1,1 @@
2.4 +SUBDIRS=plover setup
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/bootstrap.sh Thu Jul 09 08:23:50 2009 +0100
3.3 @@ -0,0 +1,8 @@
3.4 +#!/bin/sh
3.5 +set -e
3.6 +mkdir -p config
3.7 +autoheader
3.8 +aclocal
3.9 +libtoolize
3.10 +automake --foreign --add-missing
3.11 +autoconf
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/configure.ac Thu Jul 09 08:23:50 2009 +0100
4.3 @@ -0,0 +1,87 @@
4.4 +# -*- Autoconf -*-
4.5 +# Process this file with autoconf to produce a configure script.
4.6 +
4.7 +AC_INIT([plover],[0.1],[ali@juiblex.co.uk])
4.8 +AC_PREREQ(2.59)
4.9 +AC_CONFIG_AUX_DIR([config])
4.10 +AC_CONFIG_SRCDIR([plover/plover.h])
4.11 +AC_CONFIG_HEADER([config.h])
4.12 +AC_CONFIG_FILES([Makefile
4.13 +plover/Makefile
4.14 +plover/plover.pc
4.15 +setup/Makefile
4.16 +setup/resources.rc
4.17 +])
4.18 +AM_INIT_AUTOMAKE(no-define)
4.19 +case $VERSION in
4.20 + *.*.*)
4.21 + AC_SUBST(PLOVER_MAJOR_VERSION,[[`echo $VERSION | sed 's/\..*//'`]])
4.22 + AC_SUBST(PLOVER_MINOR_VERSION,
4.23 + [[`echo $VERSION | sed 's/[^.]*\.\([^.]*\)\..*/\1/'`]])
4.24 + AC_SUBST(PLOVER_MICRO_VERSION,[[`echo $VERSION | sed 's/.*\.\([^.]*\)/\1/'`]]) ;;
4.25 + *.*)
4.26 + AC_SUBST(PLOVER_MAJOR_VERSION,[[`echo $VERSION | sed 's/\..*//'`]])
4.27 + AC_SUBST(PLOVER_MINOR_VERSION,
4.28 + [[`echo $VERSION | sed 's/[^.]*\.\([^.]*\)/\1/'`]])
4.29 + AC_SUBST(PLOVER_MICRO_VERSION,0)
4.30 + ;;
4.31 + *)
4.32 + AC_SUBST(PLOVER_MAJOR_VERSION,0)
4.33 + AC_SUBST(PLOVER_MINOR_VERSION,0)
4.34 + AC_SUBST(PLOVER_MICRO_VERSION,0)
4.35 + ;;
4.36 +esac
4.37 +
4.38 +##################################################
4.39 +# Checks for programs.
4.40 +##################################################
4.41 +AC_PROG_CC
4.42 +AC_LIBTOOL_WIN32_DLL
4.43 +AC_PROG_LIBTOOL
4.44 +PKG_PROG_PKG_CONFIG
4.45 +AC_CHECK_TOOL(WINDRES,windres,no)
4.46 +AM_CONDITIONAL([HAVE_WINDRES],[test x$WINDRES != xno])
4.47 +
4.48 +##################################################
4.49 +# Checks for header files.
4.50 +##################################################
4.51 +AC_HEADER_STDC
4.52 +
4.53 +##################################################
4.54 +# Checks for typedefs, structures, and compiler characteristics.
4.55 +##################################################
4.56 +
4.57 +##################################################
4.58 +# Checks for libraries.
4.59 +##################################################
4.60 +PKG_CHECK_MODULES(RAZOR,[razor],[:],[RAZOR_LIBS=-lrazor])
4.61 +PKG_CHECK_MODULES(EXPAT,[expat],[:],[EXPAT_LIBS=-lexpat])
4.62 +PKG_CHECK_MODULES(ZLIB,[zlib],[:],[ZLIB_LIBS=-lz])
4.63 +LIBPLOVER_CFLAGS="$RAZOR_CFLAGS $EXPAT_CFLAGS $ZLIB_CFLAGS"
4.64 +LIBPLOVER_LIBS="$RAZOR_LIBS $EXPAT_LIBS $ZLIB_LIBS"
4.65 +AC_SUBST(LIBPLOVER_CFLAGS)
4.66 +AC_SUBST(LIBPLOVER_LIBS)
4.67 +save_PKG_CONFIG="$PKG_CONFIG"
4.68 +PKG_CONFIG="$PKG_CONFIG --static"
4.69 +PKG_CHECK_MODULES(SETUP,[whelk])
4.70 +PKG_CONFIG="$save_PKG_CONFIG"
4.71 +save_LIBS="$LIBS"
4.72 +AC_SEARCH_LIBS([crypt],[crypt])
4.73 +SETUP_LIBS="$SETUP_LIBS $RAZOR_LIBS -llua-posix $LIBS"
4.74 +SETUP_CFLAGS="$SETUP_CFLAGS $RAZOR_CFLAGS"
4.75 +AC_SUBST(SETUP_LIBS)
4.76 +AC_SUBST(SETUP_CFLAGS)
4.77 +LIBS="$save_LIBS"
4.78 +
4.79 +##################################################
4.80 +# Checks for library functions.
4.81 +##################################################
4.82 +
4.83 +##################################################
4.84 +# Checks for processor independent files.
4.85 +##################################################
4.86 +
4.87 +##################################################
4.88 +# Generate the various configured files
4.89 +##################################################
4.90 +AC_OUTPUT
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/plover/Makefile.am Thu Jul 09 08:23:50 2009 +0100
5.3 @@ -0,0 +1,12 @@
5.4 +AM_CFLAGS=-g $(LIBPLOVER_CFLAGS)
5.5 +LIBS=$(LIBPLOVER_LIBS)
5.6 +INCLUDES=-I$(top_srcdir)
5.7 +LDFLAGS=-no-undefined
5.8 +
5.9 +lib_LTLIBRARIES=libplover.la
5.10 +libplover_la_SOURCES=plover.h util.c import-yum.c razor.c comps.c
5.11 +
5.12 +pkginclude_HEADERS=plover.h
5.13 +
5.14 +pkgconfigdir=$(libdir)/pkgconfig
5.15 +pkgconfig_DATA=plover.pc
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/plover/comps.c Thu Jul 09 08:23:50 2009 +0100
6.3 @@ -0,0 +1,437 @@
6.4 +/*
6.5 + * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
6.6 + * Copyright (C) 2008 Red Hat, Inc
6.7 + * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
6.8 + *
6.9 + * This program is free software; you can redistribute it and/or modify
6.10 + * it under the terms of the GNU General Public License as published by
6.11 + * the Free Software Foundation; either version 2 of the License, or
6.12 + * (at your option) any later version.
6.13 + *
6.14 + * This program is distributed in the hope that it will be useful,
6.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.17 + * GNU General Public License for more details.
6.18 + *
6.19 + * You should have received a copy of the GNU General Public License along
6.20 + * with this program; if not, write to the Free Software Foundation, Inc.,
6.21 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
6.22 + */
6.23 +
6.24 +#include <string.h>
6.25 +#include <stdio.h>
6.26 +#include <errno.h>
6.27 +#include <expat.h>
6.28 +#include <assert.h>
6.29 +#include "plover/plover.h"
6.30 +
6.31 +/* Parse a comps.xml package group file. */
6.32 +
6.33 +static struct comps_requirement *comps_package_requirement_new(void)
6.34 +{
6.35 + struct comps_requirement *req;
6.36 + req=calloc(sizeof(*req),1);
6.37 + assert(req != NULL);
6.38 + req->type=COMPS_REQUIREMENT_OPTIONAL;
6.39 + return req;
6.40 +}
6.41 +
6.42 +static void comps_package_requirement_free_1(struct comps_requirement *req)
6.43 +{
6.44 + if (req)
6.45 + {
6.46 + free(req->requires);
6.47 + free(req->name);
6.48 + free(req);
6.49 + }
6.50 +}
6.51 +
6.52 +static void comps_package_requirement_free(struct comps_requirement *req)
6.53 +{
6.54 + struct comps_requirement *next;
6.55 + while(req)
6.56 + {
6.57 + next=req->next;
6.58 + comps_package_requirement_free_1(req);
6.59 + req=next;
6.60 + }
6.61 +}
6.62 +
6.63 +struct comps_group *comps_group_new(void)
6.64 +{
6.65 + struct comps_group *group;
6.66 + group=calloc(sizeof(*group),1);
6.67 + assert(group != NULL);
6.68 + group->bydefault=1;
6.69 + group->uservisible=1;
6.70 + return group;
6.71 +}
6.72 +
6.73 +static void comps_group_free_1(struct comps_group *group)
6.74 +{
6.75 + if (group)
6.76 + {
6.77 + free(group->id);
6.78 + free(group->name);
6.79 + free(group->description);
6.80 + comps_package_requirement_free(group->packages);
6.81 + free(group);
6.82 + }
6.83 +}
6.84 +static void comps_group_free(struct comps_group *group)
6.85 +{
6.86 + struct comps_group *next;
6.87 + while(group)
6.88 + {
6.89 + next=group->next;
6.90 + comps_group_free_1(group);
6.91 + group=next;
6.92 + }
6.93 +}
6.94 +
6.95 +struct comps *plover_comps_new(void)
6.96 +{
6.97 + struct comps *comps;
6.98 + comps=calloc(sizeof(*comps),1);
6.99 + assert(comps != NULL);
6.100 + return comps;
6.101 +}
6.102 +
6.103 +void plover_comps_free(struct comps *comps)
6.104 +{
6.105 + if (comps)
6.106 + {
6.107 + free(comps->vendor);
6.108 + comps_group_free(comps->groups);
6.109 + free(comps);
6.110 + }
6.111 +}
6.112 +
6.113 +enum comps_state {
6.114 + COMPS_STATE_BEGIN,
6.115 + COMPS_STATE_ROOT,
6.116 + COMPS_STATE_GROUP,
6.117 + COMPS_STATE_GROUP_ID,
6.118 + COMPS_STATE_GROUP_NAME,
6.119 + COMPS_STATE_GROUP_DESCRIPTION,
6.120 + COMPS_STATE_GROUP_DEFAULT,
6.121 + COMPS_STATE_GROUP_USERVISIBLE,
6.122 + COMPS_STATE_GROUP_PACKAGELIST,
6.123 + COMPS_STATE_GROUP_PACKAGELIST_REQ,
6.124 +};
6.125 +
6.126 +struct comps_context {
6.127 + XML_Parser parser;
6.128 + enum comps_state state;
6.129 + int unknown_elements;
6.130 + char *vendor;
6.131 + struct comps_group *group;
6.132 + void *p;
6.133 +};
6.134 +
6.135 +static enum comps_requirement_type comps_to_requirement_type(const char *flags)
6.136 +{
6.137 + if (strcmp(flags, "conditional") == 0)
6.138 + return COMPS_REQUIREMENT_CONDITIONAL;
6.139 + else if (strcmp(flags, "mandatory") == 0)
6.140 + return COMPS_REQUIREMENT_MANDATORY;
6.141 + else if (strcmp(flags, "default") == 0)
6.142 + return COMPS_REQUIREMENT_DEFAULT;
6.143 + else
6.144 + return COMPS_REQUIREMENT_OPTIONAL;
6.145 +}
6.146 +
6.147 +static void comps_start_element(void *data,const char *name,const char **atts)
6.148 +{
6.149 + struct comps_context *ctx = data;
6.150 + struct comps_group *group;
6.151 + struct comps_requirement *packages;
6.152 + int i;
6.153 +#if 0
6.154 + fprintf(stderr,"Starting element '");
6.155 + switch(ctx->state)
6.156 + {
6.157 + case COMPS_STATE_BEGIN:
6.158 + fprintf(stderr,"/");
6.159 + break;
6.160 + case COMPS_STATE_ROOT:
6.161 + fprintf(stderr,"/comps/");
6.162 + break;
6.163 + case COMPS_STATE_GROUP:
6.164 + fprintf(stderr,"/comps/group/");
6.165 + break;
6.166 + case COMPS_STATE_GROUP_ID:
6.167 + fprintf(stderr,"/comps/group/id/");
6.168 + break;
6.169 + case COMPS_STATE_GROUP_NAME:
6.170 + fprintf(stderr,"/comps/group/name/");
6.171 + break;
6.172 + case COMPS_STATE_GROUP_DESCRIPTION:
6.173 + fprintf(stderr,"/comps/group/description/");
6.174 + break;
6.175 + case COMPS_STATE_GROUP_DEFAULT:
6.176 + fprintf(stderr,"/comps/group/default/");
6.177 + break;
6.178 + case COMPS_STATE_GROUP_USERVISIBLE:
6.179 + fprintf(stderr,"/comps/group/uservisible/");
6.180 + break;
6.181 + case COMPS_STATE_GROUP_PACKAGELIST:
6.182 + fprintf(stderr,"/comps/group/packagelist/");
6.183 + break;
6.184 + case COMPS_STATE_GROUP_PACKAGELIST_REQ:
6.185 + fprintf(stderr,"/comps/group/packagelist/packagereq/");
6.186 + break;
6.187 +
6.188 + }
6.189 + for(i=0;i<ctx->unknown_elements;i++)
6.190 + fprintf(stderr,"*/");
6.191 + fprintf(stderr,"%s'\n",name);
6.192 +#endif
6.193 + if (ctx->unknown_elements)
6.194 + ctx->unknown_elements++;
6.195 + else if (ctx->state==COMPS_STATE_BEGIN && !strcmp(name,"comps"))
6.196 + {
6.197 + ctx->state=COMPS_STATE_ROOT;
6.198 + for (i=0;atts[i];i+=2)
6.199 + {
6.200 + if (!strcmp(atts[i],
6.201 + "http://project.juiblex.co.uk/plover/ns/2009\xFFvendor"))
6.202 + ctx->vendor=strdup(atts[i+1]);
6.203 + }
6.204 + }
6.205 + else if (ctx->state==COMPS_STATE_ROOT && !strcmp(name,"group"))
6.206 + {
6.207 + ctx->state=COMPS_STATE_GROUP;
6.208 + group=comps_group_new();
6.209 + group->next=ctx->group;
6.210 + ctx->group=group;
6.211 + }
6.212 + else if (ctx->state==COMPS_STATE_GROUP && !strcmp(name,"id"))
6.213 + {
6.214 + ctx->state=COMPS_STATE_GROUP_ID;
6.215 + ctx->p=&ctx->group->id;
6.216 + }
6.217 + else if (ctx->state==COMPS_STATE_GROUP && !strcmp(name,"name"))
6.218 + {
6.219 + ctx->state=COMPS_STATE_GROUP_NAME;
6.220 + ctx->p=&ctx->group->name;
6.221 + }
6.222 + else if (ctx->state==COMPS_STATE_GROUP && !strcmp(name,"description"))
6.223 + {
6.224 + ctx->state=COMPS_STATE_GROUP_DESCRIPTION;
6.225 + ctx->p=&ctx->group->description;
6.226 + }
6.227 + else if (ctx->state==COMPS_STATE_GROUP && !strcmp(name,"default"))
6.228 + {
6.229 + ctx->state=COMPS_STATE_GROUP_DEFAULT;
6.230 + ctx->p=&ctx->group->bydefault;
6.231 + }
6.232 + else if (ctx->state==COMPS_STATE_GROUP && !strcmp(name,"uservisible"))
6.233 + {
6.234 + ctx->state=COMPS_STATE_GROUP_USERVISIBLE;
6.235 + ctx->p=&ctx->group->uservisible;
6.236 + }
6.237 + else if (ctx->state==COMPS_STATE_GROUP && !strcmp(name,"packagelist"))
6.238 + ctx->state=COMPS_STATE_GROUP_PACKAGELIST;
6.239 + else if (ctx->state==COMPS_STATE_GROUP_PACKAGELIST &&
6.240 + !strcmp(name,"packagereq"))
6.241 + {
6.242 + packages=comps_package_requirement_new();
6.243 + packages->next=ctx->group->packages;
6.244 + ctx->group->packages=packages;
6.245 + for (i=0;atts[i];i+=2)
6.246 + {
6.247 + if (!strcmp(atts[i],"type"))
6.248 + packages->type=comps_to_requirement_type(atts[i+1]);
6.249 + else if (!strcmp(atts[i],"requires"))
6.250 + {
6.251 + packages->requires=strdup(atts[i+1]);
6.252 + packages->type=COMPS_REQUIREMENT_CONDITIONAL;
6.253 + }
6.254 + }
6.255 + ctx->state=COMPS_STATE_GROUP_PACKAGELIST_REQ;
6.256 + ctx->p=&packages->name;
6.257 + }
6.258 + else
6.259 + ctx->unknown_elements++;
6.260 +}
6.261 +
6.262 +struct comps_list
6.263 +{
6.264 + struct comps_list *next;
6.265 + /* body */
6.266 +};
6.267 +
6.268 +void *comps_list_reverse(void *list)
6.269 +{
6.270 + struct comps_list *link=list,*prev=NULL,*next;
6.271 + while(link)
6.272 + {
6.273 + next=link->next;
6.274 + link->next=prev;
6.275 + prev=link;
6.276 + link=next;
6.277 + }
6.278 + return prev;
6.279 +}
6.280 +
6.281 +static void comps_end_element(void *data,const char *name)
6.282 +{
6.283 + struct comps_context *ctx=data;
6.284 + if (ctx->unknown_elements)
6.285 + ctx->unknown_elements--;
6.286 + else
6.287 + switch (ctx->state)
6.288 + {
6.289 + case COMPS_STATE_ROOT:
6.290 + ctx->group=comps_list_reverse(ctx->group);
6.291 + ctx->state=COMPS_STATE_BEGIN;
6.292 + break;
6.293 + case COMPS_STATE_GROUP:
6.294 + ctx->group->packages=comps_list_reverse(ctx->group->packages);
6.295 + ctx->state=COMPS_STATE_ROOT;
6.296 + break;
6.297 + case COMPS_STATE_GROUP_ID:
6.298 + case COMPS_STATE_GROUP_NAME:
6.299 + case COMPS_STATE_GROUP_DESCRIPTION:
6.300 + case COMPS_STATE_GROUP_DEFAULT:
6.301 + case COMPS_STATE_GROUP_USERVISIBLE:
6.302 + case COMPS_STATE_GROUP_PACKAGELIST:
6.303 + ctx->state=COMPS_STATE_GROUP;
6.304 + break;
6.305 + case COMPS_STATE_GROUP_PACKAGELIST_REQ:
6.306 + ctx->state=COMPS_STATE_GROUP_PACKAGELIST;
6.307 + break;
6.308 + }
6.309 +#if 0
6.310 + fprintf(stderr,"Ending element '");
6.311 + switch(ctx->state)
6.312 + {
6.313 + case COMPS_STATE_BEGIN:
6.314 + fprintf(stderr,"/");
6.315 + break;
6.316 + case COMPS_STATE_ROOT:
6.317 + fprintf(stderr,"/comps/");
6.318 + break;
6.319 + case COMPS_STATE_GROUP:
6.320 + fprintf(stderr,"/comps/group/");
6.321 + break;
6.322 + case COMPS_STATE_GROUP_ID:
6.323 + fprintf(stderr,"/comps/group/id/");
6.324 + break;
6.325 + case COMPS_STATE_GROUP_NAME:
6.326 + fprintf(stderr,"/comps/group/name/");
6.327 + break;
6.328 + case COMPS_STATE_GROUP_DESCRIPTION:
6.329 + fprintf(stderr,"/comps/group/description/");
6.330 + break;
6.331 + case COMPS_STATE_GROUP_DEFAULT:
6.332 + fprintf(stderr,"/comps/group/default/");
6.333 + break;
6.334 + case COMPS_STATE_GROUP_USERVISIBLE:
6.335 + fprintf(stderr,"/comps/group/uservisible/");
6.336 + break;
6.337 + case COMPS_STATE_GROUP_PACKAGELIST:
6.338 + fprintf(stderr,"/comps/group/packagelist/");
6.339 + break;
6.340 + case COMPS_STATE_GROUP_PACKAGELIST_REQ:
6.341 + fprintf(stderr,"/comps/group/packagelist/packagereq/");
6.342 + break;
6.343 +
6.344 + }
6.345 + {
6.346 + int i;
6.347 + for(i=0;i<ctx->unknown_elements;i++)
6.348 + fprintf(stderr,"*/");
6.349 + }
6.350 + fprintf(stderr,"%s'\n",name);
6.351 +#endif
6.352 +}
6.353 +
6.354 +static void comps_character_data(void *data,const XML_Char *s,int len)
6.355 +{
6.356 + struct comps_context *ctx=data;
6.357 + char *str;
6.358 + switch (ctx->state)
6.359 + {
6.360 + case COMPS_STATE_GROUP_ID:
6.361 + case COMPS_STATE_GROUP_NAME:
6.362 + case COMPS_STATE_GROUP_DESCRIPTION:
6.363 + case COMPS_STATE_GROUP_PACKAGELIST_REQ:
6.364 + *(char **)ctx->p=str=malloc(len+1);
6.365 + memcpy(str,s,len);
6.366 + str[len]='\0';
6.367 + break;
6.368 + case COMPS_STATE_GROUP_DEFAULT:
6.369 + case COMPS_STATE_GROUP_USERVISIBLE:
6.370 + *(int *)ctx->p=*s=='T'||*s=='t';
6.371 + break;
6.372 + }
6.373 +}
6.374 +
6.375 +#define XML_BUFFER_SIZE 4096
6.376 +
6.377 +struct comps *plover_comps_new_from_file(const char *filename)
6.378 +{
6.379 + struct comps_context ctx={0};
6.380 + void *buf;
6.381 + int len;
6.382 + FILE *fp;
6.383 + XML_ParsingStatus status;
6.384 + struct comps *comps;
6.385 + fp=fopen(filename,"r");
6.386 + if (!fp)
6.387 + return NULL;
6.388 + ctx.state=COMPS_STATE_BEGIN;
6.389 + ctx.parser=XML_ParserCreateNS(NULL,'\xFF');
6.390 + XML_SetUserData(ctx.parser,&ctx);
6.391 + XML_SetElementHandler(ctx.parser,comps_start_element,comps_end_element);
6.392 + XML_SetCharacterDataHandler(ctx.parser,comps_character_data);
6.393 + do
6.394 + {
6.395 + XML_GetParsingStatus(ctx.parser,&status);
6.396 + switch (status.parsing)
6.397 + {
6.398 + case XML_SUSPENDED:
6.399 + XML_ResumeParser(ctx.parser);
6.400 + break;
6.401 + case XML_PARSING:
6.402 + case XML_INITIALIZED:
6.403 + buf=XML_GetBuffer(ctx.parser,XML_BUFFER_SIZE);
6.404 + len=fread(buf,1,XML_BUFFER_SIZE,fp);
6.405 + if (len<0)
6.406 + {
6.407 + comps_group_free(ctx.group);
6.408 + XML_ParserFree(ctx.parser);
6.409 + fclose(fp);
6.410 + return NULL;
6.411 + }
6.412 + if (!XML_ParseBuffer(ctx.parser,len,!len))
6.413 + {
6.414 + comps_group_free(ctx.group);
6.415 + XML_ParserFree(ctx.parser);
6.416 + fclose(fp);
6.417 + return NULL;
6.418 + }
6.419 + break;
6.420 + case XML_FINISHED:
6.421 + break;
6.422 + }
6.423 + } while (status.parsing!=XML_FINISHED);
6.424 + XML_ParserFree(ctx.parser);
6.425 + fclose(fp);
6.426 + comps=plover_comps_new();
6.427 + comps->vendor=ctx.vendor;
6.428 + comps->groups=ctx.group;
6.429 + return comps;
6.430 +}
6.431 +
6.432 +struct comps_group *plover_comps_lookup_group(struct comps *comps,
6.433 + const char *id)
6.434 +{
6.435 + struct comps_group *group;
6.436 + for(group=comps->groups;group;group=group->next)
6.437 + if (!strcmp(group->id,id))
6.438 + return group;
6.439 + return NULL;
6.440 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/plover/import-yum.c Thu Jul 09 08:23:50 2009 +0100
7.3 @@ -0,0 +1,365 @@
7.4 +/*
7.5 + * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
7.6 + * Copyright (C) 2008 Red Hat, Inc
7.7 + * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
7.8 + *
7.9 + * This program is free software; you can redistribute it and/or modify
7.10 + * it under the terms of the GNU General Public License as published by
7.11 + * the Free Software Foundation; either version 2 of the License, or
7.12 + * (at your option) any later version.
7.13 + *
7.14 + * This program is distributed in the hope that it will be useful,
7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 + * GNU General Public License for more details.
7.18 + *
7.19 + * You should have received a copy of the GNU General Public License along
7.20 + * with this program; if not, write to the Free Software Foundation, Inc.,
7.21 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
7.22 + */
7.23 +
7.24 +#define _GNU_SOURCE
7.25 +
7.26 +#include <string.h>
7.27 +#include <stdio.h>
7.28 +#include <stdint.h>
7.29 +#include <sys/stat.h>
7.30 +#include <unistd.h>
7.31 +#include <fcntl.h>
7.32 +#include <errno.h>
7.33 +
7.34 +#include <expat.h>
7.35 +#include <zlib.h>
7.36 +#include <razor.h>
7.37 +#include "plover.h"
7.38 +
7.39 +/* Import a yum filelist as a razor package set. */
7.40 +
7.41 +enum {
7.42 + YUM_STATE_BEGIN,
7.43 + YUM_STATE_PACKAGE_NAME,
7.44 + YUM_STATE_PACKAGE_ARCH,
7.45 + YUM_STATE_SUMMARY,
7.46 + YUM_STATE_DESCRIPTION,
7.47 + YUM_STATE_URL,
7.48 + YUM_STATE_LICENSE,
7.49 + YUM_STATE_CHECKSUM,
7.50 + YUM_STATE_REQUIRES,
7.51 + YUM_STATE_PROVIDES,
7.52 + YUM_STATE_OBSOLETES,
7.53 + YUM_STATE_CONFLICTS,
7.54 + YUM_STATE_FILE
7.55 +};
7.56 +
7.57 +struct yum_context {
7.58 + XML_Parser primary_parser;
7.59 + XML_Parser filelists_parser;
7.60 + XML_Parser current_parser;
7.61 +
7.62 + struct razor_importer *importer;
7.63 + struct import_property_context *current_property_context;
7.64 + char name[256], arch[64], summary[512], description[4096];
7.65 + char url[256], license[64], buffer[512], *p;
7.66 + char pkgid[128];
7.67 + uint32_t property_type;
7.68 + int state;
7.69 +
7.70 + int total, current;
7.71 +};
7.72 +
7.73 +static uint32_t
7.74 +yum_to_razor_relation (const char *flags)
7.75 +{
7.76 + if (flags[0] == 'L') {
7.77 + if (flags[1] == 'T')
7.78 + return RAZOR_PROPERTY_LESS;
7.79 + else
7.80 + return RAZOR_PROPERTY_LESS | RAZOR_PROPERTY_EQUAL;
7.81 + } else if (flags[0] == 'G') {
7.82 + if (flags[1] == 'T')
7.83 + return RAZOR_PROPERTY_GREATER;
7.84 + else
7.85 + return RAZOR_PROPERTY_GREATER | RAZOR_PROPERTY_EQUAL;
7.86 + } else
7.87 + return RAZOR_PROPERTY_EQUAL;
7.88 +}
7.89 +
7.90 +static void
7.91 +yum_primary_start_element(void *data, const char *name, const char **atts)
7.92 +{
7.93 + struct yum_context *ctx = data;
7.94 + const char *n, *epoch, *version, *release;
7.95 + char buffer[128];
7.96 + uint32_t pre, relation, flags;
7.97 + int i;
7.98 +
7.99 + if (strcmp(name, "metadata") == 0) {
7.100 + for (i = 0; atts[i]; i += 2) {
7.101 + if (strcmp(atts[i], "packages") == 0)
7.102 + ctx->total = atoi(atts[i + 1]);
7.103 + }
7.104 + } else if (strcmp(name, "name") == 0) {
7.105 + ctx->state = YUM_STATE_PACKAGE_NAME;
7.106 + ctx->p = ctx->name;
7.107 + } else if (strcmp(name, "arch") == 0) {
7.108 + ctx->state = YUM_STATE_PACKAGE_ARCH;
7.109 + ctx->p = ctx->arch;
7.110 + } else if (strcmp(name, "version") == 0) {
7.111 + epoch = NULL;
7.112 + version = NULL;
7.113 + release = NULL;
7.114 + for (i = 0; atts[i]; i += 2) {
7.115 + if (strcmp(atts[i], "epoch") == 0)
7.116 + epoch = atts[i + 1];
7.117 + else if (strcmp(atts[i], "ver") == 0)
7.118 + version = atts[i + 1];
7.119 + else if (strcmp(atts[i], "rel") == 0)
7.120 + release = atts[i + 1];
7.121 + }
7.122 + if (version == NULL || release == NULL) {
7.123 + fprintf(stderr, "invalid version tag, "
7.124 + "missing version or release attribute\n");
7.125 + return;
7.126 + }
7.127 +
7.128 + razor_build_evr(buffer, sizeof buffer, epoch, version, release);
7.129 + razor_importer_begin_package(ctx->importer,
7.130 + ctx->name, buffer, ctx->arch);
7.131 + } else if (strcmp(name, "summary") == 0) {
7.132 + ctx->p = ctx->summary;
7.133 + ctx->state = YUM_STATE_SUMMARY;
7.134 + } else if (strcmp(name, "description") == 0) {
7.135 + ctx->p = ctx->description;
7.136 + ctx->state = YUM_STATE_DESCRIPTION;
7.137 + } else if (strcmp(name, "url") == 0) {
7.138 + ctx->p = ctx->url;
7.139 + ctx->state = YUM_STATE_URL;
7.140 + } else if (strcmp(name, "checksum") == 0) {
7.141 + ctx->p = ctx->pkgid;
7.142 + ctx->state = YUM_STATE_CHECKSUM;
7.143 + } else if (strcmp(name, "rpm:license") == 0) {
7.144 + ctx->p = ctx->license;
7.145 + ctx->state = YUM_STATE_LICENSE;
7.146 + } else if (strcmp(name, "rpm:requires") == 0) {
7.147 + ctx->state = YUM_STATE_REQUIRES;
7.148 + ctx->property_type = RAZOR_PROPERTY_REQUIRES;
7.149 + } else if (strcmp(name, "rpm:provides") == 0) {
7.150 + ctx->state = YUM_STATE_PROVIDES;
7.151 + ctx->property_type = RAZOR_PROPERTY_PROVIDES;
7.152 + } else if (strcmp(name, "rpm:obsoletes") == 0) {
7.153 + ctx->state = YUM_STATE_OBSOLETES;
7.154 + ctx->property_type = RAZOR_PROPERTY_OBSOLETES;
7.155 + } else if (strcmp(name, "rpm:conflicts") == 0) {
7.156 + ctx->state = YUM_STATE_CONFLICTS;
7.157 + ctx->property_type = RAZOR_PROPERTY_CONFLICTS;
7.158 + } else if (strcmp(name, "rpm:entry") == 0 &&
7.159 + ctx->state != YUM_STATE_BEGIN) {
7.160 + n = NULL;
7.161 + epoch = NULL;
7.162 + version = NULL;
7.163 + release = NULL;
7.164 + relation = RAZOR_PROPERTY_EQUAL;
7.165 + pre = 0;
7.166 + for (i = 0; atts[i]; i += 2) {
7.167 + if (strcmp(atts[i], "name") == 0)
7.168 + n = atts[i + 1];
7.169 + else if (strcmp(atts[i], "epoch") == 0)
7.170 + epoch = atts[i + 1];
7.171 + else if (strcmp(atts[i], "ver") == 0)
7.172 + version = atts[i + 1];
7.173 + else if (strcmp(atts[i], "rel") == 0)
7.174 + release = atts[i + 1];
7.175 + else if (strcmp(atts[i], "flags") == 0)
7.176 + relation = yum_to_razor_relation(atts[i + 1]);
7.177 + else if (strcmp(atts[i], "pre") == 0)
7.178 + pre =
7.179 + RAZOR_PROPERTY_PRE |
7.180 + RAZOR_PROPERTY_POST |
7.181 + RAZOR_PROPERTY_PREUN |
7.182 + RAZOR_PROPERTY_POSTUN;
7.183 + }
7.184 +
7.185 + if (n == NULL) {
7.186 + fprintf(stderr, "invalid rpm:entry, "
7.187 + "missing name or version attributes\n");
7.188 + return;
7.189 + }
7.190 +
7.191 + razor_build_evr(buffer, sizeof buffer, epoch, version, release);
7.192 + flags = ctx->property_type | relation | pre;
7.193 + razor_importer_add_property(ctx->importer, n, flags, buffer);
7.194 + }
7.195 +}
7.196 +
7.197 +static void
7.198 +yum_primary_end_element (void *data, const char *name)
7.199 +{
7.200 + struct yum_context *ctx = data;
7.201 +
7.202 + switch (ctx->state) {
7.203 + case YUM_STATE_PACKAGE_NAME:
7.204 + case YUM_STATE_PACKAGE_ARCH:
7.205 + case YUM_STATE_SUMMARY:
7.206 + case YUM_STATE_DESCRIPTION:
7.207 + case YUM_STATE_URL:
7.208 + case YUM_STATE_LICENSE:
7.209 + case YUM_STATE_CHECKSUM:
7.210 + case YUM_STATE_FILE:
7.211 + ctx->state = YUM_STATE_BEGIN;
7.212 + break;
7.213 + }
7.214 +
7.215 + if (strcmp(name, "package") == 0) {
7.216 + razor_importer_add_details(ctx->importer, ctx->summary,
7.217 + ctx->description, ctx->url,
7.218 + ctx->license);
7.219 +
7.220 + XML_StopParser(ctx->current_parser, XML_TRUE);
7.221 + ctx->current_parser = ctx->filelists_parser;
7.222 +
7.223 + printf("\rimporting %d/%d", ++ctx->current, ctx->total);
7.224 + fflush(stdout);
7.225 + }
7.226 +}
7.227 +
7.228 +static void
7.229 +yum_character_data (void *data, const XML_Char *s, int len)
7.230 +{
7.231 + struct yum_context *ctx = data;
7.232 +
7.233 + switch (ctx->state) {
7.234 + case YUM_STATE_PACKAGE_NAME:
7.235 + case YUM_STATE_PACKAGE_ARCH:
7.236 + case YUM_STATE_SUMMARY:
7.237 + case YUM_STATE_DESCRIPTION:
7.238 + case YUM_STATE_URL:
7.239 + case YUM_STATE_LICENSE:
7.240 + case YUM_STATE_CHECKSUM:
7.241 + case YUM_STATE_FILE:
7.242 + memcpy(ctx->p, s, len);
7.243 + ctx->p += len;
7.244 + *ctx->p = '\0';
7.245 + break;
7.246 + }
7.247 +}
7.248 +
7.249 +static void
7.250 +yum_filelists_start_element(void *data, const char *name, const char **atts)
7.251 +{
7.252 + struct yum_context *ctx = data;
7.253 + const char *pkg, *pkgid;
7.254 + int i;
7.255 +
7.256 + if (strcmp(name, "package") == 0) {
7.257 + pkg = NULL;
7.258 + pkgid = NULL;
7.259 + for (i = 0; atts[i]; i += 2) {
7.260 + if (strcmp(atts[i], "name") == 0)
7.261 + pkg = atts[i + 1];
7.262 + else if (strcmp(atts[i], "pkgid") == 0)
7.263 + pkgid = atts[i + 1];
7.264 + }
7.265 + if (strcmp(pkgid, ctx->pkgid) != 0)
7.266 + fprintf(stderr, "primary.xml and filelists.xml "
7.267 + "mismatch for %s: %s vs %s",
7.268 + pkg, pkgid, ctx->pkgid);
7.269 + } else if (strcmp(name, "file") == 0) {
7.270 + ctx->state = YUM_STATE_FILE;
7.271 + ctx->p = ctx->buffer;
7.272 + }
7.273 +}
7.274 +
7.275 +static void
7.276 +yum_filelists_end_element (void *data, const char *name)
7.277 +{
7.278 + struct yum_context *ctx = data;
7.279 +
7.280 + ctx->state = YUM_STATE_BEGIN;
7.281 + if (strcmp(name, "package") == 0) {
7.282 + XML_StopParser(ctx->current_parser, XML_TRUE);
7.283 + ctx->current_parser = ctx->primary_parser;
7.284 + razor_importer_finish_package(ctx->importer);
7.285 + } else if (strcmp(name, "file") == 0)
7.286 + razor_importer_add_file(ctx->importer, ctx->buffer);
7.287 +
7.288 +}
7.289 +
7.290 +#define XML_BUFFER_SIZE 4096
7.291 +
7.292 +struct razor_set *
7.293 +plover_razor_set_create_from_yum(const char *base)
7.294 +{
7.295 + struct yum_context ctx;
7.296 + void *buf;
7.297 + int len, ret;
7.298 + gzFile primary, filelists;
7.299 + XML_ParsingStatus status;
7.300 +
7.301 + ctx.importer = razor_importer_create();
7.302 + ctx.state = YUM_STATE_BEGIN;
7.303 +
7.304 + ctx.primary_parser = XML_ParserCreate(NULL);
7.305 + XML_SetUserData(ctx.primary_parser, &ctx);
7.306 + XML_SetElementHandler(ctx.primary_parser,
7.307 + yum_primary_start_element,
7.308 + yum_primary_end_element);
7.309 + XML_SetCharacterDataHandler(ctx.primary_parser,
7.310 + yum_character_data);
7.311 +
7.312 + ctx.filelists_parser = XML_ParserCreate(NULL);
7.313 + XML_SetUserData(ctx.filelists_parser, &ctx);
7.314 + XML_SetElementHandler(ctx.filelists_parser,
7.315 + yum_filelists_start_element,
7.316 + yum_filelists_end_element);
7.317 + XML_SetCharacterDataHandler(ctx.filelists_parser,
7.318 + yum_character_data);
7.319 +
7.320 + primary = gzopen("primary.xml.gz", "rb");
7.321 + if (primary == NULL)
7.322 + return NULL;
7.323 + filelists = gzopen("filelists.xml.gz", "rb");
7.324 + if (filelists == NULL)
7.325 + return NULL;
7.326 +
7.327 + ctx.current_parser = ctx.primary_parser;
7.328 +
7.329 + ctx.current = 0;
7.330 +
7.331 + do {
7.332 + XML_GetParsingStatus(ctx.current_parser, &status);
7.333 + switch (status.parsing) {
7.334 + case XML_SUSPENDED:
7.335 + ret = XML_ResumeParser(ctx.current_parser);
7.336 + break;
7.337 + case XML_PARSING:
7.338 + case XML_INITIALIZED:
7.339 + buf = XML_GetBuffer(ctx.current_parser,
7.340 + XML_BUFFER_SIZE);
7.341 + if (ctx.current_parser == ctx.primary_parser)
7.342 + len = gzread(primary, buf, XML_BUFFER_SIZE);
7.343 + else
7.344 + len = gzread(filelists, buf, XML_BUFFER_SIZE);
7.345 + if (len < 0) {
7.346 + fprintf(stderr,
7.347 + "couldn't read input: %s\n",
7.348 + strerror(errno));
7.349 + return NULL;
7.350 + }
7.351 +
7.352 + XML_ParseBuffer(ctx.current_parser, len, len == 0);
7.353 + break;
7.354 + case XML_FINISHED:
7.355 + break;
7.356 + }
7.357 + } while (status.parsing != XML_FINISHED);
7.358 +
7.359 +
7.360 + XML_ParserFree(ctx.primary_parser);
7.361 + XML_ParserFree(ctx.filelists_parser);
7.362 +
7.363 + gzclose(primary);
7.364 + gzclose(filelists);
7.365 +
7.366 + printf ("\nsaving\n");
7.367 + return razor_importer_finish(ctx.importer);
7.368 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/plover/plover.h Thu Jul 09 08:23:50 2009 +0100
8.3 @@ -0,0 +1,54 @@
8.4 +#ifndef __PLOVER_H__
8.5 +#define __PLOVER_H__
8.6 +
8.7 +#include <razor.h>
8.8 +
8.9 +enum comps_requirement_type
8.10 +{
8.11 + COMPS_REQUIREMENT_OPTIONAL,
8.12 + COMPS_REQUIREMENT_DEFAULT,
8.13 + COMPS_REQUIREMENT_MANDATORY,
8.14 + COMPS_REQUIREMENT_CONDITIONAL
8.15 +};
8.16 +
8.17 +struct comps_requirement
8.18 +{
8.19 + struct comps_requirement *next;
8.20 + enum comps_requirement_type type;
8.21 + char *requires; /* For type == COMPS_REQUIREMENT_CONDITIONAL */
8.22 + char *name;
8.23 +};
8.24 +
8.25 +struct comps_group
8.26 +{
8.27 + struct comps_group *next;
8.28 + char *id,*name,*description;
8.29 + int bydefault,uservisible;
8.30 + struct comps_requirement *packages;
8.31 +};
8.32 +
8.33 +struct comps
8.34 +{
8.35 + char *vendor;
8.36 + struct comps_group *groups;
8.37 +};
8.38 +
8.39 +char *plover_strconcat(const char *string,...);
8.40 +
8.41 +struct razor_set *plover_razor_set_create_from_yum(const char *base);
8.42 +
8.43 +struct razor_set *plover_relocate_packages(struct razor_set *set,
8.44 + const char *base,struct razor_relocations *relocations);
8.45 +int plover_run_transaction(struct razor_transaction *trans,const char *base,
8.46 + const char *install_root,struct razor_set *system,struct razor_set *next,
8.47 + struct razor_relocations *relocations);
8.48 +int plover_install(const char *base,const char *prefix,char **pkgs);
8.49 +int plover_remove(char **pkgs);
8.50 +
8.51 +struct comps *plover_comps_new(void);
8.52 +struct comps *plover_comps_new_from_file(const char *filename);
8.53 +void plover_comps_free(struct comps *comps);
8.54 +struct comps_group *plover_comps_lookup_group(struct comps *comps,
8.55 + const char *id);
8.56 +
8.57 +#endif /* __PLOVER_H__ */
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/plover/plover.pc.in Thu Jul 09 08:23:50 2009 +0100
9.3 @@ -0,0 +1,11 @@
9.4 +prefix=@prefix@
9.5 +exec_prefix=@exec_prefix@
9.6 +libdir=@libdir@
9.7 +includedir=@includedir@
9.8 +
9.9 +Name: plover
9.10 +Description: Plover packaging system
9.11 +Version: @VERSION@
9.12 +Requires: razor expat zlib
9.13 +Libs: -L${libdir} -lplover
9.14 +Cflags: -I${includedir}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/plover/razor.c Thu Jul 09 08:23:50 2009 +0100
10.3 @@ -0,0 +1,343 @@
10.4 +/*
10.5 + * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
10.6 + * Copyright (C) 2008 Red Hat, Inc
10.7 + * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
10.8 + *
10.9 + * This program is free software; you can redistribute it and/or modify
10.10 + * it under the terms of the GNU General Public License as published by
10.11 + * the Free Software Foundation; either version 2 of the License, or
10.12 + * (at your option) any later version.
10.13 + *
10.14 + * This program is distributed in the hope that it will be useful,
10.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.17 + * GNU General Public License for more details.
10.18 + *
10.19 + * You should have received a copy of the GNU General Public License along
10.20 + * with this program; if not, write to the Free Software Foundation, Inc.,
10.21 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
10.22 + */
10.23 +
10.24 +#include <stdlib.h>
10.25 +#include <stdio.h>
10.26 +#include <stdarg.h>
10.27 +#include <string.h>
10.28 +#include <unistd.h>
10.29 +#include <razor.h>
10.30 +#include "config.h"
10.31 +#include "plover/plover.h"
10.32 +
10.33 +static char *rpm_filename(const char *name,const char *version,const char *arch)
10.34 +{
10.35 + const char *v;
10.36 + v=strchr(version,':'); /* Skip epoch */
10.37 + if (v)
10.38 + v++;
10.39 + else
10.40 + v=version;
10.41 + return plover_strconcat(name,"-",v,".",arch,".rpm",NULL);
10.42 +}
10.43 +
10.44 +struct razor_set *plover_relocate_packages(struct razor_set *set,
10.45 + const char *base,struct razor_relocations *relocations)
10.46 +{
10.47 + struct razor_importer *importer;
10.48 + struct razor_property_iterator *prop_iter;
10.49 + struct razor_package_iterator *pkg_iter;
10.50 + struct razor_file_iterator *file_iter;
10.51 + struct razor_package *package;
10.52 + struct razor_property *property;
10.53 + struct razor_rpm *rpm;
10.54 + const char *name,*version,*arch,*summary,*desc,*url,*license;
10.55 + char *s,*file;
10.56 + uint32_t flags;
10.57 + importer=razor_importer_create();
10.58 + pkg_iter=razor_package_iterator_create(set);
10.59 + while (razor_package_iterator_next(pkg_iter,&package,RAZOR_DETAIL_NAME,
10.60 + &name,RAZOR_DETAIL_VERSION,&version,RAZOR_DETAIL_ARCH,&arch,
10.61 + RAZOR_DETAIL_SUMMARY,&summary,RAZOR_DETAIL_DESCRIPTION,&desc,
10.62 + RAZOR_DETAIL_URL,&url,RAZOR_DETAIL_LICENSE,&license,RAZOR_DETAIL_LAST))
10.63 + {
10.64 + s=rpm_filename(name,version,arch);
10.65 + file=plover_strconcat(base,"/rpms/",s,NULL);
10.66 + free(s);
10.67 + rpm=razor_rpm_open(file);
10.68 + if (!rpm)
10.69 + {
10.70 + fprintf(stderr,"failed to open rpm %s\n",file);
10.71 + razor_package_iterator_destroy(pkg_iter);
10.72 + razor_importer_destroy(importer);
10.73 + free(file);
10.74 + return NULL;
10.75 + }
10.76 + free(file);
10.77 + razor_relocations_set_rpm(relocations,rpm);
10.78 + razor_rpm_close(rpm);
10.79 + razor_importer_begin_package(importer,name,version,arch);
10.80 + razor_importer_add_details(importer,summary,desc,url,license);
10.81 + prop_iter=razor_property_iterator_create(set,package);
10.82 + while (razor_property_iterator_next(prop_iter,&property,&name,&flags,
10.83 + &version))
10.84 + razor_importer_add_property(importer,name,flags,version);
10.85 + razor_property_iterator_destroy(prop_iter);
10.86 + file_iter=razor_file_iterator_create(set,package,0);
10.87 + while (razor_file_iterator_next(file_iter,&name))
10.88 + {
10.89 + name=razor_relocations_apply(relocations,name);
10.90 + razor_importer_add_file(importer,name);
10.91 + }
10.92 + razor_file_iterator_destroy(file_iter);
10.93 + razor_importer_finish_package(importer);
10.94 + }
10.95 + razor_package_iterator_destroy(pkg_iter);
10.96 + return razor_importer_finish(importer);
10.97 +}
10.98 +
10.99 +int plover_run_transaction(struct razor_transaction *trans,const char *base,
10.100 + const char *install_root,struct razor_set *system,struct razor_set *next,
10.101 + struct razor_relocations *relocations)
10.102 +{
10.103 + struct razor_install_iterator *ii;
10.104 + struct razor_package *package;
10.105 + struct razor_set *set;
10.106 + enum razor_install_action action;
10.107 + struct razor_rpm *rpm;
10.108 + const char *name,*version,*arch;
10.109 + char *s,*file;
10.110 + int count;
10.111 + ii=razor_set_create_install_iterator(system,next);
10.112 + printf("Running Transaction\n");
10.113 + while (razor_install_iterator_next(ii,&set,&package,&action,&count))
10.114 + {
10.115 + if (action==RAZOR_INSTALL_ACTION_REMOVE)
10.116 + {
10.117 + razor_package_get_details(set,package,RAZOR_DETAIL_NAME,&name,
10.118 + RAZOR_DETAIL_LAST);
10.119 + printf(" Removing : %s ",name);
10.120 + if (razor_package_remove(set,package,install_root,0)<0)
10.121 + printf(
10.122 + "\nWarning: one or more errors occurred while removing %s",
10.123 + name);
10.124 + printf("\n");
10.125 + }
10.126 + else
10.127 + {
10.128 + razor_package_get_details(set,package,RAZOR_DETAIL_NAME,&name,
10.129 + RAZOR_DETAIL_VERSION,&version,RAZOR_DETAIL_ARCH,&arch,
10.130 + RAZOR_DETAIL_LAST);
10.131 + printf(" Installing : %s ",name);
10.132 + s=rpm_filename(name,version,arch);
10.133 + file=plover_strconcat(base,"/rpms/",s,NULL);
10.134 + free(s);
10.135 + rpm=razor_rpm_open(file);
10.136 + if (!rpm)
10.137 + {
10.138 + fprintf(stderr,"failed to open rpm %s\n",file);
10.139 + free(file);
10.140 + razor_install_iterator_destroy(ii);
10.141 + return -1;
10.142 + }
10.143 + if (relocations)
10.144 + razor_rpm_set_relocations(rpm,relocations);
10.145 + razor_transaction_fixup_package(trans,package,rpm);
10.146 + if (razor_rpm_install(rpm,install_root,1)<0)
10.147 + {
10.148 + fprintf(stderr,"failed to install rpm %s\n",file);
10.149 + razor_rpm_close(rpm);
10.150 + free(file);
10.151 + razor_install_iterator_destroy(ii);
10.152 + return -1;
10.153 + }
10.154 + razor_rpm_close(rpm);
10.155 + free(file);
10.156 + printf("\n");
10.157 + }
10.158 + }
10.159 + razor_install_iterator_destroy(ii);
10.160 + return 0;
10.161 +}
10.162 +
10.163 +static int plover_mark_package_for_update(struct razor_transaction *trans,
10.164 + struct razor_set *set,const char *pkg)
10.165 +{
10.166 + struct razor_package_iterator *pi;
10.167 + struct razor_package *package;
10.168 + const char *name;
10.169 + int retval=-1;
10.170 + pi=razor_package_iterator_create(set);
10.171 + while (razor_package_iterator_next(pi,&package,RAZOR_DETAIL_NAME,&name,
10.172 + RAZOR_DETAIL_LAST))
10.173 + {
10.174 + if (!strcmp(name,pkg))
10.175 + {
10.176 + razor_transaction_update_package(trans,package);
10.177 + retval=0;
10.178 + break;
10.179 + }
10.180 + }
10.181 + razor_package_iterator_destroy(pi);
10.182 + return retval;
10.183 +}
10.184 +
10.185 +int plover_install(const char *base,const char *prefix,char **pkgs)
10.186 +{
10.187 + int i;
10.188 + char *s;
10.189 + char *install_root;
10.190 + struct razor_root *root;
10.191 + struct razor_set *system,*set,*upstream,*next;
10.192 + struct razor_transaction *trans;
10.193 + struct razor_relocations *relocations;
10.194 + install_root=getenv("RAZOR_ROOT");
10.195 + if (!install_root)
10.196 + install_root="";
10.197 + if (prefix)
10.198 + {
10.199 + relocations=razor_relocations_create();
10.200 + razor_relocations_add(relocations,"/usr",prefix);
10.201 + }
10.202 + /*
10.203 + * Calling razor_root_open() on a system that hasn't yet had
10.204 + * razor_root_create() run generates a confusing error message
10.205 + * on stderr. Avoid this by trying to open it R/O first which
10.206 + * fails without generating any error.
10.207 + */
10.208 + set=razor_root_open_read_only(install_root);
10.209 + if (set)
10.210 + razor_set_destroy(set);
10.211 + else
10.212 + razor_root_create(install_root);
10.213 + root=razor_root_open(install_root);
10.214 + if (!root)
10.215 + return -1;
10.216 + system=razor_root_get_system_set(root);
10.217 + if (!system)
10.218 + {
10.219 + razor_root_close(root);
10.220 + return -1;
10.221 + }
10.222 + s=plover_strconcat(base,"/repodata",NULL);
10.223 + if (!s)
10.224 + {
10.225 + razor_root_close(root);
10.226 + return -1;
10.227 + }
10.228 + if (chdir(s)<0)
10.229 + {
10.230 + perror(s);
10.231 + free(s);
10.232 + razor_root_close(root);
10.233 + return -1;
10.234 + }
10.235 + free(s);
10.236 + set=plover_razor_set_create_from_yum(base);
10.237 + if (!set)
10.238 + {
10.239 + razor_root_close(root);
10.240 + return -1;
10.241 + }
10.242 + upstream=plover_relocate_packages(set,base,relocations);
10.243 + razor_set_destroy(set);
10.244 + trans=razor_transaction_create(system,upstream);
10.245 + for(i=0;pkgs[i];i++)
10.246 + if (plover_mark_package_for_update(trans,upstream,pkgs[i]))
10.247 + {
10.248 + fprintf(stderr,"%s: Package not found\n",pkgs[i]);
10.249 + razor_root_close(root);
10.250 + return -1;
10.251 + }
10.252 + razor_transaction_resolve(trans);
10.253 + if (razor_transaction_describe(trans)>0)
10.254 + {
10.255 + razor_root_close(root);
10.256 + return -1;
10.257 + }
10.258 + next=razor_transaction_commit(trans);
10.259 + plover_run_transaction(trans,base,install_root,system,next,relocations);
10.260 + razor_root_update(root,next);
10.261 + razor_transaction_destroy(trans);
10.262 + razor_set_destroy(next);
10.263 + razor_set_destroy(upstream);
10.264 + if (prefix)
10.265 + razor_relocations_destroy(relocations);
10.266 + return razor_root_commit(root);
10.267 +}
10.268 +
10.269 +static int plover_mark_packages_for_removal(struct razor_transaction *trans,
10.270 + struct razor_set *set,const char *pkg)
10.271 +{
10.272 + struct razor_package_iterator *pi;
10.273 + struct razor_package *package;
10.274 + const char *name;
10.275 + int retval=pkg?-1:0;
10.276 + pi=razor_package_iterator_create(set);
10.277 + while (razor_package_iterator_next(pi,&package,RAZOR_DETAIL_NAME,&name,
10.278 + RAZOR_DETAIL_LAST))
10.279 + {
10.280 + if (!pkg || !strcmp(name,pkg))
10.281 + {
10.282 + razor_transaction_remove_package(trans,package);
10.283 + retval=0;
10.284 + }
10.285 + }
10.286 + razor_package_iterator_destroy(pi);
10.287 + return retval;
10.288 +}
10.289 +
10.290 +int plover_remove(char **pkgs)
10.291 +{
10.292 + int i;
10.293 + char *install_root;
10.294 + struct razor_root *root;
10.295 + struct razor_set *system,*set,*upstream,*next;
10.296 + struct razor_transaction *trans;
10.297 + install_root=getenv("RAZOR_ROOT");
10.298 + if (!install_root)
10.299 + install_root="";
10.300 + set=razor_root_open_read_only(install_root);
10.301 + if (!set)
10.302 + return 0;
10.303 + razor_set_destroy(set);
10.304 + root=razor_root_open(install_root);
10.305 + if (!root)
10.306 + return -1;
10.307 + system=razor_root_get_system_set(root);
10.308 + if (!system)
10.309 + {
10.310 + razor_root_close(root);
10.311 + return -1;
10.312 + }
10.313 + upstream=razor_set_create_without_root();
10.314 + trans=razor_transaction_create(system,upstream);
10.315 + if (pkgs)
10.316 + for(i=0;pkgs[i];i++)
10.317 + {
10.318 + if (plover_mark_packages_for_removal(trans,system,pkgs[i]))
10.319 + {
10.320 + fprintf(stderr,"%s: Package not found\n",pkgs[i]);
10.321 + razor_transaction_destroy(trans);
10.322 + razor_set_destroy(upstream);
10.323 + razor_set_destroy(system);
10.324 + razor_root_close(root);
10.325 + return -1;
10.326 + }
10.327 + }
10.328 + else
10.329 + plover_mark_packages_for_removal(trans,system,NULL);
10.330 + razor_transaction_resolve(trans);
10.331 + if (razor_transaction_describe(trans)>0)
10.332 + {
10.333 + razor_transaction_destroy(trans);
10.334 + razor_set_destroy(upstream);
10.335 + razor_set_destroy(system);
10.336 + razor_root_close(root);
10.337 + return -1;
10.338 + }
10.339 + next=razor_transaction_commit(trans);
10.340 + plover_run_transaction(trans,NULL,install_root,system,next,NULL);
10.341 + razor_root_update(root,next);
10.342 + razor_transaction_destroy(trans);
10.343 + razor_set_destroy(next);
10.344 + razor_set_destroy(upstream);
10.345 + return razor_root_commit(root);
10.346 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/plover/util.c Thu Jul 09 08:23:50 2009 +0100
11.3 @@ -0,0 +1,53 @@
11.4 +/*
11.5 + * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
11.6 + *
11.7 + * This program is free software; you can redistribute it and/or modify
11.8 + * it under the terms of the GNU General Public License as published by
11.9 + * the Free Software Foundation; either version 2 of the License, or
11.10 + * (at your option) any later version.
11.11 + *
11.12 + * This program is distributed in the hope that it will be useful,
11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.15 + * GNU General Public License for more details.
11.16 + *
11.17 + * You should have received a copy of the GNU General Public License along
11.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
11.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
11.20 + */
11.21 +
11.22 +#include <stdlib.h>
11.23 +#include <stdarg.h>
11.24 +#include <string.h>
11.25 +#include "config.h"
11.26 +#include "plover.h"
11.27 +
11.28 +char *plover_strconcat(const char *string,...)
11.29 +{
11.30 + va_list ap,aq;
11.31 + size_t n;
11.32 + char *result=NULL,*t;
11.33 + const char *s;
11.34 + if (string)
11.35 + {
11.36 + va_start(ap,string);
11.37 + va_copy(aq,ap);
11.38 + n=strlen(string);
11.39 + while((s=va_arg(aq,const char *)))
11.40 + n+=strlen(s);
11.41 + va_end(aq);
11.42 + result=malloc(n+1);
11.43 + if (result)
11.44 + {
11.45 + strcpy(result,string);
11.46 + t=result+strlen(result);
11.47 + while((s=va_arg(ap,const char *)))
11.48 + {
11.49 + strcpy(t,s);
11.50 + t+=strlen(t);
11.51 + }
11.52 + }
11.53 + va_end(ap);
11.54 + }
11.55 + return result;
11.56 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/setup/Makefile.am Thu Jul 09 08:23:50 2009 +0100
12.3 @@ -0,0 +1,22 @@
12.4 +AM_CFLAGS=-g $(SETUP_CFLAGS)
12.5 +LDADD=../plover/libplover.la $(SETUP_LIBS)
12.6 +INCLUDES=-I$(top_srcdir)
12.7 +
12.8 +bin_PROGRAMS=setup
12.9 +
12.10 +setup_SOURCES=setup.c
12.11 +setup_LDFLAGS=-all-static
12.12 +if HAVE_WINDRES
12.13 +setup_SOURCES+=resources.rc
12.14 +endif
12.15 +
12.16 +.png.pnm:
12.17 + pngtopnm $< | pnmquant 256 > $@
12.18 +
12.19 +resources.$(OBJEXT): resources.rc setup.ico
12.20 + $(WINDRES) resources.rc $@
12.21 +
12.22 +setup.ico: icon16.pnm icon22.pnm icon32.pnm
12.23 + ppmtowinicon -output=$@ $^
12.24 +
12.25 +EXTRA_DIST=icon16.png icon22.png icon32.png
13.1 Binary file setup/icon16.png has changed
14.1 Binary file setup/icon22.png has changed
15.1 Binary file setup/icon32.png has changed
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/setup/resources.rc.in Thu Jul 09 08:23:50 2009 +0100
16.3 @@ -0,0 +1,32 @@
16.4 +#include <winver.h>
16.5 +
16.6 +MAINICON ICON "setup.ico"
16.7 +
16.8 +VS_VERSION_INFO VERSIONINFO
16.9 + FILEVERSION @PLOVER_MAJOR_VERSION@,@PLOVER_MINOR_VERSION@,@PLOVER_MICRO_VERS
16.10 +ION@,0
16.11 + PRODUCTVERSION @PLOVER_MAJOR_VERSION@,@PLOVER_MINOR_VERSION@,@PLOVER_MICRO_V
16.12 +ERSION@,0
16.13 + FILEOS VOS__WINDOWS32
16.14 + FILETYPE VFT_APP
16.15 + {
16.16 + BLOCK "StringFileInfo"
16.17 + {
16.18 + BLOCK "080904B0"
16.19 + {
16.20 + VALUE "CompanyName","The plover development team"
16.21 + VALUE "FileDescription","Plover setup program"
16.22 + VALUE "FileVersion","@PACKAGE_VERSION@"
16.23 + VALUE "InternalName","setup"
16.24 + VALUE "LegalCopyright",
16.25 + "Copyright (c) 2009 J. Ali Harlow et al"
16.26 + VALUE "OriginalFilename","setup.exe"
16.27 + VALUE "ProductName","plover"
16.28 + VALUE "ProductVersion","@PACKAGE_VERSION@"
16.29 + }
16.30 + }
16.31 + BLOCK "VarFileInfo"
16.32 + {
16.33 + VALUE "Translation",0x809,0x4B0
16.34 + }
16.35 + }
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/setup/setup.c Thu Jul 09 08:23:50 2009 +0100
17.3 @@ -0,0 +1,175 @@
17.4 +/*
17.5 + * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
17.6 + *
17.7 + * This program is free software; you can redistribute it and/or modify
17.8 + * it under the terms of the GNU General Public License as published by
17.9 + * the Free Software Foundation; either version 2 of the License, or
17.10 + * (at your option) any later version.
17.11 + *
17.12 + * This program is distributed in the hope that it will be useful,
17.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.15 + * GNU General Public License for more details.
17.16 + *
17.17 + * You should have received a copy of the GNU General Public License along
17.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
17.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17.20 + */
17.21 +
17.22 +#include <stdlib.h>
17.23 +#include <stdio.h>
17.24 +#include <string.h>
17.25 +#include <limits.h>
17.26 +#ifdef WIN32
17.27 +#include <windows.h>
17.28 +#include <shlobj.h>
17.29 +#endif
17.30 +#include <lua.h>
17.31 +#include "config.h"
17.32 +#include "plover/plover.h"
17.33 +#include "whelk/whelk.h"
17.34 +
17.35 +LUALIB_API int luaopen_posix(lua_State *L);
17.36 +
17.37 +struct vector {
17.38 + int len,alloc;
17.39 + char **strings;
17.40 +};
17.41 +
17.42 +struct vector *vector_new(void)
17.43 +{
17.44 + struct vector *vector;
17.45 + vector=malloc(sizeof(*vector));
17.46 + vector->len=0;
17.47 + vector->alloc=16;
17.48 + vector->strings=calloc(vector->alloc,sizeof(char *));
17.49 + return vector;
17.50 +}
17.51 +
17.52 +void vector_append(struct vector *vector,const char *str)
17.53 +{
17.54 + if (++(vector->len)>=vector->alloc)
17.55 + {
17.56 + vector->alloc*=2;
17.57 + vector->strings=realloc(vector->strings,vector->alloc*sizeof(char *));
17.58 + }
17.59 + vector->strings[vector->len-1]=strdup(str);
17.60 + vector->strings[vector->len]=NULL;
17.61 +}
17.62 +
17.63 +int vector_contains(struct vector *vector,const char *str)
17.64 +{
17.65 + int i;
17.66 + for(i=0;i<vector->len;i++)
17.67 + if (!strcmp(vector->strings[i],str))
17.68 + return 1;
17.69 + return 0;
17.70 +}
17.71 +
17.72 +void vector_free(struct vector *vector)
17.73 +{
17.74 + int i;
17.75 + for(i=0;i<vector->len;i++)
17.76 + free(vector->strings[i]);
17.77 + free(vector->strings);
17.78 + free(vector);
17.79 +}
17.80 +
17.81 +static void *alloc_lua(void *user_data,void *ptr,size_t osize,size_t nsize)
17.82 +{
17.83 + if (!nsize)
17.84 + {
17.85 + free(ptr);
17.86 + return NULL;
17.87 + }
17.88 + else
17.89 + return realloc(ptr,nsize);
17.90 +}
17.91 +
17.92 +void setup()
17.93 +{
17.94 + char path[PATH_MAX],*s,*t,*prefix;
17.95 + int changed;
17.96 + struct comps *comps;
17.97 + struct comps_group *group;
17.98 + struct comps_requirement *pkg;
17.99 + struct vector *packages=NULL;
17.100 +#ifdef WIN32
17.101 + SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES|CSIDL_FLAG_DONT_VERIFY,NULL,0,
17.102 + path);
17.103 + prefix=strdup(path);
17.104 + GetModuleFileName(NULL,path,sizeof(path));
17.105 + s=strrchr(path,'/');
17.106 + if (s)
17.107 + {
17.108 + t=strrchr(s,'\\');
17.109 + if (t)
17.110 + s=t;
17.111 + }
17.112 + else
17.113 + s=strrchr(path,'\\');
17.114 + if (s)
17.115 + *s='\0';
17.116 +#else
17.117 + strcpy(path,"/tmp");
17.118 + prefix=NULL;
17.119 +#endif
17.120 + s=plover_strconcat(path,"/repodata/comps.xml",NULL);
17.121 + comps=plover_comps_new_from_file(s);
17.122 + if (!comps)
17.123 + {
17.124 + perror(s);
17.125 + exit(1);
17.126 + }
17.127 + free(s);
17.128 +#ifdef WIN32
17.129 + s=plover_strconcat(prefix,"\\",comps->vendor?comps->vendor:"Plover",NULL);
17.130 + free(prefix);
17.131 + prefix=s;
17.132 +#endif
17.133 + group=plover_comps_lookup_group(comps,"base");
17.134 + if (!group)
17.135 + {
17.136 + fprintf(stderr,"No base group found in comps.xml\n");
17.137 + exit(1);
17.138 + }
17.139 + packages=vector_new();
17.140 + do
17.141 + {
17.142 + changed=0;
17.143 + for(pkg=group->packages;pkg;pkg=pkg->next)
17.144 + {
17.145 + if (vector_contains(packages,pkg->name))
17.146 + continue;
17.147 + if (pkg->type==COMPS_REQUIREMENT_DEFAULT ||
17.148 + pkg->type==COMPS_REQUIREMENT_MANDATORY ||
17.149 + pkg->type==COMPS_REQUIREMENT_CONDITIONAL &&
17.150 + vector_contains(packages,pkg->requires))
17.151 + {
17.152 + changed++;
17.153 + vector_append(packages,pkg->name);
17.154 + }
17.155 + }
17.156 + } while(changed);
17.157 + if (!packages->len)
17.158 + {
17.159 + fprintf(stderr,"No packages to install\n");
17.160 + exit(1);
17.161 + }
17.162 + plover_install(path,prefix,packages->strings);
17.163 + vector_free(packages);
17.164 + plover_comps_free(comps);
17.165 +#ifdef WIN32
17.166 + free(prefix);
17.167 +#endif
17.168 +}
17.169 +
17.170 +int main(int argc,char **argv)
17.171 +{
17.172 + razor_set_lua_loader("posix",luaopen_posix);
17.173 + razor_set_lua_loader("whelk",luaopen_whelk);
17.174 + if (argc>1 && !strcmp(argv[1],"-u"))
17.175 + plover_remove(NULL);
17.176 + else
17.177 + setup();
17.178 +}