From patchwork Tue Nov 1 03:17:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Toth X-Patchwork-Id: 2091 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [2a01:4f9:c010:3052::1] by patchwork.archlinux.org with IMAP (fetchmail-6.4.34) for (single-drop); Wed, 02 Nov 2022 08:23:18 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id wquRFfYoYmNbnwUAK+/4rw (envelope-from ) for ; Wed, 02 Nov 2022 08:23:18 +0000 Received: from lists.archlinux.org (lists.archlinux.org [95.217.236.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id CF2EB1631717; Wed, 2 Nov 2022 08:23:16 +0000 (UTC) Authentication-Results: mail.archlinux.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=XwP99hkq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mail.archlinux.org: domain of pacman-dev-bounces@lists.archlinux.org designates 95.217.236.249 as permitted sender) smtp.mailfrom=pacman-dev-bounces@lists.archlinux.org Received: from lists.archlinux.org (localhost [IPv6:::1]) by lists.archlinux.org (Postfix) with ESMTP id 90F2E5E5C40; Wed, 2 Nov 2022 08:23:14 +0000 (UTC) Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by lists.archlinux.org (Postfix) with ESMTPS id D760C5DC62B for ; Tue, 1 Nov 2022 03:17:41 +0000 (UTC) Received: by mail-qv1-xf2b.google.com with SMTP id w10so9560590qvr.3 for ; Mon, 31 Oct 2022 20:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vU5NBUNo+8EGwzwWHb/JEImoYsAHR++tc/22C7UoWe8=; b=XwP99hkqV8Ph1qiAsw/XHg85APEeuBxApaAuTJUMnN26D7yNjGl/X+eN+SiEWRmOER v58BRJt2N1Q8z1L+ITrwUtVtZfYGK4b6xg6SCtop3sN1l8w8fWgnFjL8SS69XbvCX/Cl 1e33mp8u2dNE/UYOweICop0c0RPYmqqZFMP0m4QoP6GtHA1jyjWqxBTGW4mJokh/3A9/ KW8O66YVZK3mhpywHUYNWT3Op2b706OnzTVY5FEVLcEcTkSQPjgOexwocS8ESrWqvSN9 1ncIJq4SJb+rDfnls9IN1fVDbPjAVM55hwrHWtE5r6ZvLXsOq7EdldSMF8XLp+Bd0oCj VbQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vU5NBUNo+8EGwzwWHb/JEImoYsAHR++tc/22C7UoWe8=; b=dw7RV/sXOrlxOUnocsWt+h2opNKWE9Qc124ol6eb1nw397soz865pkMGJEsAEf15eF 6EQPUktiBvEKPVLMTnPgsZakXNkp1P0v9lIstB+mEwSHScHLaH3EvP2aM8kdnLHDIkMr Z4x1ubvOe04/09yqLqEKzSmUgIk2R5AeZLfP4bEXSmOtu190nbfWPe5Vd/SPkEwTDFtm OJhuLsKL1aDSLPs/G0DcCyd2g3g9Id1Z0CUYFv6yF/Ailf45xT7Ulbw9ulta4A+wwipX ev5Hpry9iSTVWuHQE7+qKoPlic5aoXCRu7Sg0ctRmE6mrzJ/StZ67CeVGNDRVdXQWNWc ytBw== X-Gm-Message-State: ACrzQf1iJleT7Dq16czaysfFqfOZ9bCvmTIIci8MDLdOih1y5lPJMZQB wJdYg0cy4CipI78A9uhhVunWb418nT2ZSHueF4I= X-Google-Smtp-Source: AMsMyM5tCPSdKxVRNEaj2k4F17tvKIeYvHyxLN0Dauq3SiJ33RuTAe4hiYzKp7jhtWOck33frBqV4w== X-Received: by 2002:a05:6214:27e9:b0:4bb:d54c:53d2 with SMTP id jt9-20020a05621427e900b004bbd54c53d2mr11321265qvb.54.1667272660396; Mon, 31 Oct 2022 20:17:40 -0700 (PDT) Received: from thinkpad-x280.. (pool-108-7-60-62.bstnma.fios.verizon.net. [108.7.60.62]) by smtp.gmail.com with ESMTPSA id bl6-20020a05620a1a8600b006b5cc25535fsm5836327qkb.99.2022.10.31.20.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 20:17:39 -0700 (PDT) From: Laszlo Toth To: pacman-dev@lists.archlinux.org Subject: [PATCH] Add --noconfirm-unsafe for advanced script usage Date: Mon, 31 Oct 2022 23:17:28 -0400 Message-Id: <20221101031728.74522-1-laszlth@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-MailFrom: laszlth@gmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: CWTW762254XJ2R42K26NGAG4E2QS4VFG X-Message-ID-Hash: CWTW762254XJ2R42K26NGAG4E2QS4VFG X-Mailman-Approved-At: Wed, 02 Nov 2022 08:23:11 +0000 CC: Laszlo Toth X-Mailman-Version: 3.3.5 Precedence: list List-Id: Discussion list for pacman development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Rspamd-Queue-Id: CF2EB1631717 X-Spamd-Result: default: False [0.59 / 15.00]; MID_CONTAINS_FROM(1.00)[]; DATE_IN_PAST(1.00)[29]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; R_MISSING_CHARSET(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; MAILLIST(-0.20)[mailman]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; RCVD_IN_DNSWL_MED(-0.20)[95.217.236.249:from]; R_SPF_ALLOW(-0.20)[+ip4:95.217.236.249:c]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_FIVE(0.00)[5]; FROM_NEQ_ENVFROM(0.00)[laszlth@gmail.com,pacman-dev-bounces@lists.archlinux.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::f2b:received]; PREVIOUSLY_DELIVERED(0.00)[pacman-dev@lists.archlinux.org]; NEURAL_HAM(-0.00)[-1.000]; ARC_NA(0.00)[]; ASN(0.00)[asn:24940, ipnet:95.217.0.0/16, country:DE]; FREEMAIL_CC(0.00)[gmail.com]; DKIM_TRACE(0.00)[gmail.com:+]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; RCPT_COUNT_TWO(0.00)[2]; RECEIVED_SPAMHAUS_PBL(0.00)[108.7.60.62:received]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org This is intended for e.g., regular, automated cache clearing or updating/creating Docker images. There is --noconfirm, but that selects the default answer for yes/no questions, which may be no when we want yes. Then 'yes | pacman -Scc' could be used, but that does not work reliably w/ multiselection. So, add a new option which always answers yes for yes/no, and the default for multiselections. Now --confirm disables both --noconfirm and --noconfirm-unsafe. noask is not updated to use this mode as well... it's not safe. Signed-off-by: Laszlo Toth --- doc/pacman.8.asciidoc | 11 ++++++++--- src/pacman/conf.h | 4 +++- src/pacman/pacman.c | 8 ++++++++ src/pacman/util.c | 18 ++++++++++++++---- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc index 630ff0d9..ec400175 100644 --- a/doc/pacman.8.asciidoc +++ b/doc/pacman.8.asciidoc @@ -185,11 +185,16 @@ Options the installation root setting. *\--noconfirm*:: - Bypass any and all ``Are you sure?'' messages. It's not a good idea to do - this unless you want to run pacman from a script. + Bypass any and all ``Are you sure?'' messages via using the default answer. + It's not a good idea to do this unless you want to run pacman from a script. + +*\--noconfirm-unsafe*:: + Bypass any and all ``Are you sure?'' messages via answering yes or + selecting the default option. + It's NOT a good idea to do this unless you want to run pacman from a script. *\--confirm*:: - Cancels the effects of a previous '\--noconfirm'. + Cancels the effects of a previous '\--noconfirm' or '\--noconfirm-unsafe'. *\--disable-download-timeout*:: Disable defaults for low speed limit and timeout on downloads. Use this diff --git a/src/pacman/conf.h b/src/pacman/conf.h index f7916ca9..fbed3055 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -57,6 +57,7 @@ typedef struct __config_t { unsigned short usesyslog; unsigned short color; unsigned short disable_dl_timeout; + unsigned short noconfirmunsafe; char *print_format; /* unfortunately, we have to keep track of paths both here and in the library * because they can come from both the command line or config file, and we @@ -210,7 +211,8 @@ enum { OP_DOWNLOADONLY, OP_REFRESH, OP_ASSUMEINSTALLED, - OP_DISABLEDLTIMEOUT + OP_DISABLEDLTIMEOUT, + OP_NOCONFIRMUNSAFE }; /* clean method */ diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index e5c6e420..bb04fdc8 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -226,6 +226,8 @@ static void usage(int op, const char * const myname) addlist(_(" --confirm always ask for confirmation\n")); addlist(_(" --disable-download-timeout\n" " use relaxed timeouts for download\n")); + addlist(_(" --noconfirm-unsafe\n" + " answer yes or default for every confirmation\n")); } list = alpm_list_msort(list, alpm_list_count(list), options_cmp); for(i = list; i; i = alpm_list_next(i)) { @@ -442,8 +444,13 @@ static int parsearg_global(int opt) case OP_NOCONFIRM: config->noconfirm = 1; break; + case OP_NOCONFIRMUNSAFE: + config->noconfirm = 0; + config->noconfirmunsafe = 1; + break; case OP_CONFIRM: config->noconfirm = 0; + config->noconfirmunsafe = 0; break; case OP_DBPATH: case 'b': @@ -948,6 +955,7 @@ static int parseargs(int argc, char *argv[]) {"dbonly", no_argument, 0, OP_DBONLY}, {"color", required_argument, 0, OP_COLOR}, {"disable-download-timeout", no_argument, 0, OP_DISABLEDLTIMEOUT}, + {"noconfirm-unsafe", no_argument, 0, OP_NOCONFIRMUNSAFE}, {0, 0, 0, 0} }; diff --git a/src/pacman/util.c b/src/pacman/util.c index 5f5c7c54..532e058d 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1527,7 +1527,7 @@ int multiselect_question(char *array, int count) FILE *stream; size_t response_len = 64; - if(config->noconfirm) { + if(config->noconfirm || config->noconfirmunsafe) { stream = stdout; } else { /* Use stderr so questions are always displayed when redirecting output */ @@ -1550,7 +1550,7 @@ int multiselect_question(char *array, int count) fprintf(stream, ": "); fflush(stream); - if(config->noconfirm) { + if(config->noconfirm || config->noconfirmunsafe) { fprintf(stream, "\n"); break; } @@ -1604,7 +1604,7 @@ int select_question(int count) FILE *stream; int preset = 1; - if(config->noconfirm) { + if(config->noconfirm || config->noconfirmunsafe) { stream = stdout; } else { /* Use stderr so questions are always displayed when redirecting output */ @@ -1617,6 +1617,11 @@ int select_question(int count) fprintf(stream, ": "); fflush(stream); + if(config->noconfirmunsafe) { + fprintf(stream, "y\n"); + break; + } + if(config->noconfirm) { fprintf(stream, "\n"); break; @@ -1682,7 +1687,7 @@ static int question(short preset, const char *format, va_list args) FILE *stream; int fd_in = fileno(stdin); - if(config->noconfirm) { + if(config->noconfirm || config->noconfirmunsafe) { stream = stdout; } else { /* Use stderr so questions are always displayed when redirecting output */ @@ -1705,6 +1710,11 @@ static int question(short preset, const char *format, va_list args) fputs(config->colstr.nocolor, stream); fflush(stream); + if(config->noconfirmunsafe) { + fprintf(stream, "y\n"); + return preset; + } + if(config->noconfirm) { fprintf(stream, "\n"); return preset;