-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_template.sh
executable file
·145 lines (113 loc) · 3.67 KB
/
script_template.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# Author:
# Email:
# Date:
# Script:
################################################################################
# TODO:
# -
################################################################################
################################################################################
# BASH CONFIGURATION
################################################################################
set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error when substituting.
################################################################################
# FUNTIONS
################################################################################
function USAGE() {
printf "Usage:\n\t%s -a PARAM [PARAMETERS]\n" $( basename ${0} )
printf "\t%s [-h]\n" $( basename ${0} )
cat <<EOF
Required parameters:
-a : parameter [required]
Optional parameters:
-o : output directory [by default: working directory]
-c : CPU number [by default: 1]
-v : verbose mode (yes|no) [by default: no]
Help:
-h : print this help
Description:
TO BE COMPLETED!
EOF
exit ${1:-0}
}
################################################################################
# BY DEFAULT VALUES
################################################################################
PARAM_PATH="NOTDEFINED"
OUTDIR=$( pwd )
CPU=1
VERBOSE="no"
################################################################################
# OPTION PARSING
################################################################################
while getopts ":a:o:c:v:h" OPTION ; do
case ${OPTION} in
a)
PARAM_PATH=${OPTARG}
# PARAM_FULLNAME=$( basename ${PARAM_PATH} )
# PARAM_NAME=${PARAM_FULLNAME%%.*}
# PARAM_EXTENSION=${PARAM_FULLNAME#*.}
;;
o)
OUTDIR=${OPTARG}
;;
c)
CPU=${OPTARG}
;;
v)
VERBOSE=${OPTARG}
;;
h)
USAGE
;;
:)
echo -e "Error: option -${OPTARG} requires an parameter."
exit 1
;;
\?)
echo -e "Error: invalid option -${OPTARG}"
exit 1
;;
esac
done
################################################################################
# VERIFICATIONS
################################################################################
if [[ ${PARAM_PATH} == "NOTDEFINED" ]] ; then
USAGE
exit 1
fi
if [[ ! ${CPU} =~ ^[0-9]+$ ]] ; then
echo -e "-c parameter needs an integer greater than 0"
exit 1
fi
if [[ ${VERBOSE} != "no" && ${VERBOSE} != "yes" ]] ; then
echo -e "-v parameter needs 'yes' or 'no' as value"
exit 1
fi
################################################################################
# BEGIN SCRIPT
################################################################################
echo -e "[$( basename ${0}): ${SECONDS}s] ---> START"
################################################################################
if [[ ${VERBOSE} == "yes" ]] ; then
echo -e "[$( basename ${0}): ${SECONDS}s] ---> Parameter : ${PARAM_PATH}"
echo -e "[$( basename ${0}): ${SECONDS}s] ---> Output directory: ${OUTDIR}"
echo -e "[$( basename ${0}): ${SECONDS}s] ---> CPU number : ${CPU}"
echo -e "[$( basename ${0}): ${SECONDS}s] ---> Verbose mode : ${VERBOSE}"
fi
if [[ ${VERBOSE} == "yes" ]] ; then
CMD="script.sh -a ${R1_PATH} -v"
echo -e "[$( basename ${0}): ${SECONDS}s] ---> script.sh description"
else
CMD="script.sh -a ${R1_PATH}"
fi
CMD="script.sh -a ${PARAM_PATH} -v ${VERBOSE}"
echo -e "[$( basename ${0}): ${SECONDS}s] ---> ${CMD}"
#eval ${CMD}
################################################################################
# END SCRIPT
################################################################################
echo -e "[$( basename ${0}): ${SECONDS}s] ---> END"