summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-update-bindir
blob: 9f0fd5bed5dd8e0df281354ce2206b373df963a6 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/bin/sh
# Public domain.  Originally written 2008, Karl Berry.
# Update a TeX Live Master/bin/PLATFORM directory.

vc_id='$Id$'
unset CDPATH
unset GREP_OPTIONS
unset LS_COLORS

tmpdir=${TMPDIR-/tmp}/tlupbin.$$
trap "rm -rf $tmpdir" 0 1 2 15
test -d $tmpdir || mkdir -p $tmpdir

usage="$0 [OPTION]... TL-PLATFORM...

Update the TeX Live executables for each TL-PLATFORM (which must be a TL
platform name, e.g., i386-linux) from a build directory.

The new binaries are taken from the location specified by --bin-loc,
either a directory (whose contents are copied), or a tar file (which is
unpacked and then copied).

The output directory is computed relative to the location of this script
by default, or can be explicitly specified via --master.  An upper-level
directory is specified so multiple platforms can be installed.

This checks for broken symlinks, and symlinks with the svn:executable
property set (which would mess up Subversion; see the thread around
http://svn.haxx.se/users/archive-2007-03/1259.shtml.)

It also takes care of doing the explicit remove/add sequence Subversion
requires when a symlink is replaced by a file or vice versa.

Options:
  --bin-loc DIR-OR-TAR   use binaries from DIR-OR-TAR
  --master  DIR          install binaries to DIR/bin/TL-PLATFORM
                           [default is the bin dir relative to this script]

  --help                 display this help and exit
  --quiet, --silent      no progress reports
  --version              output version information and exit

For more information about building TeX Live, see
http://tug.org/texlive/build.html.

Report bugs to tlbuild@tug.org."

# parse options.
bin_loc=
download=wget
msg=echo
tlplats=
while test $# -gt 0; do
  case $1 in
  --help|-help|-v) echo "$usage"; exit 0;;
  --version|-version|-v) echo "$vc_id"; exit 0;;
  --quiet|-quiet|-q|--silent|-silent|-s) msg=true;;

  --master) shift; Master=$1;;
  --bin-loc) shift; bin_loc=$1;;

  --no-download|-N) download=true;; # secret option for karl

  --*) echo "$0: unrecognized option \`$1'; try --help if you need it." >&2
       exit 1;;

  *) tlplats="$tlplats $1";;
  esac
  shift
done

if test -z "$tlplats"; then
  echo "$0: missing TL platform name; try --help if you need it." >&2
  exit 1
fi

if test -z "$Master"; then
  mydir=`dirname $0`
  Master=`cd $mydir/../.. && pwd`
fi
if test ! -d "$Master/bin"; then
  echo "$0: Master directory $Master has no bin/ subdir; goodbye." >&2
  exit 1
fi

# loop through tl platform names
for tlplat in $tlplats; do
  destdir=$Master/bin/$tlplat
  if test ! -d $destdir; then
    echo "$0: unrecognized platform name \`$tlplat'" >&2
    echo "$0: (no directory $destdir)" >&2
    exit 1
  fi
  
  # karl update convenience
  default_bin_loc=
  download_loc=$tmpdir/tl.$tlplat.tar.gz
  grab="$download -O $download_loc"
  if test x"$USER" = xkarl; then
   case $tlplat in 
   aarch64-linux)
    default_bin_loc=$download_loc
    $grab https://faubox.rrze.uni-erlangen.de/open/MjdwNXE5NW5UcTU4RzVIWlRVUVVI/tl2018/xz/texlive_bin_aarch64-linux.tar.xz;;
   alpha-linux)
    default_bin_loc=/home/preining/alpha-linux.tar.gz;;
   amd64-freebsd)
    download_loc=$tmpdir/tl.$tlplat.tar.xz
    default_bin_loc=$download_loc
    grab="$download -O $download_loc"
    $grab http://anthesphoria.net/FreeBSD/TeXLive-Devel/amd64-freebsd7.tar.xz;;
   amd64-kfreebsd)
    download_loc=$tmpdir/tl.$tlplat.tar.xz
    default_bin_loc=$download_loc
    grab="$download -O $download_loc"
    $grab ftp://ftp.cea.fr/incoming/y2k01/braslau/x86_64-unknown-kfreebsd9.0-gnu.tar.xz;;
   amd64-netbsd)
    download_loc=$tmpdir/tl.$tlplat.tar.xz
    default_bin_loc=$download_loc
    grab="$download -O $download_loc"
    $grab http://www.babafou.eu.org/texlive-netbsd/x86_64-netbsd.tar.xz;;
   armel-linux)
    default_bin_loc=$download_loc
    $grab http://boris.lk.net/texlive-2013/armv7l-unknown-linux-gnueabi.tgz;;
   armhf-linux)
    default_bin_loc=$download_loc
    $grab http://getthingsfixed.co.uk/texlive/builds/2018/texlive-armhf.tar.gz;;
   hppa-hpux)
    default_bin_loc=$download_loc
    $grab http://www.jtartlabs.com/test/hppa2.0-hp-hpux10.20.tar.gz;;
   i386-cygwin)
    default_bin_loc=$download_loc
    $grab http://sanibeltranquility.com/cygwin/$tlplat.tgz;;
   i386-darwin)
    default_bin_loc=$download_loc
    $grab http://dl.contextgarden.net/build/texlive/$tlplat.tar.xz;;
   i386-freebsd)
    download_loc=$tmpdir/tl.$tlplat.tar.xz
    default_bin_loc=$download_loc
    grab="$download -O $download_loc"
    $grab http://anthesphoria.net/FreeBSD/TeXLive-Devel/i386-freebsd7.tar.xz;;
   i386-kfreebsd)
    download_loc=$tmpdir/tl.$tlplat.tar.xz
    default_bin_loc=$download_loc
    grab="$download -O $download_loc"
    $grab ftp://ftp.cea.fr/incoming/y2k01/braslau/i386-unknown-kfreebsd10.0-gnu.tar.xz;;
   i386-linux)
    #default_bin_loc=/tmp/lin32.tgz;;
    default_bin_loc=$download_loc
    $grab http://dl.contextgarden.net/build/texlive/$tlplat.tar.xz;;
   i386-linuxmusl)
    default_bin_loc=$download_loc
    remurl=`curl -s https://api.github.com/repos/TeX-Live/texlive-source/releases/latest | grep browser_download_url | grep texlive-bin-i386-musl.tar.gz | cut -d : -f 2,3 | tr -d \"`
    $grab $remurl;;
   i386-netbsd)
    download_loc=$tmpdir/tl.$tlplat.tar.xz
    default_bin_loc=$download_loc
    grab="$download -O $download_loc"
    $grab http://www.babafou.eu.org/texlive-netbsd/i386-netbsd.tar.xz;;
   i386-openbsd)
    default_bin_loc=$download_loc
    $grab http://students.dec.bmth.ac.uk/ebarrett/files/tl-bin-20080810.tgz;;
   i386-solaris)
    default_bin_loc=$download_loc
    $grab http://dl.contextgarden.net/build/texlive/$tlplat.tar.xz;;
   mips-irix)
    download_loc=$tmpdir/tl.$tlplat.tar.xz
    default_bin_loc=$download_loc
    grab="$download -O $download_loc"
    $grab http://www.solid.ethz.ch/download/texlive/texlive-mips-irix.tar.xz;;
   mipsel-linux)
    echo "see mojca" >&2; exit 1;;
   powerpc-darwin)
    default_bin_loc=$download_loc
    $grab http://dl.contextgarden.net/build/texlive/$tlplat.tar.xz;;
   powerpc-linux)
    default_bin_loc=/home/tschmitz/powerpc-linux.tar.xz;;
   sparc-solaris)
    default_bin_loc=$download_loc
    $grab http://dl.contextgarden.net/build/texlive/$tlplat.tar.xz;;
   win32)
    # default_bin_loc=$tmpdir/tl.$tlplat.zip
    # $grab http://members2.jcom.home.ne.jp/wt1357ak/tl2009w32-02.zip;;
    ;; # updated by Akira.
   x86_64-cygwin)
    default_bin_loc=$download_loc
    $grab http://sanibeltranquility.com/cygwin/$tlplat.tgz;;
   x86_64-darwin)
    default_bin_loc=/home/koch/$tlplat.tar.xz;;
   x86_64-darwinlegacy)
    default_bin_loc=$download_loc
    $grab http://dl.contextgarden.net/build/texlive/$tlplat.tar.xz;;
   x86_64-linux)
    default_bin_loc=$download_loc
    remurl=`curl -s https://api.github.com/repos/TeX-Live/texlive-source/releases/latest | grep browser_download_url | grep texlive-bin-x86_64-linux.tar.gz | cut -d : -f 2,3 | tr -d \"`
    $grab $remurl;;
   x86_64-linuxmusl)
    default_bin_loc=$download_loc
    remurl=`curl -s https://api.github.com/repos/TeX-Live/texlive-source/releases/latest | grep browser_download_url | grep texlive-bin-x86_64-musl.tar.gz | cut -d : -f 2,3 | tr -d \"`
    $grab $remurl;;
   x86_64-solaris)
    default_bin_loc=$download_loc
    $grab http://dl.contextgarden.net/build/texlive/$tlplat.tar.xz;;
   esac
  fi
  
  # 
  test -z "$bin_loc" && test -n "$default_bin_loc" \
  && bin_loc=$default_bin_loc
  if test -z "$bin_loc"; then
    echo "$0: missing binary location, try --help if you need it." >&2
    exit 1
  fi

  $msg "installing from $bin_loc to $destdir via $tmpdir"
  ls -ld "$bin_loc"

  # if we were given a tar file, unpack it.
  if test -f "$bin_loc"; then
    srcdir=$tmpdir/unpacked
    mkdir $srcdir
    if echo "$bin_loc" | grep 'zip$' >/dev/null; then
      (cd $srcdir && unzip -q $bin_loc) || exit 1
    else
      (cd $srcdir && tar xf $bin_loc) || exit 1
    fi
    
  elif test -d "$bin_loc"; then
    srcdir=$bin_loc  # already have a directory

  else
    echo "$0: strange non-file non-directory binary location $bin_loc" >&2
    exit 1
  fi
  
  # in case people mistakenly include .svn dirs in their tars.
  find "$srcdir" -name .svn | xargs rm -rf
  
  # ditto, biber.
  find "$srcdir" -name biber\* | xargs rm -f

  # may need to cd into a subdirectory, depending on how the tar was made.
  while test `ls $srcdir | wc -l` = 1; do
    srcdir=$srcdir/*
  done
  
  # destdir is what is in the repo now, srcdir has the new binaries.
  (cd $destdir && ls) >$tmpdir/now  
  (cd $srcdir && ls)  >$tmpdir/new

  ourdel=$tmpdir/2del
  ouradd=$tmpdir/2add
    # looking for deletions, but don't delete (x)asy, biber, xindy.
  comm -23 $tmpdir/now $tmpdir/new \
  | egrep -v '^(x?asy(\.exe)?|freeglut\.dll)$' \
  | egrep -v '^biber(\.exe)?$' \
  | egrep -v '^dvisvgm$' \
  | egrep -v 'xindy' \
  >$ourdel  # intentionally anything matching xindy
  comm -13 $tmpdir/now $tmpdir/new >$ouradd  # looking for additions

  # get symlink list.
  (cd $destdir && find . -type l | sort) >$tmpdir/now.symlink
  (cd $srcdir && find . -type l | sort) >$tmpdir/new.symlink

  cd $destdir || exit 1

  # svn requires separate delete/add operations when symlinks change to
  # regular files or vice versa.
  #
  # remove symlinks which have become files.
  comm -23 $tmpdir/now.symlink $tmpdir/new.symlink >$tmpdir/s.now
  replaced_symlinks=
  for sl in `cat $tmpdir/s.now`; do
    test -f $srcdir/$sl && replaced_symlinks="$replaced_symlinks $sl"
  done
  test -n "$replaced_symlinks" \
  && $msg "removing symlinks which have become files..." \
  && svn rm $replaced_symlinks
  #
  # remove files which have become symlinks.
  comm -13 $tmpdir/now.symlink $tmpdir/new.symlink >$tmpdir/s.new
  replaced_files=
  for sl in `cat $tmpdir/s.new`; do
    test -f $destdir/$sl && replaced_files="$replaced_files $sl"
  done
  test -n "$replaced_files" \
  && $msg "removing files which have become symlinks..." \
  && svn rm $replaced_files

  # the bulk copy.
  $msg "copying from $srcdir"
  $msg "to $destdir"
  (cd $srcdir && tar cf - *) | tar xf -

  # the normal deletions and additions.
  $msg "removing old..."
  test -s $ourdel && svn rm `cat $ourdel`
  $msg "adding new..."
  test -s $ouradd && svn add `cat $ouradd`

  # anything which is no longer a symlink but still exists
  # needs to be added.
  test -n "$replaced_symlinks" \
  && $msg "adding files that replaced symlinks..." \
  && svn add $replaced_symlinks
  
  # anything which is now a symlink but didn't used to be
  # also needs to be added.
  test -n "$replaced_files" \
  && $msg "adding symlinks that replaced files..." \
  && svn add $replaced_files

  # be sure the svn:executable property is not set on any symlink.
  # there is also a pre-commit hook on the repo, but of course we don't
  # want to unnecessarily trigger it.
  # We redirect stderr to /dev/null because as of svn 1.9.3 (or earlier?),
  # svn gives a useless warning when the property is not set.
  badlinks=`svn propget svn:executable \`cat $tmpdir/new.symlink\` 2>/dev/null\
            | awk '{print $1}'`
  if test -n "$badlinks"; then
    $msg "removing svn:executable property from symlinks..."
    svn propdel svn:executable $badlinks
  fi
  
  # revert xindy.mem (always changes) unless xindy.run changes.
  if svn status xindy.run | grep '^M' >/dev/null \
     || svn status xindy-lisp.exe | grep '^M' >/dev/null; then
    :
  elif test -r xindy.run || test -r xindy-lisp.exe; then
    $msg "reverting xindy.mem..."
    svn revert xindy*.mem
  fi
  
  # check for broken symlinks.
  for sl in `cat $tmpdir/new.symlink`; do
    test ! -r "$sl" && echo "$0: broken new symlink $sl" >&2
  done
  
  # final results.
  $msg "final svn status..."
  svn status | sort

  rm -rf $tmpdir
done