Skip to content

Commit

Permalink
Update installation localisation
Browse files Browse the repository at this point in the history
  • Loading branch information
BCarnaval committed Jun 22, 2024
1 parent 70a2864 commit 2a70893
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 56 deletions.
54 changes: 13 additions & 41 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ ORANGE="$(printf '\033[33m')"

PROJ=UniTeX
CURRENT_DIR=$( pwd )
CONFIG=~/.config/latexmk
TAG=$(git describe --tags)
DESTINATION=/usr/local/share
LINK_DIR=/usr/local/bin/unitex
# DESTINATION=/usr/local/share
# LINK_DIR=/usr/local/bin/unitex
DESTINATION=${HOME}/.local/share
LINK_DIR=${HOME}/.local/bin/unitex

# Turn on extended globbing in bash shell
shopt -s extglob
Expand All @@ -31,34 +32,6 @@ check_rsync () {
fi
}

use_viewer () {
if command -v zathura &> /dev/null; then
echo -e "${WHITE}--------------------------\n"
echo -e "${GREEN}[@] This pdf viewer has been found on your system: \n${WHITE}$(zathura -v)"

if ! grep -s -e "\$ pdf_previewer = 'zathura';" ${CONFIG}/latexmkrc &> /dev/null; then
while true; do
read -p "${GREEN}[@] Do you want to use this viewer as default while compiling templates? [y/n]" yn
case $yn in
[Yy]*)
mkdir -p ${CONFIG}
echo -n "" > ${CONFIG}/latexmkrc
echo "\$ pdf_previewer = 'zathura';" >> ${CONFIG}/latexmkrc
break
;;
[Nn]*)
break
;;
*)
echo -e "${ORANGE}[!] Please answer yes or no."
;;
esac
done
fi

fi
}

build_directory () {
echo -e "${WHITE}\n--------------------------\n"
echo -e "${GREEN}[@] Installing ${WHITE}${PROJ}${GREEN}..."
Expand All @@ -67,36 +40,36 @@ build_directory () {

# Updating directories
echo -e "${GREEN}[@] Wiping old version if any inside ${WHITE}${DESTINATION}${GREEN}."
sudo rm -rf ${DESTINATION}/${PROJ}
rm -rf ${DESTINATION}/${PROJ}

echo -e "${GREEN}[@] Building new dirs inside ${WHITE}${DESTINATION}${GREEN}."
sudo mkdir -p ${DESTINATION}/${PROJ}
mkdir -p ${DESTINATION}/${PROJ}
else
echo -e "${GREEN}[@] Building dirs inside ${WHITE}${DESTINATION}${GREEN}."
sudo mkdir -p ${DESTINATION}/${PROJ}
mkdir -p ${DESTINATION}/${PROJ}
fi
}

fill_directory () {
echo -e "${WHITE}\n--------------------------\n"
echo -e "${GREEN}[@] Filling dirs with templates..."

sudo rsync -a --exclude='*.md' --exclude='.*' ${CURRENT_DIR}/ ${DESTINATION}/${PROJ}
rsync -a --exclude='*.md' --exclude='.*' ${CURRENT_DIR}/ ${DESTINATION}/${PROJ}

# Make scripts executable
sudo chmod +x ${DESTINATION}/${PROJ}/unitex.sh
sudo chmod +x ${DESTINATION}/${PROJ}/uninstall.sh
chmod +x ${DESTINATION}/${PROJ}/unitex.sh
chmod +x ${DESTINATION}/${PROJ}/uninstall.sh

# Version control
echo "${TAG}" | cut -d '-' -f 1 | sudo tee ${DESTINATION}/${PROJ}/version.txt &> /dev/null

# Create symlink
echo -e "${GREEN}[@] Updating symlink from ${WHITE}${LINK_DIR}${GREEN}."
if [[ -L ${LINK_DIR} ]]; then
sudo rm ${LINK_DIR}
sudo ln -s ${DESTINATION}/${PROJ}/unitex.sh ${LINK_DIR}
rm ${LINK_DIR}
ln -s ${DESTINATION}/${PROJ}/unitex.sh ${LINK_DIR}
else
sudo ln -s ${DESTINATION}/${PROJ}/unitex.sh ${LINK_DIR}
ln -s ${DESTINATION}/${PROJ}/unitex.sh ${LINK_DIR}
fi

echo -e "${GREEN}[@] ${WHITE}${PROJ}${GREEN} Installed successfully:${WHITE} Execute 'unitex -h' to verify installation."
Expand All @@ -105,7 +78,6 @@ fill_directory () {

main () {
check_rsync
use_viewer
build_directory
fill_directory
reset_terminal
Expand Down
19 changes: 5 additions & 14 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,36 @@ WHITE="$(printf '\033[37m')"
ORANGE="$(printf '\033[33m')"

PROJ=UniTeX
CONFIG=~/.config/latexmk
DESTINATION=/usr/local/share
# DESTINATION=/usr/local/share
DESTINATION=${HOME}/.local/share

reset_terminal () {
tput sgr0
}

rm_config () {
echo -e "${WHITE}--------------------------\n"
echo -e "${ORANGE}[!] Uninstalling ${WHITE}configs (commands, pdf viewer, etc.) ${ORANGE}..."

# remove zathura from latexmk config file
sed "/\$ pdf_previewer = 'zathura';/d" ${CONFIG}/latexmkrc > ${CONFIG}/latexmkrc
}

rm_directory () {
echo -e "${WHITE}\n--------------------------\n"
echo -e "${ORANGE}[!] Uninstalling ${WHITE}${PROJ}${ORANGE}..."

if [[ -d ${DESTINATION}/${PROJ} ]]; then
echo -e "${ORANGE}[!] Removing dirs from ${WHITE}${DESTINATION}${ORANGE}."
sudo rm -rf ${DESTINATION}/${PROJ}
rm -rf ${DESTINATION}/${PROJ}
fi
}

rm_symlink() {
echo -e "${WHITE}\n--------------------------\n"

if [[ -L /usr/local/bin/unitex ]]; then
if [[ -L ${HOME}/.local/bin/unitex ]]; then
echo -e "${ORANGE}[!] Destroying ${WHITE}'unitex' ${ORANGE}symlink."
sudo rm /usr/local/bin/unitex
rm ${HOME}/.local/bin/unitex
fi

echo -e "${GREEN}[@] ${WHITE}${PROJ}${GREEN} Uninstalled successfully${WHITE}."
echo -e "${WHITE}\n--------------------------"
}

main () {
rm_config
rm_directory
rm_symlink
reset_terminal
Expand Down
2 changes: 1 addition & 1 deletion unitex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BLUE="$(printf '\033[34m')"
BOLD="$(printf '\033[1m')"
REG="$(printf '\033[0m')"

PROJ_DIR=/usr/local/share/UniTeX
PROJ_DIR=${HOME}/.local/share/UniTeX

reset_terminal () {
tput sgr0
Expand Down

0 comments on commit 2a70893

Please sign in to comment.