diff options
author | rafa_99 <rafa99@protonmail.com> | 2020-09-23 11:43:56 +0100 |
---|---|---|
committer | rafa_99 <rafa99@protonmail.com> | 2020-09-23 11:43:56 +0100 |
commit | 901450fb704d263b04c2b2c3ef22ea923b6e3f87 (patch) | |
tree | 5853aafb359647a20af1d0357ee8a0ea6039cce1 | |
parent | e5b58fff841e419c8ebfda14640c106ec4898b0a (diff) |
Added Some Actions
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | actions.c | 106 | ||||
-rw-r--r-- | actions.h | 14 | ||||
-rw-r--r-- | pkg.c | 2 | ||||
-rw-r--r-- | utils.h | 2 |
5 files changed, 108 insertions, 18 deletions
@@ -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 @@ -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) +{ + +} @@ -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); @@ -1,4 +1,4 @@ -#include "utils.h" +#include <stdlib.h> /* ********************************************************** @@ -1,6 +1,4 @@ #include <stdio.h> -#include <stdlib.h> -#include <unistd.h> #define ERROR -1 |