From f0f298842325f918962791b6a63e69f91f93d7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Sun, 15 Oct 2017 00:01:00 +0200 Subject: [PATCH] Refactoring and pretty printing of information --- NAS_mounts/setup.sh | 18 +++++++++------ fish/setup.sh | 20 ++++++++--------- git/setup.sh | 10 ++++++--- helpers.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++ install.sh | 14 +++++++----- ssh/setup.sh | 10 +++++---- wm/setup.sh | 19 ++++++++-------- 7 files changed, 106 insertions(+), 40 deletions(-) create mode 100644 helpers.sh diff --git a/NAS_mounts/setup.sh b/NAS_mounts/setup.sh index 0bc9820..882affb 100755 --- a/NAS_mounts/setup.sh +++ b/NAS_mounts/setup.sh @@ -1,14 +1,16 @@ #!/usr/bin/env bash +source ${DOTFILES}/helpers.sh + function main() { - if [ ! -d "${HOME}/mnt" ]; then - mkdir "${HOME}/mnt" - mkdir "${HOME}/mnt/music" - mkdir "${HOME}/mnt/photos" - mkdir "${HOME}/mnt/video" - mkdir "${HOME}/mnt/NAS" - fi + print_info "Setting up user homedir mounts" + + makedir "${HOME}/mnt" + makedir "${HOME}/mnt/music" + makedir "${HOME}/mnt/photo" + makedir "${HOME}/mnt/video" + makedir "${HOME}/mnt/NAS" local auto_file="auto_nas_$(whoami)" @@ -73,6 +75,8 @@ function main() sudo launchctl load "${plistloc}" fi + + print_ok "User homedir mounts set up" } main "$@" diff --git a/fish/setup.sh b/fish/setup.sh index b9b68c4..2dcb441 100755 --- a/fish/setup.sh +++ b/fish/setup.sh @@ -1,11 +1,13 @@ #!/usr/bin/env bash +source ${DOTFILES}/helpers.sh + function main() { + print_info "Installing fish shell" + # Install fish shell - if ! brew list | grep fish >/dev/null; then - brew install fish - fi + brewget fish # Add to list of shells and set as default if ! grep /usr/local/bin/fish < /etc/shells >/dev/null; then @@ -14,13 +16,11 @@ function main() fi # Install configuration files - if [ ! -d ${HOME}/.config ]; then - mkdir ${HOME}/.config - fi - if [ ! -e ${HOME}/.config/fish ]; then - rm -rf ${HOME}/.config/fish - ln -s ${DOTFILES}/fish ${HOME}/.config/. - fi + makedir ${HOME}/.config + + linkfile ${DOTFILES}/fish ${HOME}/.config/fish + + print_ok "Fish shell installed" } main "$@" diff --git a/git/setup.sh b/git/setup.sh index c51ddc7..6737220 100755 --- a/git/setup.sh +++ b/git/setup.sh @@ -1,10 +1,12 @@ #!/usr/bin/env bash +source ${DOTFILES}/helpers.sh + function main() { - if ! brew list | grep git >/dev/null; then - brew install git - fi + print_info "Configuring git" + + brewget git if [ ! -f "${HOME}/.gitconfig" ]; then cat << EOF > ${HOME}/.gitconfig @@ -14,6 +16,8 @@ function main() excludesfile = ${DOTFILES}/git/gitignore_global EOF fi + + print_ok "Git configured" } main "$@" diff --git a/helpers.sh b/helpers.sh new file mode 100644 index 0000000..0353736 --- /dev/null +++ b/helpers.sh @@ -0,0 +1,55 @@ + +function print_info() { + echo -e "[\\033[36mINFO\\033[0m] $@" +} +function print_ok() { + echo -e "[\\033[32mOK\\033[0m] $@" +} +function print_warning() { + echo -e "[\\033[33mWARNING\\033[0m] $@" +} +function print_error() { + echo -e "[\\033[32mERROR\\033[0m] $@" +} + +function brewget() +{ + # Install software using homebrew + # if not already installed + local brewname=$(basename $1) + + if ! brew list | grep ${brewname} >/dev/null; then + print_info "Brewing ${brewname}" + brew install "$@" + fi +} +function caskget() +{ + # Install OSX application using homebrew cask + # if not already installed + local caskname=$(basename $1) + + if ! brew cask list | grep ${caskname} >/dev/null; then + print_info "Installing ${caskname} from cask" + brew cask install "$@" + fi +} + +function linkfile() +{ + local source=$1 + local target=$2 + + if [ ! -e ${target} ]; then + print_info "Symlinking ${source} <- ${target}" + rm -rf ${target} + ln -s ${source} ${target} + fi +} +function makedir() +{ + if [ ! -d $@ ]; then + print_info "Making directory $@" + mkdir $@ + fi +} diff --git a/install.sh b/install.sh index 99dd197..5a080cd 100755 --- a/install.sh +++ b/install.sh @@ -15,6 +15,7 @@ function install_homebrew() } + function install_casks() { brew cask install google-chrome @@ -39,10 +40,11 @@ function setup_kitty() } -export DOTFILES=/Users/thomas/dotfiles +DOTFILES=/Users/thomas/dotfiles +DOTFILES="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" -ssh/setup.sh -git/setup.sh -NAS_mounts/setup.sh -fish/setup.sh -wm/setup.sh +${DOTFILES}/ssh/setup.sh +${DOTFILES}/git/setup.sh +${DOTFILES}/NAS_mounts/setup.sh +${DOTFILES}/fish/setup.sh +${DOTFILES}/wm/setup.sh diff --git a/ssh/setup.sh b/ssh/setup.sh index c4c3374..bb1110f 100755 --- a/ssh/setup.sh +++ b/ssh/setup.sh @@ -1,15 +1,17 @@ #!/usr/bin/env bash +source ${DOTFILES}/helpers.sh + function main() { + print_info "Setting up SSH" # copy private key to .ssh # cp ${KEYFILE} ~/.ssh/thomas_rsa # chmod 400 ~/.ssh/thomas_rsa # ssh-add -K ~/.ssh/thomas_rsa - if [ ! -e ${HOME}/.ssh/config ]; then - rm -f ${HOME}/.ssh/config - ln -s ${DOTFILES}/ssh/config ${HOME}/.ssh/config - fi + linkfile ${DOTFILES}/ssh/config ${HOME}/.ssh/config + + print_ok "SSH settings installed" } main "$@" diff --git a/wm/setup.sh b/wm/setup.sh index a92e317..5450d99 100755 --- a/wm/setup.sh +++ b/wm/setup.sh @@ -1,26 +1,25 @@ #!/usr/bin/env bash +source ${DOTFILES}/helpers.sh + function main() { + print_info "Installing window manager" # Install chunkwm and khd - if ! brew list | grep chunkwm >/dev/null; then - brew install crisidev/homebrew-chunkwm/chunkwm - brew install koekeishiya/formulae/khd - fi + brewget crisidev/homebrew-chunkwm/chunkwm + brewget keokeishiya/formulae/khd # Link configuration files - if [ ! -e "${HOME}/.chunkwmrc" ]; then - rm -f "${HOME}/.chunkwmrc" - rm -f "${HOME}/.khdrc" - ln -s ${DOTFILES}/wm/khdrc ${HOME}/.khdrc - ln -s ${DOTFILES}/wm/chunkwmrc ${HOME}/.chunkwmrc - fi + linkfile ${DOTFILES}/wm/khdrc ${HOME}/.khdrc + linkfile ${DOTFILES}/wm/chunkwmrc ${HOME}/.chunkwmrc # Start services if ! brew services list | grep chunkwm >/dev/null; then brew services start khd brew services start chunkwm fi + + print_ok "Window manager installed and activated" } main "$@"