diff options
Diffstat (limited to 'actions.c')
-rw-r--r-- | actions.c | 122 |
1 files changed, 115 insertions, 7 deletions
@@ -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"); + } } |