]> git.ipfire.org Git - ipfire-2.x.git/blame - src/scripts/filesystem-cleanup
filesystem-cleanup: Add parameter to show changes
[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
56 # Read the name of the linked library
57 local link="$(readlink -m "${lib}")"
58
59 # We have two versioning schemas that we need to distinguish...
60 local files=()
61 case "${link}" in
62 # Libraries called libsomething-N.so
63 */lib*-*.so)
64 files+=( ${link%-*}-* )
65 ;;
66
67 # Libraries called libsomething.so.N.*
68 *)
69 files+=( ${lib}* )
70 ;;
71 esac
72
73 # Remove all files that have the same base name than
74 # the library we are looking at, apart from the symlink
75 # and the linked file itself.
76 local file
77 for file in ${files[@]}; do
78 case "${file}" in
79 # Ignore these files
80 ${lib}|${link})
81 ;;
82
83 *)
1475bc53
DW
84 echo "Removing ${file}..."
85
86 # Actually remove the file (maybe)
87 if [ "${dry_run}" = "false" ]; then
88 unlink "${file}"
89 fi
97756e21
MT
90 ;;
91 esac
92 done
93 done
94 done
95}
96
97main "$@" || exit $?