#!/bin/bash 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 --reinstall : force reinstallation -g/--gnome : system is intended to run in a GNOME environement, and will setup gnome-terminal accordingly. Do not activate on headless system. --font : Installs font for gnome environment (selected if --gnome) -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 FONT=false VERBOSE=false DRY=false REINSTALL=false function set_reinstall_on() { REINSTALL=true } function set_gnome_on() { GNOME=true FONT=true } function set_font_on() { FONT=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 reinstall) set_reinstall_on ;; gnome) set_gnome_on ;; verbose) set_verbose_on ;; font) set_font_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 \ .config/omf \ .config/starship.toml \ .local/share/omf \ .emacs \ .tmux.conf.local \ .config/alacritty.toml" function this_script_root_dir() { dirname $(realpath ${BASH_SOURCE[0]}) } function run() { 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 fi } function install_fish() { echo "--- Ensuring fish is current shell" local fish_good=0 if ! which fish 1>/dev/null then fish_good=1 fi local current_version=$(fish --version | cut -d " " -f 3) local current_version_test=$(cat </dev/null then echo "++ Installing direnv" run sudo apt-get install -y direnv else echo "+++ direnv is installed" fi } function install_starship() { echo "--- Ensuring starship is installed" if which starship 1>/dev/null then echo "+++ Starship is installed" if ! $REINSTALL then return fi echo "+++ Reinstalling starship" fi echo "+++ Installing starship" if $VERBOSE then echo "[curl -sS https://starship.rs/install.sh | sh -s -- --yes]" fi if ! $DRY then curl -sS https://starship.rs/install.sh | sh -s -- --yes fi } function install_ubuntu_mono_nerd() { echo "--- Ensuring Ubuntu Mono Nerd font is present" 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" fi if fc-list | grep "UbuntuMono Nerd Font" 1>/dev/null then echo "+++ UbuntuMono Nerd font is installed" if ! $REINSTALL then return fi echo "+++ Reinstalling UbuntuMono Nerd font" fi echo "+++ Fetching UbuntuMono Nerd Font" run mkdir -p ~/.local/share/fonts pushd ~/.local/share/fonts run curl -fL -o UbuntuMonoNerdFontMono-Regular.ttf https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/UbuntuMono/Regular/UbuntuMonoNerdFontMono-Regular.ttf popd run fc-cache -f } function install_deps() { install_fish install_direnv install_starship if $FONT then install_ubuntu_mono_nerd fi } function install_files() { echo "--- Ensuring symlinks to git file are present" for f in $files do run rm -Rf $HOME/$f dir=$(dirname $f) if [ ! "$dir" = "." ] then run mkdir -p $HOME/$dir fi run ln -sf $(this_script_root_dir)/$f $HOME/$f done run ln -sf $(this_script_root_dir)/.tmux/.tmux.conf $HOME/.tmux.conf } function update_oh_my_fish() { echo "--- Updating Oh My Fish" FISH=$(which fish) if $VERBOSE then echo "[$FISH -c 'omf install']" fi if ! $DRY then if $VERBOSE then $FISH -c 'omf install' else $FISH -c 'omf install' 1>/dev/null fi fi } function update_home() { if $VERBOSE then echo "--- this_script_root_dir: $(this_script_root_dir)" fi 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 } if [ -z $BASH_SOURCE ] && [ ! -d "$HOME/.home" ] then echo "--- cloning git.tuleu.science:atuleu/home.git in $HOME/.home" pushd $HOME 1>/dev/null run_git clone https://git.tuleu.science/atuleu/home.git .home popd 1>/dev/null else update_home fi