summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrafa_99 <rafa99@protonmail.com>2020-09-23 11:43:56 +0100
committerrafa_99 <rafa99@protonmail.com>2020-09-23 11:43:56 +0100
commit901450fb704d263b04c2b2c3ef22ea923b6e3f87 (patch)
tree5853aafb359647a20af1d0357ee8a0ea6039cce1
parente5b58fff841e419c8ebfda14640c106ec4898b0a (diff)
Added Some Actions
-rw-r--r--Makefile2
-rw-r--r--actions.c106
-rw-r--r--actions.h14
-rw-r--r--pkg.c2
-rw-r--r--utils.h2
5 files changed, 108 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 1ece297..a9daa4b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
all: clean
- gcc -o pkg pkg.c utils.c
+ gcc -o pkg pkg.c utils.c actions.c
clean:
rm -rf pkg
diff --git a/actions.c b/actions.c
index 661587d..1ea76ad 100644
--- a/actions.c
+++ b/actions.c
@@ -1,12 +1,14 @@
+#include <stdlib.h>
+#include <string.h>
#include "actions.h"
-void actions(char action)
+void actions(char action, char* packages)
{
int os = detectOsType();
switch (action)
{
case 'c':
- clean(os);
+ cleanPackages(os);
break;
case 'h':
@@ -14,23 +16,23 @@ void actions(char action)
break;
case 'i':
- installPackage(os);
+ installPackages(os, packages);
break;
case 'q':
- queryPackage(os);
+ queryPackages(os);
break;
case 'r':
- removePackage(os);
+ removePackages(os, packages);
break;
case 's':
- searchPackage(os);
+ searchPackages(os, packages);
break;
case 'u':
- updatePackage(os);
+ updatePackages(os);
break;
default:
@@ -38,3 +40,93 @@ void actions(char action)
help();
}
}
+
+void cleanPackages(int os)
+{
+ switch(os)
+ {
+ case pacman:
+ system("pacman -Rns \"$(pacman -Qtdq)\" || pacman -Scc");
+ break;
+
+ case apt:
+ system("apt autoremove --purge || apt clean");
+ break;
+
+ case emerge:
+ system("emerge -caq");
+ break;
+
+ case xbps:
+ system("xbps-remove -ROo");
+ }
+}
+
+void help()
+{
+ printf("PKG Options:\n"
+ "c - removes orphans and cleans the package cache\n"
+ "h - display this message\n"
+ "i - installs selected packages\n"
+ "q - display installed packages\n"
+ "r - remove a selected package\n"
+ "s - look up for a package in the available repositories\n"
+ "u - updates repos and packages\n\n");
+}
+
+void installPackages(int os, char *packages)
+{
+ if ( strlen(packages) > 0 )
+ {
+ char* command = (char *) calloc(strlen(packages) + 80, sizeof(char));
+ switch(os)
+ {
+ case pacman:
+ strcpy(command, "pacman -S ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ case apt:
+ strcpy(command, "apt install ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ case emerge:
+ strcpy(command, "emerge -aq ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ case xbps:
+ strcpy(command, "xbps-install -S ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ }
+ }
+}
+
+void queryPackages(int os)
+{
+
+}
+
+void removePackages(int os, char *packages)
+{
+
+}
+
+void searchPackages(int os, char *packages)
+{
+
+}
+
+void updatePackages(int os)
+{
+
+}
diff --git a/actions.h b/actions.h
index 7f25490..d7991a6 100644
--- a/actions.h
+++ b/actions.h
@@ -1,10 +1,10 @@
#include "utils.h"
-void actions(char action);
-void clean(int os);
+void actions(char action, char* packages);
+void cleanPackages(int os);
void help();
-void installPackage(int os);
-void queryPackage(int os);
-void removePackage(int os);
-void searchPackage(int os);
-void updatePackage(int os);
+void installPackages(int os, char* packages);
+void queryPackages(int os);
+void removePackages(int os, char* packages);
+void searchPackages(int os, char* packages);
+void updatePackages(int os);
diff --git a/pkg.c b/pkg.c
index 3b1698c..edea99c 100644
--- a/pkg.c
+++ b/pkg.c
@@ -1,4 +1,4 @@
-#include "utils.h"
+#include <stdlib.h>
/*
**********************************************************
diff --git a/utils.h b/utils.h
index 7965542..e4ddde5 100644
--- a/utils.h
+++ b/utils.h
@@ -1,6 +1,4 @@
#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
#define ERROR -1