update/update.c
author J. Ali Harlow <ali@juiblex.co.uk>
Wed Jun 22 17:04:28 2016 +0100 (2016-06-22)
changeset 44 43ffed8669ce
parent 31 a53fcb780468
permissions -rw-r--r--
Port to razor 0.6.3.60
ali@3
     1
/*
ali@13
     2
 * Copyright (C) 2009, 2011  J. Ali Harlow <ali@juiblex.co.uk>
ali@3
     3
 *
ali@3
     4
 * This program is free software; you can redistribute it and/or modify
ali@3
     5
 * it under the terms of the GNU General Public License as published by
ali@3
     6
 * the Free Software Foundation; either version 2 of the License, or
ali@3
     7
 * (at your option) any later version.
ali@3
     8
 *
ali@3
     9
 * This program is distributed in the hope that it will be useful,
ali@3
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ali@3
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ali@3
    12
 * GNU General Public License for more details.
ali@3
    13
 *
ali@3
    14
 * You should have received a copy of the GNU General Public License along
ali@3
    15
 * with this program; if not, write to the Free Software Foundation, Inc.,
ali@3
    16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ali@3
    17
 */
ali@3
    18
ali@3
    19
#include <stdlib.h>
ali@13
    20
#include <stdio.h>
ali@3
    21
#include <lua.h>
ali@3
    22
#include "config.h"
ali@3
    23
#include "plover/plover.h"
ali@3
    24
#include "whelk/whelk.h"
ali@3
    25
ali@3
    26
LUALIB_API int luaopen_posix(lua_State *L);
ali@3
    27
ali@3
    28
void update(const char *argv0)
ali@3
    29
{
ali@24
    30
    char *path;
ali@24
    31
    gchar *s,*prefix;
ali@13
    32
    int ch;
ali@3
    33
    struct comps *comps;
ali@24
    34
    GError *error=NULL;
ali@3
    35
    path=plover_get_program_directory(argv0);
ali@24
    36
    s=g_strconcat(path,"/repodata/comps.xml",NULL);
ali@3
    37
    comps=plover_comps_new_from_file(s);
ali@3
    38
    if (!comps)
ali@3
    39
    {
ali@3
    40
	perror(s);
ali@3
    41
	exit(1);
ali@3
    42
    }
ali@24
    43
    g_free(s);
ali@3
    44
    prefix=plover_default_prefix_for_vendor(comps->vendor);
ali@13
    45
    if (!plover_installed_files_match_prefix(prefix))
ali@13
    46
    {
ali@13
    47
	printf("The existing installation is not under %s\n"
ali@13
    48
	  "In order to continue, all the existing packages must be removed.\n"
ali@13
    49
	  "Do you want to remove all existing packages? ",prefix);
ali@13
    50
	ch=getchar();
ali@13
    51
	if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
ali@13
    52
	    exit(1);
ali@13
    53
	while(ch!='\n' && ch!=EOF)
ali@13
    54
	    ch=getchar();
ali@24
    55
	if (plover_remove(NULL,&error))
ali@24
    56
	{
ali@24
    57
	    fprintf(stderr,"%s\n",error->message);
ali@24
    58
	    g_error_free(error);
ali@24
    59
	    exit(1);
ali@24
    60
	}
ali@13
    61
    }
ali@3
    62
    plover_comps_free(comps);
ali@24
    63
    if (!plover_update(path,prefix,NULL,&error))
ali@24
    64
    {
ali@24
    65
	fprintf(stderr,"%s\n",error->message);
ali@24
    66
	g_error_free(error);
ali@24
    67
	exit(1);
ali@24
    68
    }
ali@24
    69
    g_free(prefix);
ali@3
    70
    free(path);
ali@3
    71
}
ali@3
    72
ali@3
    73
int main(int argc,char **argv)
ali@3
    74
{
ali@31
    75
    plover_exception_handler_init();
ali@38
    76
    razor_set_lua_loader("posix",(void (*)())luaopen_posix);
ali@38
    77
    razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
ali@3
    78
    update(argv[0]);
ali@13
    79
    exit(0);
ali@3
    80
}