From patchwork Fri Aug 17 23:49:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 959153 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.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; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="O2NCosda"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="noY4sIT6"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41sg2D0Mbnz9s8F for ; Sat, 18 Aug 2018 09:51:00 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TUoBwzJBV2yeDgjdr2XNgpioW24qyIWrIJYxfnrHcxE=; b=O2NCosda7+E2es V6rz+BJPIL3DxY07DZLdBNR9XIRd2JagNu9Ocw4b47WPGiGZjWctZeKxg4TlfpBF0Z+HgiEHjEIlG d6s1CTB7bfDoiuRHk/JmpKq5L85TFjCjn7m5YWINU7P48O6/+6vS8Ckt4MsUAB5DENQQLdtXTfthO s0zAxXJzPMKaix0xs8oca+Hw7iEuaZIgf4mVNQ0jAjYJ4A4d0CeomjBOkUwYML4NeETEzpHfSW9zj AAQUOlTn1ixcfkx0j0rxyNkqrIimYqSly8U2dPFbv3Tdi00MNBrBa7aU+bqrDLXrNI8mcR7mqanKp Y0zZ4/7Q/WlnLaMmz9bQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fqoW6-0002wd-GP; Fri, 17 Aug 2018 23:50:54 +0000 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fqoVd-0002Ea-V3 for openwrt-devel@lists.openwrt.org; Fri, 17 Aug 2018 23:50:27 +0000 Received: by mail-qt0-x243.google.com with SMTP id m13-v6so10600207qth.1 for ; Fri, 17 Aug 2018 16:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LPsOYZjMukbTDr9RsIhTSgteFXpupngysDiM8r4sD5U=; b=noY4sIT6RG7QmleiB75IDrxyHGFXNDfUVr8k5AFu0pOL4kbRGGOn3V0ciDMHE5rYD9 J72gDoxtmOMjpoS0fYSAitw2KV5TC255iWdDAwmTOw7NKb8uJaNe9Yn7G2jfbfdYVoLO Dm0R7OEf66cJRUK6NeziTrInzbmGA1ZI0LHtE6Ced++sXICx1pUGTnRJNqQi1PzjT4ut F1QujtB7JtZzITBeBg9V1A/Py2QlUEJwhPj5ayxpRvFUTyzaik4wScdeD1j9Tk8/aMUq AjCKDZ1LrRsu0HgqIvtBFszqRO2SYxG1bh/wtLBaU137juRKIldZIhJu4caOh96vKgB+ P0aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LPsOYZjMukbTDr9RsIhTSgteFXpupngysDiM8r4sD5U=; b=T+vNn8aYLS8XbY/yyL+iFuyLPx06icUeNvVQEyhHDe/S/PSEQXPXwy1sFRZmJrJjoz 74xKF09RaqyZXmSSWZVgLQmvLd2si8tXTcYLOVwnkow+K90c3f4r9/scyIXyCTTGhjTo qDv+1G3MpIj6Yv+ruhU43noJLNfpYs93E6WbFEiej3J/qGq9vRjHiXfQ1Fp4ibK7MCTV R8h9daqHBnKQRYGw3gFSIkP4Orzn+jRfcVt4NNpyTRsFO4Lrh8HnKAG6d4EthVTFDQzC lIxWDCbKA0q/N3Fxc2xLTediNYdDXt+PFCCMkpuUZVkJI4wWhVRF4SbfjqmBVOUGVPI2 JyIg== X-Gm-Message-State: AOUpUlFleaIKJFcxRY9O6BCQyGwyVSUAdPHOnYeKFvGeVsNSUpJOgL2z XLkm+MiB5Na0CKsswIMcN7pVdAcu X-Google-Smtp-Source: AA+uWPxr3Eu+Y7UShqQTccEnSfnFt7b2Gohl2qU4087l3RAZ4BPuDW4mtFdFcUvYXn3Orpa6q3YmXA== X-Received: by 2002:a0c:9281:: with SMTP id b1-v6mr33206544qvb.115.1534549814537; Fri, 17 Aug 2018 16:50:14 -0700 (PDT) Received: from tresc043793.redetresc.tre-sc.gov.br (187-049-235-010.floripa.net.br. [187.49.235.10]) by smtp.gmail.com with ESMTPSA id s66-v6sm2082618qki.24.2018.08.17.16.50.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Aug 2018 16:50:14 -0700 (PDT) From: luizluca@gmail.com To: openwrt-devel@lists.openwrt.org Date: Fri, 17 Aug 2018 20:49:52 -0300 Message-Id: <20180817234953.6149-4-luizluca@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817234953.6149-1-luizluca@gmail.com> References: <20180404232826.10815-1-luizluca@gmail.com> <20180817234953.6149-1-luizluca@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180817_165025_999477_988082DD X-CRM114-Status: GOOD ( 11.45 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400d:c0d:0:0:0:243 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (luizluca[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [PATCH v3 3/4] base-files: add sysupgrade -o to save all overlay files X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Luiz Angelo Daros de Luca MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Luiz Angelo Daros de Luca Add sysupgrade '-o' option in order to include all overlay files in backup, except for those that are from packages but including files listed in conffiles, sysupgrade.conf or /lib/upgrade/keep.d. With '-u' option, it will skip files equals to /rom and conffiles that were not changed. Signed-off-by: Luiz Angelo Daros de Luca --- package/base-files/files/sbin/sysupgrade | 52 ++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade index 45378d7266..ca02577c26 100755 --- a/package/base-files/files/sbin/sysupgrade +++ b/package/base-files/files/sbin/sysupgrade @@ -9,6 +9,7 @@ export INTERACTIVE=0 export VERBOSE=1 export SAVE_CONFIG=1 export SAVE_OVERLAY=0 +export SAVE_OVERLAY_PATH= export SAVE_PARTITIONS=1 export SKIP_UNCHANGED=0 export CONF_IMAGE= @@ -27,7 +28,8 @@ while [ -n "$1" ]; do -v) export VERBOSE="$(($VERBOSE + 1))";; -q) export VERBOSE="$(($VERBOSE - 1))";; -n) export SAVE_CONFIG=0;; - -c) export SAVE_OVERLAY=1;; + -c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;; + -o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;; -p) export SAVE_PARTITIONS=0;; -u) export SKIP_UNCHANGED=1;; -b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;; @@ -54,12 +56,14 @@ IMAGE="$1" [ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] && { cat <...] - $0 [-q] [-i] [-c] [-u] + $0 [-q] [-i] [-c] [-u] [-o] upgrade-option: -f restore configuration from .tar.gz (file or url) -i interactive mode -c attempt to preserve all changed files in /etc/ + -o attempt to preserve all changed files in /, exept those + from packages but including changed confs. -u skip from backup files that are equals to those in /rom -n do not save configuration over reflash -p do not attempt to restore the partition table after flash. @@ -129,12 +133,52 @@ add_conffiles() { add_overlayfiles() { local file="$1" - ( cd /overlay/upper/; find ./etc \( -type f -o -type l \) $find_filter | sed \ + + local packagesfiles=$1.packagesfiles + touch "$packagesfiles" + + if [ "$SAVE_OVERLAY_PATH" = / ]; then + local conffiles=$1.conffiles + local keepfiles=$1.keepfiles + + list_conffiles | cut -f2 -d ' ' | sort -u > "$conffiles" + + # backup files from /etc/sysupgrade.conf and /lib/upgrade/keep.d, but + # ignore those aready controlled by opkg conffiles + find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \ + /etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \ + \( -type f -o -type l \) 2>/dev/null | sort -u | + grep -h -v -x -F -f $conffiles > "$keepfiles" + + # backup conffiles, but only those changed if '-u' + [ $SKIP_UNCHANGED = 1 ] && + list_changed_conffiles | sort -u > "$conffiles" + + # do not backup files from packages, except those listed + # in conffiles and keep.d + { + find /usr/lib/opkg/info -type f -name "*.list" -exec cat {} \; + find /usr/lib/opkg/info -type f -name "*.control" -exec sed \ + -ne '/^Alternatives/{s/^Alternatives: //;s/, /\n/g;p}' {} \; | + cut -f2 -d: + } | grep -v -x -F -f $conffiles | + grep -v -x -F -f $keepfiles | sort -u > "$packagesfiles" + rm -f "$keepfiles" "$conffiles" + fi + + # busybox grep bug when file is empty + [ -s "$packagesfiles" ] || echo > $packagesfiles + + ( cd /overlay/upper/; find .$SAVE_OVERLAY_PATH \( -type f -o -type l \) $find_filter | sed \ -e 's,^\.,,' \ -e '\,^/etc/board.json$,d' \ -e '\,/[^/]*-opkg$,d' \ -e '\,^/etc/urandom.seed$,d' \ - )> "$file" + -e '\,^/usr/lib/opkg/.*,d' \ + ) | grep -v -x -F -f $packagesfiles > "$file" + + rm -f "$packagesfiles" + return 0 }