Debian Codegraph @

upstream/fedora-44/move-manpages.sh

raw
1 #!/bin/sh
2 #
3 # Copyright © 2018 Dr. Tobias Quathamer <[email protected]>
4 # 2025 Dr. Helge Kreutzmann <[email protected]>
5 #
6 # This program 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 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18
19 for mandir in tmp/usr/share/man/man*; do
20 section=$(echo $mandir | cut -d/ -f5)
21 # Only copy directories with files
22 files=$(ls $mandir)
23 if [ -n "$files" ]; then
24 # Remove manpages which are links, add them to links.txt
25 for manpage in $mandir/*; do
26 existing=$(readlink $manpage)
27 if [ -n "$existing" ]; then
28 # Is this a link outside? Then ignore
29 outside=$(dirname $existing | grep "\.\.\/\.\.\/")
30 if [ -n "$outside" ]; then
31 echo "Detected unsual file system layout ($outside,$existing) for $manpage"
32 else
33 linked_section=$(basename $existing .gz | sed -e "s/.\+\.//")
34 echo man$linked_section/$(basename $existing) $section/$(basename $manpage) >> links.txt
35 rm $manpage
36 fi
37 fi
38 done
39 # See if there are regular files left
40 files=$(ls $mandir)
41 if [ -n "$files" ]; then
42 mkdir tmp/$section
43 # Copy remaining manpages
44 cp $mandir/* tmp/$section
45 gzip -d tmp/$section/*
46 # Remove manpages which contain only .so links
47 for manpage in tmp/$section/*; do
48 existing=$(grep "^\.so" $manpage | sed -e "s/^\.so //")
49 if [ -n "$existing" ]; then
50 echo $existing.gz $section/$(basename $manpage).gz >> links.txt
51 rm $manpage
52 fi
53 done
54 # Copy remaining manpages
55 cp tmp/$section/* $section
56 fi
57 fi
58 done