update/update.c
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Jul 16 11:07:18 2016 +0100 (2016-07-16)
changeset 61 31fb35727621
parent 59 update/updatez.c@296eac3183bc
child 99 0121592e2512
permissions -rw-r--r--
Support parallel installations. The idea is that for CAD screener, we want
to be able to install this on the same machine as a standard AVOT setup
(most notably for John's laptop). To allow for the possibility of a second
application that might have the same requirements, we add the concept of
vendor-specific distributions. Thus we can have one distribution for CAD
screener and one for The Next Big Thing. It doesn't seem trivial to have
both CAD screener and AVOT under the same vendor tag so we'll have to have
AVOT under "City Occupational" and CAD screener under "City Occupational Ltd"
or some such kludge.

Most of this is done although we are very short of test cases (in particular
we don't test that it's actually possible to install CAD screener in parallel
with AVOT or to update either of them once installed, which is fundamental).

We also have a lot of baggage left over, including an intercept of razor_set.
The problem that this was introduced to debug has been fixed but it looks
like there are a number of memory leaks which it might be useful to help
track down so it has been left in place for now.

There is still a lot of confusion in plover between path-based and URI-based
API. We should review the API, decide what we want and have a general clear up.

There is also confusion as to the purpose of RAZOR_ROOT (and meaning; path or
URI). This is not used at all in librazor (although it is used in razor.exe).
Ideally we shouldn't use it in plover or plover-gtk either although again, we
might want to support it or an equivalent in (some of) the various executables.

Work that would still to nice to do for CAD screener:

- uninstall (ideally as an installed program that hooks into Add/Remove programs
but even re-running the installer would be acceptable).
- xz support (smaller packages).
- repomd.xml and xml:base (would be needed for an Internet installer).
- graphical installer.
     1 /*
     2  * Copyright (C) 2009, 2011, 2016  J. Ali Harlow <ali@juiblex.co.uk>
     3  *
     4  * This program is free software; you can redistribute it and/or modify
     5  * it under the terms of the GNU General Public License as published by
     6  * the Free Software Foundation; either version 2 of the License, or
     7  * (at your option) any later version.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License along
    15  * with this program; if not, write to the Free Software Foundation, Inc.,
    16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    17  */
    18 
    19 #include <stdlib.h>
    20 #include <stdio.h>
    21 #include <errno.h>
    22 #include <lua.h>
    23 #include "config.h"
    24 #include "plover/plover.h"
    25 #include "whelk/whelk.h"
    26 
    27 LUALIB_API int luaopen_posix(lua_State *L);
    28 
    29 void update(const char *argv0)
    30 {
    31     char *yum_uri,*local_database,*active_database,*alternate_database;
    32     gchar *s,*prefix,*distribution,*vendor_prefix;
    33     int ch;
    34     struct comps *comps;
    35     GError *error=NULL;
    36     s=plover_get_program(argv0);
    37     yum_uri=razor_path_to_uri(s);
    38     g_free(s);
    39     s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
    40     comps=plover_comps_new_from_uri(s,&error);
    41     g_free(s);
    42     if (g_error_matches(error,PLOVER_RAZOR_ERROR,
    43       RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE))
    44     {
    45 	g_clear_error(&error);
    46 	free(yum_uri);
    47 	s=plover_get_program_directory(argv0);
    48 	yum_uri=razor_path_to_uri(s);
    49 	g_free(s);
    50 	s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
    51 	comps=plover_comps_new_from_uri(s,&error);
    52     }
    53     if (!comps)
    54     {
    55 	fprintf(stderr,"%s\n",error->message);
    56 	g_error_free(error);
    57 	exit(1);
    58     }
    59     prefix=plover_comps_get_default_prefix(comps);
    60     if (prefix)
    61     {
    62 	s=g_strconcat(prefix,"/var/lib/razor",NULL);
    63 	local_database=razor_path_to_uri(s);
    64 	g_free(s);
    65     }
    66     else
    67 	local_database=NULL;
    68     switch(comps->database)
    69     {
    70 	case COMPS_DATABASE_DISTRIBUTION_LOCAL:
    71 	    active_database=local_database;
    72 	    alternate_database=NULL;
    73 	    break;
    74 	case COMPS_DATABASE_GLOBAL:
    75 	    active_database=NULL;
    76 	    alternate_database=local_database;
    77 	    break;
    78     }
    79     if (prefix)
    80     {
    81 	distribution=g_strdup(comps->distribution);
    82 	plover_comps_set_distribution(comps,NULL);
    83 	vendor_prefix=plover_comps_get_default_prefix(comps);
    84 	plover_comps_set_distribution(comps,distribution);
    85 	g_free(distribution);
    86 	razor_set_database_uri(alternate_database);
    87 	if (plover_installed_files_match_prefix(vendor_prefix)==1)
    88 	{
    89 	    printf("There is an existing installation under %s\n"
    90 	      "which is not compatible with this distribution. In order\n"
    91 	      "to continue, the existing installation must be uninstalled.\n"
    92 	      "Do you want to remove all packages in the existing installion? ",
    93 	      prefix);
    94 	    ch=getchar();
    95 	    if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
    96 		exit(1);
    97 	    while(ch!='\n' && ch!=EOF)
    98 		ch=getchar();
    99 	    if (plover_remove(NULL,&error))
   100 	    {
   101 		fprintf(stderr,"%s\n",error->message);
   102 		g_error_free(error);
   103 		exit(1);
   104 	    }
   105 	}
   106 	g_free(vendor_prefix);
   107     }
   108     razor_set_database_uri(active_database);
   109     if (prefix && !plover_installed_files_match_prefix(prefix))
   110     {
   111 	printf("The existing installation is not under %s\n"
   112 	  "In order to continue, all the existing packages must be removed.\n"
   113 	  "Do you want to remove all existing packages? ",prefix);
   114 	ch=getchar();
   115 	if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
   116 	    exit(1);
   117 	while(ch!='\n' && ch!=EOF)
   118 	    ch=getchar();
   119 	if (plover_remove(NULL,&error))
   120 	{
   121 	    fprintf(stderr,"%s\n",error->message);
   122 	    g_error_free(error);
   123 	    exit(1);
   124 	}
   125     }
   126     free(local_database);
   127     plover_comps_free(comps);
   128     if (!plover_update_uri(yum_uri,prefix,NULL,&error))
   129     {
   130 	fprintf(stderr,"%s\n",error->message);
   131 	g_error_free(error);
   132 	exit(1);
   133     }
   134     g_free(prefix);
   135     free(yum_uri);
   136 }
   137 
   138 int main(int argc,char **argv)
   139 {
   140     plover_exception_handler_init();
   141     razor_set_lua_loader("posix",(void (*)())luaopen_posix);
   142     razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
   143     update(argv[0]);
   144     exit(0);
   145 }