-
Notifications
You must be signed in to change notification settings - Fork 2
/
perldev_module_setup.sh
403 lines (348 loc) · 11 KB
/
perldev_module_setup.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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/usr/bin/env bash
# Copyright (c)2004,2012, 2013
# by Brian Manning. License terms are listed at the bottom of this file
#
# Install a set of modules via the 'cpanm' command for Perl development
BASE_MODULES="
App::FatPacker Capture::Tiny Config::IniFiles
Cpanel::JSON::XS DBM::Deep Devel::NYTProf Devel::Size
Digest::SHA1 Dist::Zilla Error File::Find::Rule
File::Path::Tiny File::Slurp::Tiny Getopt::Long
IO::Socket::SSL Image::ExifTool JSON JSON::Any JSON::XS
Log::Log4perl LWP LWP::Protocol::https Moo
MooX::Types::MooseLike Net::OpenSSH Number::Format
Path::Tiny Rex Role::Tiny Template Test::More Throwable
Tree::Simple Try::Tiny Type::Tiny YAML YAML::Tiny
autodie
"
ARCHIVE_MODULES="
Archive::Extract Archive::Tar Archive::Zip Compress::Bzip2
"
DB_MODULES="
DBI DBD::CSV DBD::ODBC DBD::Pg DBD::SQLite DBD::mysql
"
# NOTE: XML::LibXML requires that `brew link libxml2 --force` be run, so that
# the symlink to `xml2-config` is created in `/usr/local/bin`
MISC_MODULES="
Algorithm::Diff Class::Tiny Config::Tiny Config::Std Data::Compare
Date::Parse Date::Tiny DateTime DateTime::Locale DateTime::TimeZone
DateTime::Tiny Mac::SystemDirectory PDF::API2 PDF::Table
Parse::RecDescent Perl::Critic Perl::Tidy Pod::Weaver
Pod::Webserver Template::Tiny Text::CSV Text::CSV_XS Text::Markdown
WWW::Shorten::Simple XML::LibXML XML::Parser XML::Simple
App::Ack strictures syntax
"
GTK_MODULES="
Glib Cairo Cairo::GObject ExtUtils::Depends ExtUtils::PkgConfig
Glib::Object::Introspection Gtk2 Gtk3 Pango
"
WEBAPP_MODULES="
Mojo::Pg Mojolicious Mojolicious::Plugin::RenderFile Dancer2
"
# what's my name?
SCRIPTNAME=$(basename $0)
# assume everything will go well
EXIT_STATUS=0
# set quiet mode by default, needs to be set prior to the getops call
QUIET=0
# colorize? yes please (1=yes, colorize, 0=no, don't colorize)
COLORIZE=1
# always colorize? set via --colorize
ALWAYS_COLORIZE=0
# dry-run, i.e. show commands, don't run them? (0 = no, 1 = yes)
DRY_RUN=0
# what sets of modules to install
INSTALL_MODULES=""
INSTALL_ALL=0
INSTALL_BASE=0
INSTALL_ARCHIVE=0
INSTALL_DB=0
INSTALL_MISC=0
INSTALL_GTK=0
INSTALL_WEBAPP=0
### OUTPUT COLORIZATION VARIABLES ###
START="\x1b["
END="m"
# text attributes
NONE=0; BOLD=1; NORM=2; BLINK=5; INVERSE=7; CONCEALED=8
# background colors
B_BLK=40; B_RED=41; B_GRN=42; B_YLW=43
B_BLU=44; B_MAG=45; B_CYN=46; B_WHT=47
# foreground colors
F_BLK=30; F_RED=31; F_GRN=32; F_YLW=33
F_BLU=34; F_MAG=35; F_CYN=36; F_WHT=37
# some shortcuts
MSG_FAIL="${BOLD};${F_YLW};${B_RED}"
MSG_WARN="${F_YLW};${B_BLK}"
MSG_DRYRUN="${BOLD};${F_CYN};${B_BLU}"
MSG_OK="${BOLD};${F_WHT};${B_GRN}"
MSG_REMOTE="${F_CYN};${B_BLK}"
MSG_INFO="${BOLD};${F_WHI};${B_BLU}"
MSG_FLUFF="${BOLD};${F_BLU};${B_BLK}"
### FUNCTIONS ###
# wrap text inside of ANSI tags, unless --nocolor is set
colorize () {
local COLOR="$1"
local TEXT="$2"
if [ $COLORIZE -eq 1 ]; then
COLORIZE_OUT="${COLORIZE_OUT}${START}${COLOR}${END}${TEXT}"
COLORIZE_OUT="${COLORIZE_OUT}${START};${NONE}${END}"
else
COLORIZE_OUT="${COLORIZE_OUT}${TEXT}"
fi
}
# clear the COLORIZE_OUT variable
colorize_clear () {
COLORIZE_OUT=""
}
# check the exit status of a sub-process that was run
check_exit_status() {
local ERROR=$1
local CMD_RUN="$2"
local CMD_OUT="$3"
# check for errors from the script
if [ $ERROR -ne 0 ] ; then
if [ $QUIET -eq 0 ]; then
colorize_clear
colorize $MSG_FAIL "${CMD_RUN} exited with error: $ERROR"
$ECHO_CMD $COLORIZE_OUT
colorize_clear
colorize $MSG_FAIL "${CMD_RUN} output: "
$ECHO_CMD $COLORIZE_OUT
colorize_clear
colorize $MSG_WARN "${CMD_OUT}"
$ECHO_CMD $COLORIZE_OUT
colorize_clear
fi
EXIT_STATUS=1
fi
} # check_exit_status
show_help() {
# show script options
cat <<-EOH
${SCRIPTNAME} [options] <command>
GENERAL SCRIPT OPTIONS
-h|--help Displays this help message
-q|--quiet No script output (unless an error occurs)
-n|--dry-run Explain what will be done, don't actually do it
-c|--colorize Always colorize output, ignore '-t' test
OPTIONS FOR CPAN MODULES
-l|--list List all of the modules included in this script
-a|--all Install all modules included in this ѕcript
-b|--base Base set of modules
-z|--archive Archive modules
-d|--db Database modules
-m|--misc Misc. modules
-g|--gtk Gtk-Perl modules
-w|--webap WebApp (Mojolicious/Dancer2) modules
NOTES:
- Long switches (GNU extension) do not work with BSD 'getopt'
- Colorization is disabled when script outputs to pipe (-t set on filehandle)
EOH
}
### SCRIPT SETUP ###
# BSD's getopt is simpler than the GNU getopt; we need to detect it
if [ -x /usr/bin/uname ]; then
OSDETECT=$(/usr/bin/uname -s)
elif [ -x /bin/uname ]; then
OSDETECT=$(/bin/uname -s)
else
echo "ERROR: can't run 'uname -s' command to determine system type"
exit 1
fi
if [ $OSDETECT = "Darwin" ]; then
ECHO_CMD="echo -e"
elif [ $OSDETECT = "Linux" ]; then
ECHO_CMD="builtin echo -e"
else
ECHO_CMD="echo"
fi
# these paths cover a majority of my test machines
for GETOPT_CHECK in "/opt/local/bin/getopt" "/usr/local/bin/getopt" \
"/usr/bin/getopt";
do
if [ -x "${GETOPT_CHECK}" ]; then
GETOPT_BIN=$GETOPT_CHECK
break
fi
done
# did we find an actual binary out of the list above?
if [ -z "${GETOPT_BIN}" ]; then
echo "ERROR: getopt binary not found; exiting...."
exit 1
fi
# Use short options if we're using Darwin's getopt
if [ $OSDETECT = "Darwin" -a $GETOPT_BIN = "/usr/bin/getopt" ]; then
GETOPT_TEMP=$(${GETOPT_BIN} hqnclabzdmgj $*)
else
# Use short and long options with GNU's getopt
GETOPT_TEMP=$(${GETOPT_BIN} -o hqnclabzdmgj \
--long help,quiet,dry-run,colorize \
--long list,all,base,archive,db,database,misc,gtk,mojo \
-n "${SCRIPTNAME}" -- "$@")
fi
# if getopts exited with an error code, then exit the script
#if [ $? -ne 0 -o $# -eq 0 ] ; then
if [ $? != 0 ] ; then
echo "Run '${SCRIPTNAME} --help' to see script options" >&2
if [ $OSDETECT = "Darwin" -a $GETOPT_BIN = "/usr/bin/getopt" ]; then
echo "WARNING: 'Darwin' OS and system '/usr/bin/getopt' detected;" >&2
echo "WARNING: Only short options (-h, -e, etc.) will work" >&2
echo "WARNING: with system '/usr/bin/getopt' under 'Darwin' OS" >&2
fi
exit 1
fi
# Note the quotes around `$GETOPT_TEMP': they are essential!
# read in the $GETOPT_TEMP variable
eval set -- "$GETOPT_TEMP"
# read in command line options and set appropriate environment variables
# if you change the below switches to something else, make sure you change the
# getopts call(s) above
while true ; do
case "$1" in
-h|--help) # show the script options
show_help
exit 0;;
-e|--examples)
show_examples
exit 0;;
# Don't output anything (unless there's an error)
-q|--quiet)
QUIET=1
shift;;
# Don't use color in the output
-c|--colorize)
ALWAYS_COLORIZE=1
shift;;
# Explain what will be done, don't actually do
-n|--dry-run|--explain)
DRY_RUN=1
shift;;
# Install the base set of modules
-a|--all)
INSTALL_ALL=1
shift ;;
# Install the base set of modules
-b|--base)
INSTALL_BASE=1
shift ;;
# Install archive format modules
-z|--archive)
INSTALL_ARCHIVE=1
shift ;;
# Install database modules
-d|--db|--database)
INSTALL_DB=1
shift ;;
# Install misc/uncategorized modules
-m|--misc)
INSTALL_MISC=1
shift ;;
# Install GTK-Perl modules
-g|--gtk)
INSTALL_GTK=1
shift ;;
# Install Mojolicious modules
-j|--mojo)
INSTALL_WEBAPP=1
shift ;;
# everything else
--)
shift;
break;;
# we shouldn't get here; die gracefully
*)
echo "ERROR: unknown option '$1'" >&2
echo "ERROR: use --help to see all script options" >&2
exit 1
;;
esac
done
### SCRIPT MAIN LOOP ###
# if we're outputting to a pipe, don't colorize, unless ALWAYS_COLORIZE is set
if [ ! -t 1 ]; then
if [ $ALWAYS_COLORIZE -eq 0 ]; then
COLORIZE=0
fi
fi
# do some error checking; we need at a minimum the 'cpanm' command
CPANM_CMD=$(which cpanm)
if [ $? -gt 0 ]; then
colorize "$MSG_FAIL" "ERROR: can't find 'cpanm' command in your \$PATH"
exit 1
fi
if [ $QUIET -eq 0 ]; then
colorize_clear
colorize "$MSG_FLUFF" "=-=-=-=-=-=-=-= "
colorize "$MSG_INFO" "$SCRIPTNAME"
colorize "$MSG_FLUFF" " =-=-=-=-=-=-=-="
$ECHO_CMD $COLORIZE_OUT
colorize_clear
fi
# generate the list of modules to install
if [ $INSTALL_BASE -gt 0 ]; then
INSTALL_MODULES=$BASE_MODULES
fi
if [ $INSTALL_ARCHIVE -gt 0 ]; then
INSTALL_MODULES="$INSTALL_MODULES $ARCHIVE_MODULES"
fi
if [ $INSTALL_DB -gt 0 ]; then
INSTALL_MODULES="$INSTALL_MODULES $DB_MODULES"
fi
if [ $INSTALL_MISC -gt 0 ]; then
INSTALL_MODULES="$INSTALL_MODULES $MISC_MODULES"
fi
if [ $INSTALL_GTK -gt 0 ]; then
INSTALL_MODULES="$INSTALL_MODULES $GTK_MODULES"
fi
if [ $INSTALL_WEBAPP -gt 0 ]; then
INSTALL_MODULES="$INSTALL_MODULES $WEBAPP_MODULES"
fi
# check the --all switch last; it will overwrite the rest
if [ $INSTALL_ALL -gt 0 ]; then
INSTALL_MODULES="$BASE_MODULES $ARCHIVE_MODULES $DB_MODULES
$MISC_MODULES $GTK_MODULES $WEBAPP_MODULES"
fi
if [ ! -z "${INSTALL_MODULES}" ]; then
echo "Installing modules..."
else
echo "No modules specified to install"
echo "Use '$SCRIPTNAME --help' for script options"
exit 1
fi
for CPAN_MOD in $(echo $INSTALL_MODULES);
do
colorize_clear
if [ $QUIET -eq 0 ]; then
colorize "$MSG_FLUFF" "- ${CPAN_MOD}"
$ECHO_CMD $COLORIZE_OUT
colorize_clear
fi
if [ $DRY_RUN -eq 0 ]; then
cpanm $CPAN_MOD
else
echo "cpanm $CPAN_MOD"
fi
done
# exit cleanly if we reach here
#if [ $QUIET -eq 0 ]; then
# echo "Hit <ENTER> to exit"
# read ANSWER
#fi
exit ${EXIT_STATUS}
# ### begin license blurb ###
# 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; version 2 dated June, 1991.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# vi: set filetype=sh shiftwidth=3 tabstop=3
# end of line