1
0
mirror of https://github.com/RyanGreenup/cadmus.git synced 2025-01-17 20:58:38 +01:00

Simplified Install Script

This commit is contained in:
Ryan Greenup 2020-07-20 11:30:07 +10:00
parent e003b62746
commit d188e963c9

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
INSTALL_DIR="$HOME/.cadmus"
main () { main () {
me=`basename "$0"` me=`basename "$0"`
@ -6,16 +7,22 @@ main () {
HelpStatement $1 HelpStatement $1
UninstallQ $1 UninstallQ $1
printThis printThis
check_for_dependencies
download_the_repo download_the_repo
Install_tools "S" Install_bin
check_path
check_for_dependencies
}
check_path () {
echo "$PATH" | grep -q '.local/bin' || echo "bin-dir is not in path, you'll need to add it to the path"
} }
function UninstallQ() { function UninstallQ() {
if [ "$1" == "-rm" ] || [ "$1" == "--rm" ]; then if [ "$1" == "-rm" ] || [ "$1" == "--rm" ]; then
echo "Removing with Stow" echo "Removing..."
Install_tools "D" rm "$HOME/.local/bin/cadmus"
rm "${INSTALL_DIR}"
exit 0 exit 0
fi fi
@ -62,27 +69,34 @@ printThis () {
safePrint () { safePrint () {
if hash highlight 2>/dev/null; then if hash highlight 2>/dev/null; then
highlight "$@" highlight "${1}" --syntax=bash --stdout
else else
cat "$@" cat "${1}"
fi fi
} }
check_for_dependencies () { check_for_dependencies () {
echo "Press Any Key to Check for dependencies, press the c Key to Skip this" echo "Missing dependencies will now be printed to STDERR, missing packages to STDOUT"
read -d '' -s -n1 CheckDepQ
if [ "$CheckDepQ" == "c" ]; then ## echo "Press Any Key to Check for dependencies, press the c Key to Skip this"
return ## read -d '' -s -n1 CheckDepQ
fi ## if [ "$CheckDepQ" == "c" ]; then
## return
## fi
##
depLog="$(mktemp)"
for i in ${StringArray[@]}; do for i in ${StringArray[@]}; do
command -v "$i" >/dev/null 2>&1 || { echo >&2 "I require $i but it's not installed. Aborting."; exit 1; } command -v "$i" >/dev/null 2>&1 || { echo >&2 "I require $i but it's not installed. Aborting."; echo $i >> "${depLog}"; }
done done
if [[ $(cat "${depLog}") == "" ]]; then
echo "All Dependencies Satisfied" echo "All Dependencies Satisfied"
else
cat "${depLog}"
fi
} }
download_the_repo () { download_the_repo () {
@ -93,40 +107,37 @@ download_the_repo () {
return return
fi fi
mkdir -p $HOME/DotFiles/ if [[ -d "${INSTALL_DIR}/.git" ]]; then
cd $HOME/DotFiles echo "Detected a cadmus install"
ask_to_remove
if [[ -d ".git" ]]; then
echo "Detected a Git Repo, Press y to add a submodule or any key to exit"
read -d '' -s -n1 CheckDepQ
if [ "$CheckDepQ" != "y" ]; then
echo "You pressed any key"
fi
git submodule add https://github.com/RyanGreenup/cadmus && echo "Submodule succesfully added"
elif [[ -f ".git" ]]; then elif [[ -f ".git" ]]; then
echo "You have a file called .git In there, delete that first."; echo "You have a file called .git In "${INSTALL_DIR}", which was unexpected"
ask_to_remove
else else
git clone https://github.com/RyanGreenup/cadmus git clone https://github.com/RyanGreenup/cadmus "~/.cadmus"
fi fi
echo "Repository is downloaded" echo "Repository is downloaded"
} }
Install_tools () { ask_to_remove () {
echo "press y to remove "${INSTALL_DIR}""
DIR=$(dirname "$0") read -d '' -s -n1 CheckDepQ
cd "$DIR" && cd ../ if [ "$CheckDepQ" != "y" ]; then
echo "Stow package $DIR, target $HOME" rm -rf "${INSTALL_DIR}"
stow -t $HOME -$1 "$(basename "$DIR")" else
exit 1
fi
}
Install_bin() {
ln -s "$HOME/.cadmus/bin/cadmus" "$HOME/.local/bin/"
} }
# Declare an array of string with type # Declare an array of string with type
declare -a StringArray=("R" declare -a StringArray=(
"highlight" "highlight"
"node" "node"
"nvim" "nvim"
@ -140,6 +151,8 @@ declare -a StringArray=("R"
"tmsu" "tmsu"
"ranger" "ranger"
"mdcat" "mdcat"
"jq"
"shift"
"xclip" "xclip"
"sd" "sd"
"fd" "fd"