Compare commits
2 Commits
1b7d0d38e3
...
6a3d187a7b
Author | SHA1 | Date | |
---|---|---|---|
6a3d187a7b | |||
b9d8326017 |
@ -11,7 +11,9 @@ show_help() {
|
||||
echo
|
||||
echo "Bootstrap a Ubuntu or Linux Mint instance with:"
|
||||
echo
|
||||
echo "* Git - from apt-get"
|
||||
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"
|
||||
@ -21,80 +23,70 @@ show_help() {
|
||||
echo
|
||||
echo "optional arguments:"
|
||||
echo " -h show this help message and exit"
|
||||
echo " -d dry run, don't actuall install anything"
|
||||
echo " -n don't install pip packeges as --user"
|
||||
echo " -y assume yes when prompted"
|
||||
}
|
||||
|
||||
dry=0
|
||||
user='--user'
|
||||
sudo=''
|
||||
yes=0
|
||||
|
||||
while getopts 'hd' opt; do
|
||||
while getopts 'hdy' opt; do
|
||||
case $opt in
|
||||
h)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
d)
|
||||
dry=1
|
||||
;;
|
||||
u)
|
||||
user=''
|
||||
sudo='sudo'
|
||||
;;
|
||||
*)
|
||||
show_usage
|
||||
exit 1
|
||||
;;
|
||||
h) show_help; exit 0 ;;
|
||||
y) yes=1 ;;
|
||||
*) show_usage; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $dry -eq 1 ]; then
|
||||
echo "OPERATING IN DRY RUN MODE!"
|
||||
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() {
|
||||
pip install --user $1 &> /dev/null
|
||||
}
|
||||
|
||||
export PATH=~/.local/bin:$PATH
|
||||
|
||||
agree "Update apt cache" && sudo apt-get update > /dev/null
|
||||
agree "Upgrade apt packages" "N" && sudo apt-get 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
|
||||
|
||||
if [ "" != "$user" ]; then
|
||||
export PATH=~/.local/bin:$PATH
|
||||
fi
|
||||
missing virtualenv && agree "Install virtualenv" && pip_install virtualenv
|
||||
|
||||
# Install Git
|
||||
if [ ! -f /usr/bin/git ]; then
|
||||
if [ $dry -eq 0 ]; then
|
||||
sudo apt-get install git
|
||||
fi
|
||||
echo "Installed: Git"
|
||||
else
|
||||
echo "Satisfied: Git"
|
||||
fi
|
||||
|
||||
# Install virtualenv
|
||||
if [ ! -f ~/.local/bin/virtualenv ]; then
|
||||
if [ $dry -eq 0 ]; then
|
||||
$sudo pip install $user virtualenv &> /dev/null
|
||||
echo "Installed: virtualenv"
|
||||
fi
|
||||
else
|
||||
echo "Satisfied: virtualenv"
|
||||
fi
|
||||
|
||||
# Generate SSH key
|
||||
if [ ! -f ~/.ssh/id_rsa ]; then
|
||||
if [ ! -f ~/.ssh/id_rsa ] && agree "Generate SSH key"; then
|
||||
read -rp "SSH email: " email
|
||||
mkdir ~/.ssh
|
||||
if [ $dry -eq 0 ]; then
|
||||
ssh-keygen -t rsa -b 4096 -C "$email" -N "" -f ~/.ssh/id_rsa
|
||||
fi
|
||||
echo "Generated: SSH key"
|
||||
else
|
||||
echo "Satisfied: SSH key"
|
||||
[ ! -d ~/.ssh ] && mkdir -p ~/.ssh
|
||||
ssh-keygen -t rsa -b 4096 -C "$email" -N "" -f ~/.ssh/id_rsa
|
||||
fi
|
||||
|
||||
# GitHub public key
|
||||
env=$(mktemp -d)
|
||||
virtualenv $env &> /dev/null
|
||||
source $env/bin/activate
|
||||
pip install githubpy &> /dev/null
|
||||
python <(cat << EOF
|
||||
if agree "GitHub public key"; then
|
||||
env=$(mktemp -d)
|
||||
virtualenv $env > /dev/null
|
||||
source $env/bin/activate
|
||||
pip install githubpy > /dev/null
|
||||
python <(cat << EOF
|
||||
from __future__ import print_function
|
||||
from os import environ
|
||||
from os.path import join
|
||||
@ -131,28 +123,29 @@ if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
exit(1)
|
||||
exit(130)
|
||||
|
||||
EOF
|
||||
)
|
||||
deactivate
|
||||
rm -r $env
|
||||
|
||||
# Prompt user to setup other SSH key recipients
|
||||
echo "----------------------------------------------------------------------"
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
echo "----------------------------------------------------------------------"
|
||||
read -rp "Set other SSH key recipients, press ENTER to continue: "
|
||||
|
||||
# Install conduit
|
||||
if ! python -c 'import conduit' &> /dev/null; then
|
||||
if [ $dry -eq 0 ]; then
|
||||
$sudo pip install $user git+ssh://git@github.com:kbenzie/conduit.git
|
||||
fi
|
||||
echo "Installed: conduit"
|
||||
else
|
||||
echo "Satisfied: conduit"
|
||||
deactivate
|
||||
rm -r $env
|
||||
fi
|
||||
|
||||
echo "Completed: $0 will now be removed"
|
||||
if [ -f $0 ]; then rm $0; fi
|
||||
# TODO: Gogs SSH key
|
||||
|
||||
# Prompt user to setup other SSH key recipients
|
||||
if [ -f ~/.ssh/id_rsa.pub ]; then
|
||||
echo "----------------------------------------------------------------------"
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
echo "----------------------------------------------------------------------"
|
||||
read -rp "Set other SSH key recipients, press ENTER to continue: "
|
||||
fi
|
||||
|
||||
# Install conduit
|
||||
missing conduit && agree "Install conduit" && \
|
||||
pip_install git+ssh://git@github.com/kbenzie/conduit.git
|
||||
|
||||
echo "To use install pip packages update your PATH:"
|
||||
echo 'export PATH=~/.local/bin:$PATH'
|
||||
|
||||
[ -f $0 ] && agree "Remove $0" "N" && rm $0
|
||||
|
Loading…
x
Reference in New Issue
Block a user