From d72bf5749a8c9622d015a9f9d2077cd8f15f42a3 Mon Sep 17 00:00:00 2001 From: Marcia Ramos Date: Fri, 11 Dec 2020 19:23:12 +0000 Subject: [PATCH 1/5] Prep macos for dependencies - If the user is brand new. - Or if they never installed Homebrew and Ruby in their computer This is the way to go without having to sudo everything --- functions.sh | 1 + functions/assets/test.sh | 1 + install/prep-macos.sh | 149 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 install/prep-macos.sh diff --git a/functions.sh b/functions.sh index 907d90c..b27527c 100644 --- a/functions.sh +++ b/functions.sh @@ -49,3 +49,4 @@ source install/gitlab-dep.sh source install/gdk.sh source install/ssh_gitlab.sh source install/update-docs-shell.sh +source install/prep-macos.sh diff --git a/functions/assets/test.sh b/functions/assets/test.sh index 84df30f..7c028e0 100644 --- a/functions/assets/test.sh +++ b/functions/assets/test.sh @@ -30,6 +30,7 @@ test() { tput setaf 2; echo '25. status:'; tput sgr0; test_status tput setaf 2; echo '25. ssh:'; tput sgr0; test_ssh tput setaf 2; echo '25. update-docs-shell:'; tput sgr0; test_update_docs_shell + tput setaf 2; echo '25. macos-prep:'; tput sgr0; test_prepmacos } ifsuccess fi diff --git a/install/prep-macos.sh b/install/prep-macos.sh new file mode 100644 index 0000000..b5cad3f --- /dev/null +++ b/install/prep-macos.sh @@ -0,0 +1,149 @@ +# Test files (`docs test files`) + +test_prepmacos() { + echo 'install/prep-macos.sh ok' +} + +# ---------------------------------------------------------------- # + +# Prep new Macbook +# - Install macOS's command line tools (`xcode-select`) +# - Install Homebrew +# - Install RVM +# - Install Bundler +# - Install Code Editor + +# ---------------------------------------------------------------- # + +# Prepare installation + +prep-install() { + prep_xcode + prep_brew + prep_gpg + prep_rvm + prep_bundler + prep_code_editor +} + +# ---------------------------------------------------------------- # + +# xcode-select + +prep_xcode(){ + # Latest + echo "Installing macOS's command line tools (xcode-select)..." + xcode-select --install +} + +# ---------------------------------------------------------------- # + +# Homebrew + +prep_brew(){ + # Brew user installation + echo "Installing Homebrew (user install)..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + exec $SHELL +} + +# ---------------------------------------------------------------- # + +# GPG + +prep_gpg(){ + echo "Installing GPG suit..." + brew install --cask gpg-suite + exec $SHELL +} + +# ---------------------------------------------------------------- # + +# RVM + +prep_rvm(){ + echo "Installing RVM and Ruby" + # As a first step install GPG keys used to verify installation package: + gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB + + # Download and install + + \curl -sSL https://get.rvm.io | bash -s stable --ruby + + # Load + source ~/.rvm/scripts/rvm + + # Load RVM into a shell session *as a function* + echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bash_profile + + # Restart shell + + exec $SHELL + + # Test + type rvm | head -n 1 + rvm --version + ruby --version + gem --version +} + +# ---------------------------------------------------------------- # + +# Ruby / Rubygems (out for now - trying with rvm installation) +prep_ruby(){ + brew install ruby + export GEM_HOME="/usr/local/lib/ruby/gems/" + export PATH="$GEM_HOME/bin:$PATH" + exec $SHELL +} + +# ---------------------------------------------------------------- # + +# Bundler + +prep_bundler(){ + echo "Installing Bundler..." + gem install bundler +} + +# ---------------------------------------------------------------- # + +# Code editor + +prep_code_editor(){ + echo "Would you like to install a code editor?" + echo "Available code editors:" + echo "- Type '`tput bold`s`tput sgr0`' for `tput bold`Sublime Text 3`tput sgr0`" + echo "- Type '`tput bold`a`tput sgr0`' for `tput bold`Atom`tput sgr0`" + echo "- Type '`tput bold`v`tput sgr0`' for `tput bold`Visual Studio Code`tput sgr0`" + echo "- Type '`tput bold`n`tput sgr0`' for `tput bold`none`tput sgr0`" + ok + while : + do + read CODE_EDT + case $CODE_EDT in + a) + echo "Installing Atom..." + brew install --cask atom + break + ;; + s) + echo "Installing Sublime Text 3..." + brew install --cask sublime-text + break + ;; + v) + echo "Installing VS Code..." + brew install --cask visual-studio-code + break + ;; + n) + echo "Ok." + break + ;; + *) + echo "Sorry, I don't understand. Please choose one of the given alternatives." + ;; + esac + done +} -- GitLab From 1023663d9c15ac914c07254022af4a7a445087ce Mon Sep 17 00:00:00 2001 From: Marcia Ramos Date: Wed, 16 Dec 2020 11:17:36 +0000 Subject: [PATCH 2/5] Brew prep permissions with sudo --- install/prep-macos.sh | 50 ++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/install/prep-macos.sh b/install/prep-macos.sh index b5cad3f..b828676 100644 --- a/install/prep-macos.sh +++ b/install/prep-macos.sh @@ -19,7 +19,7 @@ test_prepmacos() { prep-install() { prep_xcode - prep_brew + # prep_brew prep_gpg prep_rvm prep_bundler @@ -40,13 +40,46 @@ prep_xcode(){ # Homebrew -prep_brew(){ +prep_sudo_access_for_brew(){ + export CURRENT_USER=$USER + tput setaf 1 ; tput bold ; echo "Warning!" ; tput sgr0 + echo "Your user account (`tput bold`$CURRENT_USER`tput sgr0`) doesn't seem to have admin privileges" + echo "necessary to install dependencies with Homebrew." + echo "To continue, we need to grant you write permissions to '$(brew --prefix)/*' by" + echo "running 'sudo chown' with an admin account." + # Get admin users + echo "These are the `tput bold`admin users`tput sgr0` of this Macbook:" + tput setaf 2 ; dscl . -read /Groups/admin GroupMembership ; tput sgr0 + + # Get only the 1st ADMIN_USER (remove GroupMembership, root, and any other admin users from the array) + export ADMIN_USER=$(dscl . -read /Groups/admin GroupMembership | sed 's|root||g' | sed 's|GroupMembership: ||g' | cut -d " " -f1) + + ok_sound + tput setaf 3 + echo "To give you permissions, we will run this command as `tput bold ; tput setaf 2`$ADMIN_USER`tput sgr0`:" + tput sgr0 + echo "$ sudo -u $ADMIN_USER chown -R $CURRENT_USER $(brew --prefix)/*`tput sgr0`" + + tput setaf 3 ; read "REPLY?Continue (y/n)?`tput sgr0`" + if [[ $REPLY =~ ^[Yy]$ ]] ; then + # Grant permissions to run brew commands to CURRENT_USER + echo "Enter the password for `tput bold ; tput setaf 2`$ADMIN_USER`tput sgr0` to continue:" + echo "`tput bold`$ sudo -u $ADMIN_USER chown -R $(whoami) $(brew --prefix)/*`tput sgr0`" + sudo -u $ADMIN_USER chown -R $CURRENT_USER $(brew --prefix)/* + else + echo "Ok. Aborting." + fi +} + +prep_brew_user_install(){ # Brew user installation - echo "Installing Homebrew (user install)..." + echo "Installing Homebrew (user installation)..." /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" exec $SHELL } +# To-Do: prep_brew : either prep_sudo_access_for_brew or prep_brew_user_install + # ---------------------------------------------------------------- # # GPG @@ -62,6 +95,7 @@ prep_gpg(){ # RVM prep_rvm(){ + echo "Installing RVM and Ruby" # As a first step install GPG keys used to verify installation package: gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB @@ -89,16 +123,6 @@ prep_rvm(){ # ---------------------------------------------------------------- # -# Ruby / Rubygems (out for now - trying with rvm installation) -prep_ruby(){ - brew install ruby - export GEM_HOME="/usr/local/lib/ruby/gems/" - export PATH="$GEM_HOME/bin:$PATH" - exec $SHELL -} - -# ---------------------------------------------------------------- # - # Bundler prep_bundler(){ -- GitLab From 7c0f5a1ca6b809bb3fa8aa6c30beaf68b7fe3381 Mon Sep 17 00:00:00 2001 From: Marcia Ramos Date: Wed, 16 Dec 2020 12:38:12 +0000 Subject: [PATCH 3/5] PREP: Brew, Finder, Ruby --- install/prep-macos.sh | 106 +++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 32 deletions(-) diff --git a/install/prep-macos.sh b/install/prep-macos.sh index b828676..7443a87 100644 --- a/install/prep-macos.sh +++ b/install/prep-macos.sh @@ -18,20 +18,38 @@ test_prepmacos() { # Prepare installation prep-install() { + prep_finder prep_xcode - # prep_brew + prep_brew prep_gpg prep_rvm prep_bundler prep_code_editor + tput setaf 2 ; echo "Prep install done." ; tput sgr0 } +# ---------------------------------------------------------------- # + +# Finder - show hidden files + +prep_finder(){ + HFILES=$(defaults read com.apple.finder AppleShowAllFiles) + if [[ $HFILES != "true" ]]; then + # Show hidden files + defaults write com.apple.Finder AppleShowAllFiles true + # Restart Finder + killall Finder + fi +} + + # ---------------------------------------------------------------- # # xcode-select prep_xcode(){ - # Latest + echo "Checking your sytem for updates..." + softwareupdate --all --install --force echo "Installing macOS's command line tools (xcode-select)..." xcode-select --install } @@ -40,6 +58,14 @@ prep_xcode(){ # Homebrew +prep_brew(){ + if ! (ls -l /usr/local | grep "Homebrew" | grep -F "admin")>/dev/null ; then + prep_sudo_access_for_brew + fi + brew update +} + +# Check access to /usr/local prep_sudo_access_for_brew(){ export CURRENT_USER=$USER tput setaf 1 ; tput bold ; echo "Warning!" ; tput sgr0 @@ -64,30 +90,28 @@ prep_sudo_access_for_brew(){ if [[ $REPLY =~ ^[Yy]$ ]] ; then # Grant permissions to run brew commands to CURRENT_USER echo "Enter the password for `tput bold ; tput setaf 2`$ADMIN_USER`tput sgr0` to continue:" - echo "`tput bold`$ sudo -u $ADMIN_USER chown -R $(whoami) $(brew --prefix)/*`tput sgr0`" - sudo -u $ADMIN_USER chown -R $CURRENT_USER $(brew --prefix)/* + echo "`tput bold`$ sudo chown -R $CURRENT_USER $(brew --prefix)/*`tput sgr0`" + su - $ADMIN_USER -c "sudo chown -R $CURRENT_USER $(brew --prefix)/*" else echo "Ok. Aborting." fi } +# LEGACY - not used - doesn't work in GL Docs' env prep_brew_user_install(){ # Brew user installation echo "Installing Homebrew (user installation)..." /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - exec $SHELL } -# To-Do: prep_brew : either prep_sudo_access_for_brew or prep_brew_user_install - # ---------------------------------------------------------------- # # GPG +# Install GPG for RVM prep_gpg(){ - echo "Installing GPG suit..." + tput setaf 5 ; echo "Installing GPG suit..." ; tput sgr0 brew install --cask gpg-suite - exec $SHELL } # ---------------------------------------------------------------- # @@ -95,30 +119,47 @@ prep_gpg(){ # RVM prep_rvm(){ - - echo "Installing RVM and Ruby" - # As a first step install GPG keys used to verify installation package: + tput setaf 5 ; echo "Installing RVM..." ; tput sgr0 + + # As a first step install GPG keys used to verify installation package gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB # Download and install - - \curl -sSL https://get.rvm.io | bash -s stable --ruby - - # Load - source ~/.rvm/scripts/rvm + \curl -sSL https://get.rvm.io | bash -s stable # Load RVM into a shell session *as a function* - echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bash_profile - - # Restart shell - - exec $SHELL - - # Test - type rvm | head -n 1 - rvm --version - ruby --version - gem --version + source "$HOME/.rvm/scripts/rvm" + echo "source "$HOME/.rvm/scripts/rvm"" >> ~/.zshrc + source ~/.zshrc + + # Get Docs'Ruby Version + LATEST_DOCS_RUBY=$(curl -s https://gitlab.com/gitlab-org/gitlab-docs/-/raw/master/.ruby-version) + + # Install Ruby: + tput setaf 5 ; echo "Installing Ruby $LATEST_DOCS_RUBY..." ; tput sgr0 + rvm get stable --auto-dotfile + rvm install $LATEST_DOCS_RUBY --autolibs=homebrew + if [[ $? == 0 ]] ; then + # User Docs' Ruby + rvm use $LATEST_DOCS_RUBY + # Test installation: + tput setaf 5 ; echo "Testing RVM's Installation..." ; tput sgr0 + type rvm | head -n 1 + tput bold + echo "$ rvm --version" + tput sgr0 + rvm --version + tput bold + echo "$ ruby --version" + tput sgr0 + ruby --version + tput bold + echo "$ gem --version" + tput sgr0 + gem --version + else + tput setaf 1; echo "Failed. Try to start over." ; tput sgr0 + fi } # ---------------------------------------------------------------- # @@ -126,8 +167,9 @@ prep_rvm(){ # Bundler prep_bundler(){ - echo "Installing Bundler..." - gem install bundler + DOCS_BUNDLER_LATEST=$(curl -s https://gitlab.com/gitlab-org/gitlab-docs/-/raw/master/Gemfile.lock | awk '/BUNDLED WITH/{getline; $1=$1 ; print}') + tput setaf 5 ; echo "Installing Bundler $DOCS_BUNDLER_LATEST..." ; tput sgr0 + gem install bundler -v $DOCS_BUNDLER_LATEST } # ---------------------------------------------------------------- # @@ -135,13 +177,13 @@ prep_bundler(){ # Code editor prep_code_editor(){ - echo "Would you like to install a code editor?" + ok_sound + tput setaf 3 ; echo "Would you like to install a code editor?" ; tput sgr0 echo "Available code editors:" echo "- Type '`tput bold`s`tput sgr0`' for `tput bold`Sublime Text 3`tput sgr0`" echo "- Type '`tput bold`a`tput sgr0`' for `tput bold`Atom`tput sgr0`" echo "- Type '`tput bold`v`tput sgr0`' for `tput bold`Visual Studio Code`tput sgr0`" echo "- Type '`tput bold`n`tput sgr0`' for `tput bold`none`tput sgr0`" - ok while : do read CODE_EDT -- GitLab From 1f8bde20db4f72f68ac55e5012eae0e13f3329a7 Mon Sep 17 00:00:00 2001 From: Marcia Ramos Date: Wed, 16 Dec 2020 12:59:34 +0000 Subject: [PATCH 4/5] Run pre-install when prep-install - Run pre-install before prep - Move iTerm check after prep_brew --- install/pre-install.sh | 40 ++++++++-------------------------------- install/prep-macos.sh | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/install/pre-install.sh b/install/pre-install.sh index e3367f6..36942ef 100644 --- a/install/pre-install.sh +++ b/install/pre-install.sh @@ -10,8 +10,7 @@ test_preinstall() { pre-install() { check_brew check_zsh - check_iterm2 - check_oh-my-zsh + #check_oh-my-zsh #script breaks here } # ---------------------------------------------------------------- # @@ -28,16 +27,14 @@ depcheck_zsh() { check_zsh() { if ! depcheck_zsh ; then + error_sound echo `tput setaf 1`'Failed. ZSH is required.'`tput sgr0` - error_sound ; tput setaf 3 ; read "REPLY?Would you like to install ZSH with Homebrew (y/n)?"; tput sgr0 - if [[ $REPLY =~ ^[Yy]$ ]] ; then - install_zsh - else - echo 'Ok. Aborting.' - fi fi } +# LEGACY: +# ZSH is macOS's default shell +# Also, cannot brew install before checking brew install_zsh() { echo `tput setaf 5`"Installing ZSH..." `tput sgr0` echo `tput bold` '$ brew install zsh' `tput sgr0` ; brew install zsh @@ -45,29 +42,6 @@ install_zsh() { echo `tput bold` '$ source ~/.zhrc' `tput sgr0` ; source ~/.zhrc } -# ---------------------------------------------------------------- # - -# Install iTerm2 - -check_iterm2() { - echo `tput setaf 5`"Checking iTerm2..." `tput sgr0` - if [ -e ~/Library/Preferences/com.googlecode.iterm2.plist ] - then - tput setaf 2 ; echo "Success: iTerm2 is installed." ; tput sgr0 - else - echo `tput setaf 1`'Failed. iTerm2 is not installed.'`tput sgr0` - install_iterm - fi -} - -install_iterm() { - ok_sound ; tput setaf 3 ; read "REPLY?Would you like to install iTerm2 (not required) (y/n)?"; tput sgr0 - if [[ $REPLY =~ ^[Yy]$ ]] ; then - echo `tput bold` '$ brew cask install iterm2' `tput sgr0` ; brew cask install iterm2 - else - echo 'Ok. Aborting.' - fi -} # ---------------------------------------------------------------- # @@ -87,7 +61,9 @@ check_oh-my-zsh() { install_ohmyzsh() { ok_sound ; tput setaf 3 ; read "REPLY?Would you like to install oh-my-zsh (not required) (y/n)?"; tput sgr0 if [[ $REPLY =~ ^[Yy]$ ]] ; then - echo `tput bold`'$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' `tput sgr0` ; sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" + echo `tput bold`'$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' `tput sgr0` + sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" + source ~/.zshrc.pre-oh-my-zsh else echo 'Ok. Aborting.' fi diff --git a/install/prep-macos.sh b/install/prep-macos.sh index 7443a87..4ede681 100644 --- a/install/prep-macos.sh +++ b/install/prep-macos.sh @@ -18,6 +18,7 @@ test_prepmacos() { # Prepare installation prep-install() { + pre-install prep_finder prep_xcode prep_brew @@ -25,6 +26,7 @@ prep-install() { prep_rvm prep_bundler prep_code_editor + check_iterm2 tput setaf 2 ; echo "Prep install done." ; tput sgr0 } @@ -110,8 +112,10 @@ prep_brew_user_install(){ # Install GPG for RVM prep_gpg(){ - tput setaf 5 ; echo "Installing GPG suit..." ; tput sgr0 - brew install --cask gpg-suite + if ! (gpg --version)>/dev/null ; then + # tput setaf 5 ; echo "Installing GPG suit..." ; tput sgr0 + brew install --cask gpg-suite + fi } # ---------------------------------------------------------------- # @@ -213,3 +217,27 @@ prep_code_editor(){ esac done } + +# ---------------------------------------------------------------- # + +# Install iTerm2 + +check_iterm2() { + echo `tput setaf 5`"Checking iTerm2..." `tput sgr0` + if [ -e ~/Library/Preferences/com.googlecode.iterm2.plist ] + then + tput setaf 2 ; echo "Success: iTerm2 is installed." ; tput sgr0 + else + echo `tput setaf 1`'Failed. iTerm2 is not installed.'`tput sgr0` + install_iterm + fi +} + +install_iterm() { + ok_sound ; tput setaf 3 ; read "REPLY?Would you like to install iTerm2 (not required) (y/n)?"; tput sgr0 + if [[ $REPLY =~ ^[Yy]$ ]] ; then + echo `tput bold` '$ brew cask install iterm2' `tput sgr0` ; brew cask install iterm2 + else + echo 'Ok. Aborting.' + fi +} -- GitLab From 44949f12cd344e73b37008a8a8514d5cce35bd55 Mon Sep 17 00:00:00 2001 From: Marcia Ramos Date: Wed, 16 Dec 2020 13:40:17 +0000 Subject: [PATCH 5/5] Access to Homebrew without checking - The grep method is the same for all mac users :( --- install/prep-macos.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/install/prep-macos.sh b/install/prep-macos.sh index 4ede681..a18a62b 100644 --- a/install/prep-macos.sh +++ b/install/prep-macos.sh @@ -61,9 +61,10 @@ prep_xcode(){ # Homebrew prep_brew(){ - if ! (ls -l /usr/local | grep "Homebrew" | grep -F "admin")>/dev/null ; then - prep_sudo_access_for_brew - fi + # if ! (ls -l /usr/local | grep "Homebrew" | grep -F "admin")>/dev/null ; then + # prep_sudo_access_for_brew + # fi + prep_sudo_access_for_brew brew update } -- GitLab