1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/update/updatez.c Thu Jul 07 19:03:54 2016 +0100
1.3 @@ -0,0 +1,80 @@
1.4 +/*
1.5 + * Copyright (C) 2009, 2011 J. Ali Harlow <ali@juiblex.co.uk>
1.6 + *
1.7 + * This program is free software; you can redistribute it and/or modify
1.8 + * it under the terms of the GNU General Public License as published by
1.9 + * the Free Software Foundation; either version 2 of the License, or
1.10 + * (at your option) any later version.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License along
1.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
1.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1.20 + */
1.21 +
1.22 +#include <stdlib.h>
1.23 +#include <stdio.h>
1.24 +#include <lua.h>
1.25 +#include "config.h"
1.26 +#include "plover/plover.h"
1.27 +#include "whelk/whelk.h"
1.28 +
1.29 +LUALIB_API int luaopen_posix(lua_State *L);
1.30 +
1.31 +void update(const char *argv0)
1.32 +{
1.33 + char *path;
1.34 + gchar *s,*prefix;
1.35 + int ch;
1.36 + struct comps *comps;
1.37 + GError *error=NULL;
1.38 + path=plover_get_program_directory(argv0);
1.39 + s=g_strconcat(path,"/repodata/comps.xml",NULL);
1.40 + comps=plover_comps_new_from_file(s);
1.41 + if (!comps)
1.42 + {
1.43 + perror(s);
1.44 + exit(1);
1.45 + }
1.46 + g_free(s);
1.47 + prefix=plover_default_prefix_for_vendor(comps->vendor);
1.48 + if (!plover_installed_files_match_prefix(prefix))
1.49 + {
1.50 + printf("The existing installation is not under %s\n"
1.51 + "In order to continue, all the existing packages must be removed.\n"
1.52 + "Do you want to remove all existing packages? ",prefix);
1.53 + ch=getchar();
1.54 + if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
1.55 + exit(1);
1.56 + while(ch!='\n' && ch!=EOF)
1.57 + ch=getchar();
1.58 + if (plover_remove(NULL,&error))
1.59 + {
1.60 + fprintf(stderr,"%s\n",error->message);
1.61 + g_error_free(error);
1.62 + exit(1);
1.63 + }
1.64 + }
1.65 + plover_comps_free(comps);
1.66 + if (!plover_update(path,prefix,NULL,&error))
1.67 + {
1.68 + fprintf(stderr,"%s\n",error->message);
1.69 + g_error_free(error);
1.70 + exit(1);
1.71 + }
1.72 + g_free(prefix);
1.73 + free(path);
1.74 +}
1.75 +
1.76 +int main(int argc,char **argv)
1.77 +{
1.78 + plover_exception_handler_init();
1.79 + razor_set_lua_loader("posix",(void (*)())luaopen_posix);
1.80 + razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
1.81 + update(argv[0]);
1.82 + exit(0);
1.83 +}