#!/bin/bash # Set up my desktop/laptop with all default setttings that I want. # # uses salt-call masterless configuration. # # to auto answer YES set the INITDESKTOP_YES=1 environment variable DOTFILES_REPO="$HOME/.dotfiles" DOTFILES_REMOTE="https://git.rre.nu:443/jonas/dotfiles.git" DOTFILES_RENAME_EXISTING_FILES=( .bashrc ) ### NO Changes below this line set -aeo pipefail function asktobreak(){ if [[ "$INITDESKTOP_YES" == 1 ]];then printf "\n" return 1 fi printf "Do you want to run this step (y/n)" while read -r -n 1 -s answer; do if [[ $answer == [YyNn] ]];then [[ $answer == [Yy] ]] && return_value=1 [[ $answer == [Nn] ]] && return_value=0 printf "\n" break; fi done return $return_value } function new_log(){ # script output printf "\n**** [%s] ***\n" "$*" } function log(){ printf "%s\n" "$*" } function gnome_key_bindings(){ new_log "Setting my default gnome bindings" if asktobreak; then return fi local KEY_PATH="/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings" local CMD="gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:$KEY_PATH" gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['$KEY_PATH/custom0/']" # Open Terminator $CMD/custom0/ name "Open Terminator" $CMD/custom0/ command "terminator" $CMD/custom0/ binding "Return" } function setup_dotfiles(){ local dotf="git --git-dir=$DOTFILES_REPO --work-tree=$HOME" new_log "Setting up dotf (dotfiles)" if asktobreak;then return fi log "creating git repo in $DOTFILES_REPO" mkdir "$HOME/.dotfiles" git init --bare "$DOTFILES_REPO" $dotf config --local status.showUntrackedFiles no log "adding remote repo ($DOTFILES_REMOTE)" $dotf remote add origin "$DOTFILES_REMOTE" for file in "${DOTFILES_RENAME_EXISTING_FILES[@]}"; do if [[ -f "$HOME/.bashrc" ]];then log "renaming local $file to ${file}.bak" mv "$HOME/$file" "$HOME/${file}.bak" fi done log "fetching dotfiles" $dotf fetch origin $dotf checkout master } function do_salt_call(){ local salt="sudo salt-call --local --file-root $HOME/salt/states --pillar-root $HOME/salt/pillars" new_log "Running salt high state" if asktobreak;then return fi $salt state.apply pillar="{username: $USER}" } setup_dotfiles do_salt_call gnome_key_bindings printf "\n DONE!!!!!!!\n"