bootstrap/bootstrap-Linux.sh

75 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
set -e
show_usage() {
echo "usage: $0 [-h] [-y]"
}
show_help() {
show_usage
echo
echo "Bootstrap Fedora or Debian-based Linux distribution with:"
echo
echo "* Update packages"
echo "* Install git, python3-pip"
echo "* Install ansible"
echo "* Clone configuration repository"
echo "* Install 1password"
echo
echo "If any already exist they will not be reinstalled."
echo
echo "optional arguments:"
echo " -h show this help message and exit"
echo " -y assume yes when prompted"
}
yes=0
while getopts 'hy' opt; do
case $opt in
h) show_help; exit 0 ;;
y) yes=1 ;;
*) show_usage; exit 1 ;;
esac
done
agree() {
local check=^[Nn]$
[ $yes -eq 1 ] && [[ ! "$2" =~ $check ]] && return 0
[[ "$2" =~ $check ]] && local default="[y/N]" || local default="[Y/n]"
read -p "$1 $default? " answer
case "$answer" in
y|Y|yes) return 0 ;;
n|N|no) return 1 ;;
'') [[ "$2" =~ $check ]] && return 1 || return 0 ;;
*) echo "invalid input: $answer" && return `agree "$1"` ;;
esac
}
if command -v apt &> /dev/null; then
agree "Update apt cache" && sudo apt-get update
agree "Upgrade apt packages" "N" && sudo apt-get upgrade
echo "Install git python3-pip"
sudo apt-get install --yes git python3-pip
fi
if command -v dnf &> /dev/null; then
agree "Upgrade dnf packages" "N" && sudo dnf upgrade
echo "Install git python3-pip"
sudo dnf install --assumeyes git python3-pip
fi
echo "Install ansible"
pip install --user --break-system-packages ansible jmespath
if [ ! -d ~/.config/local ]; then
echo "Clone configuration repository"
git clone https://git.infektor.net/config/local.git ~/.config/local
fi
agree "Install 1password" && \
~/.local/bin/ansible-playbook ~/.config/local/playbooks/1password.yaml
echo "Done"