Checkpoint #3, 24/07/2024 - My first 'DevOps' project - Part 3
Creating a script and packaging it for easy installation
I had learnt the commands needed to upload a file to the cloud, now it's time to compile those commands in a script for automated execution, in essence creating what I imagine is a very rudimentary version of a front end for something like Google Drive.
I chose to make this as user-friendly as possible, so while I could have used command line arguments i.e $1, $2 etc., I chose to prompt the user for input step by step instead.
To simplify things, I chose to create 3 separate scripts - a setup script, a script for listing region names (since the name has to match exactly) and the main script for uploading the file to Azure. The project would be called CloudUploader, and can be found at https://github.com/YashRalla/CloudUploader.
For the setup script, I wanted to create a case statement that would check for the installation of Azure CLI, and install it if not found. Else, it would skip it and log the user in. I originally attempted to use the condition:
if [ ! -d /usr/bin/az ]
But this did not work, so I instead used this command:
if [ ! ls -d /usr/bin/az >/dev/null 2>&1 ]
This lists the directories found and hides errors (stderr) by redirecting them to /dev/null, which can in simple terms be described as a black hole of sorts within the Linux file system. This condition worked for me. After this, it would run the setup command as discussed before.
Similarly, the regionLister file would list the regions if Azure CLI was found, but this time there is no need to login.
In the main file (cloudUploader_main), there are a number of arguments required, the ones required for all cases (creating a storage account, uploading or downloading) are:
Subscription ID
Name of storage account
Name of container
For creating, we need
Name of resource group
Location of resource group (should match with an option from regionLister script output)
For uploading, we need the name of the file present on the drive.
For downloading, we need:
Name of the file we wish to download
The directory we wish to save it to
The desired name of the file after downloading
For the different scenarios such as logging in or choosing between creation, upload and deletion, I used case statements that would recursively show until the user enters a valid input.
After testing the script, I committed my changes to GitHub into a separate branch and created a pull request on that site to merge it to the main branch. I then used the option to package it in a .zip release, currently titled BCU v0.1. It is in pre-release state, but it may be downloaded and used on a Linux or Windows machine that has Powershell.
As I learn more about bash and the Azure CLI, I hope to improve upon this project.
I developed a script-based project called CloudUploader to automate file upload to Azure, focusing on user-friendly interaction. The project includes three scripts: a setup script to install Azure CLI, a region lister, and the main script for file operations. Key actions involve checking and installing Azure CLI, listing Azure regions, and handling file upload/download tasks, all while prompting the user for necessary inputs. The project is available on GitHub, with a pre-release version packaged in a .zip file for Linux or Windows. Future improvements are planned as I continue learning more about bash and the Azure CLI.