aboutsummaryrefslogtreecommitdiff
path: root/mbpk.c
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-09-17 21:57:53 +1200
committerArslaan Pathan <[email protected]>2026-09-17 21:57:53 +1200
commitacbf9d6fca288d00973f0fa6dae417c00c46c488 (patch)
treed0e10c8f3e90a66592bc1fc1b0015240430ed684 /mbpk.c
parent7c85f80fc15c2a1bbf722e1094d246c1c9c63005 (diff)
downloadmbpk-acbf9d6fca288d00973f0fa6dae417c00c46c488.tar.xz
mbpk-acbf9d6fca288d00973f0fa6dae417c00c46c488.zip
pkg installing logicHEADmain
Diffstat (limited to 'mbpk.c')
-rw-r--r--mbpk.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/mbpk.c b/mbpk.c
index 1123b39..d29300b 100644
--- a/mbpk.c
+++ b/mbpk.c
@@ -1,3 +1,4 @@
+#define _POSIX_C_SOURCE 200809L
#include <string.h>
#include <stdio.h>
#include <unistd.h>
@@ -6,6 +7,7 @@
#include <stdlib.h>
#include <limits.h>
+/* random macro to log function names because why not */
#define LOGFV(s) printf("[verbose] calling %s\n", s);
void usage(void) {
@@ -17,6 +19,8 @@ int main(int argc, char **argv) {
/* parse arguments */
int verbose = 0;
int update_repos = 0;
+ int install_pkg = 0;
+ int remove_pkg = 0;
const char *pkgname = NULL;
if (argc < 2) {
@@ -25,10 +29,11 @@ int main(int argc, char **argv) {
}
int opt;
- while ((opt = getopt(argc, argv, "Si:vh")) != -1) {
+ while ((opt = getopt(argc, argv, "Si:r:vh")) != -1) {
switch (opt) {
case 'S': update_repos = 1; break;
- case 'i': pkgname = optarg; break;
+ case 'i': pkgname = optarg; install_pkg = 1; break;
+ case 'r': pkgname = optarg; remove_pkg = 1; break;
case 'v': verbose = 1; break;
case 'h': usage(); return 0;
default: usage(); return 1;
@@ -57,7 +62,10 @@ int main(int argc, char **argv) {
snprintf(x.confdir, sizeof(x.confdir), "%s/.local/mbpk/conf.d", home);
if (verbose) printf("[verbose] setting x.sysconfdir to $home/.local/mbpk/sysconf.d\n");
snprintf(x.sysconfdir, sizeof(x.sysconfdir), "%s/.local/mbpk/sysconf.d", home);
- if (verbose) x.flags |= XBPS_FLAG_VERBOSE;
+ if (verbose) {
+ x.flags |= XBPS_FLAG_VERBOSE;
+ x.flags |= XBPS_FLAG_DEBUG;
+ }
if (verbose) LOGFV("xbps_init()");
int r = xbps_init(&x);
@@ -78,7 +86,45 @@ int main(int argc, char **argv) {
printf("[*] done!\n");
}
if (pkgname) {
+ if (install_pkg) {
+ if (verbose) LOGFV("xbps_rpool_get_pkg()");
+ xbps_dictionary_t pkgd = xbps_rpool_get_pkg(&x, pkgname);
+ if (pkgd == NULL) {
+ fprintf(stderr, "ERROR: package %s not found in repository pool :c\n", pkgname);
+ return 1;
+ }
+ if (verbose) LOGFV("xbps_object_release()");
+ xbps_object_release(pkgd);
+
+ printf("[*] adding package %s to transaction...\n", pkgname);
+ if (verbose) LOGFV("xbps_transaction_install_pkg()");
+ r = xbps_transaction_install_pkg(&x, pkgname, false);
+ if (r != 0) {
+ fprintf(stderr, "failed to add %s to transaction: %s\n", pkgname, strerror(r));
+ return r;
+ }
+
+ printf("[*] preparing transaction...\n");
+ if (verbose) LOGFV("xbps_transaction_prepare()");
+ r = xbps_transaction_prepare(&x);
+ if (r != 0) {
+ fprintf(stderr, "failed to prepare transaction: %s", strerror(r));
+ return r;
+ }
+
+ printf("[*] committing...\n");
+ if (verbose) LOGFV("xbps_transaction_commit()");
+ r = xbps_transaction_commit(&x);
+ if (r != 0) {
+ fprintf(stderr, "failed to commit transaction: %s", strerror(r));
+ return r;
+ }
+ printf("[*] done!");
+ }
+ if (remove_pkg) {
+
+ }
}
return 0;