From 7bfed06d4d57f82ec880908e0a76852d64a9fce4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 20 Jul 2018 20:56:46 +0300 Subject: [PATCH] Migrate bootstrap to ansible playbooks (#184) Migrate bootstrap to ansible playbooks --- .gitignore | 2 + .travis.yml | 3 +- ansible-playbook/roles/certbot/tasks/main.yml | 13 + .../roles/dependencies/tasks/linux.yml | 103 ++++ .../roles/dependencies/tasks/macos.yml | 39 ++ .../roles/dependencies/tasks/main.yml | 8 + .../roles/dotfiles_install/tasks/main.yml | 27 + ansible-playbook/roles/nvm/tasks/main.yml | 4 + .../roles/nvm/tasks/npm_packages.yml | 9 + .../roles/nvm/tasks/nvm_install.yml | 38 ++ .../roles/transmute/tasks/main.yml | 9 + .../roles/transmute/templates/.env.j2 | 7 + ansible-playbook/transmute.yml | 16 + bootstrap | 519 +----------------- 14 files changed, 297 insertions(+), 500 deletions(-) create mode 100644 ansible-playbook/roles/certbot/tasks/main.yml create mode 100644 ansible-playbook/roles/dependencies/tasks/linux.yml create mode 100644 ansible-playbook/roles/dependencies/tasks/macos.yml create mode 100644 ansible-playbook/roles/dependencies/tasks/main.yml create mode 100644 ansible-playbook/roles/dotfiles_install/tasks/main.yml create mode 100644 ansible-playbook/roles/nvm/tasks/main.yml create mode 100644 ansible-playbook/roles/nvm/tasks/npm_packages.yml create mode 100644 ansible-playbook/roles/nvm/tasks/nvm_install.yml create mode 100644 ansible-playbook/roles/transmute/tasks/main.yml create mode 100644 ansible-playbook/roles/transmute/templates/.env.j2 create mode 100644 ansible-playbook/transmute.yml mode change 100755 => 100644 bootstrap diff --git a/.gitignore b/.gitignore index 81ce59397..dbb732642 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ okta.pem .env attic + +.idea/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 2705ec862..714db4a06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,8 @@ matrix: before_script: # bootstrap installs global dev dependencies, including the transmute-cli - - source ./bootstrap + - bash ./bootstrap + - source ~/.bashrc # This setup overwrites the transmute-cli with a build from the current branch (so the cli is tested) - cd $TRAVIS_BUILD_DIR/packages/transmute-cli - npm i diff --git a/ansible-playbook/roles/certbot/tasks/main.yml b/ansible-playbook/roles/certbot/tasks/main.yml new file mode 100644 index 000000000..a3758f422 --- /dev/null +++ b/ansible-playbook/roles/certbot/tasks/main.yml @@ -0,0 +1,13 @@ +--- +- name: install certbot + get_url: + url: "https://dl.eff.org/certbot-auto" + dest: "{{ transmute_bin }}/certbot-auto" + remote_src: yes + mode: 0755 + +- name: certbot-auto --noninteractive + shell: "certbot-auto --noninteractive" + args: + chdir: "{{ transmute_bin }}" + ignore_errors: yes diff --git a/ansible-playbook/roles/dependencies/tasks/linux.yml b/ansible-playbook/roles/dependencies/tasks/linux.yml new file mode 100644 index 000000000..75b49e93b --- /dev/null +++ b/ansible-playbook/roles/dependencies/tasks/linux.yml @@ -0,0 +1,103 @@ +--- +- name: install packages + package: + name: "{{ item }}" + state: present + become: yes + with_items: + - libncurses5-dev + - libslang2-dev + - gettext + - zlib1g-dev + - libselinux1-dev + - debhelper + - lsb-release + - pkg-config + - po-debconf + - autoconf + - automake + - autopoint + - libtool + - bison + - curl + - git + - socat + - jq + - virtualbox + +- name: create temporary directory NSENTER_TMP + tempfile: + state: directory + suffix: NSENTER_TMP + register: tmp + +- name: Unarchive util-linux + unarchive: + src: "https://www.kernel.org/pub/linux/utils/util-linux/v2.30/util-linux-2.30.2.tar.gz" + dest: "{{ tmp.path }}" + remote_src: yes + +- name: build nsenter + shell: "./autogen.sh && ./configure && make nsenter" + args: + chdir: "{{ tmp.path }}/util-linux-2.30.2" + +- name: Create dir {{ transmute_bin }} + file: + path: "{{ ansible_env.HOME }}/.local/bin" + state: directory + recurse: yes + +- name: Copy nsenter + copy: + src: "{{ tmp.path }}/util-linux-2.30.2/nsenter" + dest: "{{ ansible_env.HOME }}/.local/bin/nsenter" + remote_src: yes + mode: 0750 + +- name: Copy nsenter + copy: + src: "{{ tmp.path }}/util-linux-2.30.2/nsenter" + dest: "/usr/bin/nsenter" + remote_src: yes + mode: 0755 + become: yes + +- name: install kubectl + get_url: + url: "https://storage.googleapis.com/kubernetes-release/release/{{ transmute_kube_version }}/bin/linux/amd64/kubectl" + dest: "/usr/local/bin/kubectl" + remote_src: yes + mode: 0755 + owner: 0 + group: 0 + become: yes + +- name: install minikube + get_url: + url: "https://storage.googleapis.com/minikube/releases/v0.25.2/minikube-linux-amd64" + dest: "/usr/local/bin/minikube" + remote_src: yes + mode: 0755 + owner: 0 + group: 0 + become: yes + +- name: create temporary directory HELM_TMP + tempfile: + state: directory + suffix: HELM_TMP + register: tmp + +- name: Unarchive helm + unarchive: + src: "https://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz" + dest: "{{ tmp.path }}" + remote_src: yes + +- name: Copy helm + copy: + src: "{{ tmp.path }}/linux-amd64/helm" + dest: "{{ ansible_env.HOME }}/.transmute/bin/helm" + remote_src: yes + mode: 0750 diff --git a/ansible-playbook/roles/dependencies/tasks/macos.yml b/ansible-playbook/roles/dependencies/tasks/macos.yml new file mode 100644 index 000000000..381daece4 --- /dev/null +++ b/ansible-playbook/roles/dependencies/tasks/macos.yml @@ -0,0 +1,39 @@ +--- +- name: install homebrews + homebrew: + name: "{{ item }}" + state: present + with_items: + - kubectl + - kubernetes-helm + - kubernetes-cli + - coreutils + - curl + - git + - socat + - jq + +- name: link kubernetes-cli + homebrew: + name: "kubernetes-cli" + state: linked + ignore_errors: yes + +- name: install gnupg + homebrew: + name: "gnupg" + state: present + ignore_errors: yes + +- name: install minikube + homebrew_cask: + name: "minikube" + state: present + + +- name: install virtualbox + homebrew_cask: + name: "virtualbox" + state: present + + diff --git a/ansible-playbook/roles/dependencies/tasks/main.yml b/ansible-playbook/roles/dependencies/tasks/main.yml new file mode 100644 index 000000000..93a110ad8 --- /dev/null +++ b/ansible-playbook/roles/dependencies/tasks/main.yml @@ -0,0 +1,8 @@ +--- + +- include: linux.yml + when: "ansible_system == 'Linux' and ansible_machine == 'x86_64'" + +- include: macos.yml + when: "ansible_system == 'Darwin' and ansible_machine == 'x86_64'" + diff --git a/ansible-playbook/roles/dotfiles_install/tasks/main.yml b/ansible-playbook/roles/dotfiles_install/tasks/main.yml new file mode 100644 index 000000000..f730f3781 --- /dev/null +++ b/ansible-playbook/roles/dotfiles_install/tasks/main.yml @@ -0,0 +1,27 @@ +--- + +- name: touch {{ ansible_env.HOME }}/.zshrc + file: + path: "{{ ansible_env.HOME }}/.zshrc" + state: touch + +- name: touch {{ ansible_env.HOME }}/.bashrc + file: + path: "{{ ansible_env.HOME }}/.bashrc" + state: touch + +- name: set TRANSMUTE_BIN variable + set_fact: transmute_bin="{{ ansible_env.HOME }}/.transmute/bin" + +- name: Create dir {{ transmute_bin }} + file: + path: "{{ transmute_bin }}" + state: directory + +- name: add PATH to {{ ansible_env.HOME }}/.zshrc and {{ ansible_env.HOME }}/.bashrc + lineinfile: + path: "{{ item }}" + line: 'export PATH={{ transmute_bin }}:$PATH' + with_items: + - "{{ ansible_env.HOME }}/.zshrc" + - "{{ ansible_env.HOME }}/.bashrc" diff --git a/ansible-playbook/roles/nvm/tasks/main.yml b/ansible-playbook/roles/nvm/tasks/main.yml new file mode 100644 index 000000000..1a0d13ef1 --- /dev/null +++ b/ansible-playbook/roles/nvm/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- include: nvm_install.yml + +- include: npm_packages.yml \ No newline at end of file diff --git a/ansible-playbook/roles/nvm/tasks/npm_packages.yml b/ansible-playbook/roles/nvm/tasks/npm_packages.yml new file mode 100644 index 000000000..55e9ccd0c --- /dev/null +++ b/ansible-playbook/roles/nvm/tasks/npm_packages.yml @@ -0,0 +1,9 @@ +--- + +- name: Install npm packages globally + shell: 'bash -c "source {{ ansible_env.HOME }}/.nvm/nvm.sh && npm i -g {{ item }}"' + with_items: + - '--unsafe-perm ngrok' + - 'truffle@4.1.8' + - 'lerna@2.9.0' + - 'transmute-cli' diff --git a/ansible-playbook/roles/nvm/tasks/nvm_install.yml b/ansible-playbook/roles/nvm/tasks/nvm_install.yml new file mode 100644 index 000000000..41aa3571a --- /dev/null +++ b/ansible-playbook/roles/nvm/tasks/nvm_install.yml @@ -0,0 +1,38 @@ +--- + +- name: check if nvm already installed + stat: + path: "{{ ansible_env.HOME }}/.nvm/nvm.sh" + register: nvm_stat + +- name: create temporary directory NVM_TMP + tempfile: + state: directory + suffix: NVM_TMP + register: tmp + when: nvm_stat.stat.isreg is not defined or not nvm_stat.stat.isreg + +- name: Download nvm installer + get_url: + url: https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh + dest: "{{ tmp.path }}/install.sh" + mode: 0750 + when: nvm_stat.stat.isreg is not defined or not nvm_stat.stat.isreg + +- name: install nvm + shell: "{{ tmp.path }}/install.sh" + when: nvm_stat.stat.isreg is not defined or not nvm_stat.stat.isreg + +- name: Source nvm in {{ ansible_env.HOME }}/.profile + lineinfile: dest="{{ ansible_env.HOME }}/{{ item }}" line="source ~/.nvm/nvm.sh" create=yes + with_items: + - .profile + - .bashrc + +- name: Install node + shell: 'bash -c "source {{ ansible_env.HOME }}/.profile && nvm ls-remote --lts=carbon && nvm install --lts=carbon"' + register: nvm_install_result + changed_when: "'is already installed.' not in nvm_install_result.stdout" + +- name: Set default node version to carbon + shell: 'bash -c "source {{ ansible_env.HOME }}/.profile && nvm alias default lts/carbon"' diff --git a/ansible-playbook/roles/transmute/tasks/main.yml b/ansible-playbook/roles/transmute/tasks/main.yml new file mode 100644 index 000000000..13f225988 --- /dev/null +++ b/ansible-playbook/roles/transmute/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: generate {{ ansible_env.HOME }}/.transmute/.env + template: + src: ".env.j2" + dest: "{{ ansible_env.HOME }}/.transmute/.env" + +- name: Install npm packages globally + shell: 'bash -c "source {{ ansible_env.HOME }}/.nvm/nvm.sh && npm i -g transmute-cli"' + become: no diff --git a/ansible-playbook/roles/transmute/templates/.env.j2 b/ansible-playbook/roles/transmute/templates/.env.j2 new file mode 100644 index 000000000..844c8ac27 --- /dev/null +++ b/ansible-playbook/roles/transmute/templates/.env.j2 @@ -0,0 +1,7 @@ +#!/bin/bash + +TRANSMUTE_VERBOSITY=10 +TRANSMUTE_DIR={{ ansible_env.HOME }}/.transmute +TRANSMUTE_BIN={{ transmute_bin }} +TRANSMUTE_REPO={{ ansible_env.HOME }}/.transmute/git/transmute +TRANSMUTE_KUBE_VERSION={{ transmute_kube_version }} diff --git a/ansible-playbook/transmute.yml b/ansible-playbook/transmute.yml new file mode 100644 index 000000000..a356a439b --- /dev/null +++ b/ansible-playbook/transmute.yml @@ -0,0 +1,16 @@ +--- +- name: transmute + vars: + fix_dotfiles: true + transmute_kube_version: "v1.9.4" + nvm_version: "v0.33.11" + hosts: localhost + connection: local + gather_facts: yes + roles: + - role: dotfiles_install + when: fix_dotfiles + - role: dependencies + - role: nvm + - role: certbot + - role: transmute diff --git a/bootstrap b/bootstrap old mode 100755 new mode 100644 index f9233808b..d40cce998 --- a/bootstrap +++ b/bootstrap @@ -4,12 +4,6 @@ : ${TRANSMUTE_DIR:=$HOME/.transmute} : ${TRANSMUTE_BIN:=$TRANSMUTE_DIR/bin} : ${TRANSMUTE_REPO:=$TRANSMUTE_DIR/git/transmute} -: ${TRANSMUTE_VERBOSITY:=10} -: ${HELM_INSTALL_DIR:=$TRANSMUTE_BIN} -: ${TRANSMUTE_KUBE_VERSION:=v1.9.4} -: ${FIX_DOTFILES:="true"} -: ${NVM_DIR_ADDS:="true"} -: ${NVM_VERSION:='0.33.9'} : ${TRANSMUTE_USE_WARN:=y} export CWD=$(pwd) @@ -34,361 +28,30 @@ warn_user_of_global_install () { sleep 1 } -chkdir () { - if [ ! -w $1 ] ; then - mkdir -p $1 - #sudo chown $USER $1 - fi - if [ ! -w $1 ] ; then - echo "Cannot write to $1, please check your permissions" - exit 2 - fi -} - -# these vars are used by the following functions -LINE_TO_ADD='' -TARGET_FILE_FOR_ADD=~/.profile - -check_if_line_exists() -{ - echo "Checking for '$LINE_TO_ADD' in $TARGET_FILE_FOR_ADD" - grep -qsFx "$LINE_TO_ADD" $TARGET_FILE_FOR_ADD -} - -add_line_to() -{ - echo "Adding '$LINE_TO_ADD' to $TARGET_FILE_FOR_ADD" - TARGET_FILE=$TARGET_FILE_FOR_ADD - [ -w "$TARGET_FILE" ] || TARGET_FILE=$TARGET_FILE_FOR_ADD - printf "%s\n" "$LINE_TO_ADD" >> "$TARGET_FILE" -} - -macminikube () { - if brew ls --versions minikube > /dev/null; then - # The package is installed - printf "minikube installed, skipping.\n" - else - # The package is not installed - echo 'Installing minikube' - brew cask install minikube - fi -} - -mackubectl () { - if brew ls --versions kubectl > /dev/null; then - # The package is installed - printf "kubectl installed, skipping.\n" - else - # The package is not installed - echo 'Installing kubectl' - brew install kubectl - brew link kubernetes-cli - fi -} - -install_mac_virtualbox () { - if brew cask ls --versions virtualbox > /dev/null; then - # The package is installed - printf "virtualbox installed, skipping.\n" - else - # The package is not installed - echo 'Installing virtualbox' - brew cask install virtualbox - fi -} - -machelm () { - - if brew ls --versions kubernetes-helm > /dev/null; then - # The package is installed - printf "helm installed, skipping.\n" - else - # The package is not installed - echo 'Installing helm' - brew install kubernetes-helm - fi -} - -macnsenter () { - echo 'NOT Installing nsenter' - #brew install kubernetes-nsenter -} - - -macreadlink () { - if brew ls --versions coreutils > /dev/null; then - # The package is installed - printf "coreutils installed, skipping." - else - # The package is not installed - #Installs 'greadlink' tool - echo 'Installing coreutils' - brew install coreutils - fi -} - -windowsminikube () { - echo 'Installing minikube' - choco install minikube -} - -windowskubectl () { - echo 'Installing kubectl' - choco install kubernetes-cli -} - -windowshelm () { - echo 'Installing helm' - choco install helm -} - -windowsnsenter () { - echo 'Installing nsenter' - choco install nsenter -} - -install_nsenter_linux (){ - - sudo apt-get -y install libncurses5-dev libslang2-dev gettext zlib1g-dev libselinux1-dev debhelper lsb-release pkg-config po-debconf autoconf automake autopoint libtool bison - TMP=$(mktemp -d --suffix=NSENTER_TMP) - curl -sL https://www.kernel.org/pub/linux/utils/util-linux/v2.30/util-linux-2.30.2.tar.gz | tar -xz -C $TMP/ - cd $TMP/util-linux-2.30.2 && ./autogen.sh && ./configure && make nsenter - mkdir -p $HOME/.local/bin - cp -v $TMP/util-linux-2.30.2/nsenter $HOME/.local/bin/nsenter - chmod +x $HOME/.local/bin/nsenter - sudo cp -v $HOME/.local/bin/nsenter /usr/bin/nsenter -} - -install_kubectl_linux () { - if ! type "kubectl" >/dev/null 2>/dev/null; then - echo 'Installing kubectl' - TMP=$(mktemp -d --suffix=KUBECTLTMP) - cd $TMP - curl -LO https://storage.googleapis.com/kubernetes-release/release/$TRANSMUTE_KUBE_VERSION/bin/linux/amd64/kubectl - chmod +x kubectl - sudo chown 0:0 kubectl - sudo mv -v kubectl /usr/local/bin/ - cd - rmdir $TMP - fi -} - -install_minikube_linux () { - if ! type "minikube" >/dev/null 2>/dev/null; then - echo 'Installing minikube' - - curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.25.2/minikube-linux-amd64 - chmod +x minikube - sudo chown 0:0 minikube - sudo mv minikube /usr/local/bin/ - - fi -} - -install_helm_linux () { - if ! type "helm" >/dev/null 2>/dev/null; then - - HELM_VERSION='v2.8.2' - HELM_PREFIX="$HOME/.transmute/bin" - HELM_URL="https://storage.googleapis.com/kubernetes-helm/helm-$HELM_VERSION-linux-amd64.tar.gz" - - echo "Installing $HELM_VERSION" - curl -sL $HELM_URL -o helm.tgz - tar zxvf helm.tgz - - cd linux-amd64 - chmod +x helm - mv helm $HELM_PREFIX/helm - fi -} - -nvm_dir_adds () { - LINE_TO_ADD='export NVM_DIR=~/.nvm' - TARGET_FILE_FOR_ADD=~/.zshrc - check_if_line_exists || add_line_to - TARGET_FILE_FOR_ADD=~/.bash_profile - check_if_line_exists || add_line_to - - LINE_TO_ADD='source ~/.nvm/nvm.sh' - TARGET_FILE_FOR_ADD=~/.zshrc - check_if_line_exists || add_line_to - TARGET_FILE_FOR_ADD=~/.bash_profile - check_if_line_exists || add_line_to -} - -dotfiles_install () { - if [[ $TRANSMUTE_VERBOSITY -gt '1' ]]; then - echo 'Adjusting dotfiles' - fi - touch $HOME/.zshrc - touch $HOME/.bashrc - # here we'll make a bin dir in $HOME and add it to path - chkdir $TRANSMUTE_BIN - LINE_TO_ADD="$(printf "export PATH=%s:\$PATH" $TRANSMUTE_BIN)" - TARGET_FILE_FOR_ADD=$HOME/.bashrc - check_if_line_exists || add_line_to - TARGET_FILE_FOR_ADD=$HOME/.zshrc - check_if_line_exists || add_line_to - export PATH=$HOME/.transmute/bin:$PATH -} - -install_certbot () { - echo 'Install certbot for Lets Encrypt. This may hang for a bit.' - if ! type "certbot-auto" >/dev/null 2>/dev/null; then - curl -O https://dl.eff.org/certbot-auto - chmod a+x ./certbot-auto - curl -O https://dl.eff.org/certbot-auto.asc - if type "gpg2" >/dev/null 2>/dev/null; then - set +e - gpg2 --recv-key A2CFB51FA275A7286234E7B24D17C995CD9775F2 - gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-key A2CFB51FA275A7286234E7B24D17C995CD9775F2 - gpg2 --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-key A2CFB51FA275A7286234E7B24D17C995CD9775F2 - set -e - gpg2 --trusted-key 4D17C995CD9775F2 --verify certbot-auto.asc certbot-auto - elif type "gpg" >/dev/null 2>/dev/null; then - set +e - gpg --recv-key A2CFB51FA275A7286234E7B24D17C995CD9775F2 - gpg --keyserver hkp://pool.sks-keyservers.net --verbose --recv-key A2CFB51FA275A7286234E7B24D17C995CD9775F2 - gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --verbose --recv-key A2CFB51FA275A7286234E7B24D17C995CD9775F2 - set -e - gpg --trusted-key 4D17C995CD9775F2 --verify certbot-auto.asc certbot-auto - else - echo 'gpg not found' - fi - rm certbot-auto.asc - chmod +x certbot-auto - mv certbot-auto $TRANSMUTE_BIN/ - set +e - certbot-auto --noninteractive - set -e - cd - else - echo 'certbot-auto already installed skipping' - fi -} - -install_nvm () { - echo "Install NVM" - set +e - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion - # test if nvm is present if not, throw away the error - this_output=$(nvm --version 2>/dev/null) - set -e - - if [ "$this_output" = "$NVM_VERSION" ]; then - echo "NVM $NVM_VERSION is already installed skipping" - else - touch ~/.profile - - set +e - mkdir $HOME/.nvm - curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v$NVM_VERSION/install.sh | bash - set -e - - if [ "$NVM_DIR_ADDS" = "true" ]; then - nvm_dir_adds - fi - fi -} - - - -install_lerna_npm () { - if ! type "lerna" >/dev/null 2>/dev/null; then - npm i -g lerna@2.9.0 - else - echo 'lerna already installed skipping' - fi -} - -install_truffle_npm () { - if ! type "truffle" >/dev/null 2>/dev/null; then - npm i -g truffle@4.1.8 - else - echo 'truffle already installed skipping' - fi -} - -install_ngrok_npm () { - if ! type "ngrok" >/dev/null 2>/dev/null; then - npm i -g ngrok - else - echo 'ngrok already installed skipping' - fi -} - -lts_install () { - if ! type "npm" >/dev/null 2>/dev/null; then - if [[ $TRANSMUTE_VERBOSITY -gt '2' ]]; then - echo 'Installing Node 8 LTS/carbon' - fi - - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion - - set +e - nvm ls-remote --lts=carbon - if [[ $TRANSMUTE_VERBOSITY -gt '2' ]]; then - echo "Engage nvm to install lts/carbon" - fi - nvm install --lts=carbon - if [[ $TRANSMUTE_VERBOSITY -gt '2' ]]; then - echo "Engage nvm to alias lts/carbon to default" - fi - nvm alias default lts/carbon - nvm use default - set -e - else - echo 'npm already installed skipping' - fi -} - -install_socat () { - if ! type "socat" >/dev/null 2>/dev/null; then +install_ansible () { + if ! type "ansible" >/dev/null 2>/dev/null; then if type "apt-get" >/dev/null 2>/dev/null; then - sudo apt-get install -y socat + sudo apt-get install -y software-properties-common + sudo apt-add-repository -y ppa:ansible/ansible && \ + sudo apt-key fingerprint 0EBFCD88 && \ + sudo apt-get update && \ + sudo apt-get install -y ansible elif type "dnf" >/dev/null 2>/dev/null; then - sudo dnf install -y socat + sudo dnf install -y ansible elif type "zypper" >/dev/null 2>/dev/null; then - sudo zypper --non-interactive install -y socat + sudo zypper --non-interactive install -y ansible elif type "pacman" >/dev/null 2>/dev/null; then - sudo pacman -Sy --noconfirm socat + sudo pacman -Sy --noconfirm ansible elif type "brew" >/dev/null 2>/dev/null; then - brew install socat < /dev/null + brew install ansible < /dev/null elif type "chocolatey" >/dev/null 2>/dev/null; then - chocolatey install socat + chocolatey install ansible else - echo 'No appropriate installer found for socat, install socat and run this script again' + echo 'No appropriate installer found for ansible, install ansible and run this script again' exit 1 fi else - echo 'socat already installed skipping' - fi -} - -install_curl () { - if ! type "curl" >/dev/null 2>/dev/null; then - if type "apt-get" >/dev/null 2>/dev/null; then - sudo apt-get install -y curl - elif type "dnf" >/dev/null 2>/dev/null; then - sudo dnf install -y curl - elif type "zypper" >/dev/null 2>/dev/null; then - sudo zypper --non-interactive install -y curl - elif type "pacman" >/dev/null 2>/dev/null; then - sudo pacman -Sy --noconfirm curl - elif type "brew" >/dev/null 2>/dev/null; then - brew install curl < /dev/null - elif type "chocolatey" >/dev/null 2>/dev/null; then - chocolatey install curl - else - echo 'No appropriate installer found for curl, install curl and run this script again' - exit 1 - fi - else - echo 'curl already installed skipping' + echo 'ansible already installed skipping' fi } @@ -415,116 +78,6 @@ install_git () { fi } -install_jq () { - if ! type "jq" >/dev/null 2>/dev/null; then - if type "apt-get" >/dev/null 2>/dev/null; then - sudo apt-get install -y jq - elif type "dnf" >/dev/null 2>/dev/null; then - sudo dnf install -y jq - elif type "zypper" >/dev/null 2>/dev/null; then - sudo zypper --non-interactive install -y jq - elif type "pacman" >/dev/null 2>/dev/null; then - sudo pacman -Sy --noconfirm jq - elif type "brew" >/dev/null 2>/dev/null; then - brew install jq < /dev/null - elif type "chocolatey" >/dev/null 2>/dev/null; then - chocolatey install jq - else - echo 'No appropriate installer found for jq, install jq and run this script again' - exit 1 - fi - else - echo 'jq already installed skipping' - fi -} - -transmute_cli_install () { - npm i -g transmute-cli -} - -transmute_env_install () { - # Check for config env file - if [ -e $TRANSMUTE_DIR/.env ]; then - echo 'env file found not overwriting' - else - echo '#!/bin/bash' > $TRANSMUTE_DIR/.env - echo 'TRANSMUTE_VERBOSITY=10' >> $TRANSMUTE_DIR/.env - echo "TRANSMUTE_DIR=$TRANSMUTE_DIR" >> $TRANSMUTE_DIR/.env - echo "TRANSMUTE_BIN=$TRANSMUTE_BIN" >> $TRANSMUTE_DIR/.env - echo "TRANSMUTE_REPO=$TRANSMUTE_REPO" >> $TRANSMUTE_DIR/.env - echo "TRANSMUTE_KUBE_VERSION=$TRANSMUTE_KUBE_VERSION" >> $TRANSMUTE_DIR/.env - fi -} - -windowsreqs () { - check_cmd chocolatey - install_curl - install_git - install_socat - windowskubectl - windowsminikube - windowshelm - windowsnsenter - install_nvm - lts_install - install_ngrok_npm - install_truffle_npm - install_lerna_npm - install_certbot - install_jq - dotfiles_install - transmute_env_install - transmute_cli_install -} - -macreqs () { - check_cmd brew - install_curl - install_git - install_socat - set +e - brew install gnupg < /dev/null - set -e - install_mac_virtualbox - mackubectl - macminikube - machelm - macnsenter - macreadlink - install_nvm - lts_install - install_ngrok_npm - install_truffle_npm - install_lerna_npm - install_certbot - install_jq - dotfiles_install - transmute_env_install - transmute_cli_install -} - -linuxreqs () { - sudo apt-get update -y - install_nsenter_linux - install_curl - install_git - install_socat - install_kubectl_linux - install_minikube_linux - install_helm_linux - install_nvm - lts_install - install_ngrok_npm - install_truffle_npm - install_lerna_npm - install_certbot - install_jq - dotfiles_install - transmute_env_install - transmute_cli_install -} - - run_it () { set -e @@ -577,6 +130,8 @@ if [[ "$TRANSMUTE_USE_WARN" == 'y' ]]; then warn_user_of_global_install fi +install_ansible + echo "Checking $TRANSMUTE_DIR" mkdir -p $TRANSMUTE_BIN @@ -594,7 +149,7 @@ install_git # however this will if [ "$TRAVIS" = 'true' ]; then echo 'travis ci skipping git actions' - + cd $TRANSMUTE_DIR/git ln -s $TRAVIS_BUILD_DIR transmute @@ -617,44 +172,10 @@ else cd $CWD fi -if [ "$FIX_DOTFILES" = "true" ]; then - dotfiles_install -fi - -if [ "$PLATFORM" = "os.linux.x86_64" ] ; then - linuxreqs -elif [ "$PLATFORM" = "os.osx.x86_64" ] ; then - macreqs -elif [ "$PLATFORM" = "os.windows.x86_64" ] ; then - windowsreqs -fi - -echo 'check helm' -check_cmd helm -echo 'check kubectl' -check_cmd kubectl -echo 'check minikube' -check_cmd minikube - -echo 'The bootstrap has finished' -echo 'You can now use the transmute-cli to develop dapps!:' -echo 'https://github.com/transmute-industries/transmute#setup' - -if [ "$PLATFORM" = "os.osx.x86_64" ] ; then - SETUP_DIR=$(greadlink -f $TRANSMUTE_DIR) -else - SETUP_DIR=$(readlink -f $TRANSMUTE_DIR) -fi - -echo "If you did not source this script, you will need to source your ~/.bashrc or ~/.zshrc file" - -. $HOME/.nvm/nvm.sh - -trap - EXIT +ansible-playbook --diff -l "localhost" $TRANSMUTE_REPO/ansible-playbook/transmute.yml } # End run_it wrapper -check_cmd mktemp -check_cmd uname - run_it + +echo "Please source ~/.bashrc or restart your shell to apply .bashrc changes"