From patchwork Thu Oct 15 05:58:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rosen Penev X-Patchwork-Id: 1382463 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=PISQ95Y6; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=RXigXfbX; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (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 ozlabs.org (Postfix) with ESMTPS id 4CBdtX6SNhz9sVH for ; Thu, 15 Oct 2020 17:00:36 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=vRd4OnVL3FgGxXTQG6A6wKm+bpl3gJBHMayedIExxRY=; b=PISQ95Y6WX5Q9xyUVt0W6uAkd3 +FGDlRPidmPc0PwTCNZ57LumOTRJVRgoXER/yMC10IWzUOBG98sjxAOoXflM6bu934QJF4VdFXOO0 Z3qXKnYzptam2LTcQAu0N/I36egWj/gbT/7+WOr5thnHcNY0X130xC4Q34RocGu33iuNFgV469IE1 jfNMQQTnPhH6uDA4vtNA+WXCKJFxvCWkyzXPbqomiXqkabbwmQd8WaVo+9J3U5IjciMf9wFhjZtJa Bz+jmEgQTtFQz4u6tz0ZeOBBXCs9rvetDsTqtLqVZwg/W7Xa8w0bDapAPn5G9MkAMFwCLWUneMeZN uXowiuLg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSwHb-0008W2-Ea; Thu, 15 Oct 2020 05:58:35 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSwHY-0008V2-Qe for openwrt-devel@lists.openwrt.org; Thu, 15 Oct 2020 05:58:33 +0000 Received: by mail-pl1-x62e.google.com with SMTP id c6so1002548plr.9 for ; Wed, 14 Oct 2020 22:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=Qfv6wB2mm4n1Ve9wIDbdZDQ1i+0w1TrFssGw6CTAX6A=; b=RXigXfbXiVpoCdWTloTr+htGASHAeMNOVRWtTYAM/r2tO1eYhgEG/yMG+tCeG4ZjyX omI6wqtKzmCWAruIDpuiEUhccW0BugV4xmbqAaRtWkBIjrMUv4Yfbk45HQGvAxfO/a0t bnwf+feSFz/oy2CNSaoneMVV64DB3ZFD1+RS7UDji5ZMHpVphbkslZrSKYviLmQLpb5f uFGIRRUFtMdf9DExg26qrK+loOesGOB4/zHrJo/asy8gTMio/4CFizc/gVcwgjdGvpS+ I/Ro/tJxesu1hpsZl1hqMmRxixUuMjnOnDb8ZBAeKpldPRUDvVvdluRyBxbDlOwOBmqD G+/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Qfv6wB2mm4n1Ve9wIDbdZDQ1i+0w1TrFssGw6CTAX6A=; b=Q17wdJG1E5jpT6WTBb1Ufr+lMKZSuzerrcx3xfa5ELWzxF5nQCYjavL5S9wYTGxRIM 9mGeRyj1WZZjNbae07rkaOU+ymESCiyI3iZ9oOl2cOPV5RlSyDsFNo3EU9K3cKZn1cwN uSYR4FTLV32QMdwC0y3aHKqugiHMSS+yl9qmVtNkwbsI3lFSD8cR0BrmOcegBHUaKGVd ihH7DIG0Ik+b3TjCLJCCxuHaeJqXYu+CYu2LHXM5KbDZS83qYTC9ilUajTqRbdUH7+8M O6N/W/GFhOzAJV0sgWKPSw/1NE+npVZjZGhVPaEIAkLpyx875i8P/fSlyvneuUl8DFzi EEmw== X-Gm-Message-State: AOAM530wBWwJpvXjTqQqSbNYVm5yfBIZb2CrwXaeJjxB0cyPMNkH1q+V G5sdLdEpiifnitBio+t+v8a/Qm3FNfCLyA== X-Google-Smtp-Source: ABdhPJyvKUEGyGYL4KL5IDSAzLSMvjkMExZmVn6AhPk/8qifDiBKKJW0K2g4Av2BKpiamyjiCMK+fw== X-Received: by 2002:a17:90a:1181:: with SMTP id e1mr2820078pja.77.1602741510038; Wed, 14 Oct 2020 22:58:30 -0700 (PDT) Received: from DESKTOP-VIRSTQA.lan ([2001:470:1f05:79e:e928:5c7b:bcee:fb01]) by smtp.gmail.com with ESMTPSA id p14sm1584404pjo.46.2020.10.14.22.58.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 22:58:29 -0700 (PDT) From: Rosen Penev To: openwrt-devel@lists.openwrt.org Subject: [PATCHv2 1/4] base-files/functions.sh: read grep output by line Date: Wed, 14 Oct 2020 22:58:24 -0700 Message-Id: <20201015055827.29410-1-rosenp@gmail.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201015_015832_907796_150C5E2F X-CRM114-Status: GOOD ( 11.66 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62e listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [rosenp[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From https://github.com/koalaman/shellcheck/wiki/SC2013 For loops by default (subject to $IFS) read word by word. Additionally, glob expansion will occur. I believe the intended use case of these loops is to read lines. Signed-off-by: Rosen Penev --- package/base-files/files/lib/functions.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index 7da0c872fa..59bb0fe711 100755 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -182,7 +182,8 @@ default_prerm() { fi local shell="$(command -v bash)" - for i in $(grep -s "^/etc/init.d/" "$root/usr/lib/opkg/info/${pkgname}.list"); do + grep -s "^/etc/init.d/" "$root/usr/lib/opkg/info/${pkgname}.list" | while IFS= read -r i + do if [ -n "$root" ]; then ${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" disable else @@ -260,7 +261,8 @@ default_postinst() { if grep -m1 -q -s "^/etc/uci-defaults/" "$filelist"; then [ -d /tmp/.uci ] || mkdir -p /tmp/.uci - for i in $(grep -s "^/etc/uci-defaults/" "$filelist"); do + grep -s "^/etc/uci-defaults/" "$filelist" | while IFS= read -r i + do ( [ -f "$i" ] && cd "$(dirname $i)" && . "$i" ) && rm -f "$i" done uci commit @@ -270,7 +272,8 @@ default_postinst() { fi local shell="$(command -v bash)" - for i in $(grep -s "^/etc/init.d/" "$root$filelist"); do + grep -s "^/etc/init.d/" "$root$filelist" | while IFS= read -r i + do if [ -n "$root" ]; then ${shell:-/bin/sh} "$root/etc/rc.common" "$root$i" enable else