summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-fix-container-links
blob: 8c488f777fb3b2f30e058457230c481b05fa0426 (plain)
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
#!/bin/sh
# $Id$
# Public domain. Originally written 2019, Karl Berry.
#
# Make TL containers (in $1[/archive] || cwd) that are regular files
# into symlinks. That is, if we have foo.tar.xz as a regular file, look
# inside it for the revision number NNN, and move it (and
# foo.{doc,src}.tar.xz if they exist) to foo[.src,doc].rNNN.tar.xz, and
# leave symlinks behind.
#
# We needed to do this for TL20 to make all packages into symlinks to
# such versioned containers. Packages which had been updated since Nov 27
# or so were already versioned, but time to make it happen universally.
# No need to change the revision numbers.
# 
# We're not going to worry about quoting filename arguments.
# All our package names are simple strings, by design.

verbose=echo

if test -d "$1"; then
  cd "$1" || exit 1
  test -d archive && { cd archive || exit 1; }
fi

tmpdir=/tmp/fixtmp
rm -rf $tmpdir
mkdir $tmpdir || exit 1

getrev () {
  tarfile=$1
  test -s $tarfile || { echo "$0: empty tar file: $tarfile" >&2; exit 1; }
  #
  # let accumulate, for fun? rm -rf $tmpdir/*
  # only need/want tlpobj file, so just extract that:
  tar -C $tmpdir -xf $tarfile tlpkg/tlpobj || exit 1
  #
  # make sure we have it:
  name_without_tar=`echo $tarfile | sed 's/\.tar\.xz$//'`
  objfile=$tmpdir/tlpkg/tlpobj/$name_without_tar.tlpobj
  test -s $objfile || { echo "$0: empty tlpobj file: $objfile" >&2; exit 1; }  
  #
  rev=`awk '$1=="revision" {print $2}' $objfile`
  if echo "$rev" | egrep '^[0-9]+$' >/dev/null; then :; else
    echo "$0: goodbye, revision $rev not numeric in: $objfile" >&2
    exit 1
  fi
  echo $rev
}

linkit () {
  what=$1
  name=$2
  if test -h $name; then
    $verbose "$name: $what symlink, skipping."
  else
    #echo "$name: linking $what"
    rev=`getrev $name`
    if echo "$rev" | egrep '^[0-9]+$' >/dev/null; then :; else
      echo "$name: goodbye, revision not numeric: $rev" >&2
      exit 1
    fi
    #echo "got rev $rev"
    name_without_tar=`echo $name | sed 's/\.tar\.xz$//'`
    versioned_name=$name_without_tar.r$rev.tar.xz
    mv $name $versioned_name || exit 1
    ln -sv $versioned_name $name || exit 1
    #exit 0
  fi
}

if test ! -h texlive.infra.tar.xz; then
  # this can't be the right place.
  echo "$0: texlive.infra.tar.xz is not a link, goodbye." >&2
  exit 1
fi

for f in *; do
  if echo $f | egrep '^[^.]+(\.(doc|source))?\.tar\.xz$' >/dev/null; then
    # foo.tar.xz | foo.{doc,sourc}.tar.xz
    linkit pkg $f
  
  elif echo $f | egrep '^[^.]+(\.[^.]+)?\.r[0-9]+\.tar\.xz$' >/dev/null; then
    # foo.rNNN.tar.xz | foo.{doc,source,ARCH}.rNNN.tar.xz
    $verbose "$f: versioned, skipping."

  elif echo $f \
       | egrep '^(texlive\.infra|wintools\.windows).*\.tar\.xz$' >/dev/null; then
    # texlive.infra and wintools.windows special cases, maybe with arches.
    # some are already linked, but not all.
    if echo $f | egrep '\.r[0-9]+\.' >/dev/null; then
      $verbose "$f: versioned special, skipped."
    else
      linkit special $f
    fi

  elif echo $f | egrep '^[^.]+\.[^.]+\.tar\.xz$' >/dev/null; then
    # foo.ARCH.tar.xz
    linkit arch $f
  
  else
    echo "$f: unknown" >&2
  fi
done