16
16
17
17
18
18
# ## Initialization
19
- OPKGUPVERSION=" 0.3.2 "
19
+ OPKGUPVERSION=" 0.3.4 "
20
20
OPKGBIN=" $( which opkg 2> /dev/null) "
21
21
SSMTPBIN=" $( which ssmtp 2> /dev/null) "
22
22
BANNERSTRING=" Simple OPKG Updater v$OPKGUPVERSION "
23
23
TIMESTAMP=" $( date ' +%Y/%m/%d %H:%M:%S' 2> /dev/null) "
24
24
OPKGUP_INSTALL_DIR=' /usr/sbin'
25
+ OPENWRT_RELEASE=" /etc/openwrt_release"
26
+ ROUTER_NAME=" $( uname -n) "
27
+ HTML_FONT=" font-family:'Trebuchet MS', Helvetica, sans-serif;"
25
28
26
29
# ## Silly SH
27
30
TRUE=0
@@ -47,13 +50,19 @@ OPKGUP_LOCATION="$(readlink -f $0)"
47
50
PACKS=" "
48
51
PACKS_NAMES=" "
49
52
PACKS_COUNT=0
50
- PACKS_COLS=" 0 0 0"
51
53
52
54
53
55
54
56
55
57
# ########################## FUNCTIONS STARTS
56
58
59
+ # Load info from /etc/openwrt_release into memory
60
+ source_release () {
61
+ if is_file " $OPENWRT_RELEASE " ; then
62
+ . " $OPENWRT_RELEASE "
63
+ fi
64
+ }
65
+
57
66
# get opkg packages listings and upgradable info
58
67
opkg_init () {
59
68
check_for_opkg
@@ -67,6 +76,7 @@ opkg_init() {
67
76
68
77
# main function
69
78
main () {
79
+ source_release
70
80
print_banner
71
81
opkg_init
72
82
upgrade_check # may exit here
@@ -81,7 +91,7 @@ main() {
81
91
else
82
92
email_data=" $( print_txt_email " $uplist " ) "
83
93
fi
84
- # local email_data="$(email_subject)"$'\n\n'"$(print_banner)"$'\n\n'"Report for: $(uname -n) "$'\n\n'"$uplist"$'\n\n'"Generated on: $TIMESTAMP"
94
+ # local email_data="$(email_subject)"$'\n\n'"$(print_banner)"$'\n\n'"Report for: $ROUTER_NAME "$'\n\n'"$uplist"$'\n\n'"Generated on: $TIMESTAMP"
85
95
if just_print_html; then
86
96
echo -e " $email_data "
87
97
exit 0
@@ -96,6 +106,8 @@ main() {
96
106
fi
97
107
just_print && exit 0
98
108
opkg_has_update || { echo ' ' ; exit 0 ; }
109
+
110
+ openwrt_is_snapshot && print_snapshot_disclaimer
99
111
100
112
if ! no_confirm; then
101
113
if ! confirm_upgrade; then
@@ -126,14 +138,24 @@ list_upgrades() {
126
138
if opkg_has_update; then
127
139
echo " Packages available for upgrade: $PACKS_COUNT " $' \n '
128
140
# echo -e "$PACKS"
129
- prettyPrintPacks
141
+ print_packs_txt
130
142
return $TRUE
131
143
fi
132
144
echo $' No packages to install!\n\n '
133
145
return $FALSE
134
146
}
135
147
136
- prettyPrintPacks () {
148
+ # Print router info in plain text
149
+ print_info_txt () {
150
+ printf " %s\n" " Router name.: $ROUTER_NAME "
151
+ is_not_empty " $DISTRIB_DESCRIPTION " && printf " %s\n" " Description.: $DISTRIB_DESCRIPTION "
152
+ is_not_empty " $DISTRIB_TARGET " && printf " %s\n" " Target......: $DISTRIB_TARGET "
153
+ is_not_empty " $DISTRIB_ARCH " && printf " %s\n" " Arch........: $DISTRIB_ARCH "
154
+ echo " "
155
+ }
156
+
157
+ # Pretty print package lists in plain text
158
+ print_packs_txt () {
137
159
echo -ne " $PACKS " | awk '
138
160
function rep(c, n){ s=sprintf("%" n "s",""); gsub(/ /,c,s); return s }
139
161
BEGIN{ j=1; } NR>0{
@@ -205,6 +227,11 @@ print_error() {
205
227
echo " $@ " >&2
206
228
}
207
229
230
+ # Prints Warning about upgrading beta/trunk versions
231
+ print_snapshot_disclaimer () {
232
+ 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!"
233
+ }
234
+
208
235
# prints program name and version
209
236
print_banner () {
210
237
[[ " $1 " = ' error' ]] && { print_error $' \n ' " $BANNERSTRING " $' \n ' ; return $TRUE ; }
@@ -333,17 +360,18 @@ print_html_email() {
333
360
334
361
# prints an email report in txt format
335
362
print_txt_email () {
336
- echo " $( email_subject) " $' \n\n ' " $( print_banner) " $' \n\n ' " Report for: $( uname -n) " $' \n\n ' " $1 " $' \n\n ' " Generated on: $TIMESTAMP "
363
+ # echo "$(email_subject)"$'\n\n'"$(print_banner)"$'\n\n'"Report for: $ROUTER_NAME"$'\n\n'"$1"$'\n\n'"Generated on: $TIMESTAMP"
364
+ echo " $( email_subject) " $' \n\n ' " $( print_banner) " $' \n\n ' " $( print_info_txt) " $' \n\n ' " $1 " $' \n\n ' " Generated on: $TIMESTAMP "
337
365
}
338
366
339
367
# prints the packages html table
340
368
print_html_table () {
341
369
echo ' <br>'
342
- is_empty " $PACKS " && { echo ' <br><br><h3>No packages to install.</h3>' ; return $TRUE ; }
370
+ is_empty " $PACKS " && { echo ' <br><br><h3 style=" ' " $HTML_FONT " ' font-size:13pt; font-weight:bold" >No packages to install.</h3>' ; return $TRUE ; }
343
371
local td_padding=' padding-left:8px;padding-right:10px;padding-top:12px;padding-bottom:12px;'
344
372
local td_open=' <td style=\"' " $td_padding " ' \">'
345
373
local th_open=' <th style="' " $td_padding " ' ">'
346
- echo ' <table border="1" width="600px" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">'
374
+ echo ' <table border="1" width="600px" cellpadding="0" cellspacing="0" style="border-collapse:collapse; ' " $HTML_FONT " ' font-size:10pt ">'
347
375
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>'
348
376
# most of the table is generated using awk
349
377
echo -ne " $PACKS " | \
@@ -354,9 +382,15 @@ awk 'BEGIN{ i=1; l=""; } { if (i % 2) l=""; else l=" style=\"background-color:#d
354
382
355
383
# prints html email info
356
384
print_html_header () {
357
- echo $' \n\n ' ' <h2>' " $( print_banner ' nopadding' ) " ' </h2>'
358
- echo ' <h3>' " Report for: $( uname -n) " ' </h3>'
359
- echo ' <h3>' " Packages available for upgrade: $PACKS_COUNT " ' </h3>'
385
+ echo $' \n\n ' ' <h2 style="' " $HTML_FONT " ' font-size:14pt; margin-top:1.5em; font-weight:bold">' " $( print_banner ' nopadding' ) " ' </h2>'
386
+ echo ' <table border="1" width="600px" cellpadding="6pt" cellspacing="0" style="border-collapse:collapse;' " $HTML_FONT " ' font-size:11pt">'
387
+
388
+ echo ' <tr><td style="font-weight:bold">Router Name</td><td>' " $ROUTER_NAME " ' </td></tr>'
389
+ is_not_empty " $DISTRIB_DESCRIPTION " && echo ' <tr><td style="font-weight:bold">Description</td><td>' " $DISTRIB_DESCRIPTION " ' </td></tr>'
390
+ is_not_empty " $DISTRIB_TARGET " && echo ' <tr><td style="font-weight:bold">Target</td><td>' " $DISTRIB_TARGET " ' </td></tr>'
391
+ is_not_empty " $DISTRIB_ARCH " && echo ' <tr><td style="font-weight:bold">Arch</td><td>' " $DISTRIB_ARCH " ' </td></tr>'
392
+ echo ' <tr><td style="font-weight:bold">Updates Count</td><td>' " $PACKS_COUNT " ' </td></tr>'
393
+ echo ' </table>'
360
394
}
361
395
362
396
# prints html email mime type and format
@@ -366,7 +400,7 @@ print_html_mime() {
366
400
367
401
# prints html email info footer
368
402
print_html_timestamp () {
369
- echo $' \n ' ' <h4>' " Generated on: $TIMESTAMP by " ' <a href="https://github.com/tavinus/opkg-upgrade">opkg-upgrade</a></h4>' $' \n '
403
+ echo $' \n ' ' <h4 style=" ' " $HTML_FONT " ' " >' " Generated on: $TIMESTAMP by " ' <a href="https://github.com/tavinus/opkg-upgrade">opkg-upgrade</a></h4>' $' \n '
370
404
}
371
405
372
406
# prints the email subject
@@ -441,6 +475,12 @@ is_valid_email() {
441
475
return $TRUE
442
476
}
443
477
478
+ # returns $TRUE if it is a valid file, $FALSE otherwise
479
+ is_file () {
480
+ [ -f " $1 " ] && return $TRUE
481
+ return $FALSE
482
+ }
483
+
444
484
# returns $TRUE if it is a valid folder, $FALSE otherwise
445
485
is_dir () {
446
486
[ -d " $1 " ] && return $TRUE
@@ -471,6 +511,13 @@ opkg_has_update() {
471
511
return $TRUE
472
512
}
473
513
514
+ # returns $TRUE if $DISTRIB_RELEASE equals SNAPSHOT
515
+ openwrt_is_snapshot () {
516
+ [ " $DISTRIB_RELEASE " = " SNAPSHOT" ] && return $TRUE
517
+ return $FALSE
518
+ }
519
+
520
+
474
521
475
522
476
523
# ##### OPERATION FLAGS
0 commit comments