-
Notifications
You must be signed in to change notification settings - Fork 45
/
install.sh
executable file
·79 lines (70 loc) · 2.05 KB
/
install.sh
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
#!/bin/sh
FILE_FOLDER=`dirname $0`;
FILE_NAME=`basename $0`;
SUDO="";
message() {
TYPE="$1";
MESSAGE="$2";
if [ "${TYPE}" = "ERROR" ]; then
echo "${TYPE}: ${MESSAGE}" 1>&2;
elif [ "${TYPE}" = "EMERR" ]; then
echo "${MESSAGE}" 1>&2;
else
echo "${TYPE}: ${MESSAGE}";
fi
}
# Choose an installation folder
if [ "$#" -gt "1" ]; then
message "ERROR" "Unhandled number of arguments passed to script.";
exit 1;
elif [ "$#" -eq "1" ]; then
BASE_FOLDER="$1";
echo "using custom folder: ${BASE_FOLDER}";
else
TEX_FOLDER="/usr/share/texmf-texlive";
BASE_FOLDER="/usr/local/share/texmf";
if [ ! -d "${TEX_FOLDER}" ]; then
TEX_FOLDER="/Library/TeX";
BASE_FOLDER="${HOME}/Library/texmf";
fi
if [ ! -d "${TEX_FOLDER}" ]; then
TEX_FOLDER="/usr/local/texlive";
BASE_FOLDER="${TEX_FOLDER}";
fi
if [ ! -d "${TEX_FOLDER}" ]; then
message "ERROR" "Could not find a LaTeX installation folder, you're likely running an unhandled LaTeX distribution.";
exit 1;
fi
fi
# Check that base folder exists
if [ ! -w "$BASE_FOLDER" ]; then
message "ERROR" "Directory `${BASE_FOLDER}` does not exist.";
exit 1;
fi
# Detect the package updater
HASH_UPDATER=`which texhash`;
if [ "${HASH_UPDATER}" = "" ]; then
message "ERROR" "The system is using an unknown TeX hash updating application.";
exit 1;
fi
INSTALL_LTX_FOLDER="${BASE_FOLDER}/tex/latex/jabbrv";
INSTALL_BST_FOLDER="${BASE_FOLDER}/bibtex/bst/jabbrv";
# Make sure the user has the appropriate permissions
if [ ! -w "$BASE_FOLDER" ]; then
SUDO="sudo";
SUDO_TEST=`$SUDO -n echo "test" 2> /dev/null`;
if [ "${SUDO_TEST}" != "test" ]; then
message "ERROR" "Super user permissions are required to continue; instead run:";
message "EMERR" "$SUDO ./${FILE_NAME}";
exit 1;
fi
fi
# Copy installation files
FOLDER=`cd ${FILE_FOLDER}/; pwd`;
$SUDO mkdir -p "${INSTALL_LTX_FOLDER}";
$SUDO mkdir -p "${INSTALL_BST_FOLDER}";
$SUDO cp "${FOLDER}/"*.sty "${INSTALL_LTX_FOLDER}/";
$SUDO cp "${FOLDER}/"*.ldf "${INSTALL_LTX_FOLDER}/";
$SUDO cp "${FOLDER}/"*.bst "${INSTALL_BST_FOLDER}/";
# Update the package list
sudo ${HASH_UPDATER};