2019-12-30 09:20:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# install.sh
|
|
|
|
#
|
2020-07-08 11:51:27 +00:00
|
|
|
# Installs dotfiles and packages for my setup.
|
|
|
|
# Needs to be invoked from containing dotfile directory to work correctly.
|
2019-12-30 09:20:17 +00:00
|
|
|
#
|
2020-07-08 11:51:27 +00:00
|
|
|
# Will first install yay, then all my used packages (read from bootstrap/packages.txt)
|
2019-12-30 09:20:17 +00:00
|
|
|
#
|
2020-02-06 11:08:33 +00:00
|
|
|
# Finally, symlinks all dotfiles into their correct locations using stow
|
2019-12-30 09:20:17 +00:00
|
|
|
|
2020-07-08 11:51:27 +00:00
|
|
|
bootstrap_dir="${BOOTSTRAP_DIRECTORY:-./bootstrap}"
|
2020-01-30 12:09:10 +00:00
|
|
|
|
2019-12-30 09:20:17 +00:00
|
|
|
main() {
|
2021-04-04 18:52:52 +00:00
|
|
|
local cmd=""
|
|
|
|
local ret=0
|
2019-12-30 09:20:17 +00:00
|
|
|
|
2021-04-04 18:52:52 +00:00
|
|
|
case "$1" in
|
|
|
|
-v | --version)
|
|
|
|
printf "Personal system bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.1.1\n"
|
|
|
|
;;
|
|
|
|
-h | --help)
|
|
|
|
printf "Usage: install [-f|--force][-v|--version][-h|--help]\n\n-f Do not ask for any confirmations but force update and installation.\n"
|
|
|
|
;;
|
|
|
|
-f | --force)
|
|
|
|
install true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
install false
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2019-12-30 09:20:17 +00:00
|
|
|
|
2021-04-04 18:52:52 +00:00
|
|
|
$cmd "$@"
|
|
|
|
ret=$((ret + $?))
|
|
|
|
exit $ret
|
2019-12-30 09:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_consent() {
|
2021-04-04 18:52:52 +00:00
|
|
|
echo "This will take a while, install many packages and link dotfiles all over the place. Proceed [y/N]?"
|
|
|
|
read -r yes
|
|
|
|
if [[ "$yes" != y* ]]; then
|
|
|
|
echo "Exiting."
|
|
|
|
exit
|
|
|
|
fi
|
2019-12-30 09:20:17 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 21:31:41 +00:00
|
|
|
enable_git_hooks() {
|
2021-04-04 18:52:52 +00:00
|
|
|
if [ "$1" == "false" ]; then
|
|
|
|
echo "Should we enable git hooks for this repository, so that installed packages are automatically compared when committing? [Y/n]"
|
|
|
|
read -r no
|
|
|
|
if [[ "$no" == n* ]]; then
|
|
|
|
echo "Not changing repository settings."
|
|
|
|
return
|
|
|
|
fi
|
2020-02-07 21:31:41 +00:00
|
|
|
fi
|
2021-04-04 18:52:52 +00:00
|
|
|
git config --local core.hooksPath .githooks/
|
|
|
|
echo "Changed repository settings."
|
2020-02-07 21:31:41 +00:00
|
|
|
}
|
|
|
|
|
2019-12-30 09:20:17 +00:00
|
|
|
install() {
|
2021-04-04 18:52:52 +00:00
|
|
|
unattended=$1
|
|
|
|
if ! "$unattended"; then
|
|
|
|
check_consent
|
|
|
|
fi
|
|
|
|
echo "====================== BEGINNING INSTALLATION ============================="
|
|
|
|
if ! "$unattended"; then
|
|
|
|
export BOOTSTRAP_PACKAGES="bootstrap/packages.txt"
|
|
|
|
"$bootstrap_dir"/install_packages.sh
|
|
|
|
else
|
|
|
|
export BOOTSTRAP_PACKAGES="bootstrap/packages.txt"
|
|
|
|
"$bootstrap_dir"/install_packages.sh -f
|
|
|
|
fi
|
|
|
|
unset BOOTSTRAP_PACKAGES
|
2019-12-30 09:20:17 +00:00
|
|
|
|
2021-04-04 18:52:52 +00:00
|
|
|
echo "=================== BEGINNING DOTFILE MANAGEMENT =========================="
|
|
|
|
# get all top level directories, remove their slashes and dots
|
|
|
|
# finally get rid of .dot-directories, since they are for the repo not for my homedir
|
|
|
|
targets="$(find . -maxdepth 1 -type d | sed -e 's/^\.\/\(.*\)$/\1/' | sed -e '/^\./d')"
|
2019-12-30 09:20:17 +00:00
|
|
|
|
2021-04-04 18:52:52 +00:00
|
|
|
# shellcheck disable=2086
|
|
|
|
# -- for some reason stow only works with unqoted var expansion
|
|
|
|
stow -R ${targets} 2> >(grep -v 'Absolute/relative mismatch between Stow dir' 1>&2)
|
2019-12-30 09:20:17 +00:00
|
|
|
|
2021-04-04 18:52:52 +00:00
|
|
|
echo "================== ENABLING GIT REPOSITORY HOOKS =========================="
|
|
|
|
enable_git_hooks "$unattended"
|
2020-02-07 21:31:41 +00:00
|
|
|
|
2021-04-04 18:52:52 +00:00
|
|
|
echo "====================== INSTALLATION FINISHED =============================="
|
|
|
|
exit 0
|
2019-12-30 09:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|