]> git.ipfire.org Git - people/stevee/pakfire.git/blob - src/scripts/check-symlinks
51e067e2cefc78d87b239a93e51546d488d2ec0c
[people/stevee/pakfire.git] / src / scripts / check-symlinks
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2021 Pakfire development team #
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 ###############################################################################
21
22 error() {
23 echo "$@" >&2
24 }
25
26 main() {
27 local buildroot="${1}"
28 shift
29
30 # Check if BUILDROOT exists
31 if [ ! -d "${buildroot}" ]; then
32 error "BUILDROOT does not exist"
33 return 1
34 fi
35
36 local broken_links=()
37
38 local file
39 for file in $(find "${buildroot}" -type l); do
40 if [ ! -e "${file}" ]; then
41 broken_links+=( "${file}" )
42 fi
43 done
44
45 if [ "${#broken_links[@]}" -gt 0 ]; then
46 error "The following broken symlinks have been found:"
47
48 local link
49 for link in ${broken_links[@]}; do
50 error " ${link/${buildroot}/} -> $(readlink "${link}")"
51 done
52
53 return 1
54 fi
55
56 return 0
57 }
58
59 main "$@" || exit $?