Compare commits
9 Commits
5e232430cc
...
bench
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c6f40a62d | |||
| 9c3a2d89b8 | |||
| 91e205f44e | |||
| 8ac80fe9e8 | |||
| 72f6c868c8 | |||
| 9433857356 | |||
| 20f1b08e04 | |||
| 566a36ac40 | |||
| b84d91eb54 |
45
README.md
Normal file
45
README.md
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# bootstrap
|
||||||
|
|
||||||
|
Bootstrap an OS instance with bare essentials.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
To bootstrap a Debian based Linux instance:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ wget https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Debian.sh && chmod +x bootstrap-Debian.sh && ./bootstrap-Debian.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:
|
||||||
|
|
||||||
|
```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
|
||||||
|
```
|
||||||
|
|
||||||
|
## Package
|
||||||
|
|
||||||
|
Install as a pip package to set SSH keys on any of GitHub, GitLab, BitBucket
|
||||||
|
Cloud, or Gogs servers:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ pip install git+https://code.infektor.net/config/bootstrap.git
|
||||||
|
$ python -c 'import bootstrap; bootstrap.set_ssh_keys()'
|
||||||
|
```
|
||||||
105
bootstrap-Arch.sh
Executable file
105
bootstrap-Arch.sh
Executable file
@@ -0,0 +1,105 @@
|
|||||||
|
#!/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
|
||||||
@@ -63,41 +63,33 @@ apt_install() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pip_install() {
|
pip_install() {
|
||||||
pip install --user $1 > /dev/null
|
pip3 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 pip; then
|
if missing python; then
|
||||||
agree "Install python-pip" && apt_install python-pip
|
agree "Intsall python-is-python3" && apt_install python-is-python3
|
||||||
agree "Upgrade pip with pip" && sudo -H pip install --upgrade pip > /dev/null
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
missing virtualenv && agree "Install virtualenv" && pip_install virtualenv
|
if missing pip3; then
|
||||||
|
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 rsa -b 4096 -C "$email" -N "" -f ~/.ssh/id_rsa
|
ssh-keygen -t ed25519 -C "$email" -N "" -f ~/.ssh/id_rsa
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! missing virtualenv && agree "Set SSH keys on remote Git servers"; then
|
missing conduit && agree "Install ansible" && \
|
||||||
env=$(mktemp -d)
|
pip_install ansible
|
||||||
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'
|
||||||
|
|||||||
102
bootstrap-Fedora.sh
Executable file
102
bootstrap-Fedora.sh
Executable file
@@ -0,0 +1,102 @@
|
|||||||
|
#!/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
|
||||||
@@ -38,7 +38,7 @@ if errorlevel 1 (
|
|||||||
:: Install Windows SDK
|
:: Install Windows SDK
|
||||||
:windows_sdk
|
:windows_sdk
|
||||||
set choice=
|
set choice=
|
||||||
set /p choice="Install Windows SDK (Y/n)?"
|
set /p choice="Install Windows SDK [Y/n]? "
|
||||||
if "%choice%"=="" goto windows_sdk_yes
|
if "%choice%"=="" goto windows_sdk_yes
|
||||||
if "%choice%"=="Y" goto windows_sdk_yes
|
if "%choice%"=="Y" goto windows_sdk_yes
|
||||||
if "%choice%"=="y" goto windows_sdk_yes
|
if "%choice%"=="y" goto windows_sdk_yes
|
||||||
@@ -58,7 +58,7 @@ del %~dp0\winsdksetup.exe
|
|||||||
:: Install Chocolatey
|
:: Install Chocolatey
|
||||||
:choco
|
:choco
|
||||||
set choice=
|
set choice=
|
||||||
set /p choice="Install Chocolatey (Y/n)?"
|
set /p choice="Install Chocolatey [Y/n]? "
|
||||||
if "%choice%"=="" goto choco_yes
|
if "%choice%"=="" goto choco_yes
|
||||||
if "%choice%"=="Y" goto choco_yes
|
if "%choice%"=="Y" goto choco_yes
|
||||||
if "%choice%"=="y" goto choco_yes
|
if "%choice%"=="y" goto choco_yes
|
||||||
@@ -74,7 +74,7 @@ if errorlevel 1 exit /B 1
|
|||||||
:: Install Cmder, including Git
|
:: Install Cmder, including Git
|
||||||
:git
|
:git
|
||||||
set choice=
|
set choice=
|
||||||
set /p choice="Install Cmder, including Git (Y/n)?"
|
set /p choice="Install Cmder, including Git [Y/n]? "
|
||||||
if "%choice%"=="" goto git_yes
|
if "%choice%"=="" goto git_yes
|
||||||
if "%choice%"=="Y" goto git_yes
|
if "%choice%"=="Y" goto git_yes
|
||||||
if "%choice%"=="y" goto git_yes
|
if "%choice%"=="y" goto git_yes
|
||||||
@@ -90,7 +90,7 @@ if errorlevel 1 exit /B 1
|
|||||||
:: Install Python
|
:: Install Python
|
||||||
:python
|
:python
|
||||||
set choice=
|
set choice=
|
||||||
set /p choice="Install Python (Y/n)?"
|
set /p choice="Install Python [Y/n]? "
|
||||||
if "%choice%"=="" goto python_yes
|
if "%choice%"=="" goto python_yes
|
||||||
if "%choice%"=="Y" goto python_yes
|
if "%choice%"=="Y" goto python_yes
|
||||||
if "%choice%"=="y" goto python_yes
|
if "%choice%"=="y" goto python_yes
|
||||||
@@ -106,7 +106,7 @@ if errorlevel 1 exit /B 1
|
|||||||
:: Install virtualenv
|
:: Install virtualenv
|
||||||
:virtualenv
|
:virtualenv
|
||||||
set choice=
|
set choice=
|
||||||
set /p choice="Install virtualenv (Y/n)?"
|
set /p choice="Install virtualenv [Y/n]? "
|
||||||
if "%choice%"=="" goto virtualenv_yes
|
if "%choice%"=="" goto virtualenv_yes
|
||||||
if "%choice%"=="Y" goto virtualenv_yes
|
if "%choice%"=="Y" goto virtualenv_yes
|
||||||
if "%choice%"=="y" goto virtualenv_yes
|
if "%choice%"=="y" goto virtualenv_yes
|
||||||
@@ -122,7 +122,7 @@ if errorlevel 1 exit /B 1
|
|||||||
:: Generate SSH key
|
:: Generate SSH key
|
||||||
:ssh_key
|
:ssh_key
|
||||||
set choice=
|
set choice=
|
||||||
set /p choice="Generate SSH key (Y/n)?"
|
set /p choice="Generate SSH key [Y/n]? "
|
||||||
if "%choice%"=="" goto ssh_key_yes
|
if "%choice%"=="" goto ssh_key_yes
|
||||||
if "%choice%"=="Y" goto ssh_key_yes
|
if "%choice%"=="Y" goto ssh_key_yes
|
||||||
if "%choice%"=="y" goto ssh_key_yes
|
if "%choice%"=="y" goto ssh_key_yes
|
||||||
@@ -142,7 +142,7 @@ if errorlevel 1 exit /B 1
|
|||||||
:: Add git to the PATH to pip can find it
|
:: Add git to the PATH to pip can find it
|
||||||
set PATH=C:\tools\cmder\vendor\git-for-windows\bin;%PATH%
|
set PATH=C:\tools\cmder\vendor\git-for-windows\bin;%PATH%
|
||||||
set choice=
|
set choice=
|
||||||
set /p choice="Set SSH keys on remote Git servers (Y/n)?"
|
set /p choice="Set SSH keys on remote Git servers [Y/n]? "
|
||||||
if "%choice%"=="" goto remote_ssh_keys_yes
|
if "%choice%"=="" goto remote_ssh_keys_yes
|
||||||
if "%choice%"=="Y" goto remote_ssh_keys_yes
|
if "%choice%"=="Y" goto remote_ssh_keys_yes
|
||||||
if "%choice%"=="y" goto remote_ssh_keys_yes
|
if "%choice%"=="y" goto remote_ssh_keys_yes
|
||||||
@@ -157,10 +157,37 @@ if errorlevel 1 exit /B 1
|
|||||||
if errorlevel 1 exit /B 1
|
if errorlevel 1 exit /B 1
|
||||||
"%~dp0\bootstrap_env\Scripts\python.exe" -c "import bootstrap; bootstrap.set_ssh_keys()"
|
"%~dp0\bootstrap_env\Scripts\python.exe" -c "import bootstrap; bootstrap.set_ssh_keys()"
|
||||||
if errorlevel 1 exit /B 1
|
if errorlevel 1 exit /B 1
|
||||||
rmdir /Q /S "%~dp0\bootstrap_env"
|
|
||||||
echo "Completed: %0 will now be removed"
|
|
||||||
start /b "" cmd /c del "%~f0"&exit /b
|
|
||||||
:remote_ssh_keys_no
|
:remote_ssh_keys_no
|
||||||
|
|
||||||
|
:: Install conduit
|
||||||
|
:conduit
|
||||||
|
set choice=
|
||||||
|
set /p choice="Install conduit [Y/n]? "
|
||||||
|
if "%choice%"=="" goto conduit_yes
|
||||||
|
if "%choice%"=="Y" goto conduit_yes
|
||||||
|
if "%choice%"=="y" goto conduit_yes
|
||||||
|
if "%choice%"=="N" goto conduit_no
|
||||||
|
if "%choice%"=="n" goto conduit_no
|
||||||
|
echo invalid value: %choice%
|
||||||
|
goto conduit
|
||||||
|
:conduit_yes
|
||||||
|
"C:\Python27\Scripts\pip.exe" install git+ssh://git@github.com/kbenzie/conduit.git
|
||||||
|
rmdir /Q /S "%~dp0\bootstrap_env"
|
||||||
|
:conduit_no
|
||||||
|
|
||||||
|
:remove_bootstrap
|
||||||
|
set choice=
|
||||||
|
set /p choice="Remove bootstrap-Windows.cmd [y/N]? "
|
||||||
|
if "%choice%"=="" goto remove_bootstrap_no
|
||||||
|
if "%choice%"=="Y" goto remove_bootstrap_yes
|
||||||
|
if "%choice%"=="y" goto remove_bootstrap_yes
|
||||||
|
if "%choice%"=="N" goto remove_bootstrap_no
|
||||||
|
if "%choice%"=="n" goto remove_bootstrap_no
|
||||||
|
echo invalid value: %choice%
|
||||||
|
goto remove_bootstrap
|
||||||
|
:remove_bootstrap_yes
|
||||||
|
start /b "" cmd /c del "%~f0"&exit /b
|
||||||
|
:remove_bootstrap_no
|
||||||
|
|
||||||
:end
|
:end
|
||||||
endlocal
|
endlocal
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from getpass import getpass
|
|||||||
from os import environ
|
from os import environ
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from platform import node, system
|
from platform import node, system
|
||||||
|
|
||||||
from requests import ConnectionError, get, post
|
from requests import ConnectionError, get, post
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
from requests.compat import urlparse
|
from requests.compat import urlparse
|
||||||
@@ -104,32 +105,30 @@ 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')
|
||||||
response = post(session_url, {'login': username, 'password': password})
|
credentials = {'login': username, 'password': password}
|
||||||
if response.status_code != 201:
|
response = get(keys_url, credentials)
|
||||||
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(
|
response = post(keys_url,
|
||||||
keys_url, headers=auth, json={'title': node(),
|
credentials,
|
||||||
'key': local_key})
|
json={
|
||||||
|
'title': node(),
|
||||||
|
'key': local_key
|
||||||
|
})
|
||||||
if response.status_code != 201:
|
if response.status_code != 201:
|
||||||
raise bootstrap_error(response)
|
raise bootstrap_error(response)
|
||||||
|
|
||||||
|
|
||||||
def set_bitbucket_cloud_ssh_key():
|
def set_bitbucket_cloud_ssh_key():
|
||||||
"""Set BitBucket Cloud SSH key."""
|
"""Set BitBucket Cloud SSH key."""
|
||||||
api_url = 'https://api.bitbucket.org/1.0'
|
|
||||||
username, password = get_username_password('BitBucket Cloud')
|
username, password = get_username_password('BitBucket Cloud')
|
||||||
|
keys_url = 'https://api.bitbucket.org/1.0/users/%s/ssh-keys' % username
|
||||||
auth = HTTPBasicAuth(username, password)
|
auth = HTTPBasicAuth(username, password)
|
||||||
keys_url = '%s/users/%s/ssh-keys' % (api_url, username)
|
|
||||||
response = get(keys_url, auth=auth)
|
response = get(keys_url, auth=auth)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise bootstrap_error(response)
|
raise bootstrap_error(response)
|
||||||
|
|||||||
Reference in New Issue
Block a user