File: install.sh

package info (click to toggle)
manpages-pl 1%3A0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 22,276 kB
  • ctags: 7
  • sloc: sh: 112; makefile: 59; perl: 32
file content (127 lines) | stat: -rw-r--r-- 2,726 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# vim:et:ts=2:sw=2
# Based on script from Debian manpages package

set -e
set -o nounset
shopt -s nullglob

if [ "$#" != 1 ]; then
  echo "Usage: $0 /path/to/install/dir" 1>&2
  exit 1
fi

MANROOT=$1
SYMLINKS=""

install_symlink()
{
  local lsect="$1"
  local lpage="$2"
  local ltarget="$3"
  local tgtmustexist="$4"
  SYMLINKS="$1/$2 $SYMLINKS"
  if [ "${ltarget%/*}" = "$lsect" ]; then
    ltarget=${ltarget#*/}
  elif [ "${ltarget%/*}" != "${ltarget#*/}" ]; then
    ltarget=../$ltarget
  fi
  if [ "$tgtmustexist" = "Y" ] && [ ! -e "$MANROOT/$lsect/$ltarget" ] ; then
    echo -n "(skipped)"
  else
    echo -n "(symlinked)"
    ln -sf "$ltarget" "$MANROOT/$lsect/$lpage"
  fi
}


for dir in man[1-8n] generated/man[1-8]; do
  echo "-- Processing directory $dir"
  sect=${dir#generated/}

  [ -d $MANROOT/$sect ] || mkdir -p -m 755 $MANROOT/$sect

  for page in $dir/*.[1-8n]*; do
    page=${page##*/}
    echo -n "$page"
    Y=`head -n 1 "$dir/$page"`
    case "$Y" in
    .so*)
      Y="${Y#.so }"
      install_symlink "$sect" "$page" "$Y" "N"
      ;;
    *)
      install -p -m 644 "$dir/$page" "$MANROOT/$sect"
      ;;
    esac
    echo -n " "
  done
        echo
done
echo "-- Adding upstream symlinks:"
for file in *.links; do
  while read target page; do
  target="${target%.gz}"
  page="${page%.gz}"
  sect="${page%/*}"
  page="${page##*/}"
  echo -n "$page"
  install_symlink $sect $page $target "Y"
  echo -n " "
   done < $file
done
echo

echo "-- Moving and removing manpages:"
while read manpg old_s new_s; do
  # skip comments and empty lines
  if [ \( "X${manpg}" != "X" \) -a \( "X${manpg:0:1}" != "X#" \) ] ; then

    old_f="$MANROOT/man${old_s:0:1}/$manpg.$old_s"
    new_f="$MANROOT/man${new_s:0:1}/$manpg.$new_s"

    echo -n "$manpg.$old_s"
    if [ -e "$old_f" ] ; then
      if [ "X$new_s" = "X" ] ; then
        echo -n "(removed)"
      else
        if [ "x$old_f" = "x$new_f" ]; then
          mv "$old_f" "$old_f.tmp"
          old_f="$old_f.tmp"
        fi

        perl -pe '$i+= s;^(\.TH\s+\S+\s+)\S+(\s+.*);${1}'"${new_s}"'${2};gi unless $i>0' \
          < "$old_f" > "$new_f"

        touch -r "$old_f" "$new_f"

        if [ "x$old_s" = "x$new_s" ]; then
          cmp -s "$old_f" "$new_f" \
           && echo -n "(entry ignored)" || echo -n "(corrected .TH line)"
        else
          echo -n "(moved to section $new_s)"
        fi
      fi

      rm -f "$old_f"

    else
      echo -n "(not found!)"
    fi
    echo -n " "
  fi
done < debian/move.list
echo

echo "-- Removing dangling symlinks:"
for i in $SYMLINKS; do
  i="$MANROOT/$i"
  if [ -L "$i" -a ! -e "$i" ]; then
    echo -n "${i##*/}(removed) "
    rm -f "$i"
  fi
done
echo
rm -f debian/tmp.stamp

echo