#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include "aports-cache.h" #ifndef HAVE_PROGRAM_INVOCATION_NAME static char *program_invocation_name; #endif static void usage(int exitcode) { printf("usage %s [OPTS] DIR\n" "options:\n" " -h,--help show this help\n" " -c,--check only check if cache is updated\n" " -u,--update force cache update\n" " -v,--verbose enable verbose mode\n" " -s,--shell PROG use PROG as shell instead of /bin/sh\n" "\n", program_invocation_name); exit(exitcode); } int main(int argc, char *argv[]) { static struct option opts[] = { {"check", no_argument, 0, 'c' }, {"help", no_argument, 0, 'h' }, {"verbose", no_argument, 0, 'v' }, {"update", no_argument, 0, 'u' }, {"shell", required_argument, 0, 's' }, {"stdout", no_argument, 0, 0x0101}, { 0, 0, 0, 0} }; int i, c, verbose=0, check_only=0, force_update=0; const char *cachefile = ".aports.cache.yaml"; char dirpath_buf[PATH_MAX]; char *dirpath = dirpath_buf; int dirfd, rc; char *shell_argv[] = {"/bin/sh", NULL}; #ifndef HAVE_PROGRAM_INVOCATION_NAME program_invocation_name = argv[0]; #endif while ((c = getopt_long(argc, argv, "fs:v", opts, &i)) != -1) { switch(c) { case 'c': check_only = 1; break; case 'h': usage(0); break; case 's': shell_argv[0] = optarg; break; case 0x0101: cachefile=NULL; break; case 'u': force_update = 1; break; case 'v': verbose = 1; break; } } if (optind < argc) { dirpath = argv[optind]; } else { dirpath = getcwd(dirpath_buf, sizeof(dirpath_buf)); } dirfd = open(dirpath, O_DIRECTORY); if (dirfd < 0) err(1, "%s", dirpath); fchdir(dirfd); if (!force_update) c =aports_cache_check(dirfd, cachefile); if (check_only || !c) { if (verbose) printf("cache is %sup to date\n", c ? "not " : ""); return c; } if (verbose) printf("updating cache for %s\n", dirpath); rc = aports_cache_refresh(dirfd, cachefile, shell_argv); close(dirfd); return rc; }