-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouchbigsh.sh
More file actions
executable file
·139 lines (115 loc) · 3.04 KB
/
touchbigsh.sh
File metadata and controls
executable file
·139 lines (115 loc) · 3.04 KB
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
#!/usr/bin/bash
filename=$1
if [[ $# -eq 0 ]]; then
>&2 echo "Error: no arguments provided"
>&2 echo "USAGE: $(basename $0) [NEW_FILE_NAME]"
exit 1
fi
touch ${filename}.sh
chmod u+x ${filename}.sh
# Guts of template
template() {
cat <<'EOF'
#!/usr/bin/env bash
#------------------------------------------------------------------------------#
# Defining usage
#------------------------------------------------------------------------------#
usage() {
echo "
# --------------------------------------#
# $(basename $0) help doc
# --------------------------------------#
Usage: $0 -i INPUT -o OUTPUT [OPTIONS]
Description
Required params:
-i, --input STR Path to input file
-o, --output STR Path to output file
Optional params:
Info:
-h, --help Print help
"
}
#------------------------------------------------------------------------------#
# Defining getop params
#------------------------------------------------------------------------------#
# create command line options with getopt
opt_short="i:o:h"
opt_long="input:,output:,help"
OPTS=$(getopt -o "$opt_short" --long "$opt_long" -n 'parse-options' -- "$@")
# If wrong option is given, print error message.
if [[ $? -ne 0 ]]; then
echo "Error: Wrong input parameter used!"
usage
exit 1
fi
# eval getopt opts for while loop
eval set -- "$OPTS"
# Parsing getopt parameters
while true; do
case "$1" in
-i | --input)
input="$2"
shift 2
;;
-o | --output)
output="$2"
shift 2
;;
-h | --help)
usage
exit 0
;;
--)
shift
break
;;
*)
echo "Unknown option: $1"
usage
exit 1
;;
esac
done
#------------------------------------------------------------------------------#
# Set defaults and constants
#------------------------------------------------------------------------------#
input=${input:-""}
output=${output:-""}
threads=${threads:-1}
#------------------------------------------------------------------------------#
# Validate inputs and program availablity
#------------------------------------------------------------------------------#
# Check required params are provided
if [[ -z "$input" ]] || [[ -z "$output" ]]; then
echo "Error: Required arguments are missing."
usage
exit 1
fi
# Make sure all input files exist
if [[ $input != "" ]] && [[ ! -d "$input" && ! -f "$input" ]]; then
echo "Input ${input} not detected."
exit 1
fi
# Make sure required programs are available. e.g.:
# if ! command -v foldseek; then
# echo "foldseek not detected!"
# exit 1
# fi
#------------------------------------------------------------------------------#
# Main
#------------------------------------------------------------------------------#
echo "$0 inputs:
INPUT: $input
OUTPUT: $output
"
echo "$0: Started at $(date)"
echo ""
# Make directories if necessary
mkdir -p $(dirname ${output})
### WORK GOES HERE...
# Fin
echo ""
echo "$0: Finished at $(date)"
EOF
}
template >"${filename}.sh"