tikz-trackschematic/dev-install.sh

109 lines
2.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env sh
2022-01-06 20:17:51 +01:00
# Copyright (c) 2018 - 2022, Martin Scheidt (ISC license)
# 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.
# 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
## -- commands
2022-02-09 01:49:11 +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
return 0
fi
2022-02-09 01:49:11 +01:00
echo "Program 'kpsewhich' not found."
echo "Be sure to use texlive or mactex!"
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
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
rootrun="sudo"
else
2022-02-09 01:49:11 +01:00
echo "sudo failed"
# 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
exit 1
fi
fi
}
2022-02-09 01:49:11 +01:00
## -- checking system
check_texlive
check_sudo
TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL)
2022-02-09 01:49:11 +01:00
DEVDIR="tex/latex/tikz-trackschematic-dev"
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
fi
2022-02-09 01:49:11 +01:00
## -- copying files
if [ ! -d "$TEXMFLOCAL/$DEVDIR" ]; then
$rootrun mkdir -p $TEXMFLOCAL/$DEVDIR
fi
2022-02-09 01:49:11 +01:00
for SRC in src/*; do
$rootrun ln -sfn $PROJECTDIR/$SRC $TEXMFLOCAL/$DEVDIR/${SRC##*/}
done
$rootrun $TEXlsr --quiet