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