Last active
August 8, 2018 16:23
-
-
Save rcarmo/64e133abe9254f3ecdc5a6efa3e8c58b to your computer and use it in GitHub Desktop.
Set up Azure Dev Spaces on Mac without sudo
This file contains hidden or 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
#!/bin/bash | |
info() { echo "[INFO] $*" ; } | |
fatal() { echo "[FATAL] $*" ; exit 1 ; } | |
AZDS_SRC="https://azuredevspacestools.blob.core.windows.net/azdssetup" | |
AZDS_ZIP=AzdsCliMacOSX.zip | |
AZDS_LIB="$HOME/Library/Azure/lib/azds-cli" | |
AZDS_BIN="$HOME/Library/Azure/bin/azds" | |
KUBECTL_PATH="$AZDS_LIB/kubectl/osx/kubectl" | |
PRODUCT_NAME="Azure Dev Spaces (Preview)" | |
echo "Installing $PRODUCT_NAME client components..." | |
echo | |
# Check system configuration | |
if [ -z "$(uname -m | grep 64)" ]; then | |
fatal "$PRODUCT_NAME is only supported on x64 architectures." | |
fi | |
if ! xcode-select -p >/dev/null 2>/dev/null; then | |
fatal "$PRODUCT_NAME requires the MacOS command line tools. Install using \'xcode-select --install\'." | |
fi | |
if [ -t 0 ]; then | |
read -p "By continuing, you agree to the Microsoft Software License Terms (https://aka.ms/azds-LicenseTerms) and Microsoft Privacy Statement (https://aka.ms/privacystatement). Do you want to continue? (Y/n): " -r | |
if !([[ $REPLY =~ ^[Yy]$ ]] || [[ $REPLY =~ ^[[:space:]]*$ ]]); then | |
info "Exiting the installation." | |
exit 0 | |
fi | |
echo | |
fi | |
echo "You may be prompted for your administrator password to authorize the installation process." | |
#sudo echo | |
if [ -n "$1" ]; then | |
AZDS_SRC="$AZDS_SRC/CLI.$1" | |
info "Will install build '$1' specific binaries." | |
else | |
AZDS_SRC="$AZDS_SRC/LKS" | |
fi | |
# Setup AZDS CLI | |
#if [ ! -z $(which az) ]; then | |
# AZDS_BIN=$(dirname $(which az))/azds | |
#fi | |
if [ -e "$AZDS_BIN" -o -e "$AZDS_LIB" ]; then | |
info "Removing existing versions of $PRODUCT_NAME..." | |
if [ -w "$AZDS_BIN" ]; then | |
rm -f "$AZDS_BIN" | |
else | |
rm "$AZDS_BIN" | |
fi | |
if [ -w "$AZDS_LIB" ]; then | |
rm -rf "$AZDS_LIB" | |
else | |
rm -r "$AZDS_LIB" | |
fi | |
fi | |
if [ ! -e "$AZDS_ZIP" ]; then | |
{ | |
info "Downloading $PRODUCT_NAME Package..." | |
curl -fsS $AZDS_SRC/$AZDS_ZIP -o "$HOME/.azds.zip" | |
}||{ | |
fatal "Failed to download $PRODUCT_NAME Package." | |
} | |
else | |
cp "$AZDS_ZIP" "$HOME/.azds.zip" | |
fi | |
{ | |
mkdir -p "$AZDS_LIB" && | |
unzip -q "$HOME/.azds.zip" -d "$AZDS_LIB" && | |
rm -rf "$HOME/.azds.zip" && | |
chmod +x "$AZDS_LIB/azds" && | |
chmod +x "$KUBECTL_PATH" && | |
mkdir -p "$HOME/Library/Azure/bin" && | |
ln -s "$AZDS_LIB/azds" "$AZDS_BIN" | |
}||{ | |
fatal "Failed to install $PRODUCT_NAME." | |
} | |
BASH_COMPLETION_SCRIPT=bash_completion.sh | |
if [ ! -e $BASH_COMPLETION_SCRIPT ]; then | |
{ | |
info "Downloading Bash completion script..." | |
curl -fsS $AZDS_SRC/$BASH_COMPLETION_SCRIPT -o "$HOME/.azds.bash_completion.sh" | |
}||{ | |
fatal "Failed to download Bash completion script." | |
} | |
else | |
cp $BASH_COMPLETION_SCRIPT "$HOME/.azds.bash_completion.sh" | |
fi | |
#{ | |
# mkdir -p /etc/bash_completion.d && | |
# mv "$HOME/.azds.bash_completion.sh" /etc/bash_completion.d/azds && | |
# chmod 777 /etc/bash_completion.d/azds && | |
# . /etc/bash_completion.d/azds | |
#}||{ | |
# fatal "Failed to enable Bash completion script." | |
#} | |
#{ | |
# grep -q '^source /etc/bash_completion\.d/azds$' ~/.bash_profile || | |
# echo "source /etc/bash_completion.d/azds" >> ~/.bash_profile | |
#}||{ | |
# fatal "Failed to register Bash completion script." | |
#} | |
printf "\n\033[1;32mSuccessfully installed $PRODUCT_NAME to $AZDS_BIN.\033[0m\n\n" | |
printf "\nBinaries are in $HOME/Library/Azure/bin - add that to PATH\n" | |
printf "\nbash completion file is at $HOME/.azds.bash_completion.sh - source that in .bashrc\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment