-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppac.c
123 lines (109 loc) · 2.93 KB
/
ppac.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Utils.h"
int main(int argc, char *argv[])
{
configurationSetup();
if (argc == 1){
fullUpgrade();
return 0;
}
if (argc > 2)
{
printf("Error: ppac only accepts one agument.\n");
return 1;
}
printf("Initilizing...\n");
syncDatabase();
initilizeAll();
char *pkg = (char *)malloc(strlen(argv[1]));
strcpy(pkg, argv[1]);
printf("Checking package...\n");
if(!isInDatabase(pkg)){
printf("%s was not found to be a valid package.\nDoing Nothing.\n", pkg);
return 1;
}
if (isPackageInstalled(pkg) && !isOutdated(pkg))
{
printf("\n%s is already installed and up-to-date.\nDoing nothing.\n\n", pkg);
return 1;
}
bool explicitPkg = TRUE;
if(isPackageInstalled(pkg)){
explicitPkg = isExplicit(trimString(pkg));
}
headList = createPackage(pkg, explicitPkg);
if(headList->isExplicit){
explicitWordLen = explicitWordLen + strlen(headList->pkg);
}
else{
dependsWordLen = dependsWordLen + strlen(headList->pkg);
}
Package *whereAmI = headList;
while(whereAmI != NULL){
updateDependencyPackages(whereAmI->pkg);
whereAmI = whereAmI->next;
}
char *pDepends = (char *)malloc(dependsWordLen + dependsWordCt + 1);
char *pExplicit = (char *)malloc(explicitWordLen + explicitWordCt + 1);
pDepends[0] = '\0';
pExplicit[0] = '\0';
whereAmI = headList;
while (whereAmI != NULL)
{
if(!whereAmI->isExplicit){
strcat(pDepends, whereAmI->pkg);
strcat(pDepends, " ");
}
else{
strcat(pExplicit, whereAmI->pkg);
strcat(pExplicit, " ");
}
whereAmI = whereAmI->next;
}
printf("\nThe following dependencies will be updated:\n%s\n", pDepends);
printf("\nThe following packages will be updated/installed:\n%s\n\n", pExplicit);
char response;
bool goAhead = FALSE;
while(TRUE){
printf("Proceed with installation? [Y/n]");
response = getchar();
if(response == 110 || response == 78){
break;
}
if(response == 121 || response == 89 || response == 10){
goAhead = TRUE;
break;
}
printf("\nInvalid response.\n");
}
if(goAhead){
unsigned int size;
if(strlen(pDepends) > strlen(pExplicit)){
size = strlen(pDepends);
}
else{
size = strlen(pExplicit);
}
char *cmd = (char *)malloc(size + 100);
if(strlen(pDepends) != 0){
cmd[0] = '\0';
strcat(cmd, PHS);
strcat(cmd, "--asdeps --needed --noconfirm ");
strcat(cmd, pDepends);
system(cmd);
}
if(strlen(pExplicit) != 0){
cmd[0] = '\0';
strcat(cmd, PHS);
strcat(cmd, "--needed --noconfirm ");
strcat(cmd, pExplicit);
system(cmd);
}
free(cmd);
}
free(pDepends);
free(pExplicit);
return 0;
}