]> git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/filesystem-cleanup
d4cdfe8d3e464d6f71fad31f8e399475d9b3ea0f
[ipfire-2.x.git] / src / scripts / filesystem-cleanup
1 #!/bin/bash
2 ############################################################################
3 # #
4 # This file is part of the IPFire Firewall. #
5 # #
6 # IPFire is free software; you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation; either version 2 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # IPFire is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with IPFire; if not, write to the Free Software #
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
19 # #
20 # Copyright (C) 2020 IPFire Team <info@ipfire.org>. #
21 # #
22 ############################################################################
23
24 PATHS=(
25 /usr/lib
26 /lib
27 )
28
29 main() {
30 # Update the runtime linker cache (this may fix any broken symlinks)
31 ldconfig
32
33 local path
34 for path in ${PATHS[@]}; do
35 echo "Searching in ${path}..."
36
37 # Find all files called libsomething.so.N
38 local lib
39 for lib in $(find "${path}" -maxdepth 1 -type l -name "lib*.so.*" | sort); do
40 # Read the name of the linked library
41 local link="$(readlink -m "${lib}")"
42
43 # We have two versioning schemas that we need to distinguish...
44 local files=()
45 case "${link}" in
46 # Libraries called libsomething-N.so
47 */lib*-*.so)
48 files+=( ${link%-*}-* )
49 ;;
50
51 # Libraries called libsomething.so.N.*
52 *)
53 files+=( ${lib}* )
54 ;;
55 esac
56
57 # Remove all files that have the same base name than
58 # the library we are looking at, apart from the symlink
59 # and the linked file itself.
60 local file
61 for file in ${files[@]}; do
62 case "${file}" in
63 # Ignore these files
64 ${lib}|${link})
65 ;;
66
67 *)
68 unlink "${file}"
69 ;;
70 esac
71 done
72 done
73 done
74 }
75
76 main "$@" || exit $?