From patchwork Mon Feb 26 14:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1904391 X-Patchwork-Delegate: zajec5@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ccBKZvR7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ZKNX2Fv1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tk2hv06VBz23cm for ; Tue, 27 Feb 2024 01:15:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fXm49AkvhmE/LjDv8S0hH712mL4JxbueSCsKAI1sRVE=; b=ccBKZvR7Fvh/km 2kf3f9eOt9drtf2yOFKe5BsVPT9R2phLcMvhKzGTI2i9k60qZ3KexCWpPYEf1R00Ri6+ThcoweNaJ d/X6t3lA5r9Oy4B6cnd8DMFobi5k1XTU0HpH+10q6vVxlUdHWrHTZvNNDZ1ArVmBnbO72OEIMFJTM Palv3YXbo/qCJ41IOiuplkhil4oGcRhhqurlUf+upQdeEh6dvyTzY8qRQcBJ9+6dLPTr39enGOut8 b7SckpHs5KQapCxF5yBmuzmOWI5dcQ6tb/VverZO/sO87lHylFpEl5wpxaLtBKx2RGRWxZaBHiE8D nTUEf9OvWzLYZ6UFVeKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rebkW-000000013ic-36AZ; Mon, 26 Feb 2024 14:14:32 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rebkR-000000013d4-0wLu for openwrt-devel@lists.openwrt.org; Mon, 26 Feb 2024 14:14:30 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-512f6f263a6so1088396e87.2 for ; Mon, 26 Feb 2024 06:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708956864; x=1709561664; darn=lists.openwrt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aAwU2vwxZRBMsmnAGrOtdN2q6hQGTutKd2mxpcjk+jw=; b=ZKNX2Fv1DWPumtC5LNaBZxrEAkKiOZXQ+I+/d+H69AlZOGbC9SyeFLRrJJWkjB2g66 GJWhJMfefjDDqmUAieejOnoJMv9LwIMq0gaMC5eKbIaZLwoJnz1F5mO2j/IXZ4HqtlyJ FIZT0eAvD0jCPd2kpLsbnbPEUx6VWKdWhaicUuoXD6wKOrVDsNMDB/XL0X0grhaw3Gy4 xuHXIYVNgC0Kp3LXaH2Uxdf9loyXxV5b9ysWEDLHojef+/1EGxF6tq0+UAoztbuXBy5F 8IOvLr5xRdd5vvYVNK0iOIgy3PG134b6dcSqfW5oorsNd7v+p+A//INi/hlg9BKiOi6w q7HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956864; x=1709561664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aAwU2vwxZRBMsmnAGrOtdN2q6hQGTutKd2mxpcjk+jw=; b=S4qPcv9nnOWV1onfvN8MO+z9nXKLibKXB/lgD+gb9jxOmDAJoR6JpfMwB/yphsYdxd oLYrJunQqFL1vUqQ8H472HD4kqVQQke5bFZWGqSkZI31UQejRlqPSLDGrfrdedW9W6FR c9JAtr4y5M4HXV+HP0py/PMQsWexTMm0LBakWWKF5KoGxnovS4yniuaaRP3BLktgFPuO bjKBJTw0pUFFIxMIqC8WaAAQ8+BAkHPm87JyMOintkjVDmZXfG1XrnbIm4hT4vNSbfu1 UMzYolcG49clXEyc4LVa3SR+cqNDIEy7JDULpoq5vZ7fkjxt374VbUPTiusiXnxmtvwE 22TQ== X-Gm-Message-State: AOJu0YxTN0PCY9ooEmqWHeIANVrWMn3W6bG+8/UC8FYu3XJoEiQcfTW3 SsfaElWMcHU1EEHErYn8siRBSCBJqN6S6gi0qJHndAabWmH4oqDIuFBWLibu X-Google-Smtp-Source: AGHT+IEoQ7iVkAf96mW559dgIF9AkPE0LunbqkOnQfR8fcuLxM5+W564UfZUtA4T4uetmIMysJpJdg== X-Received: by 2002:ac2:4209:0:b0:512:be4d:36f1 with SMTP id y9-20020ac24209000000b00512be4d36f1mr4301173lfh.21.1708956863936; Mon, 26 Feb 2024 06:14:23 -0800 (PST) Received: from localhost.lan (031011218106.poznan.vectranet.pl. [31.11.218.106]) by smtp.gmail.com with ESMTPSA id k24-20020a17090666d800b00a3d00616e1fsm2471082ejp.193.2024.02.26.06.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 06:14:23 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH 2/3] base-files: sysupgrade: use tar helper to include installed_packages.txt Date: Mon, 26 Feb 2024 15:14:12 +0100 Message-Id: <20240226141413.5570-2-zajec5@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240226141413.5570-1-zajec5@gmail.com> References: <20240226141413.5570-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_061427_508880_1793EF0C X-CRM114-Status: GOOD ( 12.73 ) X-Spam-Score: 0.0 (/) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__From=3A_Rafa=C5=82_Mi=C5=82ecki_Replac?= =?unknown-8bit?q?e_mount_+_overlay_with_manually?= =?unknown-8bit?q?_built_tar_archive_that_gets_prepended_to_the_actual_config?= =?unknown-8bit?q?_files_backup=2E?= =?unknown-8bit?q?_This_allows_more_flexibility_with_including_extra_backup_f?= =?unknown-8bit?q?iles=2E_They_can_be?= =?unknown-8bit?b?IGluY2x1ZGVkIGF0IGEgWy4uLl0g?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=280=2E0_points=2C_5=2E0_req?= =?unknown-8bit?q?uired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?b?IFsyYTAwOjE0NTA6NDg2NDoyMDowOjA6MDoxMzYgbGlzdGVkIGluXQ==?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FEF__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from?= =?unknown-8bit?q?_envelope-from_domain?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FAU__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from_author=27s?= =?unknown-8bit?q?_domain?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E2_FREEMAIL=5FENVFROM=5FEND=5FDIGIT_Envelope-from_freem?= =?unknown-8bit?q?ail_username_ends_in?= =?unknown-8bit?q?_digit?= =?unknown-8bit?q?_=5Bzajec5=28at=29gmail=2Ecom=5D?= =?unknown-8bit?q?_0=2E0_FREEMAIL=5FFROM__________Sender_email_is_commonly_ab?= =?unknown-8bit?q?used_enduser_mail_provider?= =?unknown-8bit?q?_=5Bzajec5=28at=29gmail=2Ecom=5D?= =?unknown-8bit?q?_-0=2E0_T=5FSCC=5FBODY=5FTEXT=5FLINE___No_description_avail?= =?unknown-8bit?q?able=2E?= X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki Replace mount + overlay with manually built tar archive that gets prepended to the actual config files backup. This allows more flexibility with including extra backup files. They can be included at any paths and don't require writing to flash or mounting an overlay which has its own limitations (mount points). Signed-off-by: Rafał Miłecki --- package/base-files/files/sbin/sysupgrade | 44 +++++++++--------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade index 6b3fb0666f..9d5d736aef 100755 --- a/package/base-files/files/sbin/sysupgrade +++ b/package/base-files/files/sbin/sysupgrade @@ -237,8 +237,6 @@ include /lib/upgrade create_backup_archive() { local conf_tar="$1" - local umount_etcbackup_dir=0 - [ "$(rootfs_type)" = "tmpfs" ] && { echo "Cannot save config while running from ramdisk." >&2 ask_bool 0 "Abort" && exit @@ -248,41 +246,31 @@ create_backup_archive() { run_hooks "$CONFFILES" $sysupgrade_init_conffiles ask_bool 0 "Edit config file list" && vi "$CONFFILES" - if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then - echo "${INSTALLED_PACKAGES}" >> "$CONFFILES" - mkdir -p "$ETCBACKUP_DIR" - # Avoid touching filesystem on each backup - RAMFS="$(mktemp -d -t sysupgrade.XXXXXX)" - mkdir -p "$RAMFS/upper" "$RAMFS/work" - mount -t overlay overlay -o lowerdir=$ETCBACKUP_DIR,upperdir=$RAMFS/upper,workdir=$RAMFS/work $ETCBACKUP_DIR && - umount_etcbackup_dir=1 || { - echo "Cannot mount '$ETCBACKUP_DIR' as tmpfs to avoid touching disk while saving the list of installed packages." >&2 - ask_bool 0 "Abort" && exit - } - - # Format: pkg-name{rom,overlay,unknown} - # rom is used for pkgs in /rom, even if updated later - find /usr/lib/opkg/info -name "*.control" \( \ - \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \ - \( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \ - \( -exec echo {} unknown \; \) \ - \) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES} - fi - v "Saving config files..." [ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V="" sed -i -e 's,^/,,' "$CONFFILES" - tar c${TAR_V}zf "$conf_tar" -C / -T "$CONFFILES" + { + # Part of archive with installed packages info + if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then + # Format: pkg-name{rom,overlay,unknown} + # rom is used for pkgs in /rom, even if updated later + tar_make_member_inline "$INSTALLED_PACKAGES" "$(find /usr/lib/opkg/info -name "*.control" \( \ + \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \ + \( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \ + \( -exec echo {} unknown \; \) \ + \) | sed -e 's,.*/,,;s/\.control /\t/')" + fi + + # Rest of archive with config files and ending padding + tar c${TAR_V} -C / -T "$CONFFILES" + } | gzip > "$conf_tar" + local err=$? if [ "$err" -ne 0 ]; then echo "Failed to create the configuration backup." rm -f "$conf_tar" fi - [ "$umount_etcbackup_dir" -eq 1 ] && { - umount "$ETCBACKUP_DIR" - rm -rf "$RAMFS" - } rm -f "$CONFFILES" return "$err"