Project

General

Profile

Revision 15ed27d8

Added by Julien Enselme over 9 years ago

Use getopts to print help and to parse script arguments.

View differences:

bin/usage.sh
1 1
#!/bin/sh
2 2

  
3
. /home/assos/bin/scripts-config.sh
4
. scripts-utils.sh
5

  
6
help="# ARGS: Drupal_version, project_status, project_name\n
3
usage() {
4
    help="usage.sh -v Drupal_version -s project_status -n project_name\n
7 5
# List sites that have the project_name with the corresponding project_status.\n
8 6
# project status: enabled or disabled"
7
    echo -e "${help}"
8
}
9

  
10
drupal_version=''
11
project_status=''
12
project_name=''
13
while getopts "hv:s:n:" opt; do
14
    case "${opt}" in
15
	h)
16
	    usage; exit 0;;
17
	v)
18
	    drupal_version="${OPTARG}";;
19
	s)
20
	    project_status="${OPTARG}";;
21
	n)
22
	    project_name="${OPTARG}";;
23
	:)
24
	    echo "Option -$OPTARG requires an argument." >&2
25
	    usage >&2; exit 1;;
26
	\?)
27
	    usage >&2; exit 1;;
28
    esac
29
done
30
shift $((OPTIND-1))
31

  
32
# Check that all required parameters are there
33
if [ -z "${drupal_version}" ] || [ -z "${project_status}" ] || [ -z "${project_name}" ]; then
34
    echo "At least a required parameter is missing." >&2
35
    usage >&2
36
    exit 1
37
fi
38

  
39

  
40
. /home/assos/bin/scripts-config.sh
41
. scripts-utils.sh
9 42

  
10
check_arguments "$#" 3 "${help}"
11 43

  
12
if [ "$1" = d7 ] ; then
44
if [ "${drupal_version}" = d7 ] ; then
13 45
    cd "${d7_dir_sites}"
14 46
else
15 47
    echo Unrecognize version.
......
24 56
    # Print site_dir if listed.
25 57

  
26 58
    cd "${dir}";
27
	if [ 1 -le $(drush pml --status="$2" | grep "$3" | wc -l) ] ; then
59
	if [ 1 -le $(drush pml --status="${project_status}" | grep "${project_name}" | wc -l) ] ; then
28 60
        echo "${dir}";
29 61
        number_found=$(($number_found + 1))
30 62
    fi
31 63
    cd -
32 64
done
33 65

  
34
echo "Number of sites found for project $3 and status $2 : $number_found";
66
echo "Number of sites found for project ${project_name} and status ${project_status} : $number_found";

Also available in: Unified diff