refractor create check function

This commit is contained in:
koksnuss 2018-05-29 18:04:27 +02:00
parent 60188ec5fd
commit 4b9d064b32

View File

@ -1,79 +1,47 @@
#!/bin/bash #!/bin/bash
# print helper functions for safe output # print helper functions for safe output
say () { printf %s\\n "$*" ; } say () { printf %s\\n "$*" ; }
sayn () { printf %s "$*" ; } sayn () { printf %s "$*" ; }
## colors
# use ANSI escape codes
normal () { printf '\033[0m' ; }
black () { printf '\033[0;30m' ; }
red () { printf '\033[0;31m' ; }
green () { printf '\033[0;32m' ; }
brown () { printf '\033[0;33m' ; }
orange () { printf '\033[0;33m' ; }
blue () { printf '\033[0;34m' ; }
purple () { printf '\033[0;35m' ; }
cyan () { printf '\033[0;36m' ; }
gray () { printf '\033[0;37m' ; }
grey () { printf '\033[1;30m' ; }
lred () { printf '\033[1;31m' ; }
lgreen () { printf '\033[1;32m' ; }
yellow () { printf '\033[1;33m' ; }
lblue () { printf '\033[1;34m' ; }
lpurple (){ printf '\033[1;35m' ; }
lcyan () { printf '\033[1;36m' ; }
white () { printf '\033[1;37m' ; }
GRE='\033[0;32m' # colors, use ANSI escape codes
RED='\033[0;31m' normal () { printf '\033[0m'; }
NOR='\033[0m' red () { printf '\033[0;31m'; }
green () { printf '\033[0;32m'; }
orange () { printf '\033[0;33m'; }
# check function
check () {
orange
say "::: Check if, $1 is installed"
whereis $1 >/dev/null 2>/dev/null
if [[ $? -ne 0 ]]; then
red
say "::: Error, $1 is not installed. Please install it and restart the setup."
normal
exit 1
else
green
say "::: $1 is installed, moving on"
normal
fi
}
##### MAIN BEGINN
green green
say "::: Installing i3blocks:" say "::: Installing i3blocks"
##### check if i3 is installed
orange
say "::: Check if 'i3' is installed"
i3 -v >/dev/null 2>/dev/null
if [[ $? -ne 0 ]]; then
red
say "::: Nope, please install 'i3' and restart this setup."
normal
exit 1
else
green
say "::: Yes, moving on."
fi
##### check if i3blocks is installed ##### check if neccessary dependencies are installed
orange check i3
say "::: Check if 'i3blocks' is installed" check i3blocks
i3blocks -V >/dev/null 2>/dev/null check git
if [[ $? -ne 0 ]]; then
red
say "::: Nope, please install 'i3blocks' and restart this setup."
normal
exit 1
else
green
say "::: Yes, moving on."
fi
##### check if git is installed
orange
say "::: Check if 'git' is installed"
git --version >/dev/null 2>/dev/null
if [[ $? -ne 0 ]]; then
red
say "::: Nope, please install 'git' and restart this setup."
normal
exit 1
else
green
say "::: Yes, moving on."
fi
exit 0
##### check if ~/.config/i3blocks already exists is empty ##### check if ~/.config/i3blocks already exists is empty
orange orange
say "::: Check if ~/.config/i3blocks exists" say "::: Check if ~/.config/i3blocks exists"