app-manager --update and --setup are documented to take URIs but they are not treated as such
2 * Copyright (C) 2009, 2011, 2016 J. Ali Harlow <ali@juiblex.co.uk>
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.
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.
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.
24 #include "plover/plover.h"
25 #include "whelk/whelk.h"
27 LUALIB_API int luaopen_posix(lua_State *L);
29 void update(const char *argv0)
31 char *yum_uri,*local_database,*active_database,*alternate_database;
32 gchar *s,*prefix,*distribution,*vendor_prefix;
36 s=plover_get_program(argv0);
37 yum_uri=razor_path_to_uri(s);
39 s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
40 comps=plover_comps_new_from_uri(s,&error);
42 if (g_error_matches(error,PLOVER_RAZOR_ERROR,
43 RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE))
45 g_clear_error(&error);
47 s=plover_get_program_directory(argv0);
48 yum_uri=razor_path_to_uri(s);
50 s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
51 comps=plover_comps_new_from_uri(s,&error);
55 fprintf(stderr,"%s\n",error->message);
59 prefix=plover_comps_get_default_prefix(comps);
62 s=g_strconcat(prefix,"/var/lib/razor",NULL);
63 local_database=razor_path_to_uri(s);
68 switch(comps->database)
70 case COMPS_DATABASE_DISTRIBUTION_LOCAL:
71 active_database=local_database;
72 alternate_database=NULL;
74 case COMPS_DATABASE_GLOBAL:
76 alternate_database=local_database;
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);
86 razor_set_database_uri(alternate_database);
87 if (plover_installed_files_match_prefix(vendor_prefix)==1)
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? ",
95 if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
97 while(ch!='\n' && ch!=EOF)
99 if (plover_remove(NULL,&error))
101 fprintf(stderr,"%s\n",error->message);
106 g_free(vendor_prefix);
108 razor_set_database_uri(active_database);
109 if (prefix && !plover_installed_files_match_prefix(prefix))
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);
115 if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
117 while(ch!='\n' && ch!=EOF)
119 if (plover_remove(NULL,&error))
121 fprintf(stderr,"%s\n",error->message);
126 free(local_database);
127 plover_comps_free(comps);
128 if (!plover_update_uri(yum_uri,prefix,NULL,&error))
130 fprintf(stderr,"%s\n",error->message);
138 int main(int argc,char **argv)
140 plover_exception_handler_init();
141 razor_set_lua_loader("posix",(void (*)())luaopen_posix);
142 razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);