Compare commits

..

2 Commits

Author SHA1 Message Date
92053400a3 Add bootstrap-Windows.cmd
usage: bootstrap-Windows.cmd [/?]

Bootstrap a macOS instance with:

* Windows SDK - from MSDN
* Chocolatey - package manager
* Cmder, including Git - from Chocolatey
* Python - from Chocolatey
* virtualenv - from pip
* 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

optional arguments:
        /?              show this help message and exit
2018-01-08 11:48:33 +00:00
decdef3066 Add bootstrap-Debian.sh
usage: ./bootstrap-Debian.sh [-h] [-y]

Bootstrap a Debian based distribution with:

* update apt cache
* upgrade apt packages
* git - from apt
* python - from apt
* python-pip - from apt
* virtualenv - from pip
* 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
2018-01-08 11:48:33 +00:00
5 changed files with 38 additions and 248 deletions

View File

@@ -6,31 +6,19 @@ Bootstrap an OS instance with bare essentials.
To bootstrap a macOS instance: To bootstrap a macOS instance:
```console ```
$ curl -O https://code.infektor.net/config/bootstrap/raw/master/bootstrap-macOS.sh && chmod +x bootstrap-macOS.sh && ./bootstrap-macOS.sh $ curl -s https://code.infektor.net/config/bootstrap/raw/master/bootstrap-macOS.sh | sh
``` ```
To bootstrap a Debian based Linux instance: To bootstrap a Debain based Linux instance:
```console
$ wget https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Debian.sh && chmod +x bootstrap-Debian.sh && ./bootstrap-Debian.sh
``` ```
$ wget https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Debian.sh -O - | sh
To bootstrap a Arch Linux based instance:
```console
$ 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: To bootstrap a Windows instance:
```console ```
$ bitsadmin /transfer bootstrap-Windows.cmd https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Windows.cmd %cd%\bootstrap-Windows.cmd & %cd%\bootstrap-Windows.cmd $ bitsadmin /transfer bootstrap-Windows.cmd https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Windows.cmd %cd%\bootstrap-Windows.cmd & %cd%\bootstrap-Windows.cmd
``` ```
@@ -39,7 +27,7 @@ $ bitsadmin /transfer bootstrap-Windows.cmd https://code.infektor.net/config/boo
Install as a pip package to set SSH keys on any of GitHub, GitLab, BitBucket Install as a pip package to set SSH keys on any of GitHub, GitLab, BitBucket
Cloud, or Gogs servers: Cloud, or Gogs servers:
```console ```
$ pip install git+https://code.infektor.net/config/bootstrap.git pip install git+https://code.infektor.net/config/bootstrap.git
$ python -c 'import bootstrap; bootstrap.set_ssh_keys()' python -c 'import bootstrap; bootstrap.set_ssh_keys()'
``` ```

View File

@@ -1,105 +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 pacman cache"
echo "* upgrade pacman packages"
echo "* git - from pacman"
echo "* python-pip - from pacman"
echo "* virtualenv - from pacman"
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
}
pacman_install() {
sudo pacman -S --needed --noconfirm $1 > /dev/null
}
pip_install() {
pip install --user $1 > /dev/null
}
export PATH=~/.local/bin:$PATH
agree "Update pacman cache" && sudo pacman -Syy > /dev/null
agree "Upgrade pacman packages" "N" && sudo pacman -Syu > /dev/null
missing git && agree "Install git" && pacman_install git
if missing pip; then
agree "Install python-pip" && pacman_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

View File

@@ -63,33 +63,41 @@ apt_install() {
} }
pip_install() { pip_install() {
pip3 install --user $1 > /dev/null pip install --user $1 > /dev/null
} }
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 missing git && agree "Install git" && apt_install git
if missing python; then if missing pip; then
agree "Intsall python-is-python3" && apt_install python-is-python3 agree "Install python-pip" && apt_install python-pip
agree "Upgrade pip with pip" && sudo -H pip install --upgrade pip > /dev/null
fi fi
if missing pip3; then missing virtualenv && agree "Install virtualenv" && pip_install virtualenv
agree "Install python-pip" && apt_install python3-pip
fi
if missing virtualenv; then
agree "Install python3-virtualenv" && apt_install python3-virtualenv
fi
if [ ! -f ~/.ssh/id_rsa ] && agree "Generate SSH key"; then if [ ! -f ~/.ssh/id_rsa ] && agree "Generate SSH key"; then
read -rp "SSH email: " email read -rp "SSH email: " email
[ ! -d ~/.ssh ] && mkdir -p ~/.ssh [ ! -d ~/.ssh ] && mkdir -p ~/.ssh
ssh-keygen -t ed25519 -C "$email" -N "" -f ~/.ssh/id_rsa ssh-keygen -t rsa -b 4096 -C "$email" -N "" -f ~/.ssh/id_rsa
fi fi
missing conduit && agree "Install ansible" && \ if ! missing virtualenv && agree "Set SSH keys on remote Git servers"; then
pip_install ansible 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 "To use installed pip packages update your PATH:"
echo 'export PATH=~/.local/bin:$PATH' echo 'export PATH=~/.local/bin:$PATH'

View File

@@ -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

View File

@@ -105,21 +105,22 @@ def set_github_ssh_key():
def set_gitlab_ssh_key(): def set_gitlab_ssh_key():
"""Set GitLab SSH key.""" """Set GitLab SSH key."""
api_url = '%s/api/v4' % get_url('GitLab', 'https://gitlab.com') api_url = '%s/api/v4' % get_url('GitLab', 'https://gitlab.com')
session_url = '%s/session' % api_url
keys_url = '%s/user/keys' % api_url keys_url = '%s/user/keys' % api_url
username, password = get_username_password('GitLab') username, password = get_username_password('GitLab')
credentials = {'login': username, 'password': password} response = post(session_url, {'login': username, 'password': password})
response = get(keys_url, credentials) if response.status_code != 201:
raise bootstrap_error(response)
auth = {'Private-Token': response.json()['private_token']}
response = get(keys_url, headers=auth)
if response.status_code != 200: if response.status_code != 200:
raise bootstrap_error(response) raise bootstrap_error(response)
keys = response.json() keys = response.json()
local_key = get_local_key() local_key = get_local_key()
if not key_exists(keys, local_key): if not key_exists(keys, local_key):
response = post(keys_url, response = post(
credentials, keys_url, headers=auth, json={'title': node(),
json={ 'key': local_key})
'title': node(),
'key': local_key
})
if response.status_code != 201: if response.status_code != 201:
raise bootstrap_error(response) raise bootstrap_error(response)