From 60188ec5fd700b991d8e114f416a80caa4406969 Mon Sep 17 00:00:00 2001 From: koksnuss Date: Tue, 29 May 2018 16:44:37 +0200 Subject: [PATCH] Add more tests during installation --- install.sh | 136 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 123 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 5fdbac9..d9998ce 100644 --- a/install.sh +++ b/install.sh @@ -1,25 +1,135 @@ #!/bin/bash +# print helper functions for safe output say () { printf %s\\n "$*" ; } +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' RED='\033[0;31m' NOR='\033[0m' -say "${GRE}" -say "::: Installing i3blocks" -say "::: Checking if i3 is installed" -i3 -v &> /dev/null -[[ $? -ne 0 ]] && say "${RED}::: Please install i3 and restart this setup${NOR}\n" && exit 1 -say "::: Checking if i3blocks is installed" -i3blocks -V &> /dev/null -[[ $? -ne 0 ]] && say "${RED}::: Please install i3blocks and restart this setup${NOR}\n" && exit 1 -say "::: Checking if the directory ~/.config/i3blocks already exists" -[[ -d "$HOME/.config/i3blocks" ]] && say "::: Moving ~/.config/i3blocks to ~/.config/i3blocks.bak" && mv "$HOME/.config/i3blocks"{,.bak} >/dev/null 2>/dev/null +green +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 +orange +say "::: Check if 'i3blocks' is installed" +i3blocks -V >/dev/null 2>/dev/null +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 + +##### check if ~/.config/i3blocks already exists is empty +orange +say "::: Check if ~/.config/i3blocks exists" +if [[ -d "$HOME/.config/i3blocks" ]]; then + say "::: Yes, moving to ~/.config/i3blocks.bak" + mv "$HOME/.config/i3blocks"{,.bak} >/dev/null 2>/dev/null + if [[ $? -ne 0 ]]; then + red + say "::: Error during moving. Please move it manually and restart this setup." + normal + exit 1 + else + green + say "::: Done" + fi +fi + + +#### download simple-i3blocks +orange say "::: Downloading simple-i3blocks to ~/.config/i3blocks" git clone https://will.kein.hk/git/koksnuss/simple-i3blocks.git ~/.config/i3blocks &> /dev/null +if [[ $? -ne 0 ]]; then + red + say "::: Error during cloning." + normal + exit 1 +else + green + say "::: Yes, moving on." +fi + +#### masking blocks as executable +say "::: Mask i3-blocks executable" cd "$HOME/.config/i3blocks/modules" -say "::: Masking modules as execulatbles" +if [[ $? -ne 0 ]]; then + red + say "::: Error, could not move to $HOME/.config/i3blocks/modules ." + normal + exit 1 +else + green + say "::: Yes, moving on." +fi chmod u+x audio backlight battery cpu datetime ip ram storage -say "::: Finished, please reload i3. Normally you can do this with the shortcut MOD+SHIFT+R" -say "${NOR}" +if [[ $? -ne 0 ]]; then + red + say "::: Error, could not mask the blocks executable." + normal + exit 1 +else + green + say "::: Yes, moving on." +fi + +##### finish +say "::: Succesfully finished. Please put 'status_command i3blocks' inside the 'bar{ ... }' statement in '.config/i3/config' and reload i3. Normally you can relade 'i3' with the shortcut MOD+SHIFT+R" +normal +exit 0