Skip to content

Commit

Permalink
Improved documentation and making sure scripts run as bash.
Browse files Browse the repository at this point in the history
  • Loading branch information
bvboe committed Mar 16, 2023
1 parent e900ced commit f67e2d4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
37 changes: 35 additions & 2 deletions bash/lw_azure_inventory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
# Requirements: az cli, jq, cut, grep

# This script can be run from Azure Cloud Shell.
# Run ./lw_azure_inventory.sh -h for help on how to run the script.
# Or just read the text in showHelp below.

function showHelp {
echo "lw_azure_inventory.sh is a tool for estimating license vCPUs in an Azure environment, based on"
echo "subscription or management group level. It leverages the az CLI and by default analyzes all"
echo "subscriptions a user has access to. The script provides output in a CSV format to be imported"
echo "into a spreadsheet, as well as an easy-to-read summary."
echo ""
echo "By default, the script will scan all subscriptions returned by the following command:"
echo "az account subscription list"
echo ""
echo "Note the following about the script:"
echo "* Works great in a cloud shell"
echo "* It has been verified to work on Mac and Linux based systems"
echo "* Has been observed to work with Windows Subsystem for Linux to run on Windows"
echo "* Run using the following syntax: ./lw_azure_inventory.sh, sh lw_azure_inventory.sh will not work"
echo ""
echo "Available flags:"
echo " -s Comma separated list of Azure subscriptions to scan."
echo " ./lw_azure_inventory.sh -p subscription-1,subscription-2"
echo " -m Comma separated list of Azure management groups to scan."
echo " ./lw_azure_inventory.sh -m 1234,456"
}

#Ensure the script runs with the BASH shell
echo $BASH | grep -q "bash"
if [ $? -ne 0 ]
then
echo The script is running using the incorrect shell.
echo Use ./lw_azure_inventory.sh to run the script using the required shell, bash.
exit
fi

set -o errexit
set -o pipefail
Expand All @@ -17,11 +50,11 @@ while getopts ":m:s:" opt; do
MANAGEMENT_GROUP=$OPTARG
;;
\? )
printf "Usage: ./lw_azure_inventory.sh [-m management_group] [-s subscription] \nAny single scope can have multiple values comma delimited, but multiple scopes cannot be defined.\n" 1>&2
showHelp
exit 1
;;
: )
printf "Usage: ./lw_azure_inventory.sh [-m management_group] [-s subscription] \nAny single scope can have multiple values comma delimited, but multiple scopes cannot be defined.\n" 1>&2
showHelp
exit 1
;;
esac
Expand Down
46 changes: 39 additions & 7 deletions bash/lw_gcp_inventory.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
#!/bin/bash

set -o errexit
set -o pipefail

# Script to fetch GCP inventory for Lacework sizing.
# Run ./lw_gcp_inventory.sh -h for help on how to run the script.
# Or just read the text in showHelp below.
# Requirements: gcloud, jq

# This script can be run from Google Cloud Shell.
function showHelp {
echo "lw_gcp_inventory.sh is a tool for estimating license vCPUs in a GCP environment, based on folder,"
echo "project or organization level. It leverages the gcp CLI and by default analyzes all project a user"
echo "has access to. The script provides output in a CSV format to be imported into a spreadsheet, as"
echo "well as an easy-to-read summary."
echo ""
echo "By default, the script will scan all projects returned by the following command:"
echo "gcloud projects list"
echo ""
echo "Note the following about the script:"
echo "* Works great in a cloud shell"
echo "* It has been verified to work on Mac and Linux based systems"
echo "* Has been observed to work with Windows Subsystem for Linux to run on Windows"
echo "* Run using the following syntax: ./lw_gcp_inventory.sh, sh lw_gcp_inventory.sh will not work"
echo ""
echo "Available flags:"
echo " -p Comma separated list of GCP projects to scan."
echo " ./lw_gcp_inventory.sh -p project-1,project-2"
echo " -f Comma separated list of GCP folders to scan."
echo " ./lw_gcp_inventory.sh -p 1234,456"
echo " -o Comma separated list of GCP organizations to scan."
echo " ./lw_gcp_inventory.sh -o 1234,456"
}

#Ensure the script runs with the BASH shell
echo $BASH | grep -q "bash"
if [ $? -ne 0 ]
then
echo The script is running using the incorrect shell.
echo Use ./lw_gcp_inventory.sh to run the script using the required shell, bash.
exit
fi

set -o errexit
set -o pipefail

while getopts ":f:o:p:" opt; do
case ${opt} in
Expand All @@ -20,11 +52,11 @@ while getopts ":f:o:p:" opt; do
PROJECTS=$OPTARG
;;
\? )
printf "Usage: ./lw_gcp_inventory.sh [-f folder] [-o organization] [-p project] \nAny single scope can have multiple values comma delimited, but multiple scopes cannot be defined.\n" 1>&2
showHelp
exit 1
;;
: )
printf "Usage: ./lw_gcp_inventory.sh [-f folder] [-o organization] [-p project] \nAny single scope can have multiple values comma delimited, but multiple scopes cannot be defined.\n" 1>&2
showHelp
exit 1
;;
esac
Expand Down

0 comments on commit f67e2d4

Please sign in to comment.