From 30adbfe76325d3da2d47fa41f3e4dcf2c0b6c310 Mon Sep 17 00:00:00 2001 From: Harry Lascelles Date: Wed, 12 Jul 2023 12:48:24 +0100 Subject: [PATCH 1/6] Fixes for Linux --- README.md | 9 ++++++++- run_bamstrap | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b32293f..b3a1cd3 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,15 @@ Bambrew - Bamboo Engineering's development environment setup tooling # First time setup +1. On another machine (maybe) set up a GitHub [personal access token][1]. +1. Copy it to your new machine here: `~/.config/hub` in this file format: + ```yaml + github.com: + - user: + oauth_token: + protocol: https + ``` 1. Ask an existing `bambooengineering/umbrella` administrator to grant you repo access -1. Setup a GitHub [personal access token][1] 1. Run the following at a command prompt: ``` diff --git a/run_bamstrap b/run_bamstrap index b65bd94..1573d67 100755 --- a/run_bamstrap +++ b/run_bamstrap @@ -12,15 +12,30 @@ if [ "$(id -u)" = 0 ]; then exit 4 fi +echo "Requesting sudo access to install packages if needed" +sudo date + if ! command -v curl >/dev/null 2>&1; then echo "Aborting! No curl found (install and retry)" exit 5 fi +if ! [ -x "$(command -v brew)" ]; then + # https://docs.brew.sh/Homebrew-on-Linux + echo "Installing brew" + sudo apt-get install build-essential procps curl file git + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +fi + if ! command -v ruby >/dev/null || \ (command -v ruby >/dev/null && ruby -e 'exit RUBY_VERSION.split(".").first(2).join(".").to_f < 2.3'); then echo "No suitable Ruby found (installing vendor Ruby)" - eval "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install-ruby)" + RUBY_INSTALL_HTTP_STATUS=$(curl -fsSL "https://raw.githubusercontent.com/Linuxbrew/install/master/install-ruby") + + if [[ $RUBY_INSTALL_HTTP_STATUS -eq 404 ]]; then + echo "Error: 404 Not Found" + exit 1 + fi fi if [ -z "$GITHUB_TOKEN" ]; then From e8748b09143720c5bb2f518941782c7fbba6041f Mon Sep 17 00:00:00 2001 From: Harry Lascelles Date: Wed, 12 Jul 2023 12:48:30 +0100 Subject: [PATCH 2/6] Fixes for Linux --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 5e1422c..52c745b 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,8 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc +/.idea/.gitignore +/.idea/bambrew.iml +/.idea/misc.xml +/.idea/modules.xml +/.idea/vcs.xml From b5a1d6dfa26414e6ba0dae1b1f46f22187b77a86 Mon Sep 17 00:00:00 2001 From: Harry Lascelles Date: Wed, 12 Jul 2023 12:49:33 +0100 Subject: [PATCH 3/6] Fixes for Linux --- run_bamstrap | 1 + 1 file changed, 1 insertion(+) diff --git a/run_bamstrap b/run_bamstrap index 1573d67..14d410c 100755 --- a/run_bamstrap +++ b/run_bamstrap @@ -20,6 +20,7 @@ if ! command -v curl >/dev/null 2>&1; then exit 5 fi +echo "Checking for brew installation" if ! [ -x "$(command -v brew)" ]; then # https://docs.brew.sh/Homebrew-on-Linux echo "Installing brew" From 9e264d96697533689955cbb86b77ac6ef6887617 Mon Sep 17 00:00:00 2001 From: Harry Lascelles Date: Wed, 12 Jul 2023 12:50:02 +0100 Subject: [PATCH 4/6] Fixes for Linux --- run_bamstrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_bamstrap b/run_bamstrap index 14d410c..309f1cb 100755 --- a/run_bamstrap +++ b/run_bamstrap @@ -24,7 +24,7 @@ echo "Checking for brew installation" if ! [ -x "$(command -v brew)" ]; then # https://docs.brew.sh/Homebrew-on-Linux echo "Installing brew" - sudo apt-get install build-essential procps curl file git + sudo apt-get install -y build-essential procps curl file git /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" fi From d9eaae82b6e51814060d893d1fc3c7747af30ab1 Mon Sep 17 00:00:00 2001 From: Harry Lascelles Date: Wed, 12 Jul 2023 13:07:35 +0100 Subject: [PATCH 5/6] Fixes for Linux --- run_bamstrap | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/run_bamstrap b/run_bamstrap index 309f1cb..35916c5 100755 --- a/run_bamstrap +++ b/run_bamstrap @@ -1,6 +1,5 @@ -#!/bin/bash - -set -e +#!/usr/bin/env bash +set -euo pipefail if [ -z "$USER" ]; then echo "Aborting! No USER environment variable set" @@ -26,22 +25,26 @@ if ! [ -x "$(command -v brew)" ]; then echo "Installing brew" sudo apt-get install -y build-essential procps curl file git /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + # Allow brew to be used in this script + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" fi -if ! command -v ruby >/dev/null || \ - (command -v ruby >/dev/null && ruby -e 'exit RUBY_VERSION.split(".").first(2).join(".").to_f < 2.3'); then - echo "No suitable Ruby found (installing vendor Ruby)" - RUBY_INSTALL_HTTP_STATUS=$(curl -fsSL "https://raw.githubusercontent.com/Linuxbrew/install/master/install-ruby") +echo "Checking for rbenv installation" +if ! [ -x "$(command -v rbenv)" ]; then + echo "Installing rbenv" + brew install rbenv +fi - if [[ $RUBY_INSTALL_HTTP_STATUS -eq 404 ]]; then - echo "Error: 404 Not Found" - exit 1 - fi +if ! command -v ruby >/dev/null || \ + (command -v ruby >/dev/null && ruby -e 'exit RUBY_VERSION.split(".").first(2).join(".").to_f < 3.1'); then + echo "No suitable Ruby found. Installing ruby via rbenv..." + sudo apt-get install -y libz-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev + rbenv install 3.1.3 fi -if [ -z "$GITHUB_TOKEN" ]; then - echo "Please provide your Github Token (you can generate one at https://github.com/settings/tokens):" - read -s GITHUB_TOKEN +if [ ! -f "~/.config/hub" ]; then + echo "Ensure you have set up your GitHub access token in ~/.config/hub" + exit 1 fi run_curl() { From 0ebe3a921e4543224c0b4936aaf53d058409f61b Mon Sep 17 00:00:00 2001 From: Harry Lascelles Date: Fri, 14 Jul 2023 10:36:58 +0100 Subject: [PATCH 6/6] Fixes for Linux --- README.md | 3 ++- run_bamstrap | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b3a1cd3..34293be 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ Bambrew - Bamboo Engineering's development environment setup tooling # First time setup +1. Copy on your personl SSH keys to ~/.ssh (including the one you use to access GitHub). 1. On another machine (maybe) set up a GitHub [personal access token][1]. -1. Copy it to your new machine here: `~/.config/hub` in this file format: +1. Create a file in the following format and copy it to `~/.config/hub`: ```yaml github.com: - user: diff --git a/run_bamstrap b/run_bamstrap index 35916c5..c280853 100755 --- a/run_bamstrap +++ b/run_bamstrap @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -euo pipefail +set -eu if [ -z "$USER" ]; then echo "Aborting! No USER environment variable set" @@ -14,16 +14,21 @@ fi echo "Requesting sudo access to install packages if needed" sudo date -if ! command -v curl >/dev/null 2>&1; then - echo "Aborting! No curl found (install and retry)" - exit 5 +if ! [ -x "$(command -v curl)" ]; then + echo "Installing curl..." + sudo apt-get install -y curl +fi + +if [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then + echo "Ensure you have your GitHub SSH key at ~/.ssh/id_rsa.pub" + exit 1 fi echo "Checking for brew installation" if ! [ -x "$(command -v brew)" ]; then # https://docs.brew.sh/Homebrew-on-Linux - echo "Installing brew" - sudo apt-get install -y build-essential procps curl file git + echo "Installing brew..." + sudo apt-get install -y build-essential procps file git /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Allow brew to be used in this script eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" @@ -35,18 +40,19 @@ if ! [ -x "$(command -v rbenv)" ]; then brew install rbenv fi -if ! command -v ruby >/dev/null || \ - (command -v ruby >/dev/null && ruby -e 'exit RUBY_VERSION.split(".").first(2).join(".").to_f < 3.1'); then +if [ ! -f "$HOME/.rbenv/shims/ruby" ]; then echo "No suitable Ruby found. Installing ruby via rbenv..." sudo apt-get install -y libz-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev rbenv install 3.1.3 fi -if [ ! -f "~/.config/hub" ]; then +if [ ! -f "$HOME/.config/hub" ]; then echo "Ensure you have set up your GitHub access token in ~/.config/hub" exit 1 fi +GITHUB_TOKEN=$(ruby -e "require 'yaml'; puts YAML.load_file(Dir.home + '/.config/hub')['github.com'][0]['oauth_token']") + run_curl() { ORGANISATION="bambooengineering" REPO="umbrella" @@ -66,4 +72,4 @@ if [ "$code" != "200" ]; then exit 7 fi -ruby -e "$(run_curl)" +$HOME/.rbenv/shims/ruby -e "$(run_curl)"