diff --git a/update.sh b/update.sh index e29f674..1c37176 100755 --- a/update.sh +++ b/update.sh @@ -1,5 +1,5 @@ #!/bin/bash -65;6800;1c65;6800;1c + set -e function print_help() { @@ -8,9 +8,11 @@ function print_help() { 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. " @@ -21,14 +23,25 @@ function exit_error() { 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 } @@ -43,12 +56,18 @@ 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 ;; @@ -162,44 +181,62 @@ function use_direnv() { fi } + function use_starship() { echo "--- Ensuring starship is installed" - if ! which starship 1>/dev/null - then - echo "+++ Installing starship" - run curl -sS https://starship.rs/install.sh | sh - else + if which starship 1>/dev/null + then echo "+++ Starship is installed" - fi + 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 ! fc-list | grep "UbuntuMono Nerd Font" 1>/dev/null - then - run mkdir -p ~/.local/share/fonts - pushd ~/.local/share/fonts - echo "Fetching UbuntuMono Nerd Font" - curl -fL -o "Ubuntu Mono Nerd Font Complete Mono.ttf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/UbuntuMono/Regular/complete/Ubuntu%20Mono%20Nerd%20Font%20Complete%20Mono.ttf - popd - run fc-cache -f - else - 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" 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 Ubuntu_Mono_Nerd_Font_Complete_Mono.ttf https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/UbuntuMono/Regular/complete/Ubuntu%20Mono%20Nerd%20Font%20Complete%20Mono.ttf + popd + run fc-cache -f + } function install_deps() { use_fish use_direnv use_starship - if $GNOME + if $FONT then install_ubuntu_mono_nerd fi