Skip to content
Browse files

Add --noconfirm option

The --noconfirm option will skip all questions. This option is also passed down
to makepkg.

Signed-off-by: Pang Yan Han <pangyanhan@gmail.com>
  • Loading branch information...
1 parent 7cffa55 commit 619ee24aa1e6a4f09a8b1ed695a6731fa40dd990 @yanhan committed
Showing with 67 additions and 13 deletions.
  1. +1 −0 conf.h
  2. +3 −0 powaur.1.txt
  3. +5 −0 powaur.c
  4. +2 −1 powaur.h
  5. +56 −12 sync.c
View
1 conf.h
@@ -35,6 +35,7 @@ struct config_t {
unsigned opt_maxthreads : 1;
unsigned color_set : 1;
unsigned nocolor_set : 1;
+ unsigned noconfirm : 1;
};
struct config_t *config_init(void);
View
3 powaur.1.txt
@@ -72,6 +72,9 @@ Disables colorized output. This option can be supplied many times but the
effect will be the same as if it was supplied once. If --color is supplied, the
effect of this option is nullified.
.TP
+.B "--noconfirm"
+Bypass all questions. This option is passed down to makepkg.
+.TP
.B "--threads <N>"
Limits powaur to spawn up to a maximum of N threads. Currently, mutli-threading
is limited to the -G operation. This option can be used to override the
View
5 powaur.c
@@ -125,6 +125,7 @@ static void usage(unsigned short op)
printf(" --verbose display more messages\n");
printf(" --color Switches on color\n");
printf(" --nocolor Switches off color\n");
+ printf(" --noconfirm do not ask for any confirmation\n");
}
cleanup:
@@ -271,6 +272,9 @@ static int parsearg_global(int option)
config->nocolor_set = 1;
}
break;
+ case OPT_NOCONFIRM:
+ config->noconfirm = 1;
+ break;
default:
return -1;
}
@@ -304,6 +308,7 @@ static int parseargs(int argc, char *argv[])
{"crawl", no_argument, NULL, PW_OP_CRAWL},
{"debug", no_argument, NULL, OPT_DEBUG},
{"nocolor", no_argument, NULL, OPT_NOCOLOR},
+ {"noconfirm", no_argument, NULL, OPT_NOCONFIRM},
{"vote", no_argument, NULL, OPT_SORT_VOTE},
{"verbose", no_argument, NULL, OPT_VERBOSE},
{"target", required_argument, NULL, OPT_TARGET_DIR},
View
3 powaur.h
@@ -22,7 +22,8 @@ enum {
OPT_MAXTHREADS,
OPT_COLOR,
OPT_NOCOLOR,
- OPT_CHECK_ONLY
+ OPT_CHECK_ONLY,
+ OPT_NOCONFIRM
};
enum pwloglevel_t {
View
68 sync.c
@@ -20,6 +20,31 @@
#include "sync.h"
#include "util.h"
+/* Converts a list of strings into an array of char * terminated by NULL.
+ * The returned pointer is to be freed by the caller.
+
+ * @param list list of char *
+ */
+char **list_to_argv(alpm_list_t *args)
+{
+ alpm_list_t *i;
+ int cnt, total;
+
+ total = alpm_list_count(args);
+ if (!total) {
+ return NULL;
+ }
+
+ total++;
+ char **argv = xcalloc(total, sizeof(char *));
+ for (cnt = 0, i = args; i; i = i->next) {
+ argv[cnt++] = i->data;
+ }
+
+ argv[cnt] = NULL;
+ return argv;
+}
+
/* Installs a single succesfully downloaded PKGBUILD using makepkg -si
* Assumes that the package has been extracted into its own directory
*
@@ -43,6 +68,10 @@ static int install_single_package(char *pkgname)
return error(PW_ERR_CHDIR, pkgname);
}
+ if (config->noconfirm) {
+ goto fork_pacman;
+ }
+
/* Ask user to edit PKGBUILD */
snprintf(buf, PATH_MAX, "Edit PKGBUILD for %s? [Y/n/a]", pkgname);
ret = mcq(buf, choices, sizeof(choices) / sizeof(*choices), 0);
@@ -101,35 +130,50 @@ static int install_single_package(char *pkgname)
fork_pacman:
free(dotinstall);
- if (!yesno("Continue installing %s?", pkgname)) {
+ if (!config->noconfirm && !yesno("Continue installing %s?", pkgname)) {
return -2;
}
+ alpm_list_t *args = alpm_list_add(NULL, xstrdup("makepkg"));
+ alpm_list_add(args, xstrdup("-si"));
+
+ if (config->noconfirm) {
+ alpm_list_add(args, xstrdup("--noconfirm"));
+ }
+
+ /* Check if we're root. Invoke makepkg with --asroot if so */
+ uid_t myuid = geteuid();
+ if (myuid == 0) {
+ alpm_list_add(args, xstrdup("--asroot"));
+ }
+
+ char **argv = list_to_argv(args);
pid = fork();
if (pid == (pid_t) -1) {
return error(PW_ERR_FORK_FAILED);
} else if (pid == 0) {
- /* Check if we're root. Invoke makepkg with --asroot if so */
- uid_t myuid = geteuid();
- if (myuid > 0) {
- execlp("makepkg", "makepkg", "-si", NULL);
- } else {
- execlp("makepkg", "makepkg", "--asroot", "-si", NULL);
- }
+ execvp("makepkg", argv);
} else {
/* Parent process */
ret = wait_or_whine(pid, "makepkg");
if (ret) {
- return -1;
+ ret = -1;
+ goto cleanup;
}
+
+ ret = 0;
}
+cleanup:
+ free(argv);
+ FREELIST(args);
+
/* Change back to old directory */
if (chdir(cwd)) {
RET_ERR(PW_ERR_RESTORECWD, -2);
}
- return 0;
+ return ret;
}
/* Search sync db for packages. Only works for 1 package now. */
@@ -668,7 +712,7 @@ static int sync_upgrade(CURL *curl, alpm_list_t *targets)
goto cleanup;
}
- upgrade_all = yesno("Do you wish to upgrade the above packages?");
+ upgrade_all = config->noconfirm || yesno("Do you wish to upgrade the above packages?");
if (upgrade_all) {
/* Experimental */
alpm_list_t *final_targets = NULL;
@@ -772,7 +816,7 @@ static int sync_targets(CURL *curl, alpm_list_t *targets)
}
printf("\n");
- if (yesno("Do you wish to proceed?")) {
+ if (config->noconfirm || yesno("Do you wish to proceed?")) {
final_targets = alpm_list_join(reinstall, upgrade);
final_targets = alpm_list_join(final_targets, new_packages);
joined = 1;

0 comments on commit 619ee24

Please sign in to comment.
Something went wrong with that request. Please try again.