diff options
| author | Arslaan Pathan <[email protected]> | 2026-09-17 21:01:59 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-09-17 21:01:59 +1200 |
| commit | 7c85f80fc15c2a1bbf722e1094d246c1c9c63005 (patch) | |
| tree | 1f0398d2c67fde8c07f4c9992c487d912068c0a2 /mbpk.c | |
| parent | 1c9c9368d8bcb53ed43e912328c47abf99cf113e (diff) | |
| download | mbpk-7c85f80fc15c2a1bbf722e1094d246c1c9c63005.tar.xz mbpk-7c85f80fc15c2a1bbf722e1094d246c1c9c63005.zip | |
handle flags and update repository pool
Diffstat (limited to 'mbpk.c')
| -rw-r--r-- | mbpk.c | 68 |
1 files changed, 60 insertions, 8 deletions
@@ -6,28 +6,80 @@ #include <stdlib.h> #include <limits.h> -int main(void) { - /* init xbps stuff */ - struct xbps_handle x; +#define LOGFV(s) printf("[verbose] calling %s\n", s); + +void usage(void) { + printf("Usage: mbpk [OPTIONS]\n\n"); + printf("TODO: Add OPTIONS list here"); +} + +int main(int argc, char **argv) { + /* parse arguments */ + int verbose = 0; + int update_repos = 0; + const char *pkgname = NULL; + + if (argc < 2) { + usage(); + return 1; + } + int opt; + while ((opt = getopt(argc, argv, "Si:vh")) != -1) { + switch (opt) { + case 'S': update_repos = 1; break; + case 'i': pkgname = optarg; break; + case 'v': verbose = 1; break; + case 'h': usage(); return 0; + default: usage(); return 1; + } + } + + /* xbps init stuff */ + struct xbps_handle x; memset(&x, 0, sizeof(x)); - const char* home = getenv("HOME"); + + const char *home = getenv("HOME"); if (home == NULL) { struct passwd *pw = getpwuid(getuid()); - if (pw != NULL) { - home = pw->pw_dir; - } + if (pw != NULL) home = pw->pw_dir; } + if (home == NULL) { + fprintf(stderr, "cant find home directory\n"); + return 1; + } + + if (verbose) printf("[verbose] setting x.rootdir to $home/.local/mbpk/prefix\n"); snprintf(x.rootdir, sizeof(x.rootdir), "%s/.local/mbpk/prefix", home); + if (verbose) printf("[verbose] setting x.cachedir to $home/.local/mbpk/cache\n"); snprintf(x.cachedir, sizeof(x.cachedir), "%s/.local/mbpk/cache", home); + if (verbose) printf("[verbose] setting x.confdir to $home/.local/mbpk/conf.d\n"); snprintf(x.confdir, sizeof(x.confdir), "%s/.local/mbpk/conf.d", home); - x.flags = XBPS_FLAG_VERBOSE; + 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) LOGFV("xbps_init()"); int r = xbps_init(&x); if (r != 0) { fprintf(stderr, "xbps_init failed: %s\n", strerror(r)); return r; } + /* actually do stuff */ + if (update_repos) { + printf("[*] syncing repositories...\n"); + if (verbose) LOGFV("xbps_rpool_sync()"); + r = xbps_rpool_sync(&x, NULL); + if (r != 0) { + fprintf(stderr, "sync failed: %s\n", strerror(r)); + return r; + } + printf("[*] done!\n"); + } + if (pkgname) { + + } + return 0; } |
