2020-02-10 18:01:40 +01:00
#!/usr/bin/env sh
2020-02-10 16:21:48 +01:00
2022-01-06 20:17:51 +01:00
# Copyright (c) 2018 - 2022, Martin Scheidt (ISC license)
2021-01-02 14:04:05 +01:00
# Permission to use, copy, modify, and/or distribute this file for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
2020-02-10 16:21:48 +01:00
2021-01-02 14:04:05 +01:00
# Halt on error
set -e
2022-02-09 01:49:11 +01:00
## -- pass getopts
2022-02-09 14:09:41 +01:00
usage( ) { echo "Usage: dev-install.sh [-q] [-b]" ; }
2022-02-09 01:49:11 +01:00
verbose = 1
2022-02-09 14:09:41 +01:00
batch_mode = 0
2022-02-09 01:49:11 +01:00
2022-02-09 14:09:41 +01:00
while getopts ":qb" opt; do
2022-02-09 01:49:11 +01:00
case ${ opt } in
q ) verbose = 0
; ;
2022-02-09 14:09:41 +01:00
b ) batch_mode = 1
verbose = 0
; ;
2022-02-09 01:49:11 +01:00
\? ) usage
exit 1
; ;
esac
done
2021-01-02 14:04:05 +01:00
2022-02-09 17:25:15 +01:00
## -- variables
2022-02-09 01:49:11 +01:00
2022-02-09 17:25:15 +01:00
# destination folder inside the TeX Live installation
DEVDIR = "tex/latex/local/tikz-trackschematic-dev"
## -- commands
2021-01-02 14:04:05 +01:00
2022-02-09 17:25:15 +01:00
# check for kpsewhich (and mktexlsr)
2021-01-02 14:04:05 +01:00
check_texlive( ) {
status = 0
command -v kpsewhich >/dev/null 2>& 1 || status = 1
if [ $status = 0 ] ; then
2022-02-09 01:49:11 +01:00
if [ " $verbose " -eq 1 ] ; then
echo "kpsewhich found"
fi
2021-01-02 14:04:05 +01:00
return 0
fi
2022-02-09 01:49:11 +01:00
echo "Program 'kpsewhich' not found."
echo "Be sure to use texlive or mactex!"
2021-01-02 14:04:05 +01:00
exit 1
}
# checks if sudo is available
check_sudo( ) {
rootrun = ""
# If we are root, we do note require sudo
if [ " $EUID " = 0 ] ; then
2022-02-09 01:49:11 +01:00
if [ " $verbose " -eq 1 ] ; then
echo "you are root"
fi
2021-01-02 14:04:05 +01:00
return 0
fi
if sudo -v >/dev/null 2>& 1; then
2022-02-09 01:49:11 +01:00
if [ " $verbose " -eq 1 ] ; then
echo "sudo ok"
fi
2021-01-02 14:04:05 +01:00
rootrun = "sudo"
else
2022-02-09 01:49:11 +01:00
echo "sudo failed"
2021-01-02 14:04:05 +01:00
# Check if user is root (might be unnecessary)
if ! [ $( id -u) = 0 ] ; then
2022-02-09 01:49:11 +01:00
echo "This script must be run as root" 1>& 2
2021-01-02 14:04:05 +01:00
exit 1
fi
fi
}
2022-02-09 01:49:11 +01:00
## -- checking system
2021-01-02 14:04:05 +01:00
check_texlive
check_sudo
TEXMFLOCAL = $( kpsewhich --var-value TEXMFLOCAL)
PROJECTDIR = $( pwd -P)
2022-02-09 14:09:41 +01:00
if [ " $batch_mode " -eq 0 ] ; then
2022-02-09 01:49:11 +01:00
echo ""
echo "Do you wish to link this package from"
echo " $PROJECTDIR /src to "
echo " $TEXMFLOCAL / $DEVDIR ? "
echo "(y/n)"
while true; do
read -p "" answer
case $answer in
[ Yy] * ) break; ;
[ Nn] * ) exit 1; ;
* ) echo "Please answer yes or no." ; ;
esac
done
2021-01-02 14:04:05 +01:00
fi
2022-02-09 01:49:11 +01:00
## -- copying files
2022-02-09 17:25:15 +01:00
# make sure that destination folder exists
2022-02-09 01:49:11 +01:00
if [ ! -d " $TEXMFLOCAL / $DEVDIR " ] ; then
$rootrun mkdir -p $TEXMFLOCAL /$DEVDIR
fi
2021-01-02 14:04:05 +01:00
2022-02-09 17:25:15 +01:00
# copy every file in src/ and rename it
2022-02-09 01:49:11 +01:00
for SRC in src/*; do
2022-02-09 17:25:15 +01:00
FILE = $( basename " $SRC " ) # remove path
NAME = ${ FILE %.* } # remove extension
PREFIX = ${ NAME %%.* }
POSTFIX = ${ NAME #*. }
EXT = ${ SRC ##*. }
if [ " $PREFIX " = " $POSTFIX " ] ; then
DST = " $PREFIX -dev. $EXT "
else
DST = " $PREFIX -dev. $POSTFIX . $EXT "
fi
$rootrun ln -sfn $PROJECTDIR /$SRC $TEXMFLOCAL /$DEVDIR /$DST
if [ " $verbose " -eq 1 ] ; then
echo " linked ' $DST ' "
fi
2022-02-09 01:49:11 +01:00
done
2020-02-10 16:21:48 +01:00
2022-02-09 17:25:15 +01:00
# update TeX Live installation
TEXlsr = ` which mktexlsr`
if [ " $verbose " -eq 1 ] ; then
$rootrun $TEXlsr
else
$rootrun $TEXlsr --quiet
fi