X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=blobdiff_plain;f=tools%2Fcheckrootfiles;h=d11ab8d5ebc0e0d32f360b983e130f903b023eaa;hp=7b996d48054162baa46d173612482bb254f36e53;hb=HEAD;hpb=30b3b2cde7d1698228550e509b4b87e080943890 diff --git a/tools/checkrootfiles b/tools/checkrootfiles index 7b996d4805..9437de6f14 100755 --- a/tools/checkrootfiles +++ b/tools/checkrootfiles @@ -2,7 +2,7 @@ ############################################################################### # # # IPFire.org - A linux based firewall # -# Copyright (C) 2007-2015 IPFire Team info@ipfire.org # +# 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 # @@ -19,44 +19,96 @@ # # ############################################################################### -grep -r "^etc/init.d//*" ./config/rootfiles/ >/dev/null 2>&1 -if [ "${?}" == "0" ]; then - echo "Error! 'etc/init.d/...' in rootfiles files found!" - grep -r "^etc/init.d//*" ./config/rootfiles/ - echo "Change this to 'etc/rc.d/init.d/...' !" -fi - -grep -r "^var/run//*" ./config/rootfiles/ >/dev/null 2>&1 -if [ "${?}" == "0" ]; then - echo "Error! 'var/run/...' in rootfiles files found!" - grep -r "^var/run//*" ./config/rootfiles/ - echo "Comment this and create it at initskript if needed !" -fi - -grep -r '/i586' ./config/rootfiles/ --exclude gcc --exclude-dir oldcore --exclude-dir i586 >/dev/null 2>&1 -if [ "${?}" == "0" ]; then - echo "Error! '/i586' in rootfiles files found!" - grep -r '/i586' ./config/rootfiles/ --exclude gcc --exclude-dir oldcore --exclude-dir i586 - echo "Replace by MACHINE !" -fi - -grep -r '/x86_64' ./config/rootfiles/ --exclude gcc --exclude *linux* --exclude-dir oldcore --exclude-dir x86_64 >/dev/null 2>&1 -if [ "${?}" == "0" ]; then - echo "Error! '/x86_64' in rootfiles files found!" - grep -r '/x86_64' ./config/rootfiles/ --exclude gcc --exclude *linux* --exclude-dir oldcore --exclude-dir x86_64 - echo "Replace by MACHINE !" -fi - -grep -r '/armv5tel' ./config/rootfiles/ --exclude gcc --exclude-dir oldcore --exclude-dir armv5tel >/dev/null 2>&1 -if [ "${?}" == "0" ]; then - echo "Error! '/armv5tel' in rootfiles files found!" - grep -r '/armv5tel' ./config/rootfiles/ --exclude gcc --exclude-dir oldcore --exclude-dir armv5tel - echo "Replace by MACHINE !" -fi - -grep -r '/aarch64' ./config/rootfiles/ --exclude gcc --exclude-dir oldcore --exclude-dir aarch64 >/dev/null 2>&1 -if [ "${?}" == "0" ]; then - echo "Error! '/aarch64' in rootfiles files found!" - grep -r '/aarch64' ./config/rootfiles/ --exclude gcc --exclude-dir oldcore --exclude-dir aarch64 - echo "Replace by MACHINE !" -fi +# 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 $?