-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
opkg-upgrade.sh
executable file
·653 lines (546 loc) · 19.5 KB
/
opkg-upgrade.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
#!/bin/sh
###############################################
# Gustavo Arnosti Neves
#
# Created: May / 2017
# Updated: Nov / 2022
#
# Upgrade packages listed by:
# opkg list-upgradable
#
# Will list packages and ask for confirmation
# Use ./opkg-upgrade.sh --help for more info
#
# This Script:
# https://github.com/tavinus/opkg-upgrade
### Initialization
OPKGUPVERSION="0.4.1"
OPKGBIN="$(command -v opkg 2>/dev/null)"
SSMTPBIN="$(command -v ssmtp 2>/dev/null)"
MSMTPBIN="$(command -v msmtp 2>/dev/null)"
BANNERSTRING="Simple OPKG Updater v$OPKGUPVERSION"
TIMESTAMP="$(date '+%Y/%m/%d %H:%M:%S' 2>/dev/null)"
OPKGUP_INSTALL_DIR='/usr/sbin'
OPENWRT_RELEASE="/etc/openwrt_release"
ROUTER_NAME="$(uname -n)"
HTML_FONT="font-family:'Trebuchet MS', Helvetica, sans-serif;"
### Silly SH
TRUE=0
FALSE=1
### Execution FLAGS
QUIET_MODE=$FALSE
CHECK_UPDATES_FLAG=$TRUE
FORCE_FLAG=$FALSE
JUST_CHECK_FLAG=$FALSE
JUST_PRINT_FLAG=$FALSE
SSMTP_SEND_FLAG=$FALSE
MSMTP_SEND_FLAG=$FALSE
SEND_TO=""
ALWAYS_SEND_FLAG=$FALSE
HTML_FORMAT=$TRUE
JUST_PRINT_HTML_FLAG=$FALSE
### This scripts name
OPKGUP_NAME="$(basename $0)"
OPKGUP_LOCATION="$(readlink -f $0)"
### Execution vars, populated later
PACKS=""
PACKS_NAMES=""
PACKS_COUNT=0
########################### FUNCTIONS STARTS
# Load info from /etc/openwrt_release into memory
source_release() {
if is_file "$OPENWRT_RELEASE"; then
. "$OPENWRT_RELEASE"
fi
}
# get opkg packages listings and upgradable info
opkg_init() {
check_for_opkg
if should_run_update; then
opkg_update
else
message_ends "Ignoring package lists update"
fi
opkg_upgradable
}
# main function
main() {
source_release
print_banner
opkg_init
upgrade_check # may exit here
local uplist="$(list_upgrades)"
if should_send_ssmtp || should_send_msmtp || just_print_html; then
if opkg_has_update || should_always_send || just_print_html; then
QUIET_MODE=$FALSE
local email_data=''
if is_html_email; then
email_data="$(print_html_email)"
else
email_data="$(print_txt_email "$uplist")"
fi
#local email_data="$(email_subject)"$'\n\n'"$(print_banner)"$'\n\n'"Report for: $ROUTER_NAME"$'\n\n'"$uplist"$'\n\n'"Generated on: $TIMESTAMP"
if just_print_html; then
echo -e "$email_data"
exit 0
else
if should_send_ssmtp; then
echo -e "$email_data" | "$SSMTPBIN" "$SEND_TO"
elif should_send_msmtp; then
echo -e "$email_data" | "$MSMTPBIN" "$SEND_TO"
fi
exit $?
fi
fi
exit 0
else
echo -e "$uplist"
fi
just_print && exit 0
opkg_has_update || { echo '' ; exit 0 ; }
openwrt_is_snapshot && print_snapshot_disclaimer
if ! no_confirm; then
if ! confirm_upgrade; then
echo $'Cancelled by user!\n'
exit 3
fi
else
echo ""
fi
do_upgrade
exit $?
}
# Just checks if upgrades are available and exits with
# 0 - if there are updates available
# 1 - if there are NO updates available
# Depends on the $JUST_CHECK_FLAG to run
upgrade_check() {
if just_check; then
opkg_has_update && exit 0
exit 1
fi
}
# Prints the list of upgrades available,
# returns $TRUE if we have updates available, $FALSE otherwise
list_upgrades() {
if opkg_has_update; then
echo "Packages available for upgrade: $PACKS_COUNT"$'\n'
#echo -e "$PACKS"
print_packs_txt
return $TRUE
fi
echo $'No packages to install!\n\n'
return $FALSE
}
# Print router info in plain text
print_info_txt() {
printf "%s\n" "Router name.: $ROUTER_NAME"
is_not_empty "$DISTRIB_DESCRIPTION" && printf "%s\n" "Description.: $DISTRIB_DESCRIPTION"
is_not_empty "$DISTRIB_TARGET" && printf "%s\n" "Target......: $DISTRIB_TARGET"
is_not_empty "$DISTRIB_ARCH" && printf "%s\n" "Arch........: $DISTRIB_ARCH"
echo ""
}
# Pretty print package lists in plain text
print_packs_txt() {
echo -ne "$PACKS" | awk '
function rep(c, n){ s=sprintf("%" n "s",""); gsub(/ /,c,s); return s }
BEGIN{ j=1; } NR>0{
l[j, 1]=($1);
l[j, 2]=($3);
l[j++, 3]=($5);
max[1]=(length($1)>max[1]?length($1):max[1]);
max[2]=(length($3)>max[2]?length($3):max[2]);
max[3]=(length($5)>max[3]?length($5):max[3]);
max[1]=(max[1]>=7?max[1]:7);
max[2]=(max[2]>=7?max[2]:7);
max[3]=(max[3]>=7?max[3]:7);
}
function div(){ printf "+-----+%s+%s+%s+\n", rep("-", max[1]+2), rep("-", max[2]+2), rep("-", max[3]+2) }
function head() { printf "| %3s | %-" max[1] "s | %-" max[2] "s | %-" max[3] "s |\n", "#", "Package", "Current", "Update" }
END {div() ; head() ; div() ; for (i=1; i<=NR; i++) printf "| %3d | %-" max[1] "s | %-" max[2] "s | %-" max[3] "s |\n", i, l[i, 1], l[i, 2], l[i, 3]; div()}'
}
### Parse CLI options
get_options() {
while :; do
case "$1" in
-V|--version|--Version)
print_banner 'nopadding' ; exit 0 ;;
-h|--help|--Help)
print_help ; exit 0 ;;
-i|--install)
self_install "$2" ; exit $? ;;
-u|--upgrade-check|--upgrade-Check|--upgradecheck|--upgradeCheck)
QUIET_MODE=$TRUE ; JUST_CHECK_FLAG=$TRUE ; shift ;;
-l|--list-upgrades|--list-Upgrades|--listupgrades|--listUpgrades)
QUIET_MODE=$TRUE ; JUST_PRINT_FLAG=$TRUE ; shift ;;
-e|--email-list|--email-List|--emaillist|--emailList)
QUIET_MODE=$TRUE ; JUST_PRINT_HTML_FLAG=$TRUE ; shift ;;
-s|--ssmtp)
ssmtp_check "$2" ; shift ; shift ;;
-m|--msmtp)
msmtp_check "$2" ; shift ; shift ;;
-a|--always-send|--always-Send|--alwayssend|--alwaysSend)
ALWAYS_SEND_FLAG=$TRUE ; shift ;;
-t|--text-only|--text-Only|--textonly|--textOnly)
HTML_FORMAT=$FALSE ; shift ;;
-n|--no-pkg-update)
CHECK_UPDATES_FLAG=$FALSE ; shift ;;
-f|--force)
FORCE_FLAG=$TRUE ; shift ;;
-q|--quiet)
QUIET_MODE=$TRUE ; shift ;;
*)
check_invalid_opts "$1" ; break ;;
esac
done
}
# In this script's case, just check we have and emty string and we should be fine
check_invalid_opts() {
if is_not_empty "$1"; then
print_banner
echo "Invalid Option: $1"$'\n'
exit 2
fi
return 0
}
###### PRINTING MESSAGES
# prints message to stderr
print_error() {
echo "$@" >&2
}
# Prints Warning about upgrading beta/trunk versions
print_snapshot_disclaimer() {
printf "\n%s\n%s\n%s\n%s\n" "WARNING! You are running a Beta / Snapshot / Trunk version!" "Upgrading snapshots MAY cause undesired results, including soft-bricks." "The current trunk head may not be compatible with your installed version!" "You have been warned! Proceed at your own risk!"
}
# prints program name and version
print_banner() {
[[ "$1" = 'error' ]] && { print_error $'\n'"$BANNERSTRING"$'\n' ; return $TRUE ; }
is_quiet && ! just_print && return $TRUE
local str=""
if [[ "$1" = 'nopadding' ]]; then
str="$BANNERSTRING"
else
str=$'\n'"$BANNERSTRING"$'\n'
fi
echo "$str"
}
# prints help to screen and exits
print_help() {
print_banner
echo "Usage: $OPKGUP_NAME [options]
Options:
-V, --version Show program name and version and exits
-h, --help Show this help screen and exits
-i, --install [dir] Install opkg-upgrade to [dir] or /usr/sbin
Leave [dir] empty for default (/usr/sbin)
-u, --upgrade-check Returns SUCCESS if there are updates available
Quiet execution, returns 0 or 1
-l, --list-upgrades Prints the list of available updates and exits
-e, --email-list Prints the list of updates in html email format
Includes subject, mime type and html formated data
-s, --ssmtp <email> Use the system's ssmtp to send update reports
You need to install and configure ssmtp beforehand
-m, --msmtp <email> Use the system's msmtp to send update reports
You need to install and configure msmtp beforehand
-a, --always-send Send e-mail even if there are no updates
By default e-mails are only sent when updates are available
-t, --text-only Send e-mail in plain text format.
By default, e-mails are sent in html format.
-n, --no-opkg-update Skip opkg update at the beginning,
may not find packages if not up to date
-f, --force Do not ask for confirmation,
will update everything available
Notes:
- Short options should not be grouped. You must pass each parameter on its own.
- You must have a working ssmtp or msmtp install to use the email functionality.
Make sure you can send e-mails from it before trying from opkg-upgrade.
Examples:
$OPKGUP_NAME -n -f # run without updating listings and asking for upgrade
$OPKGUP_NAME --install # install to /usr/sbin/opkg-upgrade
$OPKGUP_NAME -l # just print upgrades available
$OPKGUP_NAME -e # just print html formatted email
$OPKGUP_NAME -s 'mail@example.com' # mail upgrade report if have updates
$OPKGUP_NAME -a -m 'mail@example.com' # mail upgrade report even if NO updates
$OPKGUP_NAME -u && echo 'upgrades are available' || echo 'no upgrades available'
"
}
# prints message to screen with trailling '\r' to change the line later
message_starts() {
is_quiet && return $TRUE
echo -n ".... | $1"$'\r'
}
# prints message to screen, closes a task message
message_ends() {
is_quiet && return $TRUE
is_empty "$1" && mess="" || mess="$1"
echo "Done | $mess"
}
# checks if we have opkg available
check_for_opkg() {
if ! is_executable "$OPKGBIN"; then
print_error $'ERROR! Could not find or run OPKG binary\n'
exit 1
fi
}
##### ERROR HANDLING
# Displays a runtinme error and exits execution
rt_exception() {
local r=1
is_empty "$2" || r=$2
print_error "$1"
exit $r
}
###### OPKG UPDATE AND UPGRADEABLE
# update package listings
opkg_update() {
message_starts "Updating package lists"
local err="$("$OPKGBIN" update 2>&1 >/dev/null)";
is_empty "$err" || rt_exception $'Error when trying to update the package listings.\nDebug Info:\n'"$err"
message_ends
}
# get list of upgradable packages
opkg_upgradable() {
message_starts "Getting upgradable packages list"
PACKS="$($OPKGBIN list-upgradable | sort | grep -v -e 'marked HOLD or PREFER' -e 'Not selecting')"
#[ $? -eq 0 ] || rt_exception $'Error when trying list upgradable packages. Permissions?\n'
#PACKS="$(cat pkg-example.txt)" # testing
if ! is_empty "$PACKS"; then
PACKS_NAMES="$(echo -ne "$PACKS" | awk '{ printf "%s ", $1 }')"
#echo -ne "$PACKS" | awk '{ printf "pack: %s from: %s to: %s \n", $1, $3, $5 }'
PACKS_COUNT="$(echo "$PACKS" | wc -l)"
fi
message_ends
is_quiet || echo ""
return $TRUE
}
###### CREATING EMAILS
# prints an email report in html format
print_html_email() {
echo "$(email_subject)""$(print_html_mime)""$(print_html_header)""$(print_html_table)""$(print_html_timestamp)"
}
# prints an email report in txt format
print_txt_email() {
#echo "$(email_subject)"$'\n\n'"$(print_banner)"$'\n\n'"Report for: $ROUTER_NAME"$'\n\n'"$1"$'\n\n'"Generated on: $TIMESTAMP"
echo "$(email_subject)"$'\n\n'"$(print_banner)"$'\n\n'"$(print_info_txt)"$'\n\n'"$1"$'\n\n'"Generated on: $TIMESTAMP"
}
# prints the packages html table
print_html_table() {
echo '<br>'
is_empty "$PACKS" && { echo '<br><br><h3 style="'"$HTML_FONT"' font-size:13pt; font-weight:bold">No packages to install.</h3>' ; return $TRUE ; }
local td_padding='padding-left:8px;padding-right:10px;padding-top:12px;padding-bottom:12px;'
local td_open='<td style=\"'"$td_padding"'\">'
local th_open='<th style="'"$td_padding"'">'
echo '<table border="1" width="600px" cellpadding="0" cellspacing="0" style="border-collapse:collapse; '"$HTML_FONT"' font-size:10pt">'
echo '<tr style="background-color:#2f3263; color:#EEE;" align="left" margin=0 padding=0>'$'\n\t'"$th_open"'#</th>'$'\n\t'"$th_open"'Pack</th>'$'\n\t'"$th_open"'Current</th>'$'\n\t'"$th_open"'Update</th>'$'\n''</tr>'
# most of the table is generated using awk
echo -ne "$PACKS" | \
awk 'BEGIN{ i=1; l=""; } { if (i % 2) l=""; else l=" style=\"background-color:#dedfe8;\""; printf "<tr margin=0 padding=0 align=\"left\"%s>\n\t'"$td_open"'%s</td>\n\t'"$td_open"'%s</td>\n\t'"$td_open"'%s</td>\n\t'"$td_open"'%s</td>\n</tr>\n", l, i++, $1, $3, $5 }'
echo '</table>'
return $TRUE
}
# prints html email info
print_html_header() {
echo $'\n\n''<h2 style="'"$HTML_FONT"' font-size:14pt; margin-top:1.5em; font-weight:bold">'"$(print_banner 'nopadding')"'</h2>'
echo '<table border="1" width="600px" cellpadding="6pt" cellspacing="0" style="border-collapse:collapse;'"$HTML_FONT"' font-size:11pt">'
echo '<tr><td style="font-weight:bold">Router Name</td><td>'"$ROUTER_NAME"'</td></tr>'
is_not_empty "$DISTRIB_DESCRIPTION" && echo '<tr><td style="font-weight:bold">Description</td><td>'"$DISTRIB_DESCRIPTION"'</td></tr>'
is_not_empty "$DISTRIB_TARGET" && echo '<tr><td style="font-weight:bold">Target</td><td>'"$DISTRIB_TARGET"'</td></tr>'
is_not_empty "$DISTRIB_ARCH" && echo '<tr><td style="font-weight:bold">Arch</td><td>'"$DISTRIB_ARCH"'</td></tr>'
echo '<tr><td style="font-weight:bold">Updates Count</td><td>'"$PACKS_COUNT"'</td></tr>'
echo '</table>'
}
# prints html email mime type and format
print_html_mime() {
echo $'\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8'
}
# prints html email info footer
print_html_timestamp() {
echo $'\n''<h4 style="'"$HTML_FONT"'">'"Generated on: $TIMESTAMP by "'<a href="https://github.com/tavinus/opkg-upgrade">opkg-upgrade</a></h4>'$'\n'
}
# prints the email subject
email_subject() {
echo "Subject: opkg-upgrade report - $TIMESTAMP"
}
###### UPGRADING
# asks the user to confirm the upgrade
confirm_upgrade() {
read -p $'\nProceed with upgrade? (Y/y to proceed) ' -n 1 -r
echo $'\n'
if [[ "$REPLY" = Y || "$REPLY" = y ]]; then
return $TRUE
fi
return $FALSE
}
# run the upgrade
do_upgrade() {
message_starts $'Upgrading packages\n\n'
"$OPKGBIN" install $PACKS_NAMES
ret=$?
message_ends $'\nUpgrade finished\n'
echo $'Please check for config file conflicts!\n'
return $ret
}
###### SELF INSTALL
# Locates and copies itself to target location and make it executable
self_install() {
print_banner
is_empty "$1" || OPKGUP_INSTALL_DIR="$1"
echo "Current Location: $OPKGUP_LOCATION"
echo " Target Dir: $OPKGUP_INSTALL_DIR"
if ! is_dir "$OPKGUP_INSTALL_DIR"; then
print_error $'\n'"Error! Target directory not found!"
print_error " -> $OPKGUP_INSTALL_DIR"
exit 40
fi
local t="$OPKGUP_INSTALL_DIR/opkg-upgrade"
local status="$(cp "$OPKGUP_LOCATION" "$t" 2>&1)"
#echo "status: $status"
if is_not_empty "$status"; then
print_error " Could not copy: $t"
print_error $'\n'"Error: $status"
exit 33
fi
echo " Installed to: $t"
chmod +x "$t" 2>/dev/null
[ $? -eq 0 ] && status="OK" || status="Fail"
echo "chmod executable: $status"
echo $'\nInstalled with success, bye!\n'
exit $?
}
###### VALIDATORS
# returns $TRUE if we have a valid e-mail address, $FALSE otherwise
is_valid_email() {
is_empty "$1" && return $FALSE
local f=$(echo "$1" | grep -E -o "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$")
is_empty "$f" && return $FALSE
return $TRUE
}
# check if email is valid or break execution
validate_email() {
if ! is_valid_email "$1"; then
print_banner 'error'
print_error "Error! You need to specify a valid target e-mail address!"
print_error "Invalid address -> $1"
exit 30
fi
}
# returns $TRUE if it is a valid file, $FALSE otherwise
is_file() {
[ -f "$1" ] && return $TRUE
return $FALSE
}
# returns $TRUE if it is a valid folder, $FALSE otherwise
is_dir() {
[ -d "$1" ] && return $TRUE
return $FALSE
}
# Returns $TRUE if the file exists and is executable, $FALSE otherwise
is_executable() {
[ -f "$1" ] && [ -x "$1" ] && return $TRUE
return $FALSE
}
# returns $TRUE for an empty var, $FALSE otherwise
is_empty() {
[ -z "$1" ] && return $TRUE
return $FALSE
}
# returns $FALSE for an empty var, $TRUE otherwise
is_not_empty() {
[ -z "$1" ] && return $FALSE
return $TRUE
}
# returns $TRUE if $PACKS is not empty
opkg_has_update() {
is_empty "$PACKS" && return $FALSE
return $TRUE
}
# returns $TRUE if $DISTRIB_RELEASE equals SNAPSHOT
openwrt_is_snapshot() {
[ "$DISTRIB_RELEASE" = "SNAPSHOT" ] && return $TRUE
return $FALSE
}
###### OPERATION FLAGS
# returns $TRUE if we should use the HTML format, $FALSE for TXT format
is_html_email() {
return $HTML_FORMAT
}
# returns $TRUE if we are running in quiet mode, $FALSE otherwise
is_quiet() {
return $QUIET_MODE
}
# returns $TRUE if we should update the package listings, $FALSE otherwise
should_run_update() {
return $CHECK_UPDATES_FLAG
}
# return $TRUE if we should ask the user before upgrading, $FALSE otherwise
no_confirm() {
return $FORCE_FLAG
}
# returns $TRUE if we should just check for updates and exit, $FALSE otherwise
just_check() {
return $JUST_CHECK_FLAG
}
# returns $TRUE if we should just print the list and exit, $FALSE otherwise
just_print() {
return $JUST_PRINT_FLAG
}
# returns $TRUE if we should send email with ssmtp, $FALSE otherwise
should_send_ssmtp() {
return $SSMTP_SEND_FLAG
}
# returns $TRUE if we should send email with msmtp, $FALSE otherwise
should_send_msmtp() {
return $MSMTP_SEND_FLAG
}
# returns $TRUE if we should send the e-mail even if there is no updates, $FALSE otherwise
should_always_send() {
return $ALWAYS_SEND_FLAG
}
# returns $TRUE if we should just print the html report and exit, $FALSE otherwise
just_print_html() {
return $JUST_PRINT_HTML_FLAG
}
###### SSMTP functions
# Finds and checks for ssmtp executable, returns $TRUE if found, $FALSE otherwise
find_ssmtp() {
is_executable "$SSMTPBIN" && return $TRUE
SSMTPBIN='/usr/sbin/ssmtp'
is_executable "$SSMTPBIN" && return $TRUE
return $FALSE
}
# Checks for ssmtp program, validates the target email and sets globals for emails
ssmtp_check() {
if ! find_ssmtp; then
print_banner 'error'
print_error "Error! Could not find or run the SSMTP executable, make sure it is installed!"
exit 33
fi
validate_email "$1"
SSMTP_SEND_FLAG=$TRUE
SEND_TO="$1"
QUIET_MODE=$TRUE
}
###### MSMTP functions
# Finds and checks for msmtp executable, returns $TRUE if found, $FALSE otherwise
find_msmtp() {
is_executable "$MSMTPBIN" && return $TRUE
MSMTPBIN='/usr/sbin/msmtp'
is_executable "$MSMTPBIN" && return $TRUE
return $FALSE
}
# Checks for msmtp program, validates the target email and sets globals for emails
msmtp_check() {
if ! find_msmtp; then
print_banner 'error'
print_error "Error! Could not find or run the MSMTP executable, make sure it is installed!"
exit 34
fi
validate_email "$1"
MSMTP_SEND_FLAG=$TRUE
SEND_TO="$1"
QUIET_MODE=$TRUE
}
###### START EXECUTION
get_options "$@"
main
exit 20 # should never get here