Consolidate Linux scripts into one
This commit is contained in:
		
							parent
							
								
									17d438ce0b
								
							
						
					
					
						commit
						d6ebe4fcdd
					
				@ -1,106 +0,0 @@
 | 
				
			|||||||
#!/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 install --yes --install-recommends $1 > /dev/null
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pip_install() {
 | 
					 | 
				
			||||||
  pip install --user $1 > /dev/null
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export PATH=~/.local/bin:$PATH
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
agree "Update apt cache" && sudo apt update > /dev/null
 | 
					 | 
				
			||||||
agree "Upgrade apt packages" "N" && sudo apt upgrade > /dev/null
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
missing git && agree "Install git" && apt_install git
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if missing pip; then
 | 
					 | 
				
			||||||
  agree "Install python-pip" && apt_install python-pip
 | 
					 | 
				
			||||||
  agree "Upgrade pip with pip" && \
 | 
					 | 
				
			||||||
    sudo -H pip_install --upgrade pip > /dev/null
 | 
					 | 
				
			||||||
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 > /dev/null
 | 
					 | 
				
			||||||
  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
 | 
					 | 
				
			||||||
@ -1,102 +0,0 @@
 | 
				
			|||||||
#!/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
 | 
					 | 
				
			||||||
							
								
								
									
										74
									
								
								bootstrap-Linux.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										74
									
								
								bootstrap-Linux.sh
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,74 @@
 | 
				
			|||||||
 | 
					#!/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"
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user