diff --git a/install.sh b/install.sh index 1d4850d..02e8322 100755 --- a/install.sh +++ b/install.sh @@ -2,6 +2,80 @@ set -e +function print_help() { + echo "usage .home/update.sh [-g/--gnome] [-h/--help] [-v/--berbose] [-d/--dry] + +Installs and updates shared configuration on a system. Options are: + + -h/--help : print this help + -g/--gnome : system is intended to run in a GNOME environement, and + will setup gnome-terminal accordingly. Do not + activate on headless system. + -v/--verbose : prints command before running them + -n/--dry : dry run, do not execute commands. Implies --verbose. +" +} + +function exit_error() { + print_help + exit 1 +} + + +GNOME=false +VERBOSE=false +DRY=false + +function set_gnome_on() { + GNOME=true +} +function set_verbose_on() { + VERBOSE=true +} + +function set_dry_on() { + DRY=true + VERBOSE=true +} + +while getopts "vnhg-:" optchar +do + case "${optchar}" in + -) + case "${OPTARG}" in + gnome) + set_gnome_on + ;; + verbose) + set_verbose_on + ;; + dry) + set_dry_on + ;; + *) + echo "invalid argument --${OPTARG}" + exit_error + ;; + esac;; + h) + print_help + exit 0 + ;; + g) + set_gnome_on + ;; + n) + set_dry_on + ;; + v) + set_verbose_on + ;; + *) + exit_error + ;; + esac +done + files=".config/fish \ .config/git \ @@ -12,16 +86,44 @@ files=".config/fish \ .tmux.conf.local" + + function this_script_root_dir() { dirname $(realpath ${BASH_SOURCE[0]}) } function run() { -# echo "$@" - $@ + if $VERBOSE + then + echo "[$@]" + fi + if ! $DRY + then + $@ + fi } +function run_git() { + if $VERBOSE + then + echo "[git $@] in $(this_script_root_dir)" + fi + if ! $DRY + then + pushd $(this_script_root_dir) 1>/dev/null + if $VERBOSE + then + git $@ + else + git $@ 1>/dev/null + fi + popd 1>/dev/null + fi +} + + function load_gnome_terminal_profiles() { + echo "--- Installing GNOME terminal profile" if which dconf 1>/dev/null then run dconf load /org/gnome/terminal/legacy/profiles:/ < $(this_script_root_dir)/gnome-terminal-profiles.dconf @@ -29,64 +131,68 @@ function load_gnome_terminal_profiles() { } function use_fish() { + echo "--- Ensuring fish is current shell" if ! which fish 1>/dev/null then - echo "Installing fish" + echo "+++ Installing fish" run sudo apt-get install -y fish else - echo "Fish is installed" + echo "+++ Fish is installed" fi fish=$(which fish) current_shell=$(grep $USER /etc/passwd | cut -d ":" -f 7) if [ $current_shell != $fish ] then - echo "Changing shell to $fish (you will be prompted for passwd)" + echo "+++ Changing shell to $fish (you will be prompted for passwd)" run chsh -s $fish else - echo "Default shell is $fish" + echo "+++ Default shell is $fish" fi } function use_direnv() { + echo "--- Ensuring direnv is installed" if ! which direnv 1>/dev/null then - echo "Installing direnv" + echo "++ Installing direnv" run sudo apt-get install -y direnv else - echo "direnv is installed" + echo "+++ direnv is installed" fi } function use_starship() { + echo "--- Ensuring starship is installed" if ! which starship 1>/dev/null then - echo "Installing starship" + echo "+++ Installing starship" run curl -sS https://starship.rs/install.sh | sh else - echo "Starship is installed" + echo "+++ Starship is installed" fi } function install_ubuntu_mono_nerd() { + echo "--- Ensuring UbuntuMono Nerd font is present" if ! fc-list | grep "UbuntuMono Nerd" 1>/dev/null then pushd /tmp run wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/UbuntuMono.zip run unzip UbuntuMono.zip run mkdir -p ~/.local/share/fonts - cp *.ttf ~/.local/share/fonts/ + run cp *.ttf ~/.local/share/fonts/ run fc-cache -f popd else - echo "UbuntuMono Nerd font is installed" + echo "+++ UbuntuMono Nerd font is installed" fi if [ ! -e /usr/share/terminfo/x/xterm-direct ] then run sudo apt-get install -y ncurses-term else - echo "xterm-direct is in terminfo database" + echo "+++ xterm-direct is in terminfo database" fi } @@ -94,12 +200,14 @@ function install_deps() { use_fish use_direnv use_starship - install_ubuntu_mono_nerd + if $GNOME + then + install_ubuntu_mono_nerd + fi } - -function install_home() { - install_deps +function install_files() { + echo "--- Ensuring symlinks to git file are present" for f in $files do run rm -Rf $HOME/$f @@ -111,16 +219,45 @@ function install_home() { run ln -sf $(this_script_root_dir)/$f $HOME/$f done run ln -sf $(this_script_root_dir)/.tmux/.tmux.conf $HOME/.tmux.conf - load_gnome_terminal_profiles - /usr/bin/fish -c 'omf install' } +function update_oh_my_fish() { + echo "--- Updating Oh My Fish" + if $VERBOSE + then + echo "[/usr/bin/fish -c 'omf install']" + fi + if ! $DRY + then + if $VERBOSE + then + /usr/bin/fish -c 'omf install' + else + /usr/bin/fish -c 'omf install' 1>/dev/null + fi + fi +} -pushd $(this_script_root_dir) 1>/dev/null -echo "Updating git.tuleu.science:atuleu/home.git" -git pull 1>/dev/null -git submodule init 1>/dev/null -git submodule update 1>/dev/null -popd 1>/dev/null -install_home -echo "git.tuleu.science:atuleu/home.git updated and set" +function update_home() { + update_repos + install_deps + install_files + update_oh_my_fish + if $GNOME + then + load_gnome_terminal_profiles + fi + if ! $DRY + then + echo "--- git.tuleu.science:atuleu/home.git updated and set" + fi +} + +function update_repos() { + echo "--- Updating git.tuleu.science:atuleu/home.git" + run_git pull + run_git submodule init + run_git submodule update +} + +update_home