From patchwork Fri Jan 10 11:12:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 2689 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 47vL1b1ryvz3xXp for ; Fri, 10 Jan 2020 11:12:51 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 47vL1Z0b68z2Ck; Fri, 10 Jan 2020 11:12:50 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 47vL1Y6Jclz2ybG; Fri, 10 Jan 2020 11:12:49 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 47vL1W5ftMz2xgy for ; Fri, 10 Jan 2020 11:12:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 47vL1T48mnz2Ck; Fri, 10 Jan 2020 11:12:45 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1578654765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ueh5Xf3P2HSqmyok8O1KVc7TOe1jfCtMjLJD61Qc+0Q=; b=iVPXShO7wi3F8YyB839b9ptUXJfBml++SA5AXzFpeSIT3GAWFDa3YcMPbSDKyQUg8aeMjM qroaLclTAfI6TODg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1578654765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ueh5Xf3P2HSqmyok8O1KVc7TOe1jfCtMjLJD61Qc+0Q=; b=bjv0d0Hdu0gAIbFOhhTVXzdwwqbyMv2Lv4JVhAVUyfNfacVXWxdTovW2ANtlLF5E5PaeSu rclk3EVGEbcm73lVrRUZnR5FLQsNO1hWATafqb4JTSqyFPvYga0QPXq8Wif0ZXOGZcqp4l vtGPr9JTpPzufrUuxc7T8p/Ls7KkBVMbur0ARkESQ1WaVXXXsSU01VGyYz6sN+iWRhQgq6 9HF0SxXJNLZ9vAfV0WidjaTUelN1vblIsdqp1ImUaQLpEbJGsG+7uXMpGmtXBVXhYIIfj1 kb2WzDJ6xK6ZFdkMyb9uMaPYaHf185iCfvPc0Cs2jNwNHIh3VGsCnX0+zg6ufA== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH] filesystem-cleanup: Automatically remove old libraries Date: Fri, 10 Jan 2020 11:12:36 +0000 Message-Id: <20200110111236.26105-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This script runs through /usr/lib and /lib and tries to find all libraries which are no longer being used and more and deletes them. This will help us to free space on root partitions that are limited to 2GB. However, the script does not cover 100% of the cases, so that some files still need to be deleted manually (e.g. boost with their weird versioning schema). This script should be executed after a Core Update has been installed. Fixes: #12270 Signed-off-by: Michael Tremer Reviewed-by: Peter Müller --- config/rootfiles/common/aarch64/stage2 | 1 + config/rootfiles/common/stage2 | 1 + config/rootfiles/common/x86_64/stage2 | 1 + src/scripts/filesystem-cleanup | 76 ++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 src/scripts/filesystem-cleanup diff --git a/config/rootfiles/common/aarch64/stage2 b/config/rootfiles/common/aarch64/stage2 index 366ab2bb0..2d9a70f81 100644 --- a/config/rootfiles/common/aarch64/stage2 +++ b/config/rootfiles/common/aarch64/stage2 @@ -92,6 +92,7 @@ usr/local/bin/backupiso usr/local/bin/connscheduler usr/local/bin/consort.sh usr/local/bin/convert-ovpn +usr/local/bin/filesystem-cleanup usr/local/bin/hddshutdown usr/local/bin/ipsec-interfaces usr/local/bin/makegraphs diff --git a/config/rootfiles/common/stage2 b/config/rootfiles/common/stage2 index d9068415b..b0680914e 100644 --- a/config/rootfiles/common/stage2 +++ b/config/rootfiles/common/stage2 @@ -91,6 +91,7 @@ usr/local/bin/backupiso usr/local/bin/connscheduler usr/local/bin/consort.sh usr/local/bin/convert-ovpn +usr/local/bin/filesystem-cleanup usr/local/bin/hddshutdown usr/local/bin/ipsec-interfaces usr/local/bin/makegraphs diff --git a/config/rootfiles/common/x86_64/stage2 b/config/rootfiles/common/x86_64/stage2 index d90e3d70a..9d3334e69 100644 --- a/config/rootfiles/common/x86_64/stage2 +++ b/config/rootfiles/common/x86_64/stage2 @@ -93,6 +93,7 @@ usr/local/bin/backupiso usr/local/bin/connscheduler usr/local/bin/consort.sh usr/local/bin/convert-ovpn +usr/local/bin/filesystem-cleanup usr/local/bin/hddshutdown usr/local/bin/ipsec-interfaces usr/local/bin/makegraphs diff --git a/src/scripts/filesystem-cleanup b/src/scripts/filesystem-cleanup new file mode 100644 index 000000000..d4cdfe8d3 --- /dev/null +++ b/src/scripts/filesystem-cleanup @@ -0,0 +1,76 @@ +#!/bin/bash +############################################################################ +# # +# This file is part of the IPFire Firewall. # +# # +# IPFire is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# IPFire is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with IPFire; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +# Copyright (C) 2020 IPFire Team . # +# # +############################################################################ + +PATHS=( + /usr/lib + /lib +) + +main() { + # Update the runtime linker cache (this may fix any broken symlinks) + ldconfig + + local path + for path in ${PATHS[@]}; do + echo "Searching in ${path}..." + + # Find all files called libsomething.so.N + local lib + for lib in $(find "${path}" -maxdepth 1 -type l -name "lib*.so.*" | sort); do + # Read the name of the linked library + local link="$(readlink -m "${lib}")" + + # We have two versioning schemas that we need to distinguish... + local files=() + case "${link}" in + # Libraries called libsomething-N.so + */lib*-*.so) + files+=( ${link%-*}-* ) + ;; + + # Libraries called libsomething.so.N.* + *) + files+=( ${lib}* ) + ;; + esac + + # Remove all files that have the same base name than + # the library we are looking at, apart from the symlink + # and the linked file itself. + local file + for file in ${files[@]}; do + case "${file}" in + # Ignore these files + ${lib}|${link}) + ;; + + *) + unlink "${file}" + ;; + esac + done + done + done +} + +main "$@" || exit $?