summaryrefslogtreecommitdiff
path: root/Master/tl-portable
blob: 3d02bbce29f31354c6b5aa1c2999b3893f53fde9 (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
#! /bin/sh
# $Id$
# Copyright 2008 Siep Kroonenberg.
# You may freely use, modify and/or distribute this file.

if test "x$1" = x--help; then
  cat <<END_USAGE
Usage: tl-portable
Start a new subshell with the environment set so TeX Live
can be run with minimal impact on the host, that is,
run more or less directly from DVD or USB.

For more, see the "Maximally portable" section in the TeX Live
documentation (http://tug.org/texlive).
END_USAGE

  exit 0
fi

#calculate TeX Live root
#it appears that dirname isn't always available
TEXDIR0=$0
TEXDIR=${TEXDIR0%/*}
if test "$TEXDIR" = "$TEXDIR0"; then
  TEXDIR="."
fi
unset TEXDIR0

dirsave=`pwd`
cd $TEXDIR
TEXDIR=`pwd`
cd $dirsave

# Test whether the TeX Live directory is writable.  We need an actual
# write test, because network drives aren't always identified
# correctly.  We accept negatives at face value.

if test -w $TEXDIR; then
# make sure $TEXDIR is really writable
testfile=1
  while test -e $TEXDIR/$testfile
    do testfile=`expr $testfile + 1`
  done
  echo Testing whether $TEXDIR is writable...
  touch $TEXDIR/$testfile 2>/dev/null
  if test -e $TEXDIR/$testfile; then
    rm $TEXDIR/$testfile
    echo $TEXDIR is writable.
    TEXDIRW=$TEXDIR
  else
    echo $TEXDIR is not writable.
    TEXDIRW=$HOME/.tlportable2010
  fi
else
  TEXDIRW=$HOME/.tlportable2010
fi
echo Using $TEXDIRW for generated files.

platform=`$TEXDIR/install-tl --print-arch`

if test "$platform" = ""; then
  echo 'Platform unsupported'
  exit 1
elif test ! -d $TEXDIR/bin/$platform; then
  echo 'Platform unsupported'
  exit 1
fi

if test "$TEXDIR" = "$TEXDIRW"; then 
  TEXMFCNF=$TEXDIRW
else
  TEXMFCNF=$TEXDIRW/texmf-var/web2c
  export TEXMFCNF
fi

if test ! -r $TEXMFCNF/texmf.cnf; then
  TEXLIVE_INSTALL_PREFIX=$TEXDIRW
  export TEXLIVE_INSTALL_PREFIX
  if $TEXDIR/install-tl --portable --from_dvd --profile /dev/null; then :; else
    echo "$0: Initialization of TeX Live for portable use failed!" >&2
    exit 1
  fi
  unset TEXLIVE_INSTALL_PREFIX
fi
  
# Try to block initialization scripts.
# Set custom prompt for secondary shell, but
# I know of no good way to do this for the C shell.

ENV=/dev/null
export ENV
PATH=$TEXDIR/bin/$platform:$PATH
export PATH
if test "$SHELL" = /bin/bash; then
  PS1='TL \w\$ '
  export PS1
  exec $SHELL --norc -i
elif test "$SHELL" = /bin/zsh; then
  PS1='TL %d%% '
  export PS1
  exec $SHELL -f -i
elif test "$SHELL" = /bin/csh; then
  exec $SHELL -f -i
elif test "$SHELL" = /bin/tcsh; then
  exec $SHELL -f -i
else
  PS1='TL $PWD\$ '
  export PS1
  exec $SHELL -f -i
fi