update/update.c
author J. Ali Harlow <ali@juiblex.co.uk>
Tue Jul 05 13:02:45 2016 +0100 (2016-07-05)
changeset 56 42ab9633c451
parent 31 a53fcb780468
permissions -rw-r--r--
Release 0.5.2.52
     1 /*
     2  * Copyright (C) 2009, 2011  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 <lua.h>
    22 #include "config.h"
    23 #include "plover/plover.h"
    24 #include "whelk/whelk.h"
    25 
    26 LUALIB_API int luaopen_posix(lua_State *L);
    27 
    28 void update(const char *argv0)
    29 {
    30     char *path;
    31     gchar *s,*prefix;
    32     int ch;
    33     struct comps *comps;
    34     GError *error=NULL;
    35     path=plover_get_program_directory(argv0);
    36     s=g_strconcat(path,"/repodata/comps.xml",NULL);
    37     comps=plover_comps_new_from_file(s);
    38     if (!comps)
    39     {
    40 	perror(s);
    41 	exit(1);
    42     }
    43     g_free(s);
    44     prefix=plover_default_prefix_for_vendor(comps->vendor);
    45     if (!plover_installed_files_match_prefix(prefix))
    46     {
    47 	printf("The existing installation is not under %s\n"
    48 	  "In order to continue, all the existing packages must be removed.\n"
    49 	  "Do you want to remove all existing packages? ",prefix);
    50 	ch=getchar();
    51 	if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
    52 	    exit(1);
    53 	while(ch!='\n' && ch!=EOF)
    54 	    ch=getchar();
    55 	if (plover_remove(NULL,&error))
    56 	{
    57 	    fprintf(stderr,"%s\n",error->message);
    58 	    g_error_free(error);
    59 	    exit(1);
    60 	}
    61     }
    62     plover_comps_free(comps);
    63     if (!plover_update(path,prefix,NULL,&error))
    64     {
    65 	fprintf(stderr,"%s\n",error->message);
    66 	g_error_free(error);
    67 	exit(1);
    68     }
    69     g_free(prefix);
    70     free(path);
    71 }
    72 
    73 int main(int argc,char **argv)
    74 {
    75     plover_exception_handler_init();
    76     razor_set_lua_loader("posix",(void (*)())luaopen_posix);
    77     razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
    78     update(argv[0]);
    79     exit(0);
    80 }