aboutsummaryrefslogtreecommitdiff
path: root/src/spm.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-02-28 01:06:35 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-02-28 01:06:35 -0500
commit511deab4f22a6c25f33cce1e206b656d520ab7e6 (patch)
tree669591ef38f61f0dc842e96b86aa1533f274269f /src/spm.c
parentb6587f1d905e308cab713b1d5545e4667c80d6e4 (diff)
downloadspmc-511deab4f22a6c25f33cce1e206b656d520ab7e6.tar.gz
Improvements:
* Refactored a few function names * Can read package metadata * Can delete packages * Can download! and install packages at the same time * Can prompt the user before proceeding
Diffstat (limited to 'src/spm.c')
-rw-r--r--src/spm.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/spm.c b/src/spm.c
index 8444990..7b81280 100644
--- a/src/spm.c
+++ b/src/spm.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include "spm.h"
+int RUNTIME_REMOVE = 0;
int RUNTIME_INSTALL = 0;
int RUNTIME_ROOTDIR = 0;
int RUNTIME_LIST = 0;
@@ -131,6 +132,22 @@ int main(int argc, char *argv[], char *arge[]) {
strcpy(rootdir, arg_next);
i++;
}
+ else if (strcmp(arg, "-R") == 0 || strcmp(arg, "--remove") == 0) {
+ RUNTIME_REMOVE = 1;
+ for (int p = 0; i < argc; p++) {
+ i++;
+ if (startswith(argv[i], "-") == 0 || startswith(argv[i], "--") == 0) {
+ i--;
+ break;
+ }
+ if ((argc - i) == 0) {
+ fprintf(stderr, "-R|--remove requires at least one package\n");
+ usage(program_name);
+ exit(1);
+ }
+ strlist_append(packages, argv[i]);
+ }
+ }
else if (strcmp(arg, "-I") == 0 || strcmp(arg, "--install") == 0) {
RUNTIME_INSTALL = 1;
for (int p = 0; i < argc; p++) {
@@ -165,10 +182,14 @@ int main(int argc, char *argv[], char *arge[]) {
show_global_config();
}
- if (RUNTIME_ROOTDIR && !RUNTIME_INSTALL) {
+ if (!RUNTIME_ROOTDIR && RUNTIME_INSTALL) {
fprintf(stderr, "-r|--root requires -I|--install\n");
usage(program_name);
exit(1);
+ } else if (!RUNTIME_ROOTDIR && RUNTIME_REMOVE) {
+ fprintf(stderr, "-r|--root requires -R|--remove\n");
+ usage(program_name);
+ exit(1);
}
if (isempty(rootdir)) {
@@ -190,9 +211,21 @@ int main(int argc, char *argv[], char *arge[]) {
runtime_set(rt, "SPM_LOCALSTATE", rootfs->localstatedir);
runtime_apply(rt);
+ if (RUNTIME_REMOVE) {
+ int status_remove = 0;
+ if ((status_remove = spm_do_purge(rootfs, packages)) == -1) {
+ exit(1);
+ }
+ else if (status_remove == -2) {
+ // user said no when asked to proceed
+ exit(2);
+ }
+
+ }
+
if (RUNTIME_INSTALL) {
int status_install = 0;
- if ((status_install = do_install(rootfs, mf, packages)) == -1) {
+ if ((status_install = spm_do_install(rootfs, mf, packages)) == -1) {
// failed to create temporary destination root
exit(1);
}