From d7ee801712705c97fda658bb71209d814d1db841 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 23 Aug 2024 09:50:39 +0000 Subject: [PATCH] make.sh: Integrate the rootfile consistency check Signed-off-by: Michael Tremer --- make.sh | 120 +++++++++++++++++++++++++++++++++++++++---- tools/checkrootfiles | 114 ---------------------------------------- 2 files changed, 111 insertions(+), 123 deletions(-) delete mode 100755 tools/checkrootfiles diff --git a/make.sh b/make.sh index 3faba3d76b..f474ee7aeb 100755 --- a/make.sh +++ b/make.sh @@ -46,6 +46,13 @@ KVER="${KVER/-rc/.0-rc}${KVER_SUFFIX}" # ############################################################################### +# All supported architectures +ARCHES=( + aarch64 + riscv64 + x86_64 +) + HOST_ARCH="${HOSTTYPE}" LC_ALL=POSIX PS1='\u:\w$ ' @@ -2159,8 +2166,8 @@ exec_in_namespace() { "${0}" "${args[@]}" "$@" } -check_logfiles() { - print_headline "Checking Log Files..." +check_for_missing_rootfiles() { + print_headline "Checking for missing rootfiles..." local file for file in ${LOG_DIR}/*_missing_rootfile; do @@ -2174,6 +2181,102 @@ check_logfiles() { return 0 } +check_rootfiles_for_arch() { + local arch="${1}" + + local args=( + # Search path + "${BASEDIR}/config/rootfiles" + + # Exclude old core updates + "--exclude-dir" "oldcore" + + # Ignore the update scripts + "--exclude" "update.sh" + ) + + # A list of files that are not scanned + # because they probably cause some false positives. + local excluded_files=( + qemu + ) + + # Exclude any architecture-specific directories + local a + for a in ${ARCHES[@]}; do + args+=( "--exclude-dir" "${a}" ) + done + + # Exclude all excluded files + local x + for x in ${excluded_files[@]}; do + args+=( "--exclude" "${x}" ) + done + + # Search for all lines that contain the architecture, but exclude commented lines + if grep -r "^[^#].*${arch}" "${args[@]}"; then + return 1 + fi + + return 0 +} + +check_rootfiles_for_pattern() { + local pattern="${1}" + local message="${2}" + + local args=( + # Search path + "${BASEDIR}/config/rootfiles" + + # Exclude old core updates + "--exclude-dir" "oldcore" + + # Ignore the update scripts + "--exclude" "update.sh" + ) + + if grep -r "${pattern}" "${args[@]}"; then + if [ -n "${message}" ]; then + print_line "${message}" + print_status FAIL + else + print_file "Files matching '${pattern}' have been found in the rootfiles" + print_status FAIL + fi + return 1 + fi + + return 0 +} + +check_rootfiles() { + local failed=0 + + print_headline "Checking for rootfile consistency..." + + # Check for /etc/init.d + if ! check_rootfiles_for_pattern "^etc/init\.d/" \ + "/etc/init.d/* has been found. Please replace by /etc/rc.d/init.d"; then + failed=1 + fi + + # Check for /var/run + if ! check_rootfiles_for_pattern "^var/run/.*" \ + "You cannot ship files in /var/run as it is a ramdisk"; then + failed=1 + fi + + # Check architectures + local arch + for arch in ${ARCHES[@]}; do + check_rootfiles_for_arch "${arch}" || failed=$? + done + + # Return the error + return ${failed} +} + # Set BASEDIR readonly BASEDIR="$(find_base)" @@ -2369,14 +2472,13 @@ build) # Build all packages build_packages - # Check log files - check_logfiles + # Check for missing rootfiles + check_for_missing_rootfiles - print_headline "Checking Logfiles for new Files" - - pushd "${BASEDIR}" &>/dev/null - tools/checkrootfiles - popd &>/dev/null + # Check for rootfile consistency + if ! check_rootfiles; then + exiterror "Rootfiles are inconsistent" + fi print_build_summary $(( SECONDS - START_TIME )) ;; diff --git a/tools/checkrootfiles b/tools/checkrootfiles deleted file mode 100755 index 9437de6f14..0000000000 --- a/tools/checkrootfiles +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash -############################################################################### -# # -# IPFire.org - A linux based firewall # -# Copyright (C) 2007-2023 IPFire Team info@ipfire.org # -# # -# This program 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 3 of the License, or # -# (at your option) any later version. # -# # -# This program 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 this program. If not, see . # -# # -############################################################################### - -# All supported architectures -ARCHES=( - aarch64 - riscv64 - x86_64 -) - -# A list of files that are not scanned -# because they probably cause some false positives. -EXCLUDED_FILES=( - qemu -) - -ARGS=( - # Search path - "config/rootfiles" - - # Exclude old core updates - "--exclude-dir" "oldcore" - - # Ignore the update scripts - "--exclude" "update.sh" -) - -check_for_arch() { - local arch="${1}" - - local args=( - "${ARGS[@]}" - ) - - # Exclude any architecture-specific directories - local a - for a in ${ARCHES[@]}; do - args+=( "--exclude-dir" "${a}" ) - done - - # Exclude all excluded files - local x - for x in ${EXCLUDED_FILES[@]}; do - args+=( "--exclude" "${x}" ) - done - - # Search for all lines that contain the architecture, but exclude commented lines - grep -r "^[^#].*${arch}" "${args[@]}" -} - -check_for_pattern() { - local pattern="${1}" - local message="${2}" - - local args=( - "${ARGS[@]}" - ) - - if grep -r "${pattern}" "${args[@]}"; then - if [ -n "${message}" ]; then - echo "ERROR: ${message}" - else - echo "ERROR: Files matching '${pattern}' have been found in the rootfiles" - fi - return 1 - fi - - return 0 -} - -main() { - local failed=0 - - # Check for /etc/init.d - if ! check_for_pattern "^etc/init\.d/" \ - "/etc/init.d/* has been found. Please replace by /etc/rc.d/init.d"; then - failed=1 - fi - - # Check for /var/run - if ! check_for_pattern "^var/run/.*" \ - "You cannot ship files in /var/run as it is a ramdisk"; then - failed=1 - fi - - # Check architectures - local arch - for arch in ${ARCHES[@]}; do - check_for_arch "${arch}" || failed=$? - done - - # Return the error - return ${failed} -} - -main "$@" || exit $? -- 2.39.5