98 lines
2.3 KiB
Bash
Executable File
98 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
show_usage() {
|
|
echo "usage: $0 [-h] [-y]"
|
|
}
|
|
|
|
show_help() {
|
|
show_usage
|
|
echo
|
|
echo "Bootstrap a Debian based distribution with:"
|
|
echo
|
|
echo "* update apt cache"
|
|
echo "* upgrade apt packages"
|
|
echo "* git - from apt"
|
|
echo "* python - from apt"
|
|
echo "* python-pip - from apt"
|
|
echo "* virtualenv - from pip"
|
|
echo "* SSH key - from ssh-keygen"
|
|
echo "* GitHub public key - with SSH key"
|
|
echo "* GitLab public key - with SSH key"
|
|
echo "* BitBucket Cloud public key - with SSH key"
|
|
echo "* Gogs Cloud public key - with SSH key"
|
|
echo "* conduit - configuration manager"
|
|
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
|
|
|
|
missing() {
|
|
which $1 &> /dev/null && return 1 || return 0
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
apt_install() {
|
|
sudo apt-get install --yes --install-recommends $1 > /dev/null
|
|
}
|
|
|
|
pip_install() {
|
|
pip3 install --user $1 > /dev/null
|
|
}
|
|
|
|
export PATH=~/.local/bin:$PATH
|
|
|
|
missing git && agree "Install git" && apt_install git
|
|
|
|
if missing python; then
|
|
agree "Intsall python-is-python3" && apt_install python-is-python3
|
|
fi
|
|
|
|
if missing pip3; then
|
|
agree "Install python-pip" && apt_install python3-pip
|
|
fi
|
|
|
|
if missing virtualenv; then
|
|
agree "Install python3-virtualenv" && apt_install python3-virtualenv
|
|
fi
|
|
|
|
if [ ! -f ~/.ssh/id_rsa ] && agree "Generate SSH key"; then
|
|
read -rp "SSH email: " email
|
|
[ ! -d ~/.ssh ] && mkdir -p ~/.ssh
|
|
ssh-keygen -t ed25519 -C "$email" -N "" -f ~/.ssh/id_rsa
|
|
fi
|
|
|
|
missing conduit && agree "Install ansible" && \
|
|
pip_install ansible
|
|
|
|
echo "To use installed pip packages update your PATH:"
|
|
echo 'export PATH=~/.local/bin:$PATH'
|
|
|
|
[ -f $0 ] && agree "Remove $0" "N" && rm $0 || exit 0
|