This repository was archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuspp.c
More file actions
109 lines (90 loc) · 2.52 KB
/
uspp.c
File metadata and controls
109 lines (90 loc) · 2.52 KB
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
/*The main package handling file.
*
*/
#include <unistd.h>
#include <stdlib.h>
#include "fm.h"
#include "dephandle.h"
#include "uspp.h"
#include "config.h"
/**
* Given a package name [package], installs the package file (and, if necessary,
* downloads) located in /var/uspm/storage
*
* @param package the package
*/
int install_package_file(char *package) {
char *filename = concat(package, ".uspm");
if (access(filename,F_OK) != -1) {
char *command;
if (access(package, F_OK) == -1) {
command = concat("tar -xf ", filename);
system(command);
}
if (check_for_dependencies(package) != 0) {
printf("Installation failed\n");
return 1;
}
command = concat("sh ./", package);
command = concat(command, "/PACKAGECODE install");
system(command);
command = concat("rm -rf ./", package);
command = concat(command, "/files");
system(command);
free(command);
remove(filename);
return 0;
} else {
printf("Failed to extract package file");
return 1;
}
}
/**
* Given a package name [package], installs the package file (and, if necessary,
* downloads) located in /var/uspm/storage
*
* @param package the package
*/
int install_package(char *package) {
char *filename = concat(package, ".uspm");
if (access(filename,F_OK) == -1) {
cJSON *config = load_file("config.json");
if (download_package(cJSON_GetObjectItem(config, "mirror")->valuestring, package) != 0) return 1;
}
if (install_package_file(package) == 0) {
char *file = concat("./", package);
file = concat(file, "/PACKAGEDATA");
cJSON *packagedata = load_file(file);
free(file);
add_to_packages(package, packagedata);
return 0;
} else {
return 1;
}
}
/**
* Given a package name [package], uninstalled the package
*
* @param package the package
*/
int uninstall_package(char *package) {
char *command = concat("sh ./", package);
command = concat(command, "/PACKAGECODE uninstall");
system(command);
free(command);
remove_from_packages(package);
return 0;
}
/**
* Checks if this is the first run
*
* If true, creates the necessary files for running the USPM software
*
* @return int 0 if first run 1 if not first run
*/
int check_if_first_run() {
int response = 0;
if (check_config_file() != 0) response = 1;
if (check_packages_file() != 0) response = 1;
return response;
}