Compare commits
2 Commits
6a3d187a7b
...
1b7d0d38e3
Author | SHA1 | Date | |
---|---|---|---|
1b7d0d38e3 | |||
21266c1392 |
@ -11,9 +11,7 @@ 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"
|
echo "* Git - from apt-get"
|
||||||
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"
|
||||||
@ -23,70 +21,80 @@ 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 " -y assume yes when prompted"
|
echo " -d dry run, don't actuall install anything"
|
||||||
|
echo " -n don't install pip packeges as --user"
|
||||||
}
|
}
|
||||||
|
|
||||||
yes=0
|
dry=0
|
||||||
|
user='--user'
|
||||||
|
sudo=''
|
||||||
|
|
||||||
while getopts 'hdy' opt; do
|
while getopts 'hd' opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
h) show_help; exit 0 ;;
|
h)
|
||||||
y) yes=1 ;;
|
show_help
|
||||||
*) show_usage; exit 1 ;;
|
exit 0
|
||||||
|
;;
|
||||||
|
d)
|
||||||
|
dry=1
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
user=''
|
||||||
|
sudo='sudo'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
show_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
missing() {
|
if [ $dry -eq 1 ]; then
|
||||||
which $1 &> /dev/null && return 1 || return 0
|
echo "OPERATING IN DRY RUN MODE!"
|
||||||
}
|
|
||||||
|
|
||||||
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
|
fi
|
||||||
|
|
||||||
missing virtualenv && agree "Install virtualenv" && pip_install virtualenv
|
if [ "" != "$user" ]; then
|
||||||
|
export PATH=~/.local/bin:$PATH
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -f ~/.ssh/id_rsa ] && agree "Generate SSH key"; then
|
# 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
|
||||||
read -rp "SSH email: " email
|
read -rp "SSH email: " email
|
||||||
[ ! -d ~/.ssh ] && mkdir -p ~/.ssh
|
mkdir ~/.ssh
|
||||||
ssh-keygen -t rsa -b 4096 -C "$email" -N "" -f ~/.ssh/id_rsa
|
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"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if agree "GitHub public key"; then
|
# GitHub public key
|
||||||
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
|
||||||
from os.path import join
|
from os.path import join
|
||||||
@ -123,29 +131,28 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
exit(130)
|
exit(1)
|
||||||
|
|
||||||
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
|
||||||
missing conduit && agree "Install conduit" && \
|
if ! python -c 'import conduit' &> /dev/null; then
|
||||||
pip_install git+ssh://git@github.com/kbenzie/conduit.git
|
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"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "To use install pip packages update your PATH:"
|
echo "Completed: $0 will now be removed"
|
||||||
echo 'export PATH=~/.local/bin:$PATH'
|
if [ -f $0 ]; then rm $0; fi
|
||||||
|
|
||||||
[ -f $0 ] && agree "Remove $0" "N" && rm $0
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user