summaryrefslogtreecommitdiffstats
path: root/requirements/django-ansible-base-pinned-version.sh
blob: 84905fff4e3a9fb647eb3df8b6cc8b4ba499d7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set +x

# CONSTANTS
export REGEX_LEFT='https://github.com/ansible/django-ansible-base@'
export REGEX_RIGHT='#egg=django-ansible-base'

# GLOBALS
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
REQ_FILE=$SCRIPT_DIR/requirements_git.txt

# Pin Function
DESIRED_VERSION=''
Pin()
{
    export DESIRED_VERSION
    perl -p -i -e 's/\Q$ENV{REGEX_LEFT}\E(.*?)\Q$ENV{REGEX_RIGHT}\E/$ENV{REGEX_LEFT}$ENV{DESIRED_VERSION}$ENV{REGEX_RIGHT}/g' $REQ_FILE
}

# Current Function
Current()
{
    REQUIREMENTS_LINE=$(grep django-ansible-base $REQ_FILE)

    echo "$REQUIREMENTS_LINE" | perl -nE 'say $1 if /\Q$ENV{REGEX_LEFT}\E(.*?)\Q$ENV{REGEX_RIGHT}\E/'
}


Help()
{
   # Display Help
   echo ""
   echo "Help:"
   echo ""
   echo "Interact with django-ansible-base in $REQ_FILE."
   echo "By default, output the current django-ansible-base pinned version."
   echo
   echo "Syntax: scriptTemplate [-s|h|v]"
   echo "options:"
   echo "s     Set django-ansible-base version to pin to."
   echo "h     Print this Help."
   echo "v     Verbose mode."
   echo
}

if [ $# -eq 0 ]; then
    Current
    exit
fi


while getopts ":hs:" option; do
   case $option in
      h) # display Help
         Help
         exit
         ;;
      s)
         DESIRED_VERSION=$OPTARG;;
      :)
         echo "Option -${OPTARG} requires an argument."
         Help
         exit 1
         ;;
     \?) # Invalid option
         echo "Error: Invalid option"
         echo ""
         Help
         exit;;
   esac
done

if [ -n "$DESIRED_VERSION" ]; then
    Pin
    Current
fi