Skip to content

Instantly share code, notes, and snippets.

@SaFi2266
Forked from rragundez/args_script_template.sh
Created February 3, 2023 15:19
Show Gist options
  • Save SaFi2266/534e7e89aa21106ed67186538fc93f1a to your computer and use it in GitHub Desktop.
Save SaFi2266/534e7e89aa21106ed67186538fc93f1a to your computer and use it in GitHub Desktop.

Revisions

  1. @rragundez rragundez created this gist Jun 21, 2017.
    34 changes: 34 additions & 0 deletions args_script_template.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/bin/bash
    set -e

    usage="$(basename "$0") [-h] [-i PROJECT] [-v VM] [-p PYTHON] [-d NOTEBOOKS]
    Make a user provide SSH key and jupyter notebooks (in roles/bootstrap/files/notebooks) to each user listed in var/common.yml
    where:
    -h show this help text
    -i google cloud project id
    -v name of instance/virtual machine
    -p python path
    -d if want to copy a notebooks directory"

    # constants
    PYTHON=/usr/bin/python3
    NOTEBOOK_DIR=false

    options=':hi:v:p:d:'
    while getopts $options option; do
    case "$option" in
    h) echo "$usage"; exit;;
    i) PROJECT=$OPTARG;;
    v) VM=$OPTARG;;
    p) PYTHON=$OPTARG;;
    d) NOTEBOOK_DIR=$OPTARG;;
    :) printf "missing argument for -%s\n" "$OPTARG" >&2; echo "$usage" >&2; exit 1;;
    \?) printf "illegal option: -%s\n" "$OPTARG" >&2; echo "$usage" >&2; exit 1;;
    esac
    done

    # mandatory arguments
    if [ ! "$PROJECT" ] || [ ! "$VM" ]; then
    echo "arguments -i and -v must be provided"
    echo "$usage" >&2; exit 1
    fi