dotfiles/bin/initDesktop

210 lines
5.1 KiB
Plaintext
Raw Normal View History

2020-08-01 11:21:48 +00:00
#!/bin/bash
# Set up my desktop/laptop with all default setttings that I want.
#
# uses salt-call masterless configuration.
2020-08-02 07:23:41 +00:00
#
# to auto answer YES set the INITDESKTOP_YES=1 environment variable
2020-08-01 11:21:48 +00:00
DOTFILES_REPO="$HOME/.dotfiles"
DOTFILES_REMOTE="https://git.rre.nu:443/jonas/dotfiles.git"
2020-08-02 07:40:50 +00:00
DOTFILES_RENAME_EXISTING_FILES=(
.bashrc
)
2020-08-01 11:21:48 +00:00
### NO Changes below this line
set -aeo pipefail
2020-08-03 12:03:36 +00:00
function printHelp(){
cat << EOF
Usage ${0##*/} [options..]
-h,-?, --help Show help and exit
-f, --firefox configure firefox and install addons
-g, --gnome configure gnome and install extentions
-d, --dotfiles configure dotfiles
-s, --salt run a masterless salt-call
-y, --yes answer 'yes' on all questions
EOF
}
2020-08-01 12:06:50 +00:00
function asktobreak(){
2020-08-03 12:03:36 +00:00
if [[ "$ANSWER_YES" == true ]];then
2020-08-02 07:40:50 +00:00
printf "\n"
2020-08-02 07:23:41 +00:00
return 1
fi
2020-08-01 12:06:50 +00:00
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
2020-08-02 07:40:50 +00:00
printf "\n"
2020-08-01 12:06:50 +00:00
break;
fi
done
return $return_value
}
2020-08-01 11:21:48 +00:00
function new_log(){
# script output
2020-08-02 07:40:50 +00:00
printf "\n**** [%s] ***\n" "$*"
2020-08-01 11:21:48 +00:00
}
function log(){
2020-08-02 07:40:50 +00:00
printf "%s\n" "$*"
2020-08-01 11:21:48 +00:00
}
2020-08-03 12:46:16 +00:00
function gnome_config(){
2020-08-01 12:06:50 +00:00
new_log "Setting my default gnome bindings"
log "WARNING! All running firefox instances will be killed"
2020-08-01 12:06:50 +00:00
if asktobreak; then
return
fi
2020-08-03 14:08:13 +00:00
set +e
2020-08-03 13:07:39 +00:00
pkill -f firefox
2020-08-03 14:08:13 +00:00
set -e
2020-08-03 14:30:46 +00:00
printf "Current version %s\n" "$(gnome-shell --version)"
2020-08-03 12:46:16 +00:00
log "Launching firefox to install GNOME Extetions"
firefox https://extensions.gnome.org/extension/1031/topicons/
firefox https://extensions.gnome.org/extension/600/launch-new-instance/
firefox https://extensions.gnome.org/extension/921/multi-monitors-add-on/
log "loading dconf settings"
dconf load < cat <<EOF
[system/locale]
region='sv_SE.UTF-8'
[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0]
binding='<Primary><Alt>Return'
command='terminator'
name='Open Terminator'
[org/gnome/evolution-data-server/calendar]
[org/gnome/shell]
enabled-extensions=['TopIcons@phocean.net', 'multi-monitors-add-on@spin83', 'launch-new-instance@gnome-shell-extensions.gcampax.github.com']
[org/gnome/shell/extensions/topicons]
icon-opacity=221
tray-pos='right'
tray-order=1
[org/gnome/shell/extensions/multi-monitors-add-on]
show-activities=false
show-app-menu=false
available-indicators=@as []
show-date-time=false
show-panel=false
thumbnails-on-left-side=false
show-thumbnails-slider=false
EOF
2020-08-01 11:21:48 +00:00
}
function setup_dotfiles(){
2020-08-02 07:52:17 +00:00
local dotf="git --git-dir=$DOTFILES_REPO --work-tree=$HOME"
2020-08-01 11:21:48 +00:00
new_log "Setting up dotf (dotfiles)"
2020-08-01 12:06:50 +00:00
if asktobreak;then
return
fi
2020-08-01 11:21:48 +00:00
log "creating git repo in $DOTFILES_REPO"
mkdir "$HOME/.dotfiles"
git init --bare "$DOTFILES_REPO"
2020-08-02 07:52:17 +00:00
$dotf config --local status.showUntrackedFiles no
2020-08-01 11:21:48 +00:00
log "adding remote repo ($DOTFILES_REMOTE)"
2020-08-02 07:52:17 +00:00
$dotf remote add origin "$DOTFILES_REMOTE"
2020-08-01 11:21:48 +00:00
2020-08-02 07:40:50 +00:00
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
2020-08-01 11:21:48 +00:00
2020-08-01 11:43:02 +00:00
log "fetching dotfiles"
2020-08-02 07:52:17 +00:00
$dotf fetch origin
$dotf checkout master
2020-08-01 11:21:48 +00:00
}
2020-08-01 12:06:50 +00:00
function do_salt_call(){
local salt="sudo salt-call --local --file-root $HOME/salt/states --pillar-root $HOME/salt/pillars"
2020-08-01 12:06:50 +00:00
new_log "Running salt high state"
if asktobreak;then
return
fi
2020-08-02 07:53:52 +00:00
$salt state.apply pillar="{username: $USER}"
2020-08-01 12:06:50 +00:00
}
2020-08-01 12:08:17 +00:00
2020-08-03 12:46:16 +00:00
function firefox_config(){
new_log "Installing firefox addons"
if [[ ! -f "$HOME/bin/install_firefox_addon" ]];then
printf "install firefox addon script not found, run dotfile sync first"
fi
log "WARNING! all running firefox instances will be killed"
if asktobreak;then
return
fi
2020-08-03 14:08:13 +00:00
set +e
2020-08-03 13:07:39 +00:00
pkill -f firefox
2020-08-03 14:08:13 +00:00
set -e
$HOME/bin/install_firefox_addon
}
2020-08-03 12:03:36 +00:00
#initialize all options
ALL=true
FIREFOX=false
GNOME=false
SALT=false
DOTFILES=false
ANSWER_YES=false
while :; do
case $1 in
-h|-\?|--help)
printHelp
exit
;;
-f|--firefox)
FIREFOX=true
ALL=false
;;
-g|--gnome)
GNOME=true
ALL=false
;;
-s|--salt)
SALT=true
ALL=false
;;
-d|--dotfiles)
DOTFILES=true
ALL=false
;;
-y|--yes)
ANSWER_YES=true
;;
--) #End of all options
shift
break
;;
-?*)
printf "'$1' is not a valid option\n" >&2
exit 1
;;
*) #Break out of case, no more options
break
esac
shift
done
[[ $ALL == true ]] || [[ $DOTFILES == true ]] && setup_dotfiles
[[ $ALL == true ]] || [[ $SALT == true ]] && do_salt_call
2020-08-03 12:46:16 +00:00
[[ $ALL == true ]] || [[ $FIREFOX == true ]] && firefox_config
[[ $ALL == true ]] || [[ $GNOME == true ]] && gnome_config
2020-08-01 13:02:50 +00:00
printf "\n DONE!!!!!!!\n"