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
usage( ) { echo "Usage: dev-install.sh [-q]" ; }
verbose = 1
while getopts ":q" opt; do
case ${ opt } in
q ) verbose = 0
; ;
\? ) usage
exit 1
; ;
esac
done
2021-01-02 14:04:05 +01:00
## -- commands
2022-02-09 01:49:11 +01:00
2021-01-02 14:04:05 +01:00
TEXlsr = ` which mktexlsr`
check_texlive( ) {
# check for kpsewhich
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)
2020-02-10 16:21:48 +01:00
2022-02-09 01:49:11 +01:00
DEVDIR = "tex/latex/tikz-trackschematic-dev"
2020-02-10 16:21:48 +01:00
2021-01-02 14:04:05 +01:00
PROJECTDIR = $( pwd -P)
2022-02-09 01:49:11 +01:00
if [ " $verbose " -eq 1 ] ; then
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
if [ ! -d " $TEXMFLOCAL / $DEVDIR " ] ; then
$rootrun mkdir -p $TEXMFLOCAL /$DEVDIR
fi
2021-01-02 14:04:05 +01:00
2022-02-09 01:49:11 +01:00
for SRC in src/*; do
$rootrun ln -sfn $PROJECTDIR /$SRC $TEXMFLOCAL /$DEVDIR /${ SRC ##*/ }
done
2020-02-10 16:21:48 +01:00
2021-01-02 14:04:05 +01:00
$rootrun $TEXlsr --quiet