update/updatez.c
author J. Ali Harlow <ali@juiblex.co.uk>
Fri Jul 08 08:33:44 2016 +0100 (2016-07-08)
changeset 60 772ff096a326
parent 58 4b52e95a0104
permissions -rw-r--r--
Avoid Microsoft-specific localtime_s
     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 <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_from_executable_zip(const char *argv0)
    29 {
    30     char *uri;
    31     gchar *s,*prefix;
    32     int ch;
    33     struct comps *comps;
    34     GError *error=NULL;
    35     s=plover_get_program(argv0);
    36     uri=g_strconcat("file:",s,NULL);
    37     g_free(s);
    38     s=g_strconcat(uri,"/repodata/comps.xml",NULL);
    39     comps=plover_comps_new_from_uri(s);
    40     if (!comps)
    41     {
    42 	perror(s);
    43 	exit(1);
    44     }
    45     g_free(s);
    46     prefix=plover_default_prefix_for_vendor(comps->vendor);
    47     if (!plover_installed_files_match_prefix(prefix))
    48     {
    49 	printf("The existing installation is not under %s\n"
    50 	  "In order to continue, all the existing packages must be removed.\n"
    51 	  "Do you want to remove all existing packages? ",prefix);
    52 	ch=getchar();
    53 	if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
    54 	    exit(1);
    55 	while(ch!='\n' && ch!=EOF)
    56 	    ch=getchar();
    57 	if (plover_remove(NULL,&error))
    58 	{
    59 	    fprintf(stderr,"%s\n",error->message);
    60 	    g_error_free(error);
    61 	    exit(1);
    62 	}
    63     }
    64     plover_comps_free(comps);
    65     if (!plover_update_uri(uri,prefix,NULL,&error))
    66     {
    67 	fprintf(stderr,"%s\n",error->message);
    68 	g_error_free(error);
    69 	exit(1);
    70     }
    71     g_free(prefix);
    72     free(uri);
    73 }
    74 
    75 int main(int argc,char **argv)
    76 {
    77     plover_exception_handler_init();
    78     razor_set_lua_loader("posix",(void (*)())luaopen_posix);
    79     razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
    80     update_from_executable_zip(argv[0]);
    81     exit(0);
    82 }