#/bin/bash

# setup docker to build on /mnt instead of /var/lib/docker
echo '{
    "graph": "/mnt",
    "storage-driver": "overlay"
}' > /etc/docker/daemon.json

service docker restart

mkdir -p out

# base 1.6.3
docker build base/spark1.6.3/ --tag aztk/spark:v0.1.0-spark1.6.3-base > out/base-spark1.6.3.out &&
docker push aztk/spark:v0.1.0-spark1.6.3-base

# base 2.1.0
docker build base/spark2.1.0/ --tag aztk/spark:v0.1.0-spark2.1.0-base > out/base-spark2.1.0.out &&
docker push aztk/spark:v0.1.0-spark2.1.0-base

# base 2.2.0
docker build base/spark2.2.0/ --tag aztk/spark:v0.1.0-spark2.2.0-base > out/base-spark2.2.0.out &&
docker push aztk/spark:v0.1.0-spark2.2.0-base

# base 2.3.0
docker build base/spark2.3.0/ --tag aztk/spark:v0.1.0-spark2.3.0-base > out/base-spark2.3.0.out &&
docker push aztk/spark:v0.1.0-spark2.3.0-base

# miniconda-base 1.6.3
docker build miniconda/spark1.6.3/base/ --tag aztk/spark:v0.1.0-spark1.6.3-miniconda-base > out/miniconda-spark1.6.3.out &&
docker push aztk/spark:v0.1.0-spark1.6.3-miniconda-base

# miniconda-base 2.1.0
docker build miniconda/spark2.1.0/base/ --tag aztk/spark:v0.1.0-spark2.1.0-miniconda-base > out/miniconda-spark2.1.0.out &&
docker push aztk/spark:v0.1.0-spark2.1.0-miniconda-base

# miniconda-base 2.2.0
docker build miniconda/spark2.2.0/base --tag aztk/spark:v0.1.0-spark2.2.0-miniconda-base > out/miniconda-spark2.2.0.out &&
docker push aztk/spark:v0.1.0-spark2.2.0-miniconda-base

# miniconda-base 2.3.0
docker build miniconda/spark2.3.0/base/ --tag aztk/spark:v0.1.0-spark2.3.0-miniconda-base > out/miniconda-spark2.3.0.out &&
docker push aztk/spark:v0.1.0-spark2.3.0-miniconda-base

# anaconda-base 1.6.3
docker build anaconda/spark1.6.3/base/ --tag aztk/spark:v0.1.0-spark1.6.3-anaconda-base > out/anaconda-spark1.6.3.out &&
docker push aztk/spark:v0.1.0-spark1.6.3-anaconda-base

# anaconda-base 2.1.0
docker build anaconda/spark2.1.0/base/ --tag aztk/spark:v0.1.0-spark2.1.0-anaconda-base > out/anaconda-spark2.1.0.out &&
docker push aztk/spark:v0.1.0-spark2.1.0-anaconda-base

# anaconda-base 2.2.0
docker build anaconda/spark2.2.0/base/ --tag aztk/spark:v0.1.0-spark2.2.0-anaconda-base > out/anaconda-spark2.2.0.out &&
docker push aztk/spark:v0.1.0-spark2.2.0-anaconda-base

# anaconda-base 2.3.0
docker build anaconda/spark2.3.0/base/ --tag aztk/spark:v0.1.0-spark2.3.0-anaconda-base > out/anaconda-spark2.3.0.out &&
docker push aztk/spark:v0.1.0-spark2.3.0-anaconda-base

# r-base 1.6.3
docker build r/spark1.6.3/base/ --tag aztk/spark:v0.1.0-spark1.6.3-r-base > out/r-spark1.6.3.out &&
docker push aztk/spark:v0.1.0-spark1.6.3-r-base

# r-base 2.1.0
docker build r/spark2.1.0/base/ --tag aztk/spark:v0.1.0-spark2.1.0-r-base > out/r-spark2.1.0.out &&
docker push aztk/spark:v0.1.0-spark2.1.0-r-base

# r-base 2.2.0
docker build r/spark2.2.0/base/ --tag aztk/spark:v0.1.0-spark2.2.0-r-base > out/r-spark2.2.0.out &&
docker push aztk/spark:v0.1.0-spark2.2.0-r-base

# r-base 2.3.0
docker build r/spark2.3.0/base/ --tag aztk/spark:v0.1.0-spark2.3.0-r-base > out/r-spark2.3.0.out &&
docker push aztk/spark:v0.1.0-spark2.3.0-r-base

##################
#      GPU       #
##################

# gpu 1.6.3
docker build gpu/spark1.6.3/ --tag aztk/spark:v0.1.0-spark1.6.3-gpu > out/gpu-spark1.6.3.out &&
docker push aztk/spark:v0.1.0-spark1.6.3-gpu

# gpu 2.1.0
docker build gpu/spark2.1.0/ --tag aztk/spark:v0.1.0-spark2.1.0-gpu > out/gpu-spark2.1.0.out &&
docker push aztk/spark:v0.1.0-spark2.1.0-gpu

# gpu 2.2.0
docker build gpu/spark2.2.0/ --tag aztk/spark:v0.1.0-spark2.2.0-gpu > out/gpu-spark2.2.0.out &&
docker push aztk/spark:v0.1.0-spark2.2.0-gpu

# gpu 2.3.0
docker build gpu/spark2.3.0/ --tag aztk/spark:v0.1.0-spark2.3.0-gpu > out/gpu-spark2.3.0.out &&
docker push aztk/spark:v0.1.0-spark2.3.0-gpu

# miniconda-gpu 1.6.3
docker build miniconda/spark1.6.3/gpu/ --tag aztk/spark:v0.1.0-spark1.6.3-miniconda-gpu > out/miniconda-spark1.6.3.out &&
docker push aztk/spark:v0.1.0-spark1.6.3-miniconda-gpu

# miniconda-gpu 2.1.0
docker build miniconda/spark2.1.0/gpu/ --tag aztk/spark:v0.1.0-spark2.1.0-miniconda-gpu > out/miniconda-spark2.1.0.out &&
docker push aztk/spark:v0.1.0-spark2.1.0-miniconda-gpu

# miniconda-gpu 2.2.0
docker build miniconda/spark2.2.0/gpu --tag aztk/spark:v0.1.0-spark2.2.0-miniconda-gpu > out/miniconda-spark2.2.0.out &&
docker push aztk/spark:v0.1.0-spark2.2.0-miniconda-gpu

# miniconda-gpu 2.3.0
docker build miniconda/spark2.3.0/gpu/ --tag aztk/spark:v0.1.0-spark2.3.0-miniconda-gpu > out/miniconda-spark2.3.0.out &&
docker push aztk/spark:v0.1.0-spark2.3.0-miniconda-gpu

# anaconda-gpu 1.6.3
docker build anaconda/spark1.6.3/gpu/ --tag aztk/spark:v0.1.0-spark1.6.3-anaconda-gpu > out/anaconda-spark1.6.3.out &&
docker push aztk/spark:v0.1.0-spark1.6.3-anaconda-gpu

# anaconda-gpu 2.1.0
docker build anaconda/spark2.1.0/gpu/ --tag aztk/spark:v0.1.0-spark2.1.0-anaconda-gpu > out/anaconda-spark2.1.0.out &&
docker push aztk/spark:v0.1.0-spark2.1.0-anaconda-gpu

# anaconda-gpu 2.2.0
docker build anaconda/spark2.2.0/gpu/ --tag aztk/spark:v0.1.0-spark2.2.0-anaconda-gpu > out/anaconda-spark2.2.0.out &&
docker push aztk/spark:v0.1.0-spark2.2.0-anaconda-gpu

# anaconda-gpu 2.3.0
docker build anaconda/spark2.3.0/gpu/ --tag aztk/spark:v0.1.0-spark2.3.0-anaconda-gpu > out/anaconda-spark2.3.0.out &&
docker push aztk/spark:v0.1.0-spark2.3.0-anaconda-gpu

# r-gpu 1.6.3
docker build r/spark1.6.3/gpu/ --tag aztk/spark:v0.1.0-spark1.6.3-r-gpu > out/r-spark1.6.3.out &&
docker push aztk/spark:v0.1.0-spark1.6.3-r-gpu

# r-gpu 2.1.0
docker build r/spark2.1.0/gpu/ --tag aztk/spark:v0.1.0-spark2.1.0-r-gpu > out/r-spark2.1.0.out &&
docker push aztk/spark:v0.1.0-spark2.1.0-r-gpu

# r-gpu 2.2.0
docker build r/spark2.2.0/gpu/ --tag aztk/spark:v0.1.0-spark2.2.0-r-gpu > out/r-spark2.2.0.out &&
docker push aztk/spark:v0.1.0-spark2.2.0-r-gpu

# r-gpu 2.3.0
docker build r/spark2.3.0/gpu/ --tag aztk/spark:v0.1.0-spark2.3.0-r-gpu > out/r-spark2.3.0.out &&
docker push aztk/spark:v0.1.0-spark2.3.0-r-gpu


#!/usr/bin/env bash

# This script is intended as an initialization script used in azuredeploy.json
# See documentation here: https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux#template-deployment

# see abbreviated notes in README.md
# comments below:

adminUser=$1

WD=/home/$adminUser/notebooks

echo WD is $WD

if [ ! -d $WD ]; then
    echo $WD does not exist - aborting!!
    exit
else
    cd $WD
    echo "Working in $(pwd)"
fi

# Clone the content for the workshop in notebooks dir
git clone https://github.com/Azure/Azure-AI-Camp.git
chmod -R ugo+rwx Azure-AI-Camp

## Add user to docker group
usermod -aG docker $adminUser

## Reboot jupyterhub
systemctl restart jupyterhub

echo "Done!"


#!/usr/bin/env bash

# This script is intended as an initialization script used in azuredeploy.json
# See documentation here: https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux#template-deployment

# see abbreviated notes in README.md
# comments below:

# Input args
adminUser=$1
echo $adminUser >> "/home/userscript.log"
publicIP=`dig +short myip.opendns.com @resolver1.opendns.com`
echo $publicIP >> "/home/userscript.log"

# Script to update Notbook metadata
cat << EOF > /tmp/changenbmeta.py
#!/usr/bin/python
import json,sys
if len(sys.argv) < 2 :
        print "Usage: python changenbmeta.py <filename>"
        exit()
with open(sys.argv[1], "r") as jsonFile:
    data = json.load(jsonFile)
data["metadata"]["kernelspec"]["display_name"] = "Python 3.6 - PyTorch 1.1"
data["metadata"]["kernelspec"]["name"] = "pytorch1_1"
with open(sys.argv[1], "w") as jsonFile:
    json.dump(data, jsonFile)
EOF

# Clone the content
mkdir -p /etc/skel/notebooks/AICamp
cd /etc/skel/notebooks/AICamp
# git clone <repp>

# Change metadata on notebook to match kernel name in the fast.ai notebooks
find . -name \*.ipynb -exec /usr/bin/python /tmp/changenbmeta.py {} \;

# Save host public ip address to the users text file
echo $publicIP >> "/home/usersinfo.csv"

## declare an array of user names to create on vm
declare -a arr=("temp" "storm" "jeangrey" "spiderman" "captainmarvel" "quake" "wolverine" "thor" "ironman" "firestar" "rogue")
## now loop through the above array
for u in "${arr[@]}";
# Create users and generate random password with uppercase and punc chars. Run as root:
do
    sudo useradd -m $u
    p=`openssl rand -hex 4`
    p="P$p!"
    printf "$p\n$p" | sudo passwd $u
    echo $u, $p >> "/home/usersinfo.csv"

    # add user to sudoers
    sudo adduser $u sudo

    ## now create the env...
    condapath=/home/$u/.conda/envs

    if [ ! -d $condapath ]; then
        sudo mkdir -p $condapath
    fi

    ## Update appropriate permissions
    sudo chown -R ${u}:${u} ${condapath}

    ## Add user to docker group
    sudo usermod -aG docker $u
done
echo "Created users" >> "/home/userscript.log"

# # copy the notebooks to the users' profiles
# for filename in /home/*; do
#   dir=$filename/notebooks
#   user=${filename:6}
#   cp -r /etc/skel/notebooks/Workshop $dir
#   chown -R $user $dir/Workshop/*
#   chown $user $dir/Workshop
# done

# echo "Copied Workshop notebooks into user directories" >> "/home/userscript.log"

## now create the env...
condapath=/home/$adminUser/.conda/envs

if [ ! -d $condapath ]; then
    mkdir -p $condapath
fi

#### PYTORCH 1.1 ####

/data/anaconda/bin/conda create --name pytorch1 python=3.6 ipykernel conda

## update appropriate permissions
chown -R ${adminUser}:${adminUser} ${condapath}

# Install PyTorch 1.x into environment with cuda 9.2 support as DSVM is on this now
/data/anaconda/envs/pytorch1/bin/python -m conda install pytorch==1.1.0 torchvision cudatoolkit=9.0 -c pytorch -y
/data/anaconda/envs/pytorch1/bin/python -m pip install --yes bs4 jdc jupyter numpy requests scipy sklearn tqdm
/data/anaconda/envs/pytorch1/bin/python -m pip install --yes azureml-sdk[automl]==1.0.74

# LibTorch - install into /usr/local/lib
wget https://download.pytorch.org/libtorch/nightly/cu92/libtorch-shared-with-deps-latest.zip
unzip libtorch-shared-with-deps-latest.zip
sudo mv libtorch /usr/local/lib/python3.5/dist-packages/torch

## Install it as a kernel
/data/anaconda/envs/pytorch1/bin/python -m ipykernel install --name pytorch1_1 --display-name "Python 3.6 - PyTorch 1.1"

echo "Done setting up PyTorch 1.1" >> "/home/userscript.log"

## Update appropriate permissions
chown -R ${adminUser}:${adminUser} ${condapath}

## Reboot jupyterhub
systemctl restart jupyterhub

echo "Done!" >> "/home/userscript.log"


docker build -t applens/portal-dev-env .


#!/bin/bash

# Discussion, issues and change requests at:
#   https://github.com/nodesource/distributions
#
# Script to install the NodeSource Node.js 14.x repo onto a
# Debian or Ubuntu system.
#
# Run as root or insert `sudo -E` before `bash`:
#
# curl -sL https://deb.nodesource.com/setup_14.x | bash -
#   or
# wget -qO- https://deb.nodesource.com/setup_14.x | bash -
#
# CONTRIBUTIONS TO THIS SCRIPT
#
# This script is built from a template in
# https://github.com/nodesource/distributions/tree/master/deb/src
# please don't submit pull requests against the built scripts.
#

export DEBIAN_FRONTEND=noninteractive
SCRSUFFIX="_14.x"
NODENAME="Node.js 14.x"
NODEREPO="node_14.x"
NODEPKG="nodejs"

print_status() {
    echo
    echo "## $1"
    echo
}

if test -t 1; then # if terminal
    ncolors=$(which tput > /dev/null && tput colors) # supports color
    if test -n "$ncolors" && test $ncolors -ge 8; then
        termcols=$(tput cols)
        bold="$(tput bold)"
        underline="$(tput smul)"
        standout="$(tput smso)"
        normal="$(tput sgr0)"
        black="$(tput setaf 0)"
        red="$(tput setaf 1)"
        green="$(tput setaf 2)"
        yellow="$(tput setaf 3)"
        blue="$(tput setaf 4)"
        magenta="$(tput setaf 5)"
        cyan="$(tput setaf 6)"
        white="$(tput setaf 7)"
    fi
fi

print_bold() {
    title="$1"
    text="$2"

    echo
    echo "${red}================================================================================${normal}"
    echo "${red}================================================================================${normal}"
    echo
    echo -e "  ${bold}${yellow}${title}${normal}"
    echo
    echo -en "  ${text}"
    echo
    echo "${red}================================================================================${normal}"
    echo "${red}================================================================================${normal}"
}

bail() {
    echo 'Error executing command, exiting'
    exit 1
}

exec_cmd_nobail() {
    echo "+ $1"
    bash -c "$1"
}

exec_cmd() {
    exec_cmd_nobail "$1" || bail
}

node_deprecation_warning() {
    if [[ "X${NODENAME}" == "Xio.js 1.x" ||
          "X${NODENAME}" == "Xio.js 2.x" ||
          "X${NODENAME}" == "Xio.js 3.x" ||
          "X${NODENAME}" == "XNode.js 0.10" ||
          "X${NODENAME}" == "XNode.js 0.12" ||
          "X${NODENAME}" == "XNode.js 4.x LTS Argon" ||
          "X${NODENAME}" == "XNode.js 5.x" ||
          "X${NODENAME}" == "XNode.js 6.x LTS Boron" ||
          "X${NODENAME}" == "XNode.js 7.x" ||
          "X${NODENAME}" == "XNode.js 8.x LTS Carbon" ||
          "X${NODENAME}" == "XNode.js 9.x" ||
          "X${NODENAME}" == "XNode.js 10.x" ||
          "X${NODENAME}" == "XNode.js 11.x" ||
          "X${NODENAME}" == "XNode.js 13.x" ||
          "X${NODENAME}" == "XNode.js 15.x" ]]; then

        print_bold \
"                            DEPRECATION WARNING                            " "\
${bold}${NODENAME} is no longer actively supported!${normal}

  ${bold}You will not receive security or critical stability updates${normal} for this version.

  You should migrate to a supported version of Node.js as soon as possible.
  Use the installation script that corresponds to the version of Node.js you
  wish to install. e.g.

   * ${green}https://deb.nodesource.com/setup_12.x â€” Node.js 12 LTS \"Erbium\"${normal}
   * ${green}https://deb.nodesource.com/setup_14.x â€” Node.js 14 LTS \"Fermium\"${normal} (recommended)
   * ${green}https://deb.nodesource.com/setup_16.x â€” Node.js 16 \"Gallium\"${normal}
   * ${green}https://deb.nodesource.com/setup_17.x â€” Node.js 17 \"Seventeen\"${normal} (current)

  Please see ${bold}https://github.com/nodejs/Release${normal} for details about which
  version may be appropriate for you.

  The ${bold}NodeSource${normal} Node.js distributions repository contains
  information both about supported versions of Node.js and supported Linux
  distributions. To learn more about usage, see the repository:
    ${bold}https://github.com/nodesource/distributions${normal}
"
        echo
        echo "Continuing in 20 seconds ..."
        echo
        sleep 20
    fi
}

script_deprecation_warning() {
    if [ "X${SCRSUFFIX}" == "X" ]; then
        print_bold \
"                         SCRIPT DEPRECATION WARNING                         " "\
This script, located at ${bold}https://deb.nodesource.com/setup${normal}, used to
  install Node.js 0.10, is deprecated and will eventually be made inactive.

  You should use the script that corresponds to the version of Node.js you
  wish to install. e.g.

   * ${green}https://deb.nodesource.com/setup_12.x â€” Node.js 12 LTS \"Erbium\"${normal}
   * ${green}https://deb.nodesource.com/setup_14.x â€” Node.js 14 LTS \"Fermium\"${normal} (recommended)
   * ${green}https://deb.nodesource.com/setup_16.x â€” Node.js 16 \"Gallium\"${normal}
   * ${green}https://deb.nodesource.com/setup_17.x â€” Node.js 17 \"Seventeen\"${normal} (current)

  Please see ${bold}https://github.com/nodejs/Release${normal} for details about which
  version may be appropriate for you.

  The ${bold}NodeSource${normal} Node.js Linux distributions GitHub repository contains
  information about which versions of Node.js and which Linux distributions
  are supported and how to use the install scripts.
    ${bold}https://github.com/nodesource/distributions${normal}
"

        echo
        echo "Continuing in 20 seconds (press Ctrl-C to abort) ..."
        echo
        sleep 20
    fi
}

setup() {

script_deprecation_warning
node_deprecation_warning

print_status "Installing the NodeSource ${NODENAME} repo..."

if $(uname -m | grep -Eq ^armv6); then
    print_status "You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the 'linux-armv6l' binary tarballs available directly from nodejs.org for Node.js 4 and later."
    exit 1
fi

PRE_INSTALL_PKGS=""

# Check that HTTPS transport is available to APT
# (Check snaked from: https://get.docker.io/ubuntu/)

if [ ! -e /usr/lib/apt/methods/https ]; then
    PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} apt-transport-https"
fi

if [ ! -x /usr/bin/lsb_release ]; then
    PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} lsb-release"
fi

if [ ! -x /usr/bin/curl ] && [ ! -x /usr/bin/wget ]; then
    PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} curl"
fi

# Used by apt-key to add new keys

if [ ! -x /usr/bin/gpg ]; then
    PRE_INSTALL_PKGS="${PRE_INSTALL_PKGS} gnupg"
fi

# Populating Cache
print_status "Populating apt-get cache..."
exec_cmd 'apt-get update'

if [ "X${PRE_INSTALL_PKGS}" != "X" ]; then
    print_status "Installing packages required for setup:${PRE_INSTALL_PKGS}..."
    # This next command needs to be redirected to /dev/null or the script will bork
    # in some environments
    exec_cmd "apt-get install -y${PRE_INSTALL_PKGS} > /dev/null 2>&1"
fi

IS_PRERELEASE=$(lsb_release -d | grep 'Ubuntu .*development' >& /dev/null; echo $?)
if [[ $IS_PRERELEASE -eq 0 ]]; then
    print_status "Your distribution, identified as \"$(lsb_release -d -s)\", is a pre-release version of Ubuntu. NodeSource does not maintain official support for Ubuntu versions until they are formally released. You can try using the manual installation instructions available at https://github.com/nodesource/distributions and use the latest supported Ubuntu version name as the distribution identifier, although this is not guaranteed to work."
    exit 1
fi

DISTRO=$(lsb_release -c -s)

check_alt() {
    if [ "X${DISTRO}" == "X${2}" ]; then
        echo
        echo "## You seem to be using ${1} version ${DISTRO}."
        echo "## This maps to ${3} \"${4}\"... Adjusting for you..."
        DISTRO="${4}"
    fi
}

check_alt "SolydXK"       "solydxk-9" "Debian" "stretch"
check_alt "Kali"          "sana"     "Debian" "jessie"
check_alt "Kali"          "kali-rolling" "Debian" "bullseye"
check_alt "Sparky Linux"  "Tyche"    "Debian" "stretch"
check_alt "Sparky Linux"  "Nibiru"   "Debian" "buster"
check_alt "Sparky Linux"  "Po-Tolo"   "Debian" "bullseye"
check_alt "MX Linux 17"   "Horizon"  "Debian" "stretch"
check_alt "MX Linux 18"   "Continuum" "Debian" "stretch"
check_alt "MX Linux 19"   "patito feo" "Debian" "buster"
check_alt "MX Linux 21"   "wildflower" "Debian" "bullseye"
check_alt "Linux Mint"    "maya"     "Ubuntu" "precise"
check_alt "Linux Mint"    "qiana"    "Ubuntu" "trusty"
check_alt "Linux Mint"    "rafaela"  "Ubuntu" "trusty"
check_alt "Linux Mint"    "rebecca"  "Ubuntu" "trusty"
check_alt "Linux Mint"    "rosa"     "Ubuntu" "trusty"
check_alt "Linux Mint"    "sarah"    "Ubuntu" "xenial"
check_alt "Linux Mint"    "serena"   "Ubuntu" "xenial"
check_alt "Linux Mint"    "sonya"    "Ubuntu" "xenial"
check_alt "Linux Mint"    "sylvia"   "Ubuntu" "xenial"
check_alt "Linux Mint"    "tara"     "Ubuntu" "bionic"
check_alt "Linux Mint"    "tessa"    "Ubuntu" "bionic"
check_alt "Linux Mint"    "tina"     "Ubuntu" "bionic"
check_alt "Linux Mint"    "tricia"   "Ubuntu" "bionic"
check_alt "Linux Mint"    "ulyana"   "Ubuntu" "focal"
check_alt "Linux Mint"    "ulyssa"   "Ubuntu" "focal"
check_alt "Linux Mint"    "uma"      "Ubuntu" "focal"
check_alt "Linux Mint"    "una"      "Ubuntu" "focal"
check_alt "LMDE"          "betsy"    "Debian" "jessie"
check_alt "LMDE"          "cindy"    "Debian" "stretch"
check_alt "LMDE"          "debbie"   "Debian" "buster"
check_alt "elementaryOS"  "luna"     "Ubuntu" "precise"
check_alt "elementaryOS"  "freya"    "Ubuntu" "trusty"
check_alt "elementaryOS"  "loki"     "Ubuntu" "xenial"
check_alt "elementaryOS"  "juno"     "Ubuntu" "bionic"
check_alt "elementaryOS"  "hera"     "Ubuntu" "bionic"
check_alt "elementaryOS"  "odin"     "Ubuntu" "focal"
check_alt "elementaryOS"  "jolnir"   "Ubuntu" "focal"
check_alt "Trisquel"      "toutatis" "Ubuntu" "precise"
check_alt "Trisquel"      "belenos"  "Ubuntu" "trusty"
check_alt "Trisquel"      "flidas"   "Ubuntu" "xenial"
check_alt "Trisquel"      "etiona"   "Ubuntu" "bionic"
check_alt "Uruk GNU/Linux" "lugalbanda" "Ubuntu" "xenial"
check_alt "BOSS"          "anokha"   "Debian" "wheezy"
check_alt "BOSS"          "anoop"    "Debian" "jessie"
check_alt "BOSS"          "drishti"  "Debian" "stretch"
check_alt "BOSS"          "unnati"   "Debian" "buster"
check_alt "bunsenlabs"    "bunsen-hydrogen" "Debian" "jessie"
check_alt "bunsenlabs"    "helium"   "Debian" "stretch"
check_alt "bunsenlabs"    "lithium"  "Debian" "buster"
check_alt "Tanglu"        "chromodoris" "Debian" "jessie"
check_alt "PureOS"        "green"    "Debian" "sid"
check_alt "PureOS"        "amber"    "Debian" "buster"
check_alt "PureOS"        "byzantium" "Debian" "bullseye"
check_alt "Devuan"        "jessie"   "Debian" "jessie"
check_alt "Devuan"        "ascii"    "Debian" "stretch"
check_alt "Devuan"        "beowulf"  "Debian" "buster"
check_alt "Devuan"        "chimaera"  "Debian" "bullseye"
check_alt "Devuan"        "ceres"    "Debian" "sid"
check_alt "Deepin"        "panda"    "Debian" "sid"
check_alt "Deepin"        "unstable" "Debian" "sid"
check_alt "Deepin"        "stable"   "Debian" "buster"
check_alt "Pardus"        "onyedi"   "Debian" "stretch"
check_alt "Liquid Lemur"  "lemur-3"  "Debian" "stretch"
check_alt "Astra Linux"   "orel"     "Debian" "stretch"
check_alt "Ubilinux"      "dolcetto" "Debian" "stretch"

if [ "X${DISTRO}" == "Xdebian" ]; then
  print_status "Unknown Debian-based distribution, checking /etc/debian_version..."
  NEWDISTRO=$([ -e /etc/debian_version ] && cut -d/ -f1 < /etc/debian_version)
  if [ "X${NEWDISTRO}" == "X" ]; then
    print_status "Could not determine distribution from /etc/debian_version..."
  else
    DISTRO=$NEWDISTRO
    print_status "Found \"${DISTRO}\" in /etc/debian_version..."
  fi
fi

print_status "Confirming \"${DISTRO}\" is supported..."

if [ -x /usr/bin/curl ]; then
    exec_cmd_nobail "curl -sLf -o /dev/null 'https://deb.nodesource.com/${NODEREPO}/dists/${DISTRO}/Release'"
    RC=$?
else
    exec_cmd_nobail "wget -qO /dev/null -o /dev/null 'https://deb.nodesource.com/${NODEREPO}/dists/${DISTRO}/Release'"
    RC=$?
fi

if [[ $RC != 0 ]]; then
    print_status "Your distribution, identified as \"${DISTRO}\", is not currently supported, please contact NodeSource at https://github.com/nodesource/distributions/issues if you think this is incorrect or would like your distribution to be considered for support"
    exit 1
fi

if [ -f "/etc/apt/sources.list.d/chris-lea-node_js-$DISTRO.list" ]; then
    print_status 'Removing Launchpad PPA Repository for NodeJS...'

    exec_cmd_nobail 'add-apt-repository -y -r ppa:chris-lea/node.js'
    exec_cmd "rm -f /etc/apt/sources.list.d/chris-lea-node_js-${DISTRO}.list"
fi

print_status 'Adding the NodeSource signing key to your keyring...'
keyring='/usr/share/keyrings'
node_key_url="https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
local_node_key="$keyring/nodesource.gpg"

if [ -x /usr/bin/curl ]; then
    exec_cmd "curl -s $node_key_url | gpg --dearmor | tee $local_node_key >/dev/null"
else
    exec_cmd "wget -q -O - $node_key_url | gpg --dearmor | tee $local_node_key >/dev/null"
fi

print_status "Creating apt sources list file for the NodeSource ${NODENAME} repo..."

exec_cmd "echo 'deb [signed-by=$local_node_key] https://deb.nodesource.com/${NODEREPO} ${DISTRO} main' > /etc/apt/sources.list.d/nodesource.list"
exec_cmd "echo 'deb-src [signed-by=$local_node_key] https://deb.nodesource.com/${NODEREPO} ${DISTRO} main' >> /etc/apt/sources.list.d/nodesource.list"

print_status 'Running `apt-get update` for you...'

exec_cmd 'apt-get update'

yarn_site='https://dl.yarnpkg.com/debian'
yarn_key_url="$yarn_site/pubkey.gpg"
local_yarn_key="$keyring/yarnkey.gpg"

print_status """Run \`${bold}sudo apt-get install -y ${NODEPKG}${normal}\` to install ${NODENAME} and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL $yarn_key_url | gpg --dearmor | sudo tee $local_yarn_key >/dev/null
     echo \"deb [signed-by=$local_yarn_key] $yarn_site stable main\" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn
"""

}

## Defer setup until we have the complete script
setup


docker run -it -v ${PWD}:/AngularApp -p 0.0.0.0:3000:3000 applens/portal-dev-env bash


# Set the following environment variables to run the test suite

# Common Variables
# Some of the variables need to be populated from the service principal and storage account details provided to you by Microsoft
AZ_TENANT_ID= # tenant field of the service principal
AZ_SUBSCRIPTION_ID= # subscription id of the azure subscription (will be provided)
AZ_CLIENT_ID= # appid field of the service principal
AZ_CLIENT_SECRET= # password field of the service principal
AZ_STORAGE_ACCOUNT= # name of your storage account
AZ_STORAGE_ACCOUNT_SAS="" # sas token for your storage account, please add it within the quotes
RESOURCE_GROUP= # resource group name; set this to the resource group
OFFERING_NAME= # name of the partner offering; use this variable to distinguish between the results tar for different offerings
LOCATION=eastus # location of the arc connected cluster
NAMESPACE=arc-ds-controller # namespace of the data controller
CONNECTIVITY_MODE=indirect # choose connectivty mode for data services
SERVICE_TYPE=NodePort # Using a NodePort gives you the freedom to set up your own load-balancing solution or you can set LoadBalancer service type if your environment supports to generate external IPs.
CONFIG_PROFILE=azure-arc-aks-default-storage # choose the config profile
DATA_CONTROLLER_STORAGE_CLASS=default # choose the storage class for data controller
SQL_MI_STORAGE_CLASS=default # choose the storage class for sql mi
PSQL_STORAGE_CLASS=default # choose the storage class for postgreSQL
AZDATA_USERNAME=azureuser # database username
AZDATA_PASSWORD= # database password
MEMORY=4Gi # The request for the capacity of the managed instance as an integer number followed by Gi (gigabytes). Example: 4Gi or 8Gi
SQL_INSTANCE_NAME=arc-sql # sql instance name
PSQL_SERVERGROUP_NAME=arc-psql # postgreSQL server name
INFRASTRUCTURE=azure # Allowed values are alibaba, aws, azure, gpc, onpremises, other.
## For PRE-RELEASE test please uncomment and pass the required values for below parameters.
#RELEASE_TYPE=PRE-RELEASE
## Allowed repository names are arcdata/preview or arcdata/test
#REPOSITORY=arcdata/test
## Image Tag will be changed based on PRE-RELEASE versions
#IMAGE_TAG=v1.9.0_2022-07-12

# In case your cluster is behind an outbound proxy, please add the following environment variables in the below command
# --plugin-env azure-arc-ds-platform.HTTPS_PROXY="http://<proxy ip>:<proxy port>"
# --plugin-env azure-arc-ds-platform.HTTP_PROXY="http://<proxy ip>:<proxy port>"
# --plugin-env azure-arc-ds-platform.NO_PROXY="kubernetes.default.svc,<ip CIDR etc>"

# In case your outbound proxy is setup with certificate authentication, follow the below steps:
# Create a Kubernetes generic secret with the name sonobuoy-proxy-cert with key proxycert in any namespace:
# kubectl create secret generic sonobuoy-proxy-cert --from-file=proxycert=<path-to-cert-file>
# By default we check for the secret in the default namespace. In case you have created the secret in some other namespace, please add the following variables in the sonobuoy run command:
# --plugin-env azure-arc-ds-platform.PROXY_CERT_NAMESPACE="<namespace of sonobuoy secret>"

# Add below variables at sonobuoy run command when running the test suite on an openshift cluster
# --dns-namespace openshift-dns --dns-pod-labels dns.operator.openshift.io/daemonset-dns=default

echo "Running the test suite.."

sonobuoy run --wait --config config.json \
--plugin arc-dataservices/dataservices.yaml \
--plugin-env azure-arc-ds-platform.NAMESPACE=$NAMESPACE \
--plugin-env azure-arc-ds-platform.CONFIG_PROFILE=$CONFIG_PROFILE \
--plugin-env azure-arc-ds-platform.DATA_CONTROLLER_STORAGE_CLASS=$DATA_CONTROLLER_STORAGE_CLASS \
--plugin-env azure-arc-ds-platform.CONNECTIVITY_MODE=$CONNECTIVITY_MODE \
--plugin-env azure-arc-ds-platform.SERVICE_TYPE=$SERVICE_TYPE \
--plugin-env azure-arc-ds-platform.SQL_MI_STORAGE_CLASS=$SQL_MI_STORAGE_CLASS \
--plugin-env azure-arc-ds-platform.PSQL_STORAGE_CLASS=$PSQL_STORAGE_CLASS \
--plugin-env azure-arc-ds-platform.AZDATA_USERNAME=$AZDATA_USERNAME \
--plugin-env azure-arc-ds-platform.AZDATA_PASSWORD=$AZDATA_PASSWORD \
--plugin-env azure-arc-ds-platform.MEMORY=$MEMORY \
--plugin-env azure-arc-ds-platform.SQL_INSTANCE_NAME=$SQL_INSTANCE_NAME \
--plugin-env azure-arc-ds-platform.PSQL_SERVERGROUP_NAME=$PSQL_SERVERGROUP_NAME \
--plugin-env azure-arc-ds-platform.TENANT_ID=$AZ_TENANT_ID \
--plugin-env azure-arc-ds-platform.SUBSCRIPTION_ID=$AZ_SUBSCRIPTION_ID \
--plugin-env azure-arc-ds-platform.RESOURCE_GROUP=$RESOURCE_GROUP \
--plugin-env azure-arc-ds-platform.LOCATION=$LOCATION \
--plugin-env azure-arc-ds-platform.CLIENT_ID=$AZ_CLIENT_ID \
--plugin-env azure-arc-ds-platform.CLIENT_SECRET=$AZ_CLIENT_SECRET \
--plugin-env azure-arc-ds-platform.INFRASTRUCTURE=$INFRASTRUCTURE \
--plugin-env azure-arc-ds-platform.RELEASE_TYPE=$RELEASE_TYPE \
--plugin-env azure-arc-ds-platform.REPOSITORY=$REPOSITORY \
--plugin-env azure-arc-ds-platform.IMAGE_TAG=$IMAGE_TAG

echo "Test execution completed..Retrieving results"

sonobuoyResults=$(sonobuoy retrieve)
sonobuoy results $sonobuoyResults
mkdir results
mv $sonobuoyResults results/$sonobuoyResults
cp partner-metadata.md results/partner-metadata.md
tar -czvf conformance-results.tar.gz results
rm -rf results

echo "Publishing results.."

az login --service-principal --username $AZ_CLIENT_ID --password $AZ_CLIENT_SECRET --tenant $AZ_TENANT_ID
az account set -s $AZ_SUBSCRIPTION_ID

az storage container create -n conformance-results-ds --account-name $AZ_STORAGE_ACCOUNT --sas-token $AZ_STORAGE_ACCOUNT_SAS
az storage blob upload --file conformance-results.tar.gz --name conformance-results-$OFFERING_NAME.tar.gz --container-name conformance-results-ds --account-name $AZ_STORAGE_ACCOUNT --sas-token $AZ_STORAGE_ACCOUNT_SAS


#!/bin/bash -e
while getopts "a:l:g:s:f:e:uv" opt; do
    case $opt in
        a)
            artifactsStagingDirectory=$OPTARG #the folder or sample to deploy
        ;;
        l)
            location=$OPTARG #location for the deployed resource group
        ;;
        g)
            resourceGroupName=$OPTARG
        ;;
        u)
            uploadArtifacts='true' #set this switch to upload/stage artifacs
        ;;
        s)
            storageAccountName=$OPTARG #storage account to use for staging, if not supplied one will be created and reused
        ;;
        f)
            templateFile=$OPTARG
        ;;
        e)
            parametersFile=$OPTARG
        ;;
        v)
            validateOnly='true'
        ;;
    esac
done

[[ $# -eq 0 || -z $artifactsStagingDirectory || -z $location ]] && { echo "Usage: $0 <-a foldername> <-l location> [-e parameters-file] [-g resource-group-name] [-u] [-s storageAccountName] [-v]"; exit 1; }

if [[ -z $templateFile ]]
then
    templateFile="$artifactsStagingDirectory/azuredeploy.json"
fi
if [[ -z $parametersFile ]]
then
    parametersFile="$artifactsStagingDirectory/azuredeploy.parameters.json"
fi

templateName="$( basename "${templateFile%.*}" )"
templateDirectory="$( dirname "$templateFile")"

if [[ -z $resourceGroupName ]]
then
    resourceGroupName=${artifactsStagingDirectory}
fi

parameterJson=$( cat "$parametersFile" | jq '.parameters' )

if [[ $uploadArtifacts ]]
then

    if [[ -z $storageAccountName ]]
    then

        subscriptionId=$( az account show -o json | jq -r '.id' )
        subscriptionId="${subscriptionId//-/}"
        subscriptionId="${subscriptionId:0:19}"
        artifactsStorageAccountName="stage$subscriptionId"
        artifactsResourceGroupName="ARM_Deploy_Staging"

        if [[ -z $( az storage account list -o json | jq -r '.[].name | select(. == '\"$artifactsStorageAccountName\"')' ) ]]
        then
            az group create -n "$artifactsResourceGroupName" -l "$location"
            az storage account create -l "$location" --sku "Standard_LRS" -g "$artifactsResourceGroupName" -n "$artifactsStorageAccountName" 2>/dev/null
        fi
    else
        artifactsResourceGroupName=$( az storage account list -o json | jq -r '.[] | select(.name == '\"$s\"') .resourceGroup' )
        if [[ -z $artifactsResourceGroupName ]]
        then
            echo "Cannot find storageAccount: "$storageAccountName
        fi
    fi

    artifactsStorageContainerName=${resourceGroupName}"-stageartifacts"
    artifactsStorageContainerName=$( echo "$artifactsStorageContainerName" | awk '{print tolower($0)}')

    artifactsStorageAccountKey=$( az storage account keys list -g "$artifactsResourceGroupName" -n "$artifactsStorageAccountName" -o json | jq -r '.[0].value' )
    az storage container create -n "$artifactsStorageContainerName" --account-name "$artifactsStorageAccountName" --account-key "$artifactsStorageAccountKey" >/dev/null 2>&1

    # Get a 4-hour SAS Token for the artifacts container. Fall back to OSX date syntax if Linux syntax fails.
    plusFourHoursUtc=$(date -u -v+4H +%Y-%m-%dT%H:%MZ 2>/dev/null)  || plusFourHoursUtc=$(date -u --date "$dte 4 hour" +%Y-%m-%dT%H:%MZ)

    sasToken=$( az storage container generate-sas -n "$artifactsStorageContainerName" --permissions r --expiry "$plusFourHoursUtc" --account-name "$artifactsStorageAccountName" --account-key "$artifactsStorageAccountKey" -o json | sed 's/"//g')

    blobEndpoint=$( az storage account show -n "$artifactsStorageAccountName" -g "$artifactsResourceGroupName" -o json | jq -r '.primaryEndpoints.blob' )

    parameterJson=$( echo "$parameterJson"  | jq "{_artifactsLocation: {value: "\"$blobEndpoint$artifactsStorageContainerName"\"}, _artifactsLocationSasToken: {value: \"?"$sasToken"\"}} + ." )

    artifactsStagingDirectory=$( echo "$artifactsStagingDirectory" | sed 's/\/*$//')
    artifactsStagingDirectoryLen=$((${#artifactsStagingDirectory} + 1))

    for filepath in $( find "$artifactsStagingDirectory" -type f )
    do
        relFilePath=${filepath:$artifactsStagingDirectoryLen}
        echo "Uploading file $relFilePath..."
        az storage blob upload -f $filepath --container $artifactsStorageContainerName -n $relFilePath --account-name "$artifactsStorageAccountName" --account-key "$artifactsStorageAccountKey" --verbose
    done

    templateUri=$blobEndpoint$artifactsStorageContainerName/$(basename $templateFile)?$sasToken

fi

az group create -n "$resourceGroupName" -l "$location"

# Remove line endings from parameter JSON so it can be passed in to the CLI as a single line
parameterJson=$( echo "$parameterJson" | jq -c '.' )

if [[ $validateOnly ]]
then
    if [[ $uploadArtifacts ]]
    then
        az group deployment validate -g "$resourceGroupName" --template-uri $templateUri --parameters "$parameterJson" --verbose
    else
        az group deployment validate -g "$resourceGroupName" --template-file $templateFile --parameters "$parameterJson" --verbose
    fi
else
    if [[ $uploadArtifacts ]]
    then
        az group deployment create -g "$resourceGroupName" -n AzureRMSamples --template-uri $templateUri --parameters "$parameterJson" --verbose
    else
        az group deployment create -g "$resourceGroupName" -n AzureRMSamples --template-file $templateFile --parameters "$parameterJson" --verbose
    fi
fi


#
# this script is used to set the app up as a service to run in the bg
sudo forever-service install armvalidator â€“-script ./bin/www

#After service installation, you can start service by running following command.
sudo service armvalidator start

#Check status if app is running or stopped
sudo service armvalidator status

#You can use other following commands for start/stop/ operations.
#sudo service armvalidator stop #to stop app
#sudo service armvalidator start #


#!/bin/bash

git init
git config user.name "Travis CI"
git config user.email "sedouard@microsoft.com"

echo 'Adding files to local repo '
ls -ltr
git add .
git commit -m "Deploy"

GIT_USERNAME="dokku"
GIT_TARGET_URL="${GIT_USERNAME}@${AZURE_WA_GIT_TARGET}:${DOKKU_APPNAME}"

eval "$(ssh-agent -s)"
ssh-agent -s

# write the trusted host to the known hosts file
# to avoid a prompt when connecting to it via ssh
echo $DOKKU_SSH_PUBLIC_KNOWN_HOST > ~/.ssh/known_hosts

chmod 600 ./dokku-deploy
ssh-add ./dokku-deploy

echo 'Private keys added. Starting Dokku Deployment'
git remote add $GIT_USERNAME $GIT_TARGET_URL

git push dokku master

echo 'Deployed Latest Version of Arm Validator'


# this scripts expects the following args
userName="$1" #user name which will be used as the directory to clone the repo - usually the admin
artifactsLocation="$2"
artifactsLocationSasToken="$3"

#appPath='/var/www/azure-arm-validator'
appPath="/home/$userName/azure-arm-validator"
sudo mkdir $appPath

# install azure cli - signing key has been changed - this will be broken
#echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
#sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 417A0893
#sudo apt-get install apt-transport-https
#sudo apt-get update && sudo apt-get install azure-cli

# here is the fix for CLI install
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo apt-get install apt-transport-https
sudo apt-get update && sudo apt-get install azure-cli

#install git
sudo apt-get update
sudo apt-get install git

#install npm
sudo apt-get install npm --assume-yes
sudo apt-get install nodejs-legacy
sudo npm install forever -g
sudo npm install -g forever-service -g

#Import the public key used by the package management system.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

#Create a list file for MongoDB
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

#Reload local package database.
sudo apt-get update

#Install the MongoDB packages.
sudo apt-get install -y mongodb-org

#Start MongoDB
sudo service mongod start

#Configure MongoDB to run on system startup automatically by running this command
sudo systemctl enable mongod.service

#install bits for the app
#git clone https://github.com/Azure/azure-arm-validator "/home/$userName/azure-arm-validator" #should probably pass this in, instead of hardcoding it
git clone https://github.com/Azure/azure-arm-validator $appPath #should probably pass this in, instead of hardcoding it

#Create a database where ARM validator will store its information.
#We need to have at least one document inserted in the db. Use following command to insert document
mongo 'arm-validator' --eval 'db["arm-validator"].armvalidator.insert({"name":"arm-validator-db"})'

#enable monog service
sudo systemctl enable mongod.service

#try to download the config file if it was staged.
echo "$artifactsLocation.config.json$artifactsLocationSasToken"
curl -v -f -o "$appPath/.config.json" "$artifactsLocation.config.json$artifactsLocationSasToken"
rc=$?
if test "$rc" != "0"; then
    echo "curl failed with: $rc"
else #start the app if the config file was staged
    echo "start the service if the config file was installed"
    sudo cd "$appPath"
    #sudo npm install

    # copy the service file - not sure which one we need and this isn't working right not anyway
    #sudo cp "$appPath/azure-arm-validator.service" '/etc/systemd/system'
    #sudo cp "$appPath/azure-arm-validator.service" '/lib/systemd/system'
    #sudo chmod +x "$appPath/app.js"
    #reset the service daemon and start the service
    #sudo systemctl daemon-reload
    #sudo systemctl start azure-arm-validator

    #setup the forever service
    #-----------------------------------------------------------------
    # currently this isn't working for some reason, need to run this interactively after deployment finishes
    npm install
    sudo forever-service install armvalidator --script ./bin/www
    sudo service armvalidator start

fi

#change ownership on the app, just to make life easier
sudo chown -hR $userName "$appPath"


#!/bin/sh

for d in ./workitems/*/ ; do
    echo `azbacklog --validate-only "$d"`
done


#!/usr/bin/env bash

# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

set -e

scripts_root=$(cd $(dirname $0); pwd)

export PYTHONPATH=$PATHONPATH:./src
python -m azure.cli --version
python -m azure.cli -h --debug
python -m azure.cli batch -h --debug
az --version
pip freeze
python -m azure.cli batch job create -h --debug

# Check readme formatting for PyPI
python ./setup.py check -r -s

# PyLint crashes on Python 3.6
LOCAL_PYTHON_VERSION=$(python -c 'import sys; print("{0}.{1}".format(sys.version_info[0], sys.version_info[1]))')
if [[ "$TRAVIS_PYTHON_VERSION" == "3.6" || "$LOCAL_PYTHON_VERSION" == "3.6" ]]; then
    echo 'Skipping check_style since it is not supported in python 3.6'
else
    check_style --ci;
fi

run_tests

if [[ "$CI" == "true" ]]; then
    $scripts_root/package_verify.sh
fi

python $scripts_root/license/verify.py


#!/bin/bash
set -e
export PYTHONPATH=
virtualenv package-verify-env
. package-verify-env/bin/activate
python -m pip install -I pip==9.0.3
pip install -e scripts
python -m automation.tests.verify_packages
deactivate
# If we get here, all prev. commands returned 0 exit codes so we are done.
rm -rf package-verify-env


#!/bin/sh -x

yum update -y
yum install csh
yum install mesa-libGLU.x86_64 -y
yum install libXp-1.0.2-2.1.el7.x86_64 -y
yum install libXmu-1.1.2-2.el7.x86_64 -y
yum install libXpm -y
yum install libXi -y
yum install compat-libtiff3-3.9.4-11.el7.x86_64 -y
yum install fontconfig -y
yum install libXinerama-1.1.3-2.1.el7.x86_64 -y
yum install gamin-0.1.10-16.el7.x86_64 -y
yum install libpng12-1.2.50-10.el7.x86_64 -y
yum install libXrender -y
yum install libXcomposite-0.4.4-4.1.el7.x86_64 -y
yum install libxslt-1.1.28-5.el7.x86_64 -y
yum install pulseaudio-libs -y
yum install libunwind -y
yum install libicu -y
yum install wget -y
yum install which -y
yum install rsync -y
yum install tcsh -y
rpm --import https://packages.microsoft.com/keys/microsoft.asc
sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo'
sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
yum install libunwind libicu -y
yum install ImageMagick -y
yum install dotnet-sdk-2.1.4 -y
yum install epel-release -y
yum install p7zip -y
yum install azure-cli -y
yum install sudo -y

echo 'Installing azcopy'
wget -O azcopy.tar.gz https://aka.ms/downloadazcopyprlinux
tar -xf azcopy.tar.gz
./install.sh

yum install python-pyasn1 WALinuxAgent -y
yum clean all


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

mkdir -m777 /tmp/maya2017 -p
mkdir -m777 /tmp/maya/Maya2017 -p

echo '-=Download=-'
azcopy --source $INSTALLER_SAS --destination /tmp/maya/Autodesk_MayaIO_2017_Linux_64bit.run

echo '-=Extract and Install=-'
7za e /tmp/maya/Autodesk_MayaIO_2017_Linux_64bit.run -o/tmp/maya/
7za e /tmp/maya/Autodesk_MayaIO_2017_Linux_64bit -o/tmp/maya/Maya2017/
chmod +x /tmp/maya/Maya2017/setup.sh
/tmp/maya/Maya2017/setup.sh 127.0.0.1

cp /usr/bin/maya2017.sh /usr/bin/maya.sh

chmod +x /usr/bin/maya.sh
chmod +x /usr/bin/maya2017.sh

rm -rf /tmp/maya2017
rm -rf /tmp/maya
rm -rf /usr/autodesk/mayaIO

echo '-=Install script complete=-'


#!/bin/bash
/usr/autodesk/mayaIO2017/bin/Render "$@"
exit $?


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

mkdir -m777 /tmp/mtoa

echo '-=Download=-'
azcopy --source $INSTALLER_SAS --destination /tmp/mtoa/MtoA-linux-2017.run

echo '-=Extract and Install=-'
7za x /tmp/mtoa/MtoA-linux-2017.run -o/tmp/mtoa/
7za x /tmp/mtoa/MtoA-linux-2017 -o/tmp/mtoa/MtoA2017
7za x /tmp/mtoa/MtoA2017/package.zip -o/opt/solidangle/mtoa/2017/

cp /opt/solidangle/mtoa/2017/arnoldRenderer.xml /usr/autodesk/mayaIO2017/bin/rendererDesc/
chmod 755 -R /opt/solidangle

rm -rf /tmp/mtoa

echo '-=Install script complete=-'


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

echo '-=Download=-'
echo 'download vray4batch_maya2017_linux_x64'
azcopy --source $INSTALLER_SAS --destination /tmp/vray/vray4batch_maya2017_linux_x64

echo '-=Extract and Install=-'
chmod +x /tmp/vray/vray4batch_maya2017_linux_x64
/tmp/vray/vray4batch_maya2017_linux_x64 -gui=0 -configFile='/tmp/vray/vray_config2017.xml' -ignoreErrors=1

rm -rf /tmp/vray

echo '-=Install script complete=-'


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

mkdir -m777 /tmp/maya2018 -p
mkdir -m777 /tmp/maya/Maya2018 -p

echo '-=Download=-'
azcopy --source $INSTALLER_SAS --destination /tmp/maya/Autodesk_MayaIO_2018_Linux_64bit.run

echo '-=Extract and Install=-'
7za e /tmp/maya/Autodesk_MayaIO_2018_Linux_64bit.run -o/tmp/maya/
7za e /tmp/maya/Autodesk_MayaIO_2018_Linux_64bit -o/tmp/maya/Maya2018/
chmod +x /tmp/maya/Maya2018/setup.sh
/tmp/maya/Maya2018/setup.sh 127.0.0.1

cp /usr/bin/maya2018.sh /usr/bin/maya.sh

chmod +x /usr/bin/maya2018.sh
chmod +x /usr/bin/maya.sh

rm -rf /tmp/maya2018
rm -rf /tmp/maya
rm -rf /usr/autodesk/mayaIO

echo '-=Install script complete=-'


#!/bin/bash
/usr/autodesk/mayaIO2018/bin/Render "$@"
exit $?


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

mkdir -m777 /tmp/mtoa

echo '-=Download=-'
azcopy --source $INSTALLER_SAS --destination /tmp/mtoa/MtoA-linux-2018.run

echo '-=Extract and Install=-'
7za x /tmp/mtoa/MtoA-linux-2018.run -o/tmp/mtoa/
7za x /tmp/mtoa/MtoA-linux-2018 -o/tmp/mtoa/MtoA2018
7za x /tmp/mtoa/MtoA2018/package.zip -o/opt/solidangle/mtoa/2018/

cp /opt/solidangle/mtoa/2018/arnoldRenderer.xml /usr/autodesk/mayaIO2018/bin/rendererDesc/
chmod 755 -R /opt/solidangle

rm -rf /tmp/mtoa

echo '-=Install script complete=-'


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

echo '-=Download=-'
echo 'download vray4batch_maya2018_linux_x64'
azcopy --source $INSTALLER_SAS --destination /tmp/vray/vray4batch_maya2018_linux_x64

echo '-=Extract and Install=-'
chmod +x /tmp/vray/vray4batch_maya2018_linux_x64
/tmp/vray/vray4batch_maya2018_linux_x64 -gui=0 -configFile='/tmp/vray/vray_config2018.xml' -ignoreErrors=1

rm -rf /tmp/vray

echo '-=Install script complete=-'


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

mkdir -m777 /tmp/maya2019 -p
mkdir -m777 /tmp/maya/Maya2019 -p

echo '-=Install Maya2019 specific dependencies=-'
yum install gstreamer1 -y
yum install gstreamer1-plugins-base -y
yum clean all

echo '-=Download Installer=-'
azcopy --source $INSTALLER_SAS --destination /tmp/maya/Autodesk_MayaIO_2019_Linux_64bit.run

echo '-=Extract and Install=-'
7za e /tmp/maya/Autodesk_MayaIO_2019_Linux_64bit.run -o/tmp/maya/
7za e /tmp/maya/Autodesk_MayaIO_2019_Linux_64bit -o/tmp/maya/Maya2019/
chmod +x /tmp/maya/Maya2019/setup.sh
/tmp/maya/Maya2019/setup.sh 127.0.0.1

cp /usr/bin/maya2019.sh /usr/bin/maya.sh

chmod +x /usr/bin/maya2019.sh
chmod +x /usr/bin/maya.sh

rm -rf /tmp/maya2019
rm -rf /tmp/maya
rm -rf /usr/autodesk/mayaIO

echo '-=Install script complete=-'


#!/bin/bash

#Below is needed to prevent the following warning:
#[mtoa] Error loading extension library: libAdskSeExpr.so: cannot open shared object file: No such file or directory
#[mtoa] Error loading extension library: libAdskSeExpr.so: cannot open shared object file: No such file or directory
#unable to load dynamic library /opt/solidangle/mtoa/2019/procedurals/xgen_procedural.so: libAdskSeExpr.so: cannot open shared object file: No such file or directory
#unable to load dynamic library /opt/solidangle/mtoa/2019/procedurals/xgenSpline_procedural.so: libAdskSeExpr.so: cannot open shared object file: No such file or directory
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/autodesk/mayaIO2019/plug-ins/xgen/lib

/usr/autodesk/mayaIO2019/bin/Render "$@"
exit $?


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

mkdir -m777 /tmp/mtoa

echo '-=Download=-'
azcopy --source $INSTALLER_SAS --destination /tmp/mtoa/MtoA-linux-2019.run

echo '-=Extract and Install=-'
7za x /tmp/mtoa/MtoA-linux-2019.run -o/tmp/mtoa/
7za x /tmp/mtoa/MtoA-linux-2019 -o/tmp/mtoa/MtoA2019
7za x /tmp/mtoa/MtoA2019/package.zip -o/opt/solidangle/mtoa/2019/

cp /opt/solidangle/mtoa/2019/arnoldRenderer.xml /usr/autodesk/mayaIO2019/bin/rendererDesc/
chmod 755 -R /opt/solidangle

rm -rf /tmp/mtoa

echo '-=Install script complete=-'


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

mkdir -m777 /tmp/maya2019 -p
mkdir -m777 /tmp/maya/Maya2019 -p

echo '-=Install Maya2019 specific dependencies=-'
yum install gstreamer1 -y
yum install gstreamer1-plugins-base -y
yum clean all

echo '-=Download Installer=-'
azcopy --source $INSTALLER_SAS --destination /tmp/maya/Autodesk_MayaIO_2019_1_Update_Linux_64bit.run

echo '-=Extract and Install=-'
7za e /tmp/maya/Autodesk_MayaIO_2019_1_Update_Linux_64bit.run -o/tmp/maya/
7za e /tmp/maya/Autodesk_MayaIO_2019_1_Update_Linux_64bit -o/tmp/maya/Maya2019/
chmod +x /tmp/maya/Maya2019/setup.sh
/tmp/maya/Maya2019/setup.sh 127.0.0.1

cp /usr/bin/maya2019.sh /usr/bin/maya.sh

chmod +x /usr/bin/maya2019.sh
chmod +x /usr/bin/maya.sh

rm -rf /tmp/maya2019
rm -rf /tmp/maya
rm -rf /usr/autodesk/mayaIO

echo '-=Install script complete=-'


#!/bin/sh -x

echo 'INSTALLER_SAS='$1
INSTALLER_SAS=$1

mkdir -m777 /tmp/mtoa

echo '-=Download=-'
azcopy --source $INSTALLER_SAS --destination /tmp/mtoa/MtoA-3.2.1.1-linux-2019.run

echo '-=Extract and Install=-'
7za x /tmp/mtoa/MtoA-3.2.1.1-linux-2019.run -o/tmp/mtoa/
7za x /tmp/mtoa/MtoA-3.2.1.1-linux-2019 -o/tmp/mtoa/MtoA2019
7za x /tmp/mtoa/MtoA2019/package.zip -o/opt/solidangle/mtoa/2019/

cp /opt/solidangle/mtoa/2019/arnoldRenderer.xml /usr/autodesk/mayaIO2019/bin/rendererDesc/
chmod 755 -R /opt/solidangle

rm -rf /tmp/mtoa

echo '-=Install script complete=-'


#!/bin/bash

# install-deps.sh makes it more convenient to install
# dependencies for the Azure Blob Storage File Upload Utility.
# Some dependencies are installed via packages and
# others are installed from source code.

# Ensure that getopt starts from first option if ". <script.sh>" was used.
OPTIND=1

# Ensure we dont end the user's terminal session if invoked from source (".").
if [[ $0 != "${BASH_SOURCE[0]}" ]]; then
    ret=return
else
    ret=exit
fi

# Use sudo if user is not root
SUDO=""
if [ "$(id -u)" != "0" ]; then
    SUDO="sudo"
fi

warn() { echo -e "\033[1;33mWarning:\033[0m $*" >&2; }

error() { echo -e "\033[1;31mError:\033[0m $*" >&2; }

# Setup defaults
install_all_deps=false
install_packages=false
install_packages_only=false
# The folder where source code will be placed
# for building and installing from source.
work_folder=/tmp
keep_source_code=false
use_ssh=false

# Utility Deps
install_abs_file_upload_utility_deps=false

skip_azure_iot_sdk_install=false
install_azure_iot_sdk=false
azure_sdk_ref=main

install_azure_storage_sdk=false
azure_storage_sdk_branch_ref=main
azure_storage_sdk_tag_ref=azure-core_1.6.0

# Dependencies packages
abs_utils_packages=('git' 'make' 'snap' 'build-essential' 'ninja-build' 'libcurl4-openssl-dev' 'uuid-dev' 'libssl-dev' 'lsb-release' 'curl' 'libxml2-dev' 'wget')

print_help() {
    echo "Usage: install-deps.sh [options...]"
    echo "-a, --install-all-deps    Install all dependencies."
    echo "                          Implies --install-azure-blob-storage-deps and --install-packages."
    echo "                          Can be used with --install-packages-only."
    echo "                          This is the default if no options are specified."
    echo ""
    echo "--install-azure-blob-storage-deps  Install dependencies for the Azure Blob Storage Utility"
    echo "                                   Implies --install-azure-iot-sdk, --install-azure-storage-sdk, and --install-catch2."
    echo "                                   When used with --install-packages will also install the package dependencies."
    echo "--skip-azure-iot-sdk-install Skips the installation of the Azure IoT C SDK."
    echo "                             Used when the caller knows the Azure IoT C SDK has already been installed."
    echo "--install-azure-iot-sdk   Install the Azure IoT C SDK from source."
    echo "--azure-iot-sdk-ref <ref> Install the Azure IoT C SDK from a specific branch or tag."
    echo "                          Default is public-preview."
    echo "--install-azure-storage-sdk   Install the Azure C++ Lite Blob Storage SDK from source."
    echo "--azure-storage-sdk-ref <ref> Install the Azure C++ Lite Blob Storage SDK from a specific branch or tag."
    echo ""
    echo "-p, --install-packages    Indicates that packages should be installed."
    echo ""
    echo "--install-packages-only   Indicates that only packages should be installed and that dependencies should not be installed from source."
    echo ""
    echo "-f, --work-folder <work_folder>   Specifies the folder where source code will be cloned or downloaded."
    echo "                                  Default is /tmp."
    echo "-k, --keep-source-code            Indicates that source code should not be deleted after install from work_folder."
    echo ""
    echo "--use-ssh                 Use ssh URLs to clone instead of https URLs."
    echo "--list-deps               List the states of the dependencies."
    echo "-h, --help                Show this help message."
    echo ""
    echo "Example: ${BASH_SOURCE[0]} --install-all-deps --work-folder ~/azure-blob-stroage-utiltiy --keep-source-code"
}

do_install_abs_file_upload_utility_deps() {
    echo "Installing dependency packages for the Azure Blob Storage Utility Agent..."

    $SUDO apt-get install --yes "${abs_utils_packages[@]}" || return

if [[ "$distro" == "debian11" || "$distro" == "ubuntu22.04" ]]; then
        $SUDO apt-get install --yes gcc-10 g++-10 || return
    else
        $SUDO apt-get install --yes gcc-8 g++-8 || return
    fi

    # The following is a workaround as IoT SDK references the following paths which don't exist
    # on our target platforms, and without these folders existing, static analysis will report:
    # (information) Couldn't find path given by -I '/usr/local/inc/'
    # (information) Couldn't find path given by -I '/usr/local/pal/linux/'
    $SUDO mkdir --parents /usr/local/inc /usr/local/pal/linux
}

do_install_azure_iot_sdk() {
    echo "Installing Azure IoT C SDK ..."
    local azure_sdk_dir=$work_folder/azure-iot-sdk-c
    if [[ $keep_source_code != "true" ]]; then
        $SUDO rm -rf $azure_sdk_dir || return
    elif [[ -d $azure_sdk_dir ]]; then
        warn "$azure_sdk_dir already exists! Skipping Azure IoT C SDK."
        return 0
    fi

    local azure_sdk_url
    if [[ $use_ssh == "true" ]]; then
        azure_sdk_url=git@github.com:Azure/azure-iot-sdk-c.git
    else
        azure_sdk_url=https://github.com/Azure/azure-iot-sdk-c.git
    fi

    echo -e "Building azure-iot-sdk-c ...\n\tBranch: $azure_sdk_ref\n\tFolder: $azure_sdk_dir"
    mkdir -p $azure_sdk_dir || return
    pushd $azure_sdk_dir > /dev/null
    git clone --branch $azure_sdk_ref $azure_sdk_url . || return
    git submodule update --init || return

    mkdir cmake || return
    pushd cmake > /dev/null

    # use_http is required for uHTTP support.
    local azureiotsdkc_cmake_options=(
        "-Duse_amqp:BOOL=OFF"
        "-Duse_http:BOOL=ON"
        "-Duse_mqtt:BOOL=ON"
        "-Dskip_samples:BOOL=ON"
        "-Dbuild_service_client:BOOL=OFF"
        "-Dbuild_provisioning_service_client:BOOL=OFF"
    )

    if [[ $keep_source_code == "true" ]]; then
        # If source is wanted, presumably samples and symbols are useful as well.
        azureiotsdkc_cmake_options+=("-DCMAKE_BUILD_TYPE:STRING=Debug")
    else
        azureiotsdkc_cmake_options+=("-Dskip_samples=ON")
    fi

    cmake "${azureiotsdkc_cmake_options[@]}" .. || return

    cmake --build . || return
    $SUDO cmake --build . --target install || return

    popd > /dev/null
    popd > /dev/null

    if [[ $keep_source_code != "true" ]]; then
        $SUDO rm -rf $azure_sdk_dir || return
    fi
}

do_install_azure_storage_sdk() {
    echo "Installing azure-storage-sdk"
    local azure_storage_sdk_dir=$work_folder/azure_storage_sdk_dir

    if [[ $keep_source_code != "true" ]]; then
        $SUDO rm -rf $azure_storage_sdk_dir || return
    elif [[ -d $azure_storage_sdk_dir ]]; then
        warn "$azure_storage_sdk_dir already exists! Skipping Azure Storage SDK."
        return 0
    fi

    local azure_storage_sdk_url
    if [[ $use_ssh == "true" ]]; then
        azure_storage_sdk_url=git@github.com:Azure/azure-sdk-for-cpp.git
    else
        azure_storage_sdk_url=https://github.com/Azure/azure-sdk-for-cpp.git
    fi

    echo -e "Building Azure Storage SDK ...\n\tBranch: $azure_storage_sdk_branch_ref\n\t Folder: $azure_storage_sdk_dir"
    mkdir -p $azure_storage_sdk_dir || return
    pushd $azure_storage_sdk_dir > /dev/null
    git clone --recursive --single-branch --branch $azure_storage_sdk_branch_ref $azure_storage_sdk_url . || return

    git checkout tags/$azure_storage_sdk_tag_ref

    mkdir cmake || return
    pushd cmake > /dev/null

    local azure_blob_storage_file_upload_utility_cmake_options
    if [[ $keep_source_code == "true" ]]; then
        # If source is wanted, presumably samples and symbols are useful as well.
        azure_blob_storage_file_upload_utility_cmake_options+=("-DCMAKE_BUILD_TYPE:STRING=Debug")
    else
        azure_blob_storage_file_upload_utility_cmake_options+=("-DCMAKE_BUILD_TYPE:STRING=Release")
    fi

    local architecture
    architecture=`uname -m`
    echo "${architecture}"
    local cmake_url
    local cmake_tar_path
    local cmake_dir_path
    local cmake_build_from_source=false
    if [[ "${architecture}" == "x86_64" ]]; then
        echo "Detected x86_64 architecture"
        echo "Attempting to use existing binary for CMake"
        cmake_url="https://cmake.org/files/v3.19/cmake-3.19.8-Linux-x86_64.tar.gz"
        cmake_tar_path="./cmake-3.19.8-Linux-x86_64.tar.gz"
        cmake_dir_path="./cmake-3.19.8-Linux-x86_64/"
        cmake_build_from_source=false
    elif [ "${architecture}" == "aarch64" ]; then
        echo "Detected aarch64 architecture"
        echo "Attempting to use existing binary for CMake"
        cmake_url="https://cmake.org/files/v3.19/cmake-3.19.8-Linux-aarch64.tar.gz"
        cmake_tar_path="./cmake-3.19.8-Linux-aarch64.tar.gz"
        cmake_dir_path="./cmake-3.19.8-Linux-aarch64/"
        cmake_build_from_source=false
    else
        echo "Unknown architecture... Attempting to build from source"
        echo "Attempting to build CMake from source"
        cmake_url="https://cmake.org/files/v3.21/cmake-3.21.4.tar.gz"
        cmake_tar_path="./cmake-3.21.4.tar.gz"
        cmake_dir_path="./cmake-3.21.4/"
        cmake_build_from_source=true
    fi

    wget ${cmake_url}
    tar -zxvf ${cmake_tar_path}

    if [[ $cmake_build_from_source == "true"  ]]; then
        echo "Building CMake from source."
        pushd $cmake_dir_path > /dev/null
        ./bootstrap
        make > /dev/null
        popd > /dev/null
    fi

    ${cmake_dir_path}/bin/cmake "${azure_blob_storage_file_upload_utility_cmake_options[@]}" .. || return

    ${cmake_dir_path}/bin/cmake --build . || return
    $SUDO ${cmake_dir_path}/bin/cmake --build . --target install || return

    rm -fr ${cmake_dir_path}
    rm -fr ${cmake_tar_path}

    popd > /dev/null
    popd > /dev/null

    if [[ $keep_source_code != "true" ]]; then
        $SUDO rm -rf $azure_storage_sdk_dir || return
    fi
}

determine_machine_architecture() {
    local arch=''
    arch="$(uname -m)"
    local ret_val=$?
    if [[ $ret_val != 0 ]]; then
        error "Failed to get cpu architecture."
        return 1
    else
        if [[ $arch == aarch64* || $arch == armv8* ]]; then
            is_arm64=true
        elif [[ $arch == armv7* || $arch == 'arm' ]]; then
            is_arm32=true
        elif [[ $arch == 'x86_64' || $arch == 'amd64' ]]; then
            is_amd64=true
        else
            error "Machine architecture '$arch' is not supported."
            return 1
        fi
    fi
}

determine_distro_and_arch() {
    # Checking distro name and version
    if [ -r /etc/os-release ]; then
        # freedesktop.org and systemd
        OS=$(grep "^ID\s*=\s*" /etc/os-release | sed -e "s/^ID\s*=\s*//")
        VER=$(grep "^VERSION_ID=" /etc/os-release | sed -e "s/^VERSION_ID=//")
        VER=$(sed -e 's/^"//' -e 's/"$//' <<< "$VER")
    elif type lsb_release > /dev/null 2>&1; then
        # linuxbase.org
        OS=$(lsb_release -si)
        VER=$(lsb_release -sr)
    elif [ -f /etc/lsb-release ]; then
        # For some versions of Debian/Ubuntu without lsb_release command
        OS=$(grep DISTRIB_ID /etc/lsb-release | awk -F'=' '{ print $2 }')
        VER=$(grep DISTRIB_RELEASE /etc/lsb-release | awk -F'=' '{ print $2 }')
    elif [ -f /etc/debian_version ]; then
        # Older Debian/Ubuntu/etc.
        OS=Debian
        VER=$(cat /etc/debian_version)
    else
        # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
        OS=$(uname -s)
        VER=$(uname -r)
    fi

    # Convert OS to lowercase
    OS="$(echo "$OS" | tr '[:upper:]' '[:lower:]')"

    determine_machine_architecture || return 1
}

do_list_all_deps() {
    declare -a deps_set=()
    deps_set+=(${abs_utils_packages[@]})
    deps_set+=(${compiler_packages[@]})
    echo "Listing the state of dependencies:"
    dpkg-query -W -f='${binary:Package} ${Version} (${Architecture})\n' "${deps_set[@]}"
    ret_val=$?
    if [ $ret_val -eq 1 ]; then
        warn "dpkg-query failed"
        return 0
    elif [ $ret_val -ge 2 ]; then
        error "dpkg-query failed with status $ret_val"
        return $ret_val
    fi
    return 0
}

###############################################################################

# Check if no options were specified.
if [[ $1 == "" ]]; then
    error "Must specify at least one option."
    $ret 1
fi

# Parse cmd options
while [[ $1 != "" ]]; do
    case $1 in
    -a | --install-all-deps)
        install_all_deps=true
        ;;
    --install-azure-blob-storage-deps)
        install_abs_file_upload_utility_deps=true
        ;;
    --install-azure-iot-sdk)
        install_azure_iot_sdk=true
        ;;
    --azure-iot-sdk-ref)
        shift
        azure_sdk_ref=$1
        ;;
    --skip-azure-iot-sdk-install)
        shift
        skip_azure_iot_sdk_install=true
        ;;
    --install-azure-storage-sdk)
        shift
        install_azure_storage_sdk=true
        ;;
    --azure-storage-sdk-ref)
        shift
        azure_storage_sdk_ref=$1
        ;;
    -p | --install-packages)
        install_packages=true
        ;;
    --install-packages-only)
        install_packages_only=true
        ;;
    -f | --work-folder)
        shift
        work_folder=$(realpath "$1")
        ;;
    -k | --keep-source-code)
        keep_source_code=true
        ;;
    --use-ssh)
        use_ssh=true
        ;;
    --list-deps)
        do_list_all_deps
        $ret $?
        ;;
    -h | --help)
        print_help
        $ret 0
        ;;
    *)
        error "Invalid argument: $*"
        $ret 1
        ;;
    esac
    shift
done

# Get OS, VER, machine architecture for use in other parts of the script.
determine_distro_and_arch
distro=$OS$VER
if [[ "$distro" == "debian11" ]]; then
    compiler_packages=(gcc-10)
else
    compiler_packages=(gcc-8)
fi

# If there is no install action specified,
# assume that we want to install all deps.
if [[ $install_all_deps != "true" && $install_abs_file_upload_utility_deps != "true" && $install_azure_iot_sdk != "true" ]]; then
    install_all_deps=true
fi

# If --all was specified,
# set all install actions to "true".
if [[ $install_all_deps == "true" ]]; then
    install_abs_file_upload_utility_deps=true
    install_packages=true
fi

# Set implied options for aduc deps.
if [[ $install_abs_file_upload_utility_deps == "true" ]]; then

    if [[ $skip_azure_iot_sdk_install == "true" ]]; then
        install_azure_iot_sdk=false
    else
        install_azure_iot_sdk=true
    fi
    install_azure_storage_sdk=true
fi

# Set implied options for packages only.
if [[ $install_packages_only == "true" ]]; then
    install_packages=true
    install_azure_iot_sdk=false
fi

if [[ $install_packages == "true" ]]; then
    # Check if we need to install any packages
    # before we call apt update.
    if [[ $install_abs_file_upload_utility_deps == "true" ]]; then
        echo "Updating repository list..."
        $SUDO apt-get update --yes --fix-missing --quiet || $ret
    fi
fi

if [[ $install_abs_file_upload_utility_deps == "true" ]]; then
    do_install_abs_file_upload_utility_deps || $ret
fi

# Install dependencies from source
if [[ $install_packages_only == "false" ]]; then
    if [[ $install_azure_iot_sdk == "true" ]]; then
        do_install_azure_iot_sdk || $ret
    fi

    if [[ $install_azure_storage_sdk == "true" ]]; then
        do_install_azure_storage_sdk || $ret
    fi
fi

# After installation, it prints out the states of dependencies
if [[ $install_abs_file_upload_utility_deps == "true" || $install_packages_only == "true" || $install_packages == "true" ]]; then
    do_list_all_deps || $ret $?
fi


#!/bin/bash
#set -o pipefail
#

set -e

script_dir=$(cd "$(dirname "$0")" && pwd)
build_root=$(cd "${script_dir}/../.." && pwd)
run_unit_tests=ON
make_install=
run_valgrind=0
run_unittests=OFF

usage ()
{
    echo "build.sh [options]"
    echo "options"
    echo " -cl, --compileoption <value>  specify a compile option to be passed to gcc"
    echo "   Example: -cl -O1 -cl ..."
    echo "-rv, --run_valgrind will execute ctest with valgrind"
    echo "--run-unittests run the unit tests"

    exit 1
}

process_args ()
{
    save_next_arg=0
    extracloptions=" "

    for arg in $*
    do
      if [ $save_next_arg == 1 ]
      then
        # save arg to pass to gcc
        extracloptions="$arg $extracloptions"
        save_next_arg=0
      elif [ $save_next_arg == 2 ]
	  then
        build_root="$arg"
        save_next_arg=0
      else
          case "$arg" in
              "-cl" | "--compileoption" ) save_next_arg=1;;
              "-i" | "--install" ) make_install=1;;
              "-rv" | "--run_valgrind" ) run_valgrind=1;;
              "--run-unittests" ) run_unittests=ON;;
              "--build-root" ) save_next_arg=2;;
              * ) usage;;
          esac
      fi
    done
}

process_args $*
log_dir=$build_root
build_folder=$build_root"/cmake/shared-util_linux"

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake -DcompileOption_C:STRING="$extracloptions" -Drun_valgrind:BOOL=$run_valgrind $build_root -Drun_unittests:BOOL=$run_unittests
make --jobs=$CORES
if [[ $make_install == 1 ]] ;
then
    echo "Installing packaging"
    # install the package
    make install
fi

if [[ $run_valgrind == 1 ]] ;
then
	#use doctored openssl
	export LD_LIBRARY_PATH=/usr/local/ssl/lib
	ctest -j $CORES --output-on-failure
	export LD_LIBRARY_PATH=
else
	ctest -j $CORES -C "Debug" --output-on-failure
fi

popd


#! /bin/bash

# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -o errexit # Exit if command failed.
set -o pipefail # Exit if pipe failed.

# Only for testing E2E behaviour !!!
TEST_CORES=16

# Refresh dynamic libs to link to
sudo ldconfig

ctest -T test --no-compress-output -C "Debug" -V -j $TEST_CORES --schedule-random


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

build_root=$(cd "$(dirname "$0")/.." && pwd)
cd $build_root

build_folder=$build_root"/cmake"

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake -Drun_valgrind:BOOL=ON $build_root -Drun_unittests:BOOL=ON
make --jobs=$CORES

popd


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

# Print version
cat /etc/*release | grep VERSION*
gcc --version
curl --version

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
cmake . -Bcmake -Duse_bearssl:BOOL=ON -Drun_unittests:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=gcc
cd cmake

make --jobs=$CORES

ctest -j $CORES --output-on-failure


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

# Print version
cat /etc/*release | grep VERSION*
gcc --version
curl --version

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
cmake . -Bcmake -Duse_bearssl:BOOL=ON -Drun_unittests:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
cd cmake

make --jobs=$CORES


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -x # Set trace on
set -o errexit # Exit if command failed
set -o nounset # Exit if variable not set
set -o pipefail # Exit if pipe failed

# Print version
cat /etc/*release | grep VERSION*
gcc --version
curl --version

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
cmake . -Bcmake -Duse_c_ares:BOOL=ON -Drun_e2e_tests:BOOL=ON
cd cmake

make --jobs=$CORES


#!/bin/bash
#set -o pipefail
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

cat /etc/*release | grep VERSION*
gcc --version
openssl version

script_dir=$(cd "$(dirname "$0")" && pwd)
build_root=$(cd "${script_dir}/.." && pwd)
build_folder=$build_root"/cmake"

# Set the default cores
MAKE_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

echo "Initial MAKE_CORES=$MAKE_CORES"

# Make sure there is enough virtual memory on the device to handle more than one job
MINVSPACE="1500000"

# Acquire total memory and total swap space setting them to zero in the event the command fails
MEMAR=( $(sed -n -e 's/^MemTotal:[^0-9]*\([0-9][0-9]*\).*/\1/p' -e 's/^SwapTotal:[^0-9]*\([0-9][0-9]*\).*/\1/p' /proc/meminfo) )
[ -z "${MEMAR[0]##*[!0-9]*}" ] && MEMAR[0]=0
[ -z "${MEMAR[1]##*[!0-9]*}" ] && MEMAR[1]=0

let VSPACE=${MEMAR[0]}+${MEMAR[1]}

if [ "$VSPACE" -lt "$MINVSPACE" ] ; then
echo "WARNING: Not enough space.  Setting MAKE_CORES=1"
MAKE_CORES=1
fi

declare -a arr=(
    "-Dskip_samples=ON"
    "-Dno_logging=ON"
    "-Denable_raw_logging=ON"
    "-Denable_raw_logging=ON -Dno_logging=ON"
    "-Duse_builtin_httpapi=ON"
    "-Duse_default_uuid=ON"
    "-Dno_openssl_engine=ON"
    "-Duse_http=OFF"
)

for item in "${arr[@]}"
do
    rm -r -f $build_folder
    mkdir -p $build_folder
    pushd $build_folder

    echo "executing cmake/make with options <<$item>>"
    cmake $build_root "$item"

    make --jobs=$MAKE_CORES
done
popd


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

# Print version
cat /etc/*release | grep VERSION*
gcc --version

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

build_root=$(cd "$(dirname "$0")/.." && pwd)
clone_root=$(cd "$(dirname "$0")/../.." && pwd)
cd $build_root

echo "Build Root $build_root"

sdk_build_folder=$build_root"/cmake"

# Build the SDK
rm -rf $sdk_build_folder
mkdir -p $sdk_build_folder
pushd $sdk_build_folder
cmake $build_root
make install --jobs=$CORES
popd

# Now use the deps
rm -rf $sdk_build_folder
mkdir -p $sdk_build_folder
pushd $sdk_build_folder
cmake $build_root -Duse_installed_dependencies=ON
make --jobs=$CORES
popd


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

build_root=$(cd "$(dirname "$0")/.." && pwd)
cd $build_root

build_folder=$build_root"/cmake"

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake -Drun_valgrind:BOOL=ON -Duse_mbedtls=ON -Duse_openssl=OFF $build_root -Drun_unittests:BOOL=ON -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++
make --jobs=$CORES

ctest -j $CORES --output-on-failure

popd


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

build_root=$(cd "$(dirname "$0")/.." && pwd)
cd $build_root

build_folder=$build_root"/cmake"

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake -Drun_valgrind:BOOL=ON -Duse_mbedtls=ON -Duse_openssl=OFF $build_root -Drun_unittests:BOOL=ON -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
make --jobs=$CORES

popd


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

build_root=$(cd "$(dirname "$0")/.." && pwd)
cd $build_root

build_folder=$build_root"/cmake"

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake $build_root -Drun_unittests:BOOL=ON -Duse_wolfssl:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=gcc
make --jobs=$CORES

#use doctored openssl
export LD_LIBRARY_PATH=/usr/local/ssl/lib
ctest -j $CORES --output-on-failure
export LD_LIBRARY_PATH=

popd


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

build_root=$(cd "$(dirname "$0")/.." && pwd)
cd $build_root

build_folder=$build_root"/cmake"

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake $build_root -Drun_unittests:BOOL=ON -Duse_wolfssl:BOOL=ON -Duse_openssl:BOOL=OFF -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
make --jobs=$CORES

popd


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

set -e

script_dir=$(cd "$(dirname "$0")" && pwd)
build_root=$(cd "${script_dir}/.." && pwd)
build_folder=$build_root"/cmake"

CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake .. -DOPENSSL_ROOT_DIR:PATH=/usr/local/opt/openssl -Duse_openssl:bool=ON -Drun_unittests:bool=ON
cmake --build . -- --jobs=$CORES


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

set -e

script_dir=$(cd "$(dirname "$0")" && pwd)
build_root=$(cd "${script_dir}/.." && pwd)
build_folder=$build_root"/cmake"

CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake .. -Drun_unittests:bool=ON -G Xcode
cmake --build . -- --jobs=$CORES
ctest -C "debug" -V
popd


#!/bin/bash
# assume directory is root of downloaded repo
mkdir cmake
cd cmake
ls -al

# Create a cmake toolchain file on the fly
echo "SET(CMAKE_SYSTEM_NAME Linux)     # this one is important" > toolchain.cmake
echo "SET(CMAKE_SYSTEM_VERSION 1)      # this one not so much" >> toolchain.cmake

echo "SET(CMAKE_C_COMPILER ${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-gcc)" >> toolchain.cmake
echo "SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-g++)" >> toolchain.cmake
echo "SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_SYSROOT})" >> toolchain.cmake
echo "SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> toolchain.cmake
echo "SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> toolchain.cmake
echo "SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> toolchain.cmake
ls -al

# Build the SDK. This will use the OpenSSL, cURL and uuid binaries that we built before
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake -Duse_prov_client=OFF -DCMAKE_INSTALL_PREFIX=${TOOLCHAIN_PREFIX} -Drun_e2e_tests=ON -Drun_unittests=ON ..
make -j 2
ls -al


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.

set -e

build_root=$(cd "$(dirname "$0")/.." && pwd)
cd $build_root

build_folder=$build_root"/cmake"

# Set the default cores
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake $build_root -Drun_unittests:BOOL=ON -Drun_valgrind:BOOL=ON
make --jobs=$CORES

popd


#!/bin/bash
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

set -e

script_dir=$(cd "$(dirname "$0")" && pwd)
build_root=$(cd "${script_dir}/.." && pwd)
build_folder=$build_root"/cmake"

rm -r -f $build_folder
mkdir -p $build_folder
pushd $build_folder
cmake .. -Drun_valgrind:BOOL=ON -Drun_unittests:bool=ON
cmake --build . -- --jobs=$(nproc)

popd
:


#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
# Create a python 3 virtual environment for developing this Azure CLI extension.
#
# Syntax: ./create-dev-env.sh
#

set -x

python3 -m venv env

# Activate the virtualenv automatically in GitHub Codespace shells
if [ "$CODESPACES" == "true" ]; then
    echo 'if [ -d "./env" ]; then source ./env/bin/activate; fi' >> ~/.bashrc
    echo 'if [ -d "./env" ]; then source ./env/bin/activate; fi' >> ~/.zshrc
fi

source ./env/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install azdev
azdev setup --repo . --ext capi --verbose


# <copyright file="DownloadDeployerVMPackages.sh" company="Microsoft Corporation">
# Copyright (c) Microsoft Corporation. All rights reserved.
# </copyright>

#!/bin/bash

#Exit when any command fails
set -e

#download packages locally

workloadWorkdir=DeployerVMPackages

if [[ ! -d "$workloadWorkdir" ]]; then
        mkdir $workloadWorkdir
fi

if [[ ! -d "$workloadWorkdir/packages" ]]; then
        mkdir $workloadWorkdir/packages
fi

#download python3-pip
cd $workloadWorkdir/packages

if [[ ! -f "pip-21.3.1.tar.gz" ]]; then
        wget -nv -q https://files.pythonhosted.org/packages/da/f6/c83229dcc3635cdeb51874184241a9508ada15d8baa337a41093fab58011/pip-21.3.1.tar.gz
        tar -xvf pip-21.3.1.tar.gz
fi

cd pip-21.3.1/

#Check if pip3 is already installed
if [[ -z $(which pip3) ]]; then
        #Install pip
        echo "Installing pip3."
        sudo python3 setup.py install
fi

cd ../../..
#download wheel
pip3 download -d $workloadWorkdir/packages wheel==0.37.1

#download netaddr
pip3 download -d $workloadWorkdir/packages netaddr==0.8.0

#download jq 1.6
if [[ ! -d "$workloadWorkdir/jq_pkg" ]]; then
        mkdir $workloadWorkdir/jq_pkg
fi

cd $workloadWorkdir/jq_pkg
wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x jq

cd -
#download ansible
if [[ ! -d "$workloadWorkdir/ansible_pkg" ]]; then
        mkdir $workloadWorkdir/ansible_pkg
fi
pip3 download -d $workloadWorkdir/ansible_pkg "ansible==2.9.27"

#download azure cli libraries
if [[ ! -d "$workloadWorkdir/azure_cli_pkg" ]]; then
        mkdir $workloadWorkdir/azure_cli_pkg
fi

cd $workloadWorkdir/azure_cli_pkg
wget -nv -q https://raw.githubusercontent.com/Azure/azure-cli/azure-cli-2.30.0/src/azure-cli/requirements.py3.Linux.txt

cd -
if [[ ! -d "$workloadWorkdir/azure_cli_pkg/azure_cli_requirements" ]]; then
        mkdir $workloadWorkdir/azure_cli_pkg/azure_cli_requirements
fi

pip3 download -r $workloadWorkdir/azure_cli_pkg/requirements.py3.Linux.txt -d $workloadWorkdir/azure_cli_pkg/azure_cli_requirements

#Check if zip is already installed
if [[ -z $(which zip) ]]; then
        echo "Installing zip package."
        #Install zip
        sudo apt-get --assume-yes install zip
fi

zip -r $workloadWorkdir.zip $workloadWorkdir

#Check if user have an existing storage account
echo "Do you have an existing storage account?"
echo -n "y/n: "
read -r userInput

if [[ ${userInput^^} == "Y" ]]; then
        #sapbits_location_base_path
        echo "Enter the SAP storage account base path(sapbits-location-base-path) url copied from storage container properties. This is the storage container where SAP installation bits and deployer vm packages are stored/will be stored."
        read -r sapbits_location_base_path

        #check if customer entered an empty string
        while [ -z $sapbits_location_base_path ]
        do
            echo "Empty sapbits-location-base-path given, please re-enter the SAP storage account base path(sapbits-location-base-path) url else press 'Ctrl+C' or type 'exit' to end the process."
            read -r sapbits_location_base_path

            if [[ ${sapbits_location_base_path^^} == "EXIT" ]]; then
                    exit 1
            fi
        done
        IFS='//'
        read -ra arr <<< $sapbits_location_base_path
        container=${arr[3]}

        IFS='.'
        read -ra arr <<< ${arr[2]}
        storageAccountName=${arr[0]}

        #Fetch container name
        IFS='"'
        read -ra arr <<< $container
        containerName=${arr[0]}
else
        #Storage account name
        echo "Enter the new storage account name you want to create."
        read -r storageAccountName
        while [ -z $storageAccountName ]
        do
            echo "Empty storage account name given, please re-enter the storage account name else press 'Ctrl+C' or type 'exit' to end the process."
            read -r storageAccountName

            if [[ ${storageAccountName^^} == "EXIT" ]]; then
                    exit 2
            fi
        done

        #Check subscription
        subscription=$(az account show --query name)
        echo "Current subscription is $subscription, do you want to change the subscription? This is the subscription where storage account will be created."
        echo -n "y/n: "
        read -r userInput

        if [[ ${userInput^^} == "Y" ]]; then
                echo "Enter the new subscription name or id. (Use az account list to get a list of subscriptions for the logged in account)."
                read -r subscription
                az account set --subscription "$subscription"
        fi

        echo "Do you want to use an existing resource group? This is the resource group where storage account will be created."
        echo -n "y/n: "
        read -r userInput
        if [[ ${userInput^^} == "Y" ]]; then
                echo "Enter the resource group name."
                read -r resourceGroupName
                while [ -z $resourceGroupName ]
                do
                    echo "Empty resource group name given, please re-enter the resource group name else press 'Ctrl+C' or type 'exit' to end the process."
                    read -r resourceGroupName

                    if [[ ${resourceGroupName^^} == "EXIT" ]]; then
                            exit 3
                    fi
                done
        else
                echo "Enter the new resource group name to create a new resource group."
                read -r resourceGroupName
                while [ -z $resourceGroupName ]
                do
                    echo "Empty resource group name given, please re-enter the resource group name else press 'Ctrl+C' or type 'exit' to end the process."
                    read -r resourceGroupName

                    if [[ ${resourceGroupName^^} == "EXIT" ]]; then
                            exit 4
                    fi
                done

                echo "Enter the location where you want to create resource group."
                read -r resourceGroupLocation
                while [ -z $resourceGroupLocation ]
                do
                    echo "Empty resource group locaion given, please re-enter the resource group name else press 'Ctrl+C' or type 'exit' to end the process."
                    read -r resourceGroupLocation

                    if [[ ${resourceGroupLocation^^} == "EXIT" ]]; then
                            exit 5
                    fi
                done
                az group create --location $resourceGroupLocation --name $resourceGroupName
        fi

        echo "Creating storage account $storageAccountName in resource group $resourceGroupName and subscription $subscription"
        az storage account create --name $storageAccountName --resource-group $resourceGroupName

        #Container name
        echo "Enter the new container name you want to create."
        read -r containerName
        while [ -z $containerName ]
        do
            echo "Empty container name given, please re-enter the container name else press 'Ctrl+C' or type 'exit' to end the process."
            read -r containerName

            if [[ ${containerName^^} == "EXIT" ]]; then
                    exit 6
            fi
        done

        echo "Create container $containerName in storage account $storageAccountName"
        az storage container create --name $containerName --account-name $storageAccountName
fi

#sapbits-access-key
echo "Enter the sapbits-access-key copied from storage account 'Access keys'."
read -r sapbits_access_key

#Repeat while loop until customer enters a non empty sapbits-access-key
while [ -z $sapbits_access_key ]
do
    read -r sapbits_access_key
    echo "No sapbits-access-key detected, please re-enter the sapbits-access-key else press 'Ctrl+C' or type 'exit' to end the process."

    if [[ ${sapbits_access_key^^} == "EXIT" ]]; then
            exit 7
    fi
done

echo "Storage account name where deployer vm packages are stored/will be stored: $storageAccountName."
echo "Container name where deployer vm packages are stored/will be stored: $containerName/deployervmpackages."

isBlobExists=$(az storage blob exists --account-name $storageAccountName --account-key "$sapbits_access_key" --container-name $containerName/deployervmpackages --name $workloadWorkdir.zip --query exists)

if [[ $isBlobExists == "false" ]]; then
        #upload to storage account
        az storage blob upload --account-name $storageAccountName --account-key "$sapbits_access_key" --container-name $containerName/deployervmpackages --name $workloadWorkdir.zip --file $workloadWorkdir.zip --if-none-match "*" --no-progress
else
        echo "Existing blob $workloadWorkdir.zip found in storage account, do you want to update the blob?"
        echo -n "y/n: "
        read -r userInput

        if [[ ${userInput^^} == "Y" ]]; then
                #delete existing blob
                az storage blob delete --account-name $storageAccountName --account-key "$sapbits_access_key" --container-name $containerName/deployervmpackages --name $workloadWorkdir.zip
                az storage blob upload --account-name $storageAccountName --account-key "$sapbits_access_key" --container-name $containerName/deployervmpackages --name $workloadWorkdir.zip --file $workloadWorkdir.zip --if-none-match "*" --no-progress
        fi
fi


#!/usr/bin/env bash

#######################################################################################################################
# This script installs all dependencies found in this repository directly, without transitive dependencies, then uses
# the appropriate requirements.txt file to install all transitive dependencies.
#
# NOTE: It should be invoked from an activated virtual environment, unless targeting system python directly is
# acceptable.
#
# The intention is to allow packagers, people working with the RPM spec or debian rules file for example, to not have
# duplicate that logic required to install from source what is distributed in this repository and via PyPI for items
# living outside of this repository.
#######################################################################################################################

REPO_ROOT="$(dirname ${BASH_SOURCE[0]})/.."

pushd ${REPO_ROOT} > /dev/null

find src/ -name setup.py -type f | xargs -I {} dirname {} | grep -v azure-cli-testsdk | xargs pip install --no-deps
pip install -r ./src/azure-cli/requirements.$(python ./scripts/get-python-version.py).$(uname).txt

popd > /dev/null


#!/usr/bin/env bash
# Build wheel and set the $share_folder to the artifacts folder

. $(dirname ${BASH_SOURCE[0]})/build.sh
share_folder=$(pwd)/artifacts


#!/usr/bin/env bash

# Build wheel packages containing both CLI product and tests. The script doesn't rely on a pre-existing virtual
# environment.

set -ev

##############################################
# clean up and dir search
mkdir -p ./artifacts

# Current folder (/azure-cli) is mounted from host which has different owner than docker container's
# current user 0(root).
# https://github.blog/2022-04-12-git-security-vulnerability-announced/
git config --global --add safe.directory $(pwd)
echo `git rev-parse --verify HEAD` > ./artifacts/build.sha

mkdir -p ./artifacts/build
mkdir -p ./artifacts/source
mkdir -p ./artifacts/testsrc

output_dir=$(cd artifacts/build && pwd)
sdist_dir=$(cd artifacts/source && pwd)
testsrc_dir=$(cd artifacts/testsrc && pwd)
script_dir=`cd $(dirname $BASH_SOURCE[0]); pwd`

target_profile=${AZURE_CLI_TEST_TARGET_PROFILE:-latest}
if [ "$target_profile" != "latest" ]; then
    # example: hybrid-2019-03-01. Python module name can't begin with a digit.
    target_profile=hybrid_${target_profile//-/_}
fi
echo Pick up profile: $target_profile

##############################################
# Define colored output func
function title {
    LGREEN='\033[1;32m'
    CLEAR='\033[0m'

    echo -e ${LGREEN}$1${CLEAR}
}

##############################################
# Update version strings
title 'Determine version'
. $script_dir/version.sh $1
# echo -n $version > ./artifacts/version

##############################################
# build product packages
title 'Build Azure CLI and its command modules'
for setup_file in $(find src -name 'setup.py'); do
    pushd $(dirname ${setup_file}) >/dev/null
    echo "Building module at $(pwd) ..."
    python setup.py -q bdist_wheel -d $output_dir
    python setup.py -q sdist -d $sdist_dir
    popd >/dev/null
done

##############################################
# copy private packages
if [ -z ./privates ]; then
    cp ./privates/*.whl $output_dir
fi

##############################################
# build test packages
title 'Build Azure CLI tests package'

for test_src in $(find src/azure-cli/azure/cli/command_modules -name tests -type d); do
    rel_path=${test_src##src/azure-cli/}

    mkdir -p $testsrc_dir/$rel_path
    cp -R $test_src/* $testsrc_dir/$rel_path
done

if [ "$target_profile" == "latest" ]; then
    # don't pack core tests for profiles other than latest
    for test_src in $(find src -name tests | grep -v command_modules); do
        rel_path=${test_src##src/}
        rel_path=(${rel_path/\// })
        rel_path=${rel_path[1]}

        mkdir -p $testsrc_dir/$rel_path
        cp -R $test_src/* $testsrc_dir/$rel_path
    done
fi

cat >$testsrc_dir/setup.py <<EOL
#!/usr/bin/env python

from setuptools import setup

VERSION = "1.0.0.$version"

CLASSIFIERS = [
    'Development Status :: 3 - Alpha',
    'Intended Audience :: Developers',
    'Programming Language :: Python',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.7',
    'Programming Language :: Python :: 3.8',
    'Programming Language :: Python :: 3.9',
    'Programming Language :: Python :: 3.10',
    'License :: OSI Approved :: MIT License',
]

DEPENDENCIES = [
    'azure-cli',
    'azure-cli-testsdk'
]

setup(
    name='azure-cli-fulltest',
    version=VERSION,
    description='Microsoft Azure Command-Line Tools Full Tests',
    license='MIT',
    author='Microsoft Corporation',
    author_email='azpycli@microsoft.com',
    url='https://github.com/Azure/azure-cli',
    zip_safe=False,
    classifiers=CLASSIFIERS,
    packages=[
EOL

if [ "$target_profile" == "latest" ]; then
    echo "        'azure.cli.core.tests'," >>$testsrc_dir/setup.py
fi

for name in `ls src/azure-cli/azure/cli/command_modules`; do
    test_folder=src/azure-cli/azure/cli/command_modules/$name/tests
    if [ -d $test_folder ]; then
        echo "        'azure.cli.command_modules.$name.tests'," >>$testsrc_dir/setup.py
        if [ -d $test_folder/$target_profile ]; then
            echo "        'azure.cli.command_modules.$name.tests.$target_profile'," >>$testsrc_dir/setup.py
        fi
    fi
done

cat >>$testsrc_dir/setup.py <<EOL
    ],
    package_data={'': ['*.bat',
                       '*.byok',
                       '*.cer',
                       '*.gql',  # graphql used by apim
                       '*.js',
                       '*.json',
                       '*.kql',
                       '*.md',
                       '*.pem',
                       '*.pfx',
                       '*.sql',
                       '*.txt',
                       '*.txt',
                       '*.xml',
                       '*.yml',
                       '*.zip',
                       '**/*.bat',
                       '**/*.byok',
                       '**/*.cer',
                       '**/*.gql',
                       '**/*.ipynb',
                       '**/*.jar',
                       '**/*.js',
                       '**/*.json',
                       '**/*.kql',
                       '**/*.md',
                       '**/*.pem',
                       '**/*.pfx',
                       '**/*.sql',
                       '**/*.txt',
                       '**/*.txt',
                       '**/*.xml',
                       'data/*',
                       'recordings/*.yaml']},
    install_requires=DEPENDENCIES
)
EOL

cat >>$testsrc_dir/setup.cfg <<EOL
[bdist_wheel]
universal=1
EOL

cat >>$testsrc_dir/README.txt <<EOL
Azure CLI Test Cases
EOL

pushd $testsrc_dir >/dev/null
python setup.py -q bdist_wheel -d $output_dir
python setup.py -q sdist -d $sdist_dir
popd >/dev/null

##############################################
# clear afterwards
rm -rf $testsrc_dir
git checkout src

##############################################
# summary
title 'Results'
echo $(ls $sdist_dir | wc -l) packages created.


#!/usr/bin/env bash

set -ev

REPO_ROOT="$(dirname ${BASH_SOURCE[0]})/../.."

# Upgrade pip to the latest version
python -m pip install --upgrade pip

# Uninstall any cruft that can poison the rest of the checks in this script.
pip freeze > baseline_deps.txt
pip uninstall -y -r baseline_deps.txt || true
pip list
pip check
rm baseline_deps.txt

# Install everything from our repository first.
${REPO_ROOT}/scripts/install_full.sh

pip check

python -m azure.cli --version

python -m azure.cli self-test


#!/usr/bin/env bash
# ARM64 image does not have docker, install manually
set -evx
if [[ $(dpkg --print-architecture) == "amd64" ]]; then
    echo "Docker is already installed on AMD64"
    exit 0
fi
# https://docs.docker.com/engine/security/rootless/
/bin/bash -c "$(curl -fsSL https://get.docker.com)"
sudo apt-get install -y uidmap
dockerd-rootless-setuptool.sh install
export XDG_RUNTIME_DIR=/home/cloudtest/.docker/run
PATH=/usr/bin:/sbin:/usr/sbin:$PATH dockerd-rootless.sh &
sleep 5
docker context use rootless


#!/usr/bin/env bash

# Set the storage credentials for the given travis repo.

# Pre-requisite:
# 1. Travis CLI https://github.com/travis-ci/travis.rb
# 2. Azure CLI
# 3. Login Azure CLI with credential which has access to the target storage account.

# Input:
# $1 - storage account name
# $2 - travis CI repo name

set -ev

export AZURE_STORAGE_ACCOUNT=$1

az storage container create -n store -otsv
az storage container create -n edge -otsv

expiry_date=`date -v+6m +'%Y-%m-%dT00:00Z'`
echo "Set SAS expiry date to $expiry_date"

travis env set -r $2 PUBLISH_STORAGE_ACCT $1
travis env set -r $2 PUBLISH_STORAGE_SAS $(az storage container generate-sas -n store --permissions w --expiry $expiry_date -otsv)
travis env set -r $2 -P PUBLISH_CONTAINER store

travis env set -r $2 EDGE_STORAGE_ACCT $1
travis env set -r $2 EDGE_STORAGE_SAS $(az storage container generate-sas -n edge --permissions lw --expiry $expiry_date -otsv)
travis env set -r $2 -P EDGE_CONTAINER edge

travis env list -r $2


#!/usr/bin/env bash

. $(cd $(dirname $0); pwd)/artifacts.sh

ls -la $share_folder/build

ALL_MODULES=`find $share_folder/build/ -name "*.whl"`

pip install -e ./tools
[ -d privates ] && pip install -qqq privates/*.whl
pip install $ALL_MODULES

echo "Listing Available Extensions:"
az extension list-available -otable

# turn off telemetry as it crowds output
export AZURE_CLI_DIAGNOSTICS_TELEMETRY=
output=$(az extension list-available --query [].name -otsv)
exit_code=0

# azure-cli-ml: https://github.com/Azure/azure-cli-extensions/issues/826
ignore_list='azure-cli-ml fzf arcappliance arcdata connectedk8s'

for ext in $output; do
    echo
    # Use regex to detect if $ext is in $ignore_list
    if [[ $ignore_list =~ $ext ]]; then
        echo "Ignore extension: $ext"
        continue
    fi

    echo "Verifying extension:" $ext
    az extension add -n $ext
    if [ $? != 0 ]
    then
        exit_code=1
        echo "Failed to load:" $ext
    fi
done

pip list -v

az self-test --debug
if [ $? != 0 ]
then
    exit_code=1
    echo "Failed to verify:" $ext
fi

exit $exit_code