dotfiles/bin/initDesktop

253 lines
6.7 KiB
Plaintext
Raw Permalink 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"
DOTFILES_REMOTE_SSH="ssh://git@curry.rre.nu:3022/jonas/dotfiles.git"
2020-08-01 11:21:48 +00:00
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
2020-10-14 08:52:24 +00:00
set -aeou pipefail
2020-08-01 11:21:48 +00:00
2020-08-03 12:03:36 +00:00
function printHelp(){
cat << EOF
Usage ${0##*/} [options..]
-h,-?, --help Show help and exit
-c, --codecs install propriatory media codecs (openSUSE)
2020-08-03 12:03:36 +00:00
-f, --firefox configure firefox and install addons
-g, --gnome configure gnome and install extentions
-G, --google-chrome configure and install google-chrome extentions
2020-08-03 12:03:36 +00:00
-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 google-chrome 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"
google-chrome https://extensions.gnome.org/extension/1031/topicons/ 2> /dev/null
google-chrome https://extensions.gnome.org/extension/600/launch-new-instance/ 2> /dev/null
google-chrome https://extensions.gnome.org/extension/921/multi-monitors-add-on/ 2> /dev/null
2020-08-14 08:01:27 +00:00
google-chrome https://extensions.gnome.org/extension/1319/gsconnect/ 2> /dev/null
google-chrome https://extensions.gnome.org/extension/906/sound-output-device-chooser/ 2> /dev/null
2020-08-03 12:46:16 +00:00
log "loading dconf settings"
dconf load / < "$HOME/.dconf.conf"
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
printf "Do you want to switch to SSH remote on dotfiles [N/y]? "
read -r -n 1 -s answer
if [[ $answer == [Yy] ]];then
$dotf remote set-url origin "$DOTFILES_REMOTE_SSH"
fi
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
2020-10-13 07:13:20 +00:00
"$HOME"/bin/install_firefox_addon
}
function chrome_config(){
new_log "Installing chrome extentions"
log "WARNING! all running instances of google-chrome will be killed"
if asktobreak; then
return
fi
set +e
pkill -f google-chrome
set -e
google-chrome https://chrome.google.com/webstore/detail/gnome-shell-integration/gphhapmejobijbbhgpjhcjognlahblep 2> /dev/null
}
function suse_install_codecs(){
new_log "Install Proprietary media codecs?"
log "WARNING! This is for openSUSE only"
if asktobreak; then
return
fi
sudo "$HOME/bin/install_codecs"
}
2020-08-06 09:51:15 +00:00
function check_prerequisites(){
2020-08-06 10:01:11 +00:00
set +e
2020-08-06 09:51:15 +00:00
local answer
2020-08-06 10:01:11 +00:00
type git > /dev/null 2>&1
RESULT=$?
if [[ $RESULT != 0 ]];then
2020-08-06 09:51:15 +00:00
printf "git is not installed, do your want to install it [y/N]?"
read -r -n 1 -s answer;
printf "\n"
if [[ $answer == [yY] ]];then
sudo zypper --non-interactive install git
2020-08-06 09:51:15 +00:00
fi
fi
2020-08-06 10:01:11 +00:00
type salt-call > /dev/null 2>&1
RESULT=$?
if [[ $RESULT != 0 ]];then
2020-08-06 09:51:15 +00:00
printf "salt-minion is not installed, do your want to install it [y/N]?"
read -r -n 1 -s answer;
printf "\n"
if [[ $answer == [yY] ]];then
sudo zypper --non-interactive install salt-minion
2020-08-06 09:51:15 +00:00
fi
fi
2020-08-06 10:01:11 +00:00
set -e
2020-08-06 09:51:15 +00:00
}
2020-08-03 12:03:36 +00:00
#initialize all options
ALL=true
CODECS=false
2020-08-03 12:03:36 +00:00
FIREFOX=false
GNOME=false
SALT=false
DOTFILES=false
CHROME=false
2020-08-03 12:03:36 +00:00
ANSWER_YES=false
while :; do
case $1 in
-c|--codecs)
CODECS=true
ALL=false
;;
2020-08-03 12:03:36 +00:00
-h|-\?|--help)
printHelp
exit
;;
-f|--firefox)
FIREFOX=true
ALL=false
;;
-g|--gnome)
GNOME=true
ALL=false
;;
-G|--google-chrome)
CHROME=true
ALL=false
;;
2020-08-03 12:03:36 +00:00
-s|--salt)
SALT=true
ALL=false
;;
-d|--dotfiles)
DOTFILES=true
ALL=false
;;
-y|--yes)
ANSWER_YES=true
;;
--) #End of all options
shift
break
;;
-?*)
2020-10-13 07:13:20 +00:00
printf "'%s' is not a valid option\n" "$1" >&2
2020-08-03 12:03:36 +00:00
exit 1
;;
*) #Break out of case, no more options
break
esac
shift
done
2020-08-06 09:51:15 +00:00
check_prerequisites
2020-08-03 12:03:36 +00:00
[[ $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 ]] || [[ $CHROME == true ]] && chrome_config
2020-08-03 12:46:16 +00:00
[[ $ALL == true ]] || [[ $GNOME == true ]] && gnome_config
[[ $ALL == true ]] || [[ $CODECS == true ]] && suse_install_codecs
2020-08-01 13:02:50 +00:00
printf "\n DONE!!!!!!!\n"