From 9c3a2d89b8801f2eb225a70bee6b0cef92667b3b Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 31 Dec 2020 15:10:50 +0000 Subject: [PATCH] Add bootstrap-Fedora.sh usage: ./bootstrap-Fedora.sh [-h] [-y] Bootstrap a Debian based distribution with: * upgrade dnf packages * git - from dnf * virtualenv - from dnf * SSH key - from ssh-keygen * GitHub public key - with SSH key * GitLab public key - with SSH key * BitBucket Cloud public key - with SSH key * Gogs Cloud public key - with SSH key * conduit - configuration manager If any already exist they will not be reinstalled. optional arguments: -h show this help message and exit -y assume yes when prompted --- README.md | 6 +++ bootstrap-Fedora.sh | 102 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100755 bootstrap-Fedora.sh diff --git a/README.md b/README.md index 1e89790..89694ee 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ To bootstrap a Arch Linux based instance: $ curl -O https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Arch.sh && chmod +x bootstrap-Arch.sh && ./bootstrap-Arch.sh ``` +To bootstrap a Fedora Linux instance: + +```console +$ curl -O https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Fedora.sh && chmod +x bootstrap-Fedora.sh && ./bootstrap-Fedora.sh +``` + To bootstrap a Windows instance: ```console diff --git a/bootstrap-Fedora.sh b/bootstrap-Fedora.sh new file mode 100755 index 0000000..dbd7c23 --- /dev/null +++ b/bootstrap-Fedora.sh @@ -0,0 +1,102 @@ +#!/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 "* upgrade dnf packages" + echo "* git - from dnf" + echo "* virtualenv - from dnf" + 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 +} + +dnf_install() { + sudo dnf install --assumeyes $1 +} + +pip_install() { + pip install --user $1 +} + +export PATH=~/.local/bin:$PATH + +agree "Upgrade dnf packages" "N" && sudo dnf upgrade + +missing git && agree "Install git" && dnf_install git + +if missing pip; then + agree "Install python3-pip" && dnf_install python3-pip + agree "Upgrade pip with pip" && \ + sudo -H pip_install --upgrade pip +fi + +missing virtualenv && agree "Install virtualenv" && pip_install virtualenv + +if [ ! -f ~/.ssh/id_rsa ] && agree "Generate SSH key"; then + read -rp "SSH email: " email + [ ! -d ~/.ssh ] && mkdir -p ~/.ssh + ssh-keygen -t rsa -b 4096 -C "$email" -N "" -f ~/.ssh/id_rsa +fi + +if ! missing virtualenv && agree "Set SSH keys on remote Git servers"; then + env=$(mktemp -d) + virtualenv $env > /dev/null + source $env/bin/activate + pip install git+https://code.infektor.net/config/bootstrap.git + python -c 'import bootstrap; bootstrap.set_ssh_keys()' + deactivate + rm -r $env +fi + +missing conduit && agree "Install conduit" && \ + pip_install git+ssh://git@github.com/kbenzie/conduit.git + +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