From 62fdf8689cb356824dd94b9c48e3a1af8356c6a1 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 9 Jan 2019 11:25:29 +0100 Subject: [PATCH] Initial commit --- LICENSE | 2 +- README.md | 1 + tforgione.sh | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100755 tforgione.sh diff --git a/LICENSE b/LICENSE index 8015026..33b2c95 100644 --- a/LICENSE +++ b/LICENSE @@ -602,7 +602,7 @@ Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - Copyright (C) +tforgione.sh Copyright (C) 2019 Thomas Forgione This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. diff --git a/README.md b/README.md index c428a92..7656895 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # sh.tforgione.fr +A small script to install zsh and its dependencies, and setup my config files. diff --git a/tforgione.sh b/tforgione.sh new file mode 100755 index 0000000..58cff49 --- /dev/null +++ b/tforgione.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash + +# This script installs the default things for having a stylish zsh +user_shell=`getent passwd $USER | cut -f7 -d:` + +echo_green() { + echo -e '\033[32;1m'$@'\033[0m' +} + +echo_green_n() { + echo -en '\033[32;1m'$@'\033[0m' +} + +echo_yellow() { + echo -e '\033[33;1m'$@'\033[0m' +} + +echo_yellow_n() { + echo -en '\033[33;1m'$@'\033[0m' +} + +echo_red() { + echo -e '\033[31;1m'$@'\033[0m' +} + +echo_red_n() { + echo -en '\033[31;1m'$@'\033[0m' +} + +test_command() { + command -v $1 > /dev/null 2>&1 +} + +yes_no_ask() { + echo_green_n $1 "[Y/n]" + read -n 1 answer + echo_green + if ! [[ "$answer" == "Y" ]] && ! [[ "$answer" == "y" ]] && ! [[ "$anwser" == "" ]] + then + echo_green "Can't continue..." + exit 1 + fi +} + +configure_zsh() { + + test_command git + if [ $? -ne 0 ] + then + yes_no_ask "You'll need git for this, do you wish to install git ?" + sudo apt install git + fi + + test_command zsh + if [ $? -ne 0 ] + then + yes_no_ask "This magnificent prompt is based on zsh, do you wish to install zsh ?" + sudo apt install zsh + fi + + mkdir -p $HOME/.config + if [ ! -d $HOME/.config/oh-my-zsh ] + then + echo_green "Cloning oh-my-zsh" + git clone https://github.com/robbyrussell/oh-my-zsh/ $HOME/.config/oh-my-zsh + fi + + if [ ! -d $HOME/.config/dotfiles ] + then + echo_green "Cloning tforgione's dotfiles..." + git clone https://github.com/tforgione/dotfiles/ $HOME/.config/dotfiles + fi + + should_make_link=0 + if [ -f "$HOME/.zshrc" ] + then + path1=`realpath $HOME/.zshrc` + path2=`realpath $HOME/.config/dotfiles/zshrc` + if [ "$path1" == "$path2" ] + then + should_make_link=1 + fi + fi + + if [ $should_make_link -eq 0 ] + then + if [ -f `realpath $HOME/.zshrc` ] + then + echo_green "Warning: you already have a zshrc, it will be moved to ~/.zshrc.bak" + mv $HOME/.zshrc $HOME/.zshrc.bak + fi + echo_green "Linking zshrc" + ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc + fi + + chsh_executed=0 + + if [ ! "$user_shell" == "/bin/zsh" ] + then + echo_green "Changing user's default shell..." + chsh $user -s /bin/zsh + chsh_executed=1 + fi + + if [ $chsh_executed -eq 1 ] + then + echo_green "chsh was executed, you might need to log-out and log-in to finalize the changes." + echo_green "Everything else has been configured. Have a good day!" + else + echo_green "Everything has been configured. Have a good day!" + fi +} + +configure_zsh < /dev/tty +