Created
August 9, 2018 18:56
-
-
Save toolboc/1e9557f5832e3395aa3c7693c9490d1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage(){ | |
echo "***Azure IoT Edge GPU Provisioning Script***" | |
echo "Usage: ./edgeprovision.sh <iothub.name> <environment> <platform> <acr.host> <acr.username> <acr.password>" | |
} | |
provision(){ | |
install_docker | |
if [ $platform == "gpu" ] | |
then | |
install_nvidia_docker | |
fi | |
install_iot_edge_runtime | |
configure_iot_edge_runtime | |
} | |
install_docker(){ | |
echo "***Installing Docker***" | |
docker -v | |
# Check if docker installed | |
if [ $? -ne 0 ] | |
then | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
sudo apt-get update | |
sudo apt-get install -y docker-ce=18.03.1~ce-0~ubuntu | |
else | |
echo "***Docker already installed***" | |
fi | |
sudo usermod -aG docker $USER | |
} | |
install_nvidia_docker(){ | |
echo "***Installing Nvidia Docker***" | |
nvidia-docker -v | |
# Check if nvidia-docker installed | |
if [ $? -ne 0 ] | |
then | |
# Add the kernel headers to support the nvida module | |
sudo apt-get install -y gcc jq linux-headers-$(uname -r) | |
# Add the package repositories | |
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.2.88-1_amd64.deb | |
sudo dpkg -i cuda-repo-ubuntu1604_9.2.88-1_amd64.deb | |
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub | |
sudo apt-get update | |
sudo apt-get install -y cuda | |
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \ | |
sudo apt-key add - | |
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) | |
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \ | |
sudo tee /etc/apt/sources.list.d/nvidia-docker.list | |
sudo apt-get update | |
# Install nvidia-docker2 and reload the Docker daemon configuration | |
sudo apt-get install -y nvidia-docker2 | |
sudo pkill -SIGHUP dockerd | |
else | |
echo "***Nvidia Docker already installed***" | |
fi | |
#Remove the current (if any) default-runtime | |
sudo cat /etc/docker/daemon.json | jq 'del(.[ "default-runtime" ])' | sudo tee /etc/docker/daemon.json > /dev/null | |
#Set the new runtime | |
sudo sed -i '2 i\"default-runtime": "nvidia",' /etc/docker/daemon.json | |
sudo service docker restart | |
} | |
install_iot_edge_runtime(){ | |
echo "***Installing IoT Edge Runtime***" | |
sudo apt install -y python-pip | |
sudo -H pip install -U azure-iot-edge-runtime-ctl | |
} | |
configure_iot_edge_runtime(){ | |
echo "***Configuring IoT Edge Runtime***" | |
az iot hub device-identity create --device-id $(hostname) --hub-name $iothub_name --edge-enabled | |
connectionString=$(az iot hub device-identity show-connection-string --device-id $(hostname) --hub-name $iothub_name | jq -r '.cs') | |
az iot hub device-twin update --device-id $(hostname) --hub-name $iothub_name --set tags='{"environment":"'$environment'","platform":"'$platform'"}' | |
sudo iotedgectl setup --connection-string $connectionString --auto-cert-gen-force-no-passwords | |
sudo iotedgectl login --address $acr_host --username $acr_user --password $acr_password | |
sudo iotedgectl start | |
} | |
# Arguments | |
iothub_name=$1 | |
environment=$2 | |
platform=$3 | |
acr_host=$4 | |
acr_user=$5 | |
acr_password=$6 | |
# Check Arguments | |
[ "$#" -ne 6 ] && { usage && exit 1; } || provision |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment