Skip to content

Commit

Permalink
Add --noconfirm option
Browse files Browse the repository at this point in the history
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
yanhan committed Jun 28, 2011
1 parent 7cffa55 commit 619ee24
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
1 change: 1 addition & 0 deletions conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions powaur.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions powaur.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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},
Expand Down
3 changes: 2 additions & 1 deletion powaur.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ enum {
OPT_MAXTHREADS,
OPT_COLOR,
OPT_NOCOLOR,
OPT_CHECK_ONLY
OPT_CHECK_ONLY,
OPT_NOCONFIRM
};

enum pwloglevel_t {
Expand Down
68 changes: 56 additions & 12 deletions sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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);
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 619ee24

Please sign in to comment.