1
0
mirror of https://github.com/RyanGreenup/cadmus.git synced 2025-01-17 12:48:35 +01:00
cadmus/install.sh

205 lines
5.0 KiB
Bash
Raw Normal View History

2020-07-13 02:29:58 +10:00
#!/usr/bin/env bash
2020-07-20 11:30:07 +10:00
INSTALL_DIR="$HOME/.cadmus"
2020-07-20 13:28:12 +10:00
BIN_DIR="$HOME/.local/bin/"
mkdir "${BIN_DIR} > /dev/null
2020-07-13 02:29:58 +10:00
2020-07-13 02:52:33 +10:00
main () {
2020-07-12 21:51:51 +10:00
me=`basename "$0"`
HelpStatement $1
UninstallQ $1
2020-07-12 22:16:24 +10:00
printThis
download_the_repo
2020-07-20 11:30:07 +10:00
Install_bin
check_path
check_for_dependencies
2020-07-20 13:28:12 +10:00
echo -e "\nInstallation Complete \n"
2020-07-20 11:30:07 +10:00
}
check_path () {
echo "$PATH" | grep -q '.local/bin' || echo "bin-dir is not in path, you'll need to add it to the path"
2020-07-12 21:51:51 +10:00
}
function UninstallQ() {
if [ "$1" == "-rm" ] || [ "$1" == "--rm" ]; then
2020-07-20 11:30:07 +10:00
echo "Removing..."
rm "$HOME/.local/bin/cadmus"
rm "${INSTALL_DIR}"
2020-07-12 21:54:41 +10:00
exit 0
2020-07-12 21:51:51 +10:00
fi
}
HelpStatement() {
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
2020-07-20 13:28:12 +10:00
echo -e "To uninstall do `basename $0` --rm ,
2020-07-12 21:51:51 +10:00
If you are on Arch stow 2.3.1-2 is broken, downgrade with
\e[1;35m
sudo pacman -U https://archive.archlinux.org/packages/s/stow/stow-2.2.2-5-any.pkg.tar.xz
\e[0m
See this for more information:
\e[1;34m
https://github.com/aspiers/stow/issues/65
\e[0m
"
fi
2020-07-13 02:29:58 +10:00
}
2020-07-13 02:52:33 +10:00
printThis () {
echo "This Script will print to the terminal for review, press any key to continue"
read -d '' -s -n1
cd $(dirname "$0")
pwd
me=`basename "$0"`
safePrint $me
2020-07-20 13:28:12 +10:00
echo -e "\nAre you happy to proceed? Press y to continue \n"
2020-07-13 02:52:33 +10:00
read -d '' -s -n1 proceedQ
if [ "$proceedQ" != "y" ]; then
2020-07-12 20:19:34 +10:00
exit 0
2020-07-13 02:52:33 +10:00
fi
}
safePrint () {
if hash highlight 2>/dev/null; then
2020-07-20 11:30:07 +10:00
highlight "${1}" --syntax=bash --stdout
2020-07-13 02:52:33 +10:00
else
2020-07-20 11:30:07 +10:00
cat "${1}"
2020-07-13 02:52:33 +10:00
fi
}
check_for_dependencies () {
2020-07-13 02:29:58 +10:00
2020-07-20 11:30:07 +10:00
## echo "Press Any Key to Check for dependencies, press the c Key to Skip this"
## read -d '' -s -n1 CheckDepQ
## if [ "$CheckDepQ" == "c" ]; then
## return
## fi
##
depLog="$(mktemp)"
2020-07-13 02:29:58 +10:00
for i in ${StringArray[@]}; do
2020-07-20 13:28:12 +10:00
command -v "$i" >/dev/null 2>&1 || { echo $i >> "${depLog}"; }
2020-07-13 02:29:58 +10:00
done
2020-07-20 11:30:07 +10:00
if [[ $(cat "${depLog}") == "" ]]; then
2020-07-20 13:28:12 +10:00
echo -e "\nAll Dependencies Satisfied\n"
2020-07-20 11:30:07 +10:00
else
2020-07-20 13:28:12 +10:00
echo -e "\e[1;31m \nMissing the Following Dependencies \e[0m \n"
echo -e " \e[1;31m -------------------------\e[0m "
echo -e "\e[1;32m \n"
addBullets "$(cat "${depLog}")"
echo -e "\e[0m \n"
echo -e "They are listed in \e[1;34m "${depLog}" \e[0m \n"
2020-07-20 11:30:07 +10:00
fi
2020-07-13 02:29:58 +10:00
}
2020-07-20 13:28:12 +10:00
addBullets() {
command -v sed >/dev/null 2>&1 || { echo >&2 "I require sed but it's not installed. Aborting."; exit 1; }
echo "$1" | sed 's/^/\t‣\ /g'
}
2020-07-13 02:52:33 +10:00
download_the_repo () {
2020-07-13 02:29:58 +10:00
2020-07-20 13:28:12 +10:00
if [[ -d "${INSTALL_DIR}" ]]; then
echo -e "Detected a cadmus install"
if [ -f "${INSTALL_DIR}/config.json" ]; then
oldConfigFile="$(mktemp)" && cat "${INSTALL_DIR}/config.json" > "${oldConfigFile}"
echo -e "\n\tConfig File Backed up for later restore\n"
fi
2020-07-13 02:29:58 +10:00
2020-07-20 11:30:07 +10:00
ask_to_remove
2020-07-20 13:28:12 +10:00
download_the_repo
return
2020-07-13 02:29:58 +10:00
else
2020-07-20 13:28:12 +10:00
git clone https://github.com/RyanGreenup/cadmus "$HOME/.cadmus"
2020-07-13 02:29:58 +10:00
fi
2020-07-20 13:28:12 +10:00
echo -e "Repository is downloaded\n\n"
2020-07-13 06:09:57 +10:00
2020-07-20 13:28:12 +10:00
if [[ "$CheckDepQ" == "y" ]] && [[ -f "${oldConfigFile}" ]]; then
echo -e "Press y to restore the old config or any other key to continue otherwise\n"
read -d '' -s -n1 CheckDepQ
cp "${oldConfigFile}" "${INSTALL_DIR}/config.json"
2020-07-20 13:37:56 +10:00
echo -e "Config Successfully restored"
2020-07-20 13:28:12 +10:00
fi
2020-07-13 02:29:58 +10:00
}
2020-07-20 11:30:07 +10:00
ask_to_remove () {
echo "press y to remove "${INSTALL_DIR}""
read -d '' -s -n1 CheckDepQ
2020-07-20 13:28:12 +10:00
if [ "$CheckDepQ" == "y" ]; then
2020-07-20 11:30:07 +10:00
rm -rf "${INSTALL_DIR}"
else
exit 1
fi
}
2020-07-12 21:51:51 +10:00
2020-07-20 11:30:07 +10:00
Install_bin() {
2020-07-20 13:28:12 +10:00
if [ -f "${BIN_DIR}/cadmus" ]; then
echo -e "The executable \e[1;32m "${BIN_DIR}"/cadmus \e[0m already exists, it must be replaced, press y to continue or any key to exit"
read -d '' -s -n1 CheckDepQ
if [ "$CheckDepQ" == "y" ]; then
rm "${BIN_DIR}/cadmus"
else
exit 1
fi
Install_bin
else
ln -s "$HOME/.cadmus/bin/cadmus" "$HOME/.local/bin/" && echo -e "\nSuccessfully created symlink from $HOME/.cadmus/bin/cadmus to $HOME/.local/bin/ \n"
fi
2020-07-13 06:09:57 +10:00
}
2020-07-13 02:29:58 +10:00
# Declare an array of string with type
2020-07-20 11:30:07 +10:00
declare -a StringArray=(
2020-07-13 02:29:58 +10:00
"highlight"
2020-07-13 02:52:33 +10:00
"node"
"nvim"
"fzf"
"code"
"sk"
"rg"
"perl"
2020-07-20 13:28:12 +10:00
"tectonic"
2020-07-13 02:52:33 +10:00
"stow"
"python"
"tmsu"
"ranger"
"mdcat"
2020-07-20 11:30:07 +10:00
"jq"
"shift"
2020-07-20 13:42:05 +10:00
"ip"
2020-07-13 02:52:33 +10:00
"xclip"
"sd"
"fd"
"sed"
"cut"
"grep"
"find"
"realpath"
2020-07-13 02:29:58 +10:00
)
# Iterate the string array using for loop
##
2020-07-12 21:51:51 +10:00
main "$@"
2020-07-13 02:29:58 +10:00
exit 0
2020-07-12 21:51:51 +10:00
2020-07-12 22:16:24 +10:00
## DONE Help
## DONE Uninstall