-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·85 lines (67 loc) · 2.46 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
80
81
82
83
84
85
#!/usr/bin/env bash
RED="$(printf '\033[31m')"
CYAN="$(printf '\033[36m')"
GREEN="$(printf '\033[32m')"
WHITE="$(printf '\033[37m')"
ORANGE="$(printf '\033[33m')"
PROJ=UniTeX
CURRENT_DIR=$( pwd )
TAG=$(git describe --tags)
DESTINATION=${INSTALL_DIR:-${1:-${HOME}/.local/share}}
LINK_DIR=${2:-${HOME}/.local/bin/unitex}
# Turn on extended globbing in bash shell
shopt -s extglob
reset_terminal () {
tput sgr0
}
check_rsync () {
if ! type rsync &> /dev/null; then
echo -e "${WHITE}--------------------------\n"
echo -e "${ORANGE}[!] Please install ${WHITE}rsync ${ORANGE}command on your system!"
echo -e "${ORANGE}[!] For MacOS intallation, run ${WHITE}'brew install rsync'}."
echo -e "${ORANGE}[!] For common Linux distribution, run ${WHITE}'apt-get install rsync'."
echo -e "${GREEN} [@] Exiting..."
exit 0
fi
}
build_directory () {
echo -e "${WHITE}\n--------------------------\n"
echo -e "${GREEN}[@] Installing ${WHITE}${PROJ}${GREEN}..."
if [[ -d "${DESTINATION}"/UniTeX ]]; then
# Updating directories
echo -e "${GREEN}[@] Wiping old version if any inside ${WHITE}${DESTINATION}${GREEN}."
rm -rf ${DESTINATION}/${PROJ}
echo -e "${GREEN}[@] Building new dirs inside ${WHITE}${DESTINATION}${GREEN}."
mkdir -p ${DESTINATION}/${PROJ}
else
echo -e "${GREEN}[@] Building dirs inside ${WHITE}${DESTINATION}${GREEN}."
mkdir -p ${DESTINATION}/${PROJ}
fi
}
fill_directory () {
echo -e "${WHITE}\n--------------------------\n"
echo -e "${GREEN}[@] Filling dirs with templates..."
rsync -a --exclude='*.md' --exclude='.*' ${CURRENT_DIR}/ ${DESTINATION}/${PROJ}
# Make scripts executable
chmod +x ${DESTINATION}/${PROJ}/unitex.sh
chmod +x ${DESTINATION}/${PROJ}/uninstall.sh
# Version control
echo "${TAG}" | cut -d '-' -f 1 | tee ${DESTINATION}/${PROJ}/version.txt &> /dev/null
# Create symlink
echo -e "${GREEN}[@] Updating symlink from ${WHITE}${LINK_DIR}${GREEN}."
if [[ -L ${LINK_DIR} ]]; then
rm ${LINK_DIR}
ln -s ${DESTINATION}/${PROJ}/unitex.sh ${LINK_DIR}
else
ln -s ${DESTINATION}/${PROJ}/unitex.sh ${LINK_DIR}
fi
echo -e "${GREEN}[@] ${WHITE}${PROJ}${GREEN} Installed successfully:${WHITE} Execute 'unitex -h' to verify installation."
echo -e "${WHITE}\n--------------------------"
}
main () {
check_rsync
build_directory
fill_directory
reset_terminal
}
main "${@}"