]> git.ipfire.org Git - ipfire-2.x.git/blame - src/scripts/filesystem-cleanup
suricata: Change midstream policy to "pass-flow"
[ipfire-2.x.git] / src / scripts / filesystem-cleanup
CommitLineData
97756e21 1#!/bin/bash
66c36198
PM
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
97756e21
MT
21
22PATHS=(
23 /usr/lib
24 /lib
25)
26
27main() {
1475bc53
DW
28 local dry_run="false"
29
30 while [ $# -gt 0 ]; do
31 case "${1}" in
32 --dry-run)
33 dry_run="true"
34 ;;
35
36 *)
37 echo "${0}: Invalid argument: ${1}" >&2
38 return 2
39 ;;
40 esac
41 shift
42 done
43
97756e21
MT
44 # Update the runtime linker cache (this may fix any broken symlinks)
45 ldconfig
46
47 local path
48 for path in ${PATHS[@]}; do
49 echo "Searching in ${path}..."
50
51 # Find all files called libsomething.so.N
52 local lib
53 for lib in $(find "${path}" -maxdepth 1 -type l -name "lib*.so.*" | sort); do
3358a84f
MT
54 # Ignore some libraries
55 case "${lib}" in
56 */libboost*)
57 continue
58 ;;
59 esac
60
97756e21
MT
61 # Read the name of the linked library
62 local link="$(readlink -m "${lib}")"
63
64 # We have two versioning schemas that we need to distinguish...
65 local files=()
66 case "${link}" in
67 # Libraries called libsomething-N.so
68 */lib*-*.so)
69 files+=( ${link%-*}-* )
70 ;;
71
72 # Libraries called libsomething.so.N.*
73 *)
74 files+=( ${lib}* )
75 ;;
76 esac
77
78 # Remove all files that have the same base name than
79 # the library we are looking at, apart from the symlink
80 # and the linked file itself.
81 local file
82 for file in ${files[@]}; do
83 case "${file}" in
84 # Ignore these files
85 ${lib}|${link})
86 ;;
87
88 *)
1475bc53
DW
89 echo "Removing ${file}..."
90
91 # Actually remove the file (maybe)
8c0ab3d4 92 if [ "${dry_run}" = "false" ]; then
1475bc53
DW
93 unlink "${file}"
94 fi
97756e21
MT
95 ;;
96 esac
97 done
98 done
99 done
100}
101
102main "$@" || exit $?