-
Notifications
You must be signed in to change notification settings - Fork 5
/
system_info.v3.1.7
7129 lines (6447 loc) · 178 KB
/
system_info.v3.1.7
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# system_info.sh
# Written by: Ken Cormack, [email protected]
# Copyright (c) 2020-2021, Ken Cormack
# github: https://github.com/kencormack/system_info
# license: GPL 3.0
# Contributor: William Stearns, [email protected]
#
# This script attempts to perform a fairly complete audit of the current
# configuration of a Raspberry Pi. The target hardware is any variant or
# model of Pi (except the Pico), up to and including the Pi 4B, 400,
# and CM4 modules.
#
# Supported OS versions include Raspbian Buster and the newly renamed
# "Raspberry Pi OS", in 32-bit. Expect things not to work on the
# 64-bit OS, while it is still beta. For those running Stretch,
# version 2.1.2 of this script, the last version to support Stretch,
# will remain available on the github page. Beginning with version
# 3.0.0, support for Stretch has been REMOVED.
#
# No attempt will be made to back-port any later version of this script
# to Stretch or older, nor will I port this to Ubuntu, OSMC, LibreELEC,
# or any other OS distribution available for the Pi.
#
# See the README.md file, at the github link above, for additional info.
#
##################################################
#---------------
readonly MY_VERSION="3.1.7"
#---------------
# Called by fnPARSE_CMDLINE
#
fnUSAGE()
{
# This line, included in every function, is part of the debugging/trace
# log stuff used in testing & development of this script. See the file
# DEBBUGGING.md on the github page, for a full explaination of how I
# chose to implement a debug/trace log.
echo -e "\nenter: ${FUNCNAME[*]}" >&3
echo "Usage: $(basename "${0}") [-h|--help] [-v|--version] [-m|--menu <1-17>] [-o|--output <filename>]" >&2
exit 1
}
#---------------
# Called by fnPARSE_CMDLINE
#
fnVALIDATE_FILENAME()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
local CHECK=""
CHECK="$(echo "${REPORT}" | grep -q "^[^-_.A-Za-z0-9/]")"
if [[ -n "${CHECK}" ]]
then
echo
echo "WARNING: SPECIAL CHARS DETECTED IN FILENAME \"${REPORT}\"" >&2
echo "Use only A-Z, a-z, 0-9, hyphen (-), underscore (_), period (.), and slash (/)" >&2
echo
exit 1
fi
if [[ -w "${REPORT}" ]]
then
echo "WARNING: FILE EXISTS" >&2
echo "Will not overwrite existing file." >&2
echo "Please choose another filename." >&2
echo
exit 1
fi
if touch "${REPORT}" 2> /dev/null
then
true
else
echo
echo "WARNING: PERMISSION DENIED" >&2
echo "Cannot write file: ${REPORT}" >&2
echo
exit 1
fi
}
#---------------
# Called by mainline
# Calls fnGET_HELP
# Calls fnVERSION
# Calls fnUSAGE
# Calls fnVALIDATE_FILENAME
#
fnPARSE_CMDLINE()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
local INDEX=""
local ARG_LIST=""
local PARSE_STATUS=""
# Convert the arguments string ($*) to an array and
# loop through it. In the loop, current value will
# be the option and the next one will be the parameter.
# shellcheck disable=SC2206
ARG_LIST=(${MY_CMDLINE})
INDEX=0
# Something is wrong here.
# I should be able to use 'for ARGUMENT in ${ARG_LIST}' here,
# but it only works here, using MY_CMDLINE.
# :: still scratching my head here ::
#
# The following test line correctly shows that the ARG_LIST
# array ends up with multiple descrete elements...
# echo "Number of elements in the array: ${#ARG_LIST[@]}"
# Yet for some reason, I can't use it in the for loop.
# Puzzling. Will have to dig into this a little more, when
# my brain hurts a little less. :/
PARSE_STATUS=NOT_OK
# for ARGUMENT in ${ARG_LIST}
for ARGUMENT in ${MY_CMDLINE}
do
INDEX=$((INDEX+1))
case ${ARGUMENT} in
-h|--help)
fnGET_HELP
;;
-v|--version)
fnVERSION
;;
-m|--menu)
if [[ ${ARG_LIST[INDEX]} -ge 1 ]] && [[ ${ARG_LIST[INDEX]} -le 17 ]]
then
MENU="${ARG_LIST[INDEX]}"
else
echo "Invalid menu option" >&2
fnUSAGE
fi
PARSE_STATUS=OK
;;
-o|--output)
if [[ "${ARG_LIST[INDEX]}" = "" ]]
then
echo "Missing filename" >&2
fnUSAGE
else
REPORT="${ARG_LIST[INDEX]}"
fnVALIDATE_FILENAME
fi
PARSE_STATUS=OK
;;
*)
if [[ "${PARSE_STATUS}" = "OK" ]]
then
continue
else
fnUSAGE
fi
;;
esac
done
}
#---------------
# Called by fnPARSE_CMDLINE
#
fnGET_HELP()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
# Thor: "Hey, let's do 'Get Help'. It's great. Works every time."
# Loki: "It's humiliating. We are not doing 'Get Help'."
# Thor: "GET HELP! MY BROTHER'S DYING!"
clear
cat <<'EOF' | more -d
SYSTEM_INFO - HELP
Run without parameters, the script presents a menu, and assigns a default
filename for the report... ${HOME}/hostname-scriptname-yyyymmdd-hhmmss
The following parameters and options are supported;
-h|--help
You are here.
-m|--menu <1-17>
Specifies a menu option to pre-select. Normally, options chosen from
the menu are saved in ${HOME}/.system_inforc). Those saved options
are recalled and selected next time the script is run. When the "-m"
or "--menu" is used, it must be accompanied by a number, 1-17, which
corresponds to a selection on the menu. Only one menu option can be
specified with this parameter. Use of this flag ignores .system_inforc
-o|--output <filename>
Specifies the filename to use for the report. The script will NOT
overwrite an existing file, and allows only the following characters
to be used in the filename:
A-Z, a-z, 0-9, hyphen (-), underscore (_), period (.), and slash (/)
-v|--version
Display version number, and warranty & licensing info.
ADDITIONAL TOOLS FOR DEVELOPMENT...
The script also supports creation of a pair of reports for development-use.
These development and testing logs are made available on file descriptors
3 and 4, and are not meant or required, for normal operation. They are
intended to provide valuable troubleshooting data for those who wish to
modify system_info for their own use.
See the following for more information about these development options:
https://github.com/kencormack/system_info/blob/master/DEBUGGING_PROFILING.md
A Debugging log:
system_info 3> debug.log
A profiling log:
system_info 4> profile.log
Simultaneous creation of both logs:
system_info 3> debug.log 4> profile.log
These do not affect parsing of the commandline parameters described above,
and each datastream is independent of the other (and, the normal report.)
EOF
# Thor: "Classic!"
# Loki: "Humiliating."
# -- 'Thor: Ragnarok'
exit
}
#---------------
# Called by fnPARSE_CMDLINE
#
fnVERSION()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
clear
echo "$(basename "${0}") version: ${MY_VERSION}"
cat <<'EOF' | more -d
Copyright (c) 2020-2021 Ken Cormack
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 3 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
EOF
exit
}
#---------------
# Called by fnMAIN
#
fnINITIALIZE()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
# Indexed arrays
declare -a CHOICES
declare -a OPTIONS
export PATH="${PATH:+${PATH}:}/usr/sbin:/sbin"
LC_ALL=C
LANG=C
if [[ "${TERM}" = "" ]] || [[ "${TERM}" = "dumb" ]]
then
REV=""
SGR0=""
BELL=""
else
REV="$(tput rev 2>/dev/null)"
SGR0="$(tput sgr0 2>/dev/null)"
BELL="$(tput bel 2>/dev/null)"
fi
RCFILE="${HOME}/.system_inforc"
ERROR=" "
DEG_SYMBOL=$'\xc2\xb0'
SECTION=""
}
#---------------
# Called by fnMAIN
#
fnDEFINE_OPTIONS()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
local INDEX=""
for INDEX in {0..16}
do
CHOICES[${INDEX}]=""
done
# The array of menu OPTIONS is defined
OPTIONS[0]="Pi Hardware"
OPTIONS[1]="Performance"
OPTIONS[2]="O/S Config"
OPTIONS[3]="Memory"
OPTIONS[4]="Logging"
OPTIONS[5]="Services"
OPTIONS[6]="Hardware Busses"
OPTIONS[7]="Serial & Bluetooth"
OPTIONS[8]="USB & Other Devices"
OPTIONS[9]="Filesystems & Storage"
OPTIONS[10]="Audio & Video"
OPTIONS[11]="Networking"
OPTIONS[12]="Network Filesystems"
OPTIONS[13]="Containers & Virtualization"
OPTIONS[14]="Modules and Packages"
OPTIONS[15]="System Security"
OPTIONS[16]="Run All Of The Above"
}
#---------------
# Called by fnMAIN
#
fnCONFIRM_BASH()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
# This guards against people launching this script with an incorrect shell,
# such as by running 'sh scriptname', overriding the 'shebang'.
if [[ "${BASH_VERSION}" = "" ]]
then
clear
echo "${BELL}"
echo "################################################################"
echo
echo "ERROR: THE WRONG SHELL IS BEING USED TO RUN THIS SCRIPT."
echo
echo "${0} is written for the bash shell only."
echo "It will not run under sh, ksh, or any other shell but \"bash\"."
echo
echo "Please do either this..."
echo " $ chmod +x ${0}"
echo " $ ./${0}"
echo
echo "or this..."
echo " $ bash ${0}"
echo
echo "...to execute under bash, as intended."
echo
echo "################################################################"
echo
exit
fi
}
#---------------
# Called by the mainline
#
fnABORT()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
# Called by a trap, whenever the signals
# SIGHUP SIGINT SIGQUIT SIGABRT or SIGTERM
# are received. We clean up after ourselves.
echo
echo "ABORT${BELL}"
# delete the lshw tmp file
rm "${TEMPFILE}" 2>/dev/null
# close the debugging file descriptor
exec 3>&- 2> /dev/null
# close the profiling file descriptor
set +x
exec 4>&- 2> /dev/null
# exit the script
exit
}
#---------------
# Called by fnMAIN and fnDO_INSPECTIONS
#
fnTITLE()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
echo
echo " _ VERSION ${MY_VERSION} _ __"
echo $' ___ _ _ ___| |_ ___ _ __ ___ (_)_ __ / _| ___'
echo $'/ __| | | / __| __/ _ \\ \'_ \` _ \\ | | \'_ \\| |_ / _ \\'
echo $'\__ \ |_| \__ \ || __/ | | | | | | | | | | _| (_) |'
echo $'|___/\__, |___/\__\___|_| |_| |_| |_|_| |_|_| \___/'
echo $' |___/'
echo " RASPBERRY PI SYSTEM INFORMATION REPORT"
echo
}
#---------------
# Called by multiple functions
#
fnBANNER()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
echo "==============================================================================="
echo "SYSTEM_INFO(${SECTION}): ${*}"
echo "==============================================================================="
echo
}
#---------------
# Called by multiple functions
#
fnSUB_BANNER()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
echo "-------------------------------------------------------"
echo " ${*}"
echo
}
#---------------
# Called by multiple functions
#
fnCHECK_COMMAND()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
# Checks for existence of the command passed in as the function argument.
# Exit value of 0 when exists, 1 if not exists.
local CHECK_COMMAND="${1}"
command -v "${CHECK_COMMAND}" >/dev/null 2>&1
}
#---------------
# Inspect the "mode" (permissions - in octal), owner, and group
# of a specified directory or file.
# Called by passing 4 parameters to the function as follows:
# fnMOG octal_mode owner group file_or_directory
# Called by fnUSERCHECK and fnCHECK_PERMISSIONS
#
fnMOG()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
local OCTAL=""
local OWNER=""
local GROUP=""
local CHECKPATH=""
local COCTAL=""
local SYMBOLIC=""
local COWNER=""
local CGROUP=""
OCTAL="${1}" # recommended perms, eg: 755 (rwxr-xr-x)
OWNER="${2}" # recommended owner
GROUP="${3}" # recommended group
CHECKPATH="${4}" # path to check
if ${SUDO} test -e "${CHECKPATH}"
then
# Run commands
COCTAL="$(${SUDO} stat -L -c %a "${CHECKPATH}")"
SYMBOLIC="$(${SUDO} stat -L -c %A "${CHECKPATH}")"
COWNER="$(${SUDO} stat -L -c %U "${CHECKPATH}")"
CGROUP="$(${SUDO} stat -L -c %G "${CHECKPATH}")"
# Compare
echo "[${CHECKPATH}]"
if [[ "${COCTAL}" != "${OCTAL}" ]]
then
echo " Permissions ... WARN [${COCTAL}] (${SYMBOLIC}) - Recommend [${OCTAL}])"
else
echo " Permissions ... OK [${OCTAL}] (${SYMBOLIC})"
fi
if [[ "${COWNER}" != "${OWNER}" ]]
then
echo " Owner ......... WARN [${COWNER}] - Recommend [${OWNER}]"
else
echo " Owner ......... OK [${OWNER}]"
fi
if [[ "${CGROUP}" != "${GROUP}" ]]
then
echo " Group ......... WARN [${CGROUP}] - Recommend [${GROUP}]"
else
echo " Group ......... OK [${GROUP}]"
fi
fi
}
#---------------
# Called by fnCONFIRM_PREREQS
# Calls fnBANNER
#
fnCONFIRM_OS()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
# Written for Raspbian Buster and above. Stretch and older not supported.
# if os-release file exists...
if [[ -f /etc/os-release ]]
then
# source the os-release file
. /etc/os-release 2>/dev/null
# if Raspbian...
if [[ "${ID}" = "raspbian" ]]
then
# and if older than Buster...
if [[ "$(echo "${VERSION_ID} < 10" | bc)" -eq 1 ]]
then
# too old.
echo
fnBANNER "UNSUPPORTED RASPBIAN VERSION"
echo "This script is designed for Raspbian GNU/Linux 10 (Buster), and above."
echo "Version ${PRETTY_NAME} is not supported."
echo
exit 1
else
# if Raspbian, and Buster or newer, then ok.
echo "OS version check: ok"
fi
else
# if not Raspbian, then unsupported.
echo
fnBANNER "LINUX VERSION UNKNOWN"
echo "This script is designed for Raspbian GNU/Linux 10 (Buster), and above."
echo "Unable to identify your version of the operating system... Exiting."
echo
exit 1
fi
else
# if os-release file doesn't exist...
echo
fnBANNER "LINUX VERSION UNKNOWN"
echo "This script is designed for Raspbian GNU/Linux 10 (Buster), and above."
echo "Unable to identify your version of the operating system... Exiting."
echo
exit 1
fi
if [[ -n "$(readlink /sbin)" ]] && [[ -n "$(readlink /lib)" ]] && [[ -n "$(readlink /bin)" ]]
then
PROVENANCE="\"Raspberry Pi OS\""
RPIOS=1
else
PROVENANCE="legacy \"Raspbian\""
RPIOS=0
fi
}
#---------------
# Called by fnCONFIRM_PREREQS
# Calls fnBANNER
#
fnRING_BUF()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
# Check that dmesg contains anything we might need. Examples include the
# "memory split", "active display driver", "rtc", and several other tests.
if [[ "$(dmesg | grep "Booting Linux")" = "" ]]
then
echo
fnBANNER "DMESG RING BUFFER HAS WRAPPED - PLEASE REBOOT"
echo "This script relies on \"dmesg\" to provide some of the data it needs."
echo
echo "Kernel messages are stored in a data structure called a ring buffer."
echo "The buffer is fixed in size, with new data overwriting the oldest data."
echo "When data we need has already been overwritten, that data is lost to us."
echo
echo "Your ring buffer has already wrapped. Please reboot your system before"
echo "attempting to re-run this script, to ensure that the buffer contains"
echo "any data we need."
echo
exit 1
else
echo "dmesg ring buffer: ok"
fi
}
#---------------
# Called by fnCONFIRM_PREREQS
#
fnSUDO()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
# Disallow direct execution by "root".
if [[ "${EUID}" -eq 0 ]]
then
echo
echo "ERROR:"
echo " Execution directly by \"root\" not permitted."
echo " Please run as a normal (non-root) userid."
echo " That userid must have \"sudo\" privileges."
echo
exit
fi
# Set "${SUDO}" so that commands that need
# root privs will run under sudo
SUDO=$(type -path sudo)
if [[ "${EUID}" -ne 0 ]] && [[ "${SUDO}" = "" ]]
then
echo
echo "${0} has not been run as root and sudo is not available, exiting." >&2
exit 1
else
echo "running as user: $(whoami)"
if [[ "${EUID}" -ne 0 ]]
then
if [[ -n "${SUDO}" ]]
then
echo "sudo is available: ok"
fi
fi
fi
}
#---------------
# Called by fnCONFIRM_PREREQS
# Calls fnBANNER
#
fnCHECK_VIRT()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
if [[ "$(systemd-detect-virt)" = "none" ]]
then
echo "virtual machine: ok"
else
echo
fnBANNER "RUNNING WITHIN A VIRTUAL MACHINE IS NOT SUPPORTED"
echo "This script does not support running inside a virtual machine."
echo "Please exit the VM and run the script again."
echo
exit 1
fi
}
#---------------
# Called by fnCONFIRM_PREREQS
# Calls fnBANNER
#
fnCHECK_CHROOT()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
if ${SUDO} systemd-detect-virt --chroot
then
echo
fnBANNER "RUNNING WITHIN A CHROOT'D ENVIRONMENT IS NOT SUPPORTED"
echo "This script does not support running in a chroot'd environment."
echo "Please exit the chroot'd environment and run the script again."
echo
exit 1
else
echo "chroot check: ok"
fi
echo
}
#---------------
# Called by fnCONFIRM_PREREQS
# Calls fnNEW_STYLE_REV_CODES and fnOLD_STYLE_REV_CODES
#
fnGET_REVISION_CODE()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
local PCB_REVISION=""
local MODEL_NAME=""
local PROCESSOR=""
local MANUFACTURER=""
local MEMORY_SIZE=""
local ENCODED_FLAG=""
local WARRANTY_VOID_OLD=""
local WARRANTY_VOID_NEW=""
# NOTE: Revision codes, old and new style, are documented here and elsewhere:
# https://github.com/raspberrypi/documentation/blob/master/hardware/raspberrypi/revision-codes/README.md
MY_REVISION=$(awk '/^Revision/ { print $NF }' /proc/cpuinfo 2>/dev/null)
# Force a rev code for testing...
# MY_REVISION=c03141 ; # CM4
# MY_REVISION=1000002 ; # Old rev, expired warranty
# MY_REVISION=0003 ; # Model B w/ mods
# MY_REVISION=2a020d3 ; # Model 3B+, expired warranty
# MY_REVISION=902120 ; # Zero 2 W
## The following revision-decoding logic was shamelessly borrowed from:
## https://raspberrypi.stackexchange.com/questions/100076/what-revisions-does-cat-proc-cpuinfo-return-on-the-new-pi-4-1-2-4gb
## I've made only some coding style changes to match the rest of this script,
## and accomodated new models released since the original post.
# These are from the new style revision codes, but we can borrow some
# of the values, for the old style codes. The arrays lack the "2.0"
# board revs, the "Qisda" manufacturer, and the "256/512" MB value used
# by some of the old-style revision codes. Rather than modify these
# arrays, I just use those values directly, in sorting out the old codes.
PCB_REVISION=("v1.0" "v1.1" "v1.2" "v1.3" "v1.4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15")
MODEL_NAME=("A" "B" "A+" "B+" "Pi2B" "Alpha" "CM1" "unknown" "3B" "Zero" "CM3" "unknown" "Zero W" "3B+" "3A+" "internal use only" "CM3+" "4B" "Zero 2 W" "400" "CM4")
PROCESSOR=("BCM2835" "BCM2836" "BCM2837" "BCM2711" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15")
MANUFACTURER=("Sony UK" "Egoman" "Embest" "Sony Japan" "Embest" "Stadium" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15")
MEMORY_SIZE=("256 MB" "512 MB" "1024 MB" "2048 MB" "4096 MB" "8192 MB" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15")
ENCODED_FLAG=("" "revision is a bit field")
# This adds a prefix of "1" to the revision code
WARRANTY_VOID_OLD=("" "warranty void - Pre Pi2")
# This adds a prefix of "2" to the revision code
WARRANTY_VOID_NEW=("" "warranty void - Post Pi2")
# Save as globals so we can make decisions later based on model, ram, etc.
MY_PCB_REVISION=${PCB_REVISION[$((0x${MY_REVISION}&0xf))]}
MY_MODEL_NAME=${MODEL_NAME[$((0x${MY_REVISION}>>4&0xff))]}
MY_PROCESSOR=${PROCESSOR[$((0x${MY_REVISION}>>12&0xf))]}
MY_MANUFACTURER=${MANUFACTURER[$((0x${MY_REVISION}>>16&0xf))]}
MY_MEMORY_SIZE=${MEMORY_SIZE[$((0x${MY_REVISION}>>20&7))]}
MY_ENCODED_FLAG=${ENCODED_FLAG[$((0x${MY_REVISION}>>23&1))]}
MY_WARRANTY_VOID_OLD=${WARRANTY_VOID_OLD[$((0x${MY_REVISION}>>24&1))]}
MY_WARRANTY_VOID_NEW=${WARRANTY_VOID_NEW[$((0x${MY_REVISION}>>25&1))]}
MY_COMMENT=""
MY_RELEASE_DATE=""
ENCODED=$((0x${MY_REVISION} >> 23 & 1))
if [[ ${ENCODED} = 1 ]]
then
# NEW STYLE REV CODES
# See if the rev code has a warranty-void prefix.
# If yes, a 1-char prefix ("1"=Bit 24, or "2"=Bit 25) is present
# and the last 6 chars are the actual revision code
if [[ "${#MY_REVISION}" = 7 ]]
then
MY_WARRANTY_VOID_PREFIX="$(echo "${MY_REVISION}" | cut -c1)"
# Trim off the prefix for other lookups later on.
MY_BASE_REVISION="$(echo "${MY_REVISION}" | cut -c2-)"
else
MY_WARRANTY_VOID_PREFIX=""
MY_BASE_REVISION="${MY_REVISION}"
fi
fnNEW_STYLE_REV_CODES
else
# OLD STYLE REV CODES
# See if the rev code has a warranty-void prefix
# If yes, the 3-char warranty-void prefix ("100") is present
# and the last 4 chars are the actual revision code
if [[ "${#MY_REVISION}" = 7 ]]
then
MY_WARRANTY_VOID_PREFIX="$(echo "${MY_REVISION}" | cut -c1-3)"
# Trim off the prefix for other lookups later on.
MY_BASE_REVISION="$(echo "${MY_REVISION}" | cut -c4-)"
else
# Otherwise, no prefix is present
MY_WARRANTY_VOID_PREFIX=""
MY_BASE_REVISION="${MY_REVISION}"
fi
fnOLD_STYLE_REV_CODES
fi
# Some features of the 4B, also present in later models, allow these
# to be lumped together for certain processing in this script. With
# this, they can all be treated in common fashion without having to
# check for each model type specifically.
case "${MY_MODEL_NAME}" in
4B|CM4|400)
PI4_FAMILY="1"
;;
*)
PI4_FAMILY="0"
;;
esac
# Here, I strip the lead alpha-character from the base revision number,
# that indicates the amount of RAM present (a=1GB, b=4GB, c=4GB, d=8GB),
# to get to the data that otherwise designates the model/rev.
# Pi 4B:
# Revision [abc]03111 is original board with USB-C power design flaw.
# Revision [abc]03112 is v1.2 board with fix.
# (First char, a, b, c or d, refers to 1GB, 2GB, 4GB, or 8GB memory.)
# Revision [bcd]03114 are the 2/4/8GB v1.4 board, which also has the fix.
if [[ "$(echo "${MY_REVISION}" | cut -c2-)" = "03111" ]]
then
MY_COMMENT="USB-C power design flaw affecting \"Smart\" USB-C cables."
fi
# Pi CM4:
# Educated guesses for the as yet unreleased CM4
if [[ "$(echo "${MY_REVISION}" | cut -c2-)" = "03141" ]]
then
MY_COMMENT="Guessing at this - CM4 rev codes not yet published."
fi
}
#---------------
# Called by fnGET_REVISION_CODE
#
fnNEW_STYLE_REV_CODES()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
case "${MY_BASE_REVISION}" in
a01040)
# 2 Model B
MY_RELEASE_DATE="Unknown"
;;
a01041)
# 2 Model B
MY_RELEASE_DATE="Q1 2015"
;;
a21041)
# 2 Model B
MY_RELEASE_DATE="Q1 2015"
;;
a22042)
# 2 Model B (with BCM2837)
MY_RELEASE_DATE="Q3 2016"
;;
900021)
# A+
MY_RELEASE_DATE="Q3 2016"
;;
900032)
# B+
MY_RELEASE_DATE="Q2 2016?"
;;
900092)
# Zero
MY_RELEASE_DATE="Q4 2015"
;;
900093)
# Zero
MY_RELEASE_DATE="Q2 2016"
;;
902120)
# Zero 2 W
MY_RELEASE_DATE="Q4 2021"
;;
920093)
# Zero
MY_RELEASE_DATE="Q4 2016?"
;;
9000c1)
# Zero W
MY_RELEASE_DATE="Q1 2017"
;;
a02082)
# 3 Model B
MY_RELEASE_DATE="Q1 2016"
;;
a020a0)
# CM3 (and CM3 Lite)
MY_RELEASE_DATE="Q1 2017"
;;
a22082)
# 3 Model B
MY_RELEASE_DATE="Q1 2016"
;;
a32082)
# 3 Model B
MY_RELEASE_DATE="Q4 2016"
;;
a020d3)
# 3 Model B+
MY_RELEASE_DATE="Q1 2018"
;;
9020e0)
# 3 Model A+
MY_RELEASE_DATE="Q4 2018"
;;
a02100)
# CM3+
MY_RELEASE_DATE="Q1 2019"
;;
[abc]03111)
# 4 Model B v1.1 - 1/2/4GB
MY_RELEASE_DATE="Q2 2019"
;;
a03112)
# 4 Model B v1.2 - 1GB
MY_RELEASE_DATE="Q1 2020 - Special Order Only"
;;
[bc]03112)
# 4 Model B v1.2 - 2/4GB
MY_RELEASE_DATE="Q1 2020"
;;
[bc]03114)
# 4 Model B v1.4 - 2/4GB
MY_RELEASE_DATE="Q3 2020"
;;
d03114)
# 4 Model B v1.4 - 8GB
MY_RELEASE_DATE="Q1 2020"
;;
c03130)
# Pi 400
MY_RELEASE_DATE="Q4 2020"
;;
[abcd]03141)
# CM4 - 1/2/4/8GB?
MY_RELEASE_DATE="Q4 2020"
;;
*)
# No match found
MY_RELEASE_DATE="Unknown"
;;
esac
}
#---------------
# Called by fnGET_REVISION_CODE
#
fnOLD_STYLE_REV_CODES()
{
echo -e "\nenter: ${FUNCNAME[*]}" >&3
case "${MY_BASE_REVISION}" in
0002)
# B 1.0 256MB
MY_PCB_REVISION=${PCB_REVISION[0]}
MY_MODEL_NAME=${MODEL_NAME[1]}
MY_PROCESSOR=${PROCESSOR[0]}
MY_MANUFACTURER=${MANUFACTURER[1]}
MY_MEMORY_SIZE=${MEMORY_SIZE[0]}
MY_RELEASE_DATE="Q1 2012"
;;
0003)
# B 1.0 256MB
MY_PCB_REVISION=${PCB_REVISION[0]}
MY_MODEL_NAME=${MODEL_NAME[1]}
MY_PROCESSOR=${PROCESSOR[0]}
MY_MANUFACTURER=${MANUFACTURER[1]}
MY_MEMORY_SIZE=${MEMORY_SIZE[0]}
MY_RELEASE_DATE="Q3 2012"
MY_COMMENT="No fuses, D14 removed"
;;
0004)
# B 2.0 256MB
MY_PCB_REVISION="2.0"
MY_MODEL_NAME=${MODEL_NAME[1]}
MY_PROCESSOR=${PROCESSOR[0]}
MY_MANUFACTURER=${MANUFACTURER[0]}
MY_RELEASE_DATE="Q3 2012"
MY_MEMORY_SIZE=${MEMORY_SIZE[0]}
;;
0005)
# B 2.0 256MB
MY_PCB_REVISION="2.0"
MY_MODEL_NAME=${MODEL_NAME[1]}
MY_PROCESSOR=${PROCESSOR[0]}
MY_MANUFACTURER="Qisda"
MY_MEMORY_SIZE=${MEMORY_SIZE[0]}
MY_RELEASE_DATE="Q4 2012"
;;
0006)
# B 2.0 256MB
MY_PCB_REVISION="2.0"
MY_MODEL_NAME=${MODEL_NAME[1]}
MY_PROCESSOR=${PROCESSOR[0]}
MY_MANUFACTURER=${MANUFACTURER[1]}
MY_MEMORY_SIZE=${MEMORY_SIZE[0]}
MY_RELEASE_DATE="Q4 2012"
;;
0007)
# A 2.0 256MB
MY_PCB_REVISION="2.0"
MY_MODEL_NAME=${MODEL_NAME[0]}
MY_PROCESSOR=${PROCESSOR[0]}
MY_MANUFACTURER=${MANUFACTURER[1]}
MY_MEMORY_SIZE=${MEMORY_SIZE[0]}
MY_RELEASE_DATE="Q1 2013"
;;
0008)
# A 2.0 256MB
MY_PCB_REVISION="2.0"
MY_MODEL_NAME=${MODEL_NAME[0]}
MY_PROCESSOR=${PROCESSOR[0]}
MY_MANUFACTURER=${MANUFACTURER[0]}
MY_MEMORY_SIZE=${MEMORY_SIZE[0]}
MY_RELEASE_DATE="Q1 2013"
;;
0009)
# A 2.0 256MB
MY_PCB_REVISION="2.0"
MY_MODEL_NAME=${MODEL_NAME[0]}