-
Notifications
You must be signed in to change notification settings - Fork 1
/
scriptcreator
executable file
·279 lines (278 loc) · 9.64 KB
/
scriptcreator
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash
#
# scriptcreator
# Author- Shawn Miller
###########################################################
## This script is designed to create other scripts
## pre-populated with standard fields and ready
## for writing code.
## Requires 1 arguement, a 2nd arguement is optional.
###########################################################
## Completed-
## 1. Create another file with the contents of the template
## 2. Edit the new file with Author and script name
## 4. Set the executable permisson on the new file
## 5. On First-Run of This script, request User Input
## for Author and PATH
## 6. Set choice to edit the new file immediately or not
## 7. Add colors to output
#
###########################################################
##### GNU_GPL
###########################################################
#
gpl_info () {
cat <<EOT
${LTCYN}
####c4#############################################################################
### ###
## GNU/GPL Info ##
## create_script ver-1.1 - Alpha/Beta begun 15 August 2018 ##
## create_script ver-2.1 - Production release 11 Sepember 2018 ##
## Forked to scriptcreator ver-2.1 - 16 Sepember 2018 ##
## Released under GPL v2.0, See www.gnu.org for full license info ##
## Copyright (C) 2015 Shawn Miller, The Wood-Bee Company ##
## EMAIL- [email protected] ##
## - [email protected] ##
## This program is free software; you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation; either version 2 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## See this complete License at: ##
## https://github.com/SeaPhor/SeaPhor-Scripts/blob/master/LICENSE ##
### ###
####w#################################b######################################c####4
${RESET}
EOT
}
#
###########################################################
#### Global Variables
###########################################################
#
PROGNAME=$(basename $0)
PROGVERS="1.0.1-03"
REVDATE="07 Oct 2018"
#
###########################################################
#### Script Options/Usage
###########################################################
#
## Usage - Options
opts_use () {
cat <<EOT
${BOLD}${LTCYN} ${PROGNAME}${RESET}${LTYLLW}-
Author-${LTCYN} Shawn Miller${BOLD}${YLLW}
Description-${RESET}${LTYLLW}
This script is designed to create other scripts
pre-populated with standard fields and ready
for writing code.
Requires 1 arguement, a 2nd arguement is optional.${BOLD}${YLLW}
Usage-${RESET}${LTCYN}
${PROGNAME} [<scriptname>|OPTION] [OPTIONAL]${BOLD}${GRN}
${PROGNAME} ${LTCYN}<${GRN}scriptname${LTCYN}>${GRN}
${PROGNAME} help${RESET}${LTYLLW}
Optional-${BOLD}${GRN}
${PROGNAME} ${LTCYN}<${GRN}scriptname${LTCYN}>${GRN} edit${YLLW}
Options-${RESET}${LTCYN}
<scriptname>${LTYLLW} What you want your script to be named${LTCYN}
help${LTYLLW} Prints this dialog and exits${LTCYN}
vers${LTYLLW} Prints the release version and date of release and exits${LTCYN}
gpl${LTYLLW} Prints the GPL Info and exits${BOLD}${YLLW}
Optional-${RESET}${LTCYN}
edit${LTYLLW} If${BOLD}${LTCYN} \$EDITOR${RESET}${LTYLLW} is set, otherwise it will open your script with vim${BOLD}${YLLW}
Adding GPL to your script-${RESET}${LTMAG} (Run "${LTCYN}${PROGNAME} gpl${LTMAG}" to see mine)${LTYLLW}
If you want to add a GNU/GPL to your new script, I suggest you create/copy-edit
one and place it in your "snippets" directory. Then edit the script you just
created with vim, I named mine "~/snippets/gnugpl". In command mode move the
cursor to the line above where you want to insert the GPL and type this:${LTCYN}
:r ~/snippets/gnugpl${LTYLLW} and hit ENTER.
${RESET}
EOT
}
#
#######################################
#### Declare Color Variables ####
#######################################
#
[[ $@ =~ "nocolor" ]] && COLR=false || COLR=true
#
if $COLR; then
RED="$(tput setaf 1)"
GRN="$(tput setaf 2)"
YLLW="$(tput setaf 3)"
BLU="$(tput setaf 4)"
MAG="$(tput setaf 5)"
CYN="$(tput setaf 6)"
LTRED="$(tput setaf 9)"
LTGRN="$(tput setaf 10)"
LTYLLW="$(tput setaf 11)"
LTBLU="$(tput setaf 12)"
LTMAG="$(tput setaf 13)"
LTCYN="$(tput setaf 14)"
#
BLRED=${BOLD}${LTRED}
BLYLW=${BOLD}${LTYLLW}
BYLW=${BOLD}${YLLW}
BLCYN=${BOLD}${LTCYN}
BCYN=${BOLD}${CYN}
#
BGBLU="$(tput setab 4)"
BGYLLW="$(tput setab 3)"
BGLYLLW="$(tput setab 11)"
#
ULINE="$(tput smul)"
NULINE="$(tput rmul)"
SOMODE="$(tput smso)"
NSOMODE="$(tput rmso)"
BOLD="$(tput bold)"
RESET="$(tput sgr0)"
fi
#
#
###########################################################
#### Environment Variables and Information Gathering
###########################################################
#
## Check for arguements
[[ $1 ]] || { opts_use; echo "${BOLD}${RED}Missing arguement${RESET}"; exit 1; }
[[ $@ =~ "help" ]] && { opts_use; exit 1; }
[[ $1 = "vers" ]] && { echo "${PROGNAME} - ${PROGVERS} released ${REVDATE}"; exit 1; }
[[ $1 = "gpl" ]] && { gpl_info; exit 0; }
[[ $@ =~ "edit" ]] && EDITNOW=true || EDITNOW=false
PWD=`pwd`
PROGDATE="${RDATE}"
RDATE="`date +%d\ %b\ %Y`"
SCRPTNAM="$1"
BINDIR="${HOME}/scripts"
FILNAM="${BINDIR}/${SCRPTNAM}"
[[ $EDITOR ]] || EDITOR="vim"
AUTHOR="`getent passwd ${USER} | awk -F: '{print $5}'`"
TDATE="`date +%a\ %b\ %d\ %Y`"
if [[ ! -d ${BINDIR} ]]; then
if mkdir "${BINDIR}"; then
echo "${CYN}Created ${BINDIR}${RESET}"
else
echo "${BOLD}${RED}Could not create ${BINDIR}${RESET}"
exit 1
fi
fi
if [[ -e ${FILNAM} ]]; then
echo "${BOLD}${RED}Filename ${FILNAM} already exists.${RESET}"
exit 1
fi
if type "${SCRPTNAME}" > /dev/null 2>&1; then
echo "${BOLD}${RED}There is already a command with the name ${SCRPTNAM}${RESET}"
exit 1
fi
#
###########################################################
#### Declare Functions, Loops, and other statements
###########################################################
#
script_templt () {
## Use 'DON' instead of 'EOT' so that template can use the standard 'EOT'.
cat <<DON
#!/bin/bash
#
# ${SCRPTNAM}
# Author- ${AUTHOR}
# Creation Date- ${TDATE}
###########################################################
## First line of script description
## Second line of script description
#### Third line of script description
###########################################################
## First script objective
## Second script objective
## Third script objective
#
###########################################################
#### Global Variables
###########################################################
#
PROGNAME=\$(basename \$0)
PROGVERS="0.0.0-01"
PROGDATE="${RDATE}"
#
###########################################
#### Declare Color Variables
###########################################
#
[[ \$@ =~ "nocolor" ]] && NOCOLR=true || NOCOLR=false
#
if ! \$NOCOLR; then
RED="\$(tput setaf 1)"
GRN="\$(tput setaf 2)"
YLLW="\$(tput setaf 3)"
BLU="\$(tput setaf 4)"
MAG="\$(tput setaf 5)"
CYN="\$(tput setaf 6)"
LTRED="\$(tput setaf 9)"
LTGRN="\$(tput setaf 10)"
LTYLLW="\$(tput setaf 11)"
LTBLU="\$(tput setaf 12)"
LTMAG="\$(tput setaf 13)"
LTCYN="\$(tput setaf 14)"
BGBLU="\$(tput setab 4)"
BGYLLW="\$(tput setab 3)"
BGLYLLW="\$(tput setab 11)"
ULINE="\$(tput smul)"
NULINE="\$(tput rmul)"
SOMODE="\$(tput smso)"
NSOMODE="\$(tput rmso)"
BOLD="\$(tput bold)"
RESET="\$(tput sgr0)"
fi
#
###########################################################
#### Script Options/Usage
###########################################################
#
usage () {
cat <<EOT
Description-
Begin Description
Options-
Begin Options
Usage-
Begin Usage
EOT
}
###########################################################
#### Env Variables, Conditional Logic, Information Gathering
###########################################################
## Comment 1 - what why
## Comment 2 - how
###########################################################
#### Declare Functions, Loops, and other statements
###########################################################
## Comment 1 - what why
## Comment 2 - how
###########################################################
#### Execution - CleanUp - Exit/Status
###########################################################
## Comment 1 - what why
## Comment 2 - how
## Exit Cleanly
exit 0
DON
} > ${FILNAM}
#
###########################################################
#### Execution - CleanUp - Exit/Status
###########################################################
#
script_templt
chmod u+x ${FILNAM}
if ${EDITNOW}; then
${EDITOR} ${FILNAM}
fi
## Exit Cleanly
exit 0