]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blame - src/scripts/filesystem-cleanup
Merge branch 'temp-c165-development' into next
[people/mfischer/ipfire-2.x.git] / src / scripts / filesystem-cleanup
CommitLineData
97756e21
MT
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
24PATHS=(
25 /usr/lib
26 /lib
27)
28
29main() {
1475bc53
DW
30 local dry_run="false"
31
32 while [ $# -gt 0 ]; do
33 case "${1}" in
34 --dry-run)
35 dry_run="true"
36 ;;
37
38 *)
39 echo "${0}: Invalid argument: ${1}" >&2
40 return 2
41 ;;
42 esac
43 shift
44 done
45
97756e21
MT
46 # Update the runtime linker cache (this may fix any broken symlinks)
47 ldconfig
48
49 local path
50 for path in ${PATHS[@]}; do
51 echo "Searching in ${path}..."
52
53 # Find all files called libsomething.so.N
54 local lib
55 for lib in $(find "${path}" -maxdepth 1 -type l -name "lib*.so.*" | sort); do
3358a84f
MT
56 # Ignore some libraries
57 case "${lib}" in
58 */libboost*)
59 continue
60 ;;
61 esac
62
97756e21
MT
63 # Read the name of the linked library
64 local link="$(readlink -m "${lib}")"
65
66 # We have two versioning schemas that we need to distinguish...
67 local files=()
68 case "${link}" in
69 # Libraries called libsomething-N.so
70 */lib*-*.so)
71 files+=( ${link%-*}-* )
72 ;;
73
74 # Libraries called libsomething.so.N.*
75 *)
76 files+=( ${lib}* )
77 ;;
78 esac
79
80 # Remove all files that have the same base name than
81 # the library we are looking at, apart from the symlink
82 # and the linked file itself.
83 local file
84 for file in ${files[@]}; do
85 case "${file}" in
86 # Ignore these files
87 ${lib}|${link})
88 ;;
89
90 *)
1475bc53
DW
91 echo "Removing ${file}..."
92
93 # Actually remove the file (maybe)
8c0ab3d4 94 if [ "${dry_run}" = "false" ]; then
1475bc53
DW
95 unlink "${file}"
96 fi
97756e21
MT
97 ;;
98 esac
99 done
100 done
101 done
102}
103
104main "$@" || exit $?