|
ali@0
|
1 |
/*
|
|
ali@13
|
2 |
* Copyright (C) 2009, 2011 J. Ali Harlow <ali@juiblex.co.uk>
|
|
ali@0
|
3 |
*
|
|
ali@0
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
ali@0
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
ali@0
|
6 |
* the Free Software Foundation; either version 2 of the License, or
|
|
ali@0
|
7 |
* (at your option) any later version.
|
|
ali@0
|
8 |
*
|
|
ali@0
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
ali@0
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
ali@0
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
ali@0
|
12 |
* GNU General Public License for more details.
|
|
ali@0
|
13 |
*
|
|
ali@0
|
14 |
* You should have received a copy of the GNU General Public License along
|
|
ali@0
|
15 |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
ali@0
|
16 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
ali@0
|
17 |
*/
|
|
ali@0
|
18 |
|
|
ali@0
|
19 |
#include <stdlib.h>
|
|
ali@0
|
20 |
#include <stdio.h>
|
|
ali@0
|
21 |
#include <string.h>
|
|
ali@0
|
22 |
#include <limits.h>
|
|
ali@0
|
23 |
#ifdef WIN32
|
|
ali@0
|
24 |
#include <windows.h>
|
|
ali@0
|
25 |
#include <shlobj.h>
|
|
ali@0
|
26 |
#endif
|
|
ali@0
|
27 |
#include <lua.h>
|
|
ali@0
|
28 |
#include "config.h"
|
|
ali@0
|
29 |
#include "plover/plover.h"
|
|
ali@0
|
30 |
#include "whelk/whelk.h"
|
|
ali@0
|
31 |
|
|
ali@0
|
32 |
LUALIB_API int luaopen_posix(lua_State *L);
|
|
ali@0
|
33 |
|
|
ali@3
|
34 |
void setup(const char *argv0)
|
|
ali@0
|
35 |
{
|
|
ali@24
|
36 |
char *path;
|
|
ali@24
|
37 |
gchar *s,*prefix;
|
|
ali@13
|
38 |
int ch,changed;
|
|
ali@0
|
39 |
struct comps *comps;
|
|
ali@0
|
40 |
struct comps_group *group;
|
|
ali@0
|
41 |
struct comps_requirement *pkg;
|
|
ali@24
|
42 |
struct plover_vector *packages=NULL;
|
|
ali@24
|
43 |
GError *error=NULL;
|
|
ali@3
|
44 |
path=plover_get_program_directory(argv0);
|
|
ali@24
|
45 |
s=g_strconcat(path,"/repodata/comps.xml",NULL);
|
|
ali@0
|
46 |
comps=plover_comps_new_from_file(s);
|
|
ali@0
|
47 |
if (!comps)
|
|
ali@0
|
48 |
{
|
|
ali@0
|
49 |
perror(s);
|
|
ali@0
|
50 |
exit(1);
|
|
ali@0
|
51 |
}
|
|
ali@24
|
52 |
g_free(s);
|
|
ali@3
|
53 |
prefix=plover_default_prefix_for_vendor(comps->vendor);
|
|
ali@13
|
54 |
if (!plover_installed_files_match_prefix(prefix))
|
|
ali@13
|
55 |
{
|
|
ali@13
|
56 |
printf("The existing installation is not under %s\n"
|
|
ali@13
|
57 |
"In order to continue, all the existing packages must be removed.\n"
|
|
ali@13
|
58 |
"Do you want to remove all existing packages? ",prefix);
|
|
ali@13
|
59 |
ch=getchar();
|
|
ali@13
|
60 |
if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
|
|
ali@13
|
61 |
exit(1);
|
|
ali@13
|
62 |
while(ch!='\n' && ch!=EOF)
|
|
ali@13
|
63 |
ch=getchar();
|
|
ali@24
|
64 |
if (plover_remove(NULL,&error))
|
|
ali@24
|
65 |
{
|
|
ali@24
|
66 |
fprintf(stderr,"%s\n",error->message);
|
|
ali@24
|
67 |
g_error_free(error);
|
|
ali@24
|
68 |
exit(1);
|
|
ali@24
|
69 |
}
|
|
ali@13
|
70 |
}
|
|
ali@0
|
71 |
group=plover_comps_lookup_group(comps,"base");
|
|
ali@0
|
72 |
if (!group)
|
|
ali@0
|
73 |
{
|
|
ali@0
|
74 |
fprintf(stderr,"No base group found in comps.xml\n");
|
|
ali@0
|
75 |
exit(1);
|
|
ali@0
|
76 |
}
|
|
ali@24
|
77 |
packages=plover_vector_new();
|
|
ali@0
|
78 |
do
|
|
ali@0
|
79 |
{
|
|
ali@0
|
80 |
changed=0;
|
|
ali@0
|
81 |
for(pkg=group->packages;pkg;pkg=pkg->next)
|
|
ali@0
|
82 |
{
|
|
ali@24
|
83 |
if (plover_vector_contains(packages,pkg->name))
|
|
ali@0
|
84 |
continue;
|
|
ali@0
|
85 |
if (pkg->type==COMPS_REQUIREMENT_DEFAULT ||
|
|
ali@0
|
86 |
pkg->type==COMPS_REQUIREMENT_MANDATORY ||
|
|
ali@0
|
87 |
pkg->type==COMPS_REQUIREMENT_CONDITIONAL &&
|
|
ali@24
|
88 |
plover_vector_contains(packages,pkg->requires))
|
|
ali@0
|
89 |
{
|
|
ali@0
|
90 |
changed++;
|
|
ali@24
|
91 |
plover_vector_append(packages,pkg->name);
|
|
ali@0
|
92 |
}
|
|
ali@0
|
93 |
}
|
|
ali@0
|
94 |
} while(changed);
|
|
ali@3
|
95 |
plover_comps_free(comps);
|
|
ali@0
|
96 |
if (!packages->len)
|
|
ali@0
|
97 |
{
|
|
ali@0
|
98 |
fprintf(stderr,"No packages to install\n");
|
|
ali@0
|
99 |
exit(1);
|
|
ali@0
|
100 |
}
|
|
ali@24
|
101 |
if (!plover_install(path,prefix,packages->strings,&error))
|
|
ali@24
|
102 |
{
|
|
ali@24
|
103 |
fprintf(stderr,"%s\n",error->message);
|
|
ali@24
|
104 |
g_error_free(error);
|
|
ali@24
|
105 |
exit(1);
|
|
ali@24
|
106 |
}
|
|
ali@24
|
107 |
plover_vector_free(packages);
|
|
ali@24
|
108 |
g_free(prefix);
|
|
ali@3
|
109 |
free(path);
|
|
ali@0
|
110 |
}
|
|
ali@0
|
111 |
|
|
ali@0
|
112 |
int main(int argc,char **argv)
|
|
ali@0
|
113 |
{
|
|
ali@24
|
114 |
GError *error=NULL;
|
|
ali@0
|
115 |
razor_set_lua_loader("posix",luaopen_posix);
|
|
ali@0
|
116 |
razor_set_lua_loader("whelk",luaopen_whelk);
|
|
ali@0
|
117 |
if (argc>1 && !strcmp(argv[1],"-u"))
|
|
ali@24
|
118 |
{
|
|
ali@24
|
119 |
if (!plover_remove(NULL,&error))
|
|
ali@24
|
120 |
{
|
|
ali@24
|
121 |
fprintf(stderr,"%s\n",error->message);
|
|
ali@24
|
122 |
g_error_free(error);
|
|
ali@24
|
123 |
exit(1);
|
|
ali@24
|
124 |
}
|
|
ali@24
|
125 |
}
|
|
ali@0
|
126 |
else
|
|
ali@3
|
127 |
setup(argv[0]);
|
|
ali@13
|
128 |
exit(0);
|
|
ali@0
|
129 |
}
|