This repository has been archived by the owner on Feb 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More robust CLI detection on macOS Catalina (#34)
* Tab -> Spaces * Simplify headless interaction * Bump installer version * Roll out the new changes.
- Loading branch information
Showing
4 changed files
with
87 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
# | ||
# Copyright (C) 2018 - 2019 James Joseph Balamuta <[email protected]> | ||
# | ||
# Version 3.2.1 -- 2019-12-17 | ||
# Version 3.2.2 -- 2019-12-30 | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -30,7 +30,7 @@ echo "[setup] Creating an environment for the installer..." | |
chmod a+x scripts/* | ||
|
||
# Version of installer | ||
INSTALLER_VERSION=3.2.1 | ||
INSTALLER_VERSION=3.2.2 | ||
|
||
# Previously, we created a payload-free package due to downloading | ||
# components as needed. We used a read receipt trick of including an empty | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
# | ||
# Copyright (C) 2018 - 2019 James Joseph Balamuta <[email protected]> | ||
# | ||
# Version 3.2.1 -- 2019-12-17 | ||
# Version 3.2.2 -- 2019-12-30 | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -53,42 +53,31 @@ if [ ! -d "/Library/Developer/CommandLineTools" ]; then | |
|
||
echo "[setup] Begin install procedure for Xcode CLI..." | ||
|
||
# Create a temporary file for the header | ||
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | ||
# Create a temporary file for the header | ||
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | ||
|
||
# Reset the Xcode CLI path | ||
if [[ ${os_vers_minor} -ge 14 ]]; then | ||
if [[ ${os_vers_minor} -ge 14 ]]; then | ||
echo "[note] Needed to reset Xcode CLI path..." | ||
sudo xcode-select --reset | ||
fi | ||
sudo xcode-select --reset | ||
fi | ||
|
||
echo "[note] Retrieving correct Xcode CLI..." | ||
|
||
# Figure out the correct Xcode CLI for the given mac OS | ||
PROD="" | ||
if [[ ${os_vers_minor} -ge 15 ]]; then | ||
echo "[note] Retrieving Xcode CLI on Catalina (10.15) or higher OS..." | ||
PROD=$(sudo softwareupdate -l | | ||
grep "\*.*Command Line" | | ||
head -n 1 | awk -F"*" '{print $2}' | | ||
sed -e 's/^ * Label: //' | | ||
tr -d '\n') | ||
else | ||
echo "[note] Retrieving Xcode CLI on Mojave (10.14) or lower OS..." | ||
PROD=$(sudo softwareupdate -l | | ||
grep "\*.*Command Line" | | ||
tail -n 1 | awk -F"*" '{print $2}' | | ||
sed -e 's/^ *//' | | ||
tr -d '\n') | ||
fi | ||
# Figure out the correct Xcode CLI for the given mac OS | ||
PROD=$(sudo softwareupdate -l | | ||
grep "\*.*Command Line" | | ||
tail -n 1 | awk -F"*" '{print $2}' | | ||
sed -e 's/^ *Label: //' -e 's/^ *//' | | ||
tr -d '\n') | ||
|
||
echo "[setup] Installing Xcode CLI via softwareupdate..." | ||
# Install Xcode CLI | ||
sudo softwareupdate -i "$PROD" --verbose; | ||
# Install Xcode CLI | ||
sudo softwareupdate -i "$PROD" --verbose; | ||
echo "[clean] Removing temporary file created..." | ||
# Clean up the script | ||
rm -rf /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | ||
rm -rf /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | ||
|
||
echo "[done] Xcode CLI has been installed..." | ||
else | ||
|
@@ -100,27 +89,27 @@ fi | |
#1 Base URL (with trailing /) | ||
#2 File name | ||
download_file(){ | ||
if [ -f "$2" ]; then | ||
echo "[note] $2 has already been downloaded..." | ||
else | ||
echo "[status] Downloading file $2 ... Please be patient..." | ||
# Download file into working directory | ||
curl -O $1$2 | ||
fi | ||
if [ -f "$2" ]; then | ||
echo "[note] $2 has already been downloaded..." | ||
else | ||
echo "[status] Downloading file $2 ... Please be patient..." | ||
# Download file into working directory | ||
curl -O $1$2 | ||
fi | ||
} | ||
|
||
#1 File name | ||
extract_file(){ | ||
# Extract in working directory | ||
tar fvxz $1 -C / | ||
# Extract in working directory | ||
tar fvxz $1 -C / | ||
} | ||
|
||
################################################################ | ||
|
||
#1 Path to File | ||
#2 md5 Hash to Check Against | ||
check_md5_hash() { | ||
# Obtain file hash | ||
FILE_HASH=$(md5 $1 | awk '{print $4}') | ||
|
||
|
@@ -131,16 +120,16 @@ check_md5_hash() { | |
if [ "$FILE_HASH" = "$2" ]; then | ||
echo 0 | ||
else | ||
echo "[error] File does not match hash..." | ||
echo "[status] Hash 1: ${FILE_HASH} $2" | ||
echo "[status] Hash 2: $2" | ||
echo "[error] File does not match hash..." | ||
echo "[status] Hash 1: ${FILE_HASH} $2" | ||
echo "[status] Hash 2: $2" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# 1: Package to install | ||
install_pkg_root() { | ||
sudo installer -package $1 -target / | ||
sudo installer -package $1 -target / | ||
} | ||
|
||
################################################################ | ||
|
@@ -152,47 +141,47 @@ install_pkg_root() { | |
#2 Config file to search | ||
remove_config_variable(){ | ||
|
||
pattern=$1 | ||
config_file=$2 | ||
pattern=$1 | ||
config_file=$2 | ||
|
||
# Check if there are matches | ||
if grep -q $pattern $config_file; then | ||
# Remove matches | ||
# '' required due to macOS | ||
sed -i '' "/$pattern/d" $config_file | ||
echo "[status] Removed configuration line containing: $pattern ..." | ||
fi | ||
# Check if there are matches | ||
if grep -q $pattern $config_file; then | ||
# Remove matches | ||
# '' required due to macOS | ||
sed -i '' "/$pattern/d" $config_file | ||
echo "[status] Removed configuration line containing: $pattern ..." | ||
fi | ||
} | ||
|
||
#1 Variable to find | ||
#2 Value to append | ||
#3 Config file to search | ||
append_config_variable(){ | ||
pattern=$1 | ||
append_with=$2 | ||
config_file=$3 | ||
|
||
# Check if there are matches | ||
if grep -q $pattern $config_file; then | ||
# Append to the end of the line of each match | ||
# '' required due to macOS | ||
sed -i '' "\~$pattern~s~$~ $append_with~" $config_file | ||
echo "[status] Appended configuration line containing $pattern with $append_with ..." | ||
else | ||
# Append a new line to end of config file | ||
echo "$pattern=$append_with" >> $config_file | ||
echo "[status] Added new configuration line $pattern=$append_with to end of $config_file..." | ||
fi | ||
pattern=$1 | ||
append_with=$2 | ||
config_file=$3 | ||
|
||
# Check if there are matches | ||
if grep -q $pattern $config_file; then | ||
# Append to the end of the line of each match | ||
# '' required due to macOS | ||
sed -i '' "\~$pattern~s~$~ $append_with~" $config_file | ||
echo "[status] Appended configuration line containing $pattern with $append_with ..." | ||
else | ||
# Append a new line to end of config file | ||
echo "$pattern=$append_with" >> $config_file | ||
echo "[status] Added new configuration line $pattern=$append_with to end of $config_file..." | ||
fi | ||
} | ||
|
||
add_config_variable(){ | ||
config_var=$1 | ||
config_file=$2 | ||
config_var=$1 | ||
config_file=$2 | ||
|
||
echo "[status] Adding configuration line $config_var to $config_file ..." | ||
echo "[status] Adding configuration line $config_var to $config_file ..." | ||
|
||
# Append a new line to end of config file | ||
echo "$config_var" >> $config_file | ||
# Append a new line to end of config file | ||
echo "$config_var" >> $config_file | ||
} | ||
|
||
################################################################ | ||
|
@@ -242,14 +231,14 @@ CXX_COMPILER=/usr/local/${CLANG_BINARY}/bin/clang++ | |
HEADER_LOCATION="-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" | ||
|
||
echo "[init] Checking if file '~/.R/Makevars' exists" | ||
if [ -f "${R_MAKEVARS_LOCAL}" ]; then | ||
echo "[setup] Ensuring the existing '~/.R/Makevars' is writable ..." | ||
sudo chown ${USER} ${R_MAKEVARS_LOCAL} | ||
echo "[setup] '~/.R/Makevars' detected. Making a backup at ''~/.R/Makevars.bck' ..." | ||
cp ${R_MAKEVARS_LOCAL} ${R_MAKEVARS_LOCAL}.bck | ||
if [ -f "${R_MAKEVARS_LOCAL}" ]; then | ||
echo "[setup] Ensuring the existing '~/.R/Makevars' is writable ..." | ||
sudo chown ${USER} ${R_MAKEVARS_LOCAL} | ||
echo "[setup] '~/.R/Makevars' detected. Making a backup at ''~/.R/Makevars.bck' ..." | ||
cp ${R_MAKEVARS_LOCAL} ${R_MAKEVARS_LOCAL}.bck | ||
else | ||
echo "[setup] Creating '~/.R/' directory ..." | ||
mkdir -p ~/.R | ||
echo "[setup] Creating '~/.R/' directory ..." | ||
mkdir -p ~/.R | ||
fi | ||
|
||
echo "[init] Creating '~/.R/Makevars' from scratch ..." | ||
|
@@ -284,10 +273,10 @@ R_ENVIRON_LOCAL=~/.Renviron | |
echo "[init] Checking if file '~/.Renviron' exists" | ||
|
||
if [ -f "${R_ENVIRON_LOCAL}" ]; then | ||
echo "[setup] Ensuring the existing '~/.Renviron' is writable ..." | ||
sudo chown ${USER} ${R_ENVIRON_LOCAL} | ||
echo "[setup] '~/.Renviron' detected. Making a backup at ''~/.Renviron.bck'..." | ||
cp ${R_ENVIRON_LOCAL} ${R_ENVIRON_LOCAL}.bck | ||
echo "[setup] Ensuring the existing '~/.Renviron' is writable ..." | ||
sudo chown ${USER} ${R_ENVIRON_LOCAL} | ||
echo "[setup] '~/.Renviron' detected. Making a backup at ''~/.Renviron.bck'..." | ||
cp ${R_ENVIRON_LOCAL} ${R_ENVIRON_LOCAL}.bck | ||
fi | ||
|
||
echo "[setup] Writing configuration to '~/.Renviron' ..." | ||
|