Skip to content

Instantly share code, notes, and snippets.

@noelbundick
Last active June 3, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noelbundick/f03200a4387b4bf4d3eed2d97169fc89 to your computer and use it in GitHub Desktop.
Save noelbundick/f03200a4387b4bf4d3eed2d97169fc89 to your computer and use it in GitHub Desktop.
Setup Azure Cloud Shell share
MIT License
Copyright (c) 2018 Noel Bundick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#!/bin/sh
# Usage:
# 1. Run this setup script (one-time)
# 2. When you want to mount your drive, run ~/mountclouddrive.sh
# - Note: Because Bash on Windows tears down the environment when the last console is closed, you'll
# need to run mountclouddrive.sh for each new Bash session where you want to access Cloud Shell files
# Explanation:
# - Connect to Azure to get info about your Azure Cloud Shell storage account
# - Register your credentials with Windows
# - Drop a mountclouddrive.sh file in your home directory
# One-time setup steps
# Get some required values from Azure
STORAGE_NAME=$(az storage account list --query "[?starts_with(resourceGroup,'cloud-shell-storage-')] | [0].name" -o tsv)
STORAGE_RG=$(az storage account list --query "[?starts_with(resourceGroup,'cloud-shell-storage-')] | [0].resourceGroup" -o tsv)
STORAGE_KEY=$(az storage account keys list -n $STORAGE_NAME -g $STORAGE_RG --query [0].value -o tsv)
SHARE_NAME=$(az storage share list --account-name $STORAGE_NAME --account-key $STORAGE_KEY --query "[?starts_with(name, 'cs-')] | [0].name" -o tsv)
# Invoke Windows executable to save creds
cmdkey.exe /add:$STORAGE_NAME.file.core.windows.net /user:AZURE\\$STORAGE_NAME /pass:$STORAGE_KEY
# Make sure there's a place to mount the share
mkdir -p ~/clouddrive
# Create a new mount script with details specific to your Azure Cloud Shell
cat << EOF > ~/mountclouddrive.sh
#!/bin/sh
sudo mount -t drvfs '\\\\$STORAGE_NAME.file.core.windows.net\\$SHARE_NAME' ~/clouddrive
EOF
# Make sure the mount script is executable
chmod +x ~/mountclouddrive.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment