summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrafa_99 <rafa99@protonmail.com>2020-09-23 12:31:49 +0100
committerrafa_99 <rafa99@protonmail.com>2020-09-23 12:31:49 +0100
commit60dd645963042139c9c61d588ea81fb54ce59b6a (patch)
tree740507d336cd932c14bf2c801a3c42fc16ff4353
parent901450fb704d263b04c2b2c3ef22ea923b6e3f87 (diff)
Finished Base Code
-rw-r--r--actions.c122
-rw-r--r--pkg.c2
2 files changed, 117 insertions, 7 deletions
diff --git a/actions.c b/actions.c
index 1ea76ad..3753a35 100644
--- a/actions.c
+++ b/actions.c
@@ -65,13 +65,13 @@ void cleanPackages(int os)
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");
+ "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)
@@ -107,26 +107,134 @@ void installPackages(int os, char *packages)
strcat(command, packages);
system(command);
free(command);
+ break;
+
+ default:
+ free(command);
}
}
}
void queryPackages(int os)
{
+ switch(os)
+ {
+ case pacman:
+ system("pacman -Qs");
+ break;
+
+ case apt:
+ system("apt list --installed");
+ break;
+ case emerge:
+ system("cd /var/db/pkg/ && ls -d */* | sed 's:\\/$::'");
+ break;
+
+ case xbps:
+ system("xbps-query -l");
+ }
}
void removePackages(int os, char *packages)
{
+ if ( strlen(packages) > 0 )
+ {
+ char* command = (char *) calloc(strlen(packages) + 80, sizeof(char));
+ switch(os)
+ {
+ case pacman:
+ strcpy(command, "pacman -Rnsc ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ case apt:
+ strcpy(command, "apt autoremove --purge ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ case emerge:
+ strcpy(command, "emerge -caq ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+ case xbps:
+ strcpy(command, "xbps-remove -ROo ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ default:
+ free(command);
+ }
+ }
}
void searchPackages(int os, char *packages)
{
+ if ( strlen(packages) > 0 )
+ {
+ char* command = (char *) calloc(strlen(packages) + 80, sizeof(char));
+ switch(os)
+ {
+ case pacman:
+ strcpy(command, "pacman -Ss ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ case apt:
+ strcpy(command, "apt search ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ case emerge:
+ strcpy(command, "emerge -s ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+ case xbps:
+ strcpy(command, "xbps-query -Rs ");
+ strcat(command, packages);
+ system(command);
+ free(command);
+ break;
+
+ default:
+ free(command);
+ }
+ }
}
void updatePackages(int os)
{
+ switch(os)
+ {
+ case pacman:
+ system("pacman -Syyuu");
+ break;
+
+ case apt:
+ system("apt update && apt upgrade -y");
+ break;
+ case emerge:
+ system("emerge-webrsync && emerge -uaqDU --keep-going --with-bdeps=y --newuse @world");
+ break;
+
+ case xbps:
+ system("xbps-install -Su");
+ }
}
diff --git a/pkg.c b/pkg.c
index edea99c..a16e71b 100644
--- a/pkg.c
+++ b/pkg.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include "actions.h"
/*
**********************************************************
@@ -9,6 +10,7 @@
int main(int argc, char **argv)
{
char* arg = stringedArgument(argc, argv);
+ actions(*(argv[1]), arg);
free(arg);
return 0;
}