-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paths76-t20-test-setup.sh
More file actions
executable file
·2500 lines (2273 loc) · 139 KB
/
s76-t20-test-setup.sh
File metadata and controls
executable file
·2500 lines (2273 loc) · 139 KB
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
#!/bin/bash
# Flask service endpoint for submitting TEC data
FLASK_SERVICE_URL="http://10.17.89.69:7432/api"
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
SCRIPT_PATH="$(realpath "$0")"
AUTOSTART_DIR="${HOME}/.config/autostart"
AUTORUN_DESKTOP="${AUTOSTART_DIR}/s76-t20-test-setup.desktop"
UPDATE_MARKER="${HOME}/.update"
AUTORUN_CLEANUP_PENDING="false"
if [ ! -f "$UPDATE_MARKER" ]; then
mkdir -p "$AUTOSTART_DIR"
cat > "$AUTORUN_DESKTOP" <<EOF
[Desktop Entry]
Type=Application
Name=System76 T20 Setup
Comment=Resume T20 test setup after applying updates
Exec=$SCRIPT_PATH
Terminal=true
X-GNOME-Autostart-enabled=true
EOF
chmod +x "$AUTORUN_DESKTOP"
touch "$UPDATE_MARKER"
echo "Initial update phase detected. Installing system updates before T20 setup..."
if command -v apt-proxy &>/dev/null; then
APT_COMMAND="apt-proxy"
else
APT_COMMAND="sudo apt"
fi
until $APT_COMMAND update; do
echo "apt update failed, retrying in 10 seconds..."
sleep 10
done
$APT_COMMAND -y full-upgrade
echo "Updates applied. Rebooting to continue T20 setup."
sudo reboot
exit 0
else
# Don't remove marker/desktop files yet - we'll check for battery first
AUTORUN_CLEANUP_PENDING="true"
fi
# Check for battery and prompt user to note capacity, then shutdown for battery removal
# This must happen before any setup work (git clone, settings changes, etc.)
BATTERY_CAPACITY_FILE="/tmp/battery_capacity_wh.txt"
battery_device=$(ls /sys/class/power_supply/ 2>/dev/null | grep -E '^BAT[0-9]' | head -1)
# Cache system/chassis metadata for reuse throughout the script
DMI_TYPE0=$(sudo dmidecode --type 0 2>/dev/null)
DMI_TYPE1=$(sudo dmidecode --type 1 2>/dev/null)
DMI_TYPE2=$(sudo dmidecode --type 2 2>/dev/null)
DMI_TYPE17=$(sudo dmidecode --type 17 2>/dev/null)
DMI_CHASSIS=$(sudo dmidecode --type chassis 2>/dev/null)
BIOS_VENDOR=$(echo "$DMI_TYPE0" | grep "Vendor:" | head -1 | cut -d: -f2 | xargs)
BIOS_VERSION=$(echo "$DMI_TYPE0" | grep "Version:" | head -1 | cut -d: -f2 | xargs)
BIOS_DATE=$(echo "$DMI_TYPE0" | grep "Release Date:" | head -1 | cut -d: -f2 | xargs)
BIOS_RELEASE_DATE="$BIOS_DATE"
SYSTEM_MANUFACTURER=$(echo "$DMI_TYPE1" | grep "Manufacturer:" | head -1 | cut -d: -f2 | xargs)
PRODUCT_NAME=$(echo "$DMI_TYPE1" | grep "Product Name:" | head -1 | cut -d: -f2 | xargs)
SYSTEM_VERSION=$(echo "$DMI_TYPE1" | grep "Version:" | head -1 | cut -d: -f2 | xargs)
BASEBOARD_MANUFACTURER=$(echo "$DMI_TYPE2" | grep "Manufacturer:" | head -1 | cut -d: -f2 | xargs)
BASEBOARD_PRODUCT=$(echo "$DMI_TYPE2" | grep "Product Name:" | head -1 | cut -d: -f2 | xargs)
BASEBOARD_VERSION=$(echo "$DMI_TYPE2" | grep "Version:" | head -1 | cut -d: -f2 | xargs)
CHASSIS_TYPE=$(echo "$DMI_CHASSIS" | grep "Type:" | head -1 | cut -d: -f2 | xargs)
CHASSIS_MANUFACTURER=$(echo "$DMI_CHASSIS" | grep "Manufacturer:" | head -1 | cut -d: -f2 | xargs)
CHASSIS_VERSION=$(echo "$DMI_CHASSIS" | grep "Version:" | head -1 | cut -d: -f2 | xargs)
PRODUCT_LOWER=$(echo "$PRODUCT_NAME" | tr '[:upper:]' '[:lower:]')
VERSION_LOWER=$(echo "$SYSTEM_VERSION" | tr '[:upper:]' '[:lower:]')
BASEBOARD_VERSION_LOWER=$(echo "$BASEBOARD_VERSION" | tr '[:upper:]' '[:lower:]')
CHASSIS_TYPE_LOWER=$(echo "$CHASSIS_TYPE" | tr '[:upper:]' '[:lower:]')
IS_NOTEBOOK="false"
if [[ "$CHASSIS_TYPE_LOWER" == "notebook" || "$CHASSIS_TYPE_LOWER" == "laptop" ]]; then
IS_NOTEBOOK="true"
fi
IS_PORTABLE_ALL_IN_ONE="false"
if [[ "$CHASSIS_TYPE_LOWER" == portable* ]] || [[ "$CHASSIS_TYPE_LOWER" == "portable all in one" ]] || [[ "$PRODUCT_LOWER" == meer* ]] || [[ "$VERSION_LOWER" == meer* ]]; then
IS_PORTABLE_ALL_IN_ONE="true"
fi
BATTERY_REMOVED="false"
if [[ "$CHASSIS_TYPE" == "Notebook" || "$CHASSIS_TYPE" == "Laptop" ]] && [ -z "$battery_device" ]; then
BATTERY_REMOVED="true"
fi
if [ -n "$battery_device" ]; then
echo "=========================================="
echo "BATTERY DETECTED: ${battery_device}"
echo "=========================================="
echo ""
echo "Please check the battery label and note the capacity printed on it (in Wh)."
echo "The system will shutdown after you press Enter so you can remove the battery."
echo ""
read -p "Press Enter when ready to shutdown and remove the battery... "
echo ""
echo "Shutting down system in 5 seconds..."
sleep 5
sudo shutdown -h now
exit 0
fi
# Clean up autorun files after battery check
# Only keep them if this is a notebook and we just shut down for battery removal
# (which means we'll be autorunning again after the shutdown)
if [ "$AUTORUN_CLEANUP_PENDING" = "true" ]; then
# If we're here and battery was detected, the script would have already exited above
# So we only reach here if no battery was detected, meaning we can safely clean up
rm -f "$UPDATE_MARKER"
rm -f "$AUTORUN_DESKTOP"
fi
# If no battery detected, check for saved capacity from previous run
# If not found, prompt for capacity (engineer should have noted it before removing)
if [ -f "$BATTERY_CAPACITY_FILE" ]; then
battery_capacity_wh=$(cat "$BATTERY_CAPACITY_FILE" 2>/dev/null | xargs)
rm -f "$BATTERY_CAPACITY_FILE"
elif [ -f ~/battery_capacity_wh.txt ]; then
battery_capacity_wh=$(cat ~/battery_capacity_wh.txt 2>/dev/null | xargs)
rm -f ~/battery_capacity_wh.txt
else
# No battery and no saved capacity - check if this is a notebook
if [[ "$CHASSIS_TYPE" == "Notebook" || "$CHASSIS_TYPE" == "Laptop" ]]; then
echo "No battery detected. Please enter the battery capacity that was noted before removal."
read -p "Enter battery capacity from the label (in Wh): " battery_capacity_wh
echo ""
fi
fi
# Install necessary packages
# Try to use install.sh if it exists, otherwise fall back to direct apt install
if [ -f "$SCRIPT_DIR/install.sh" ]; then
"$SCRIPT_DIR/install.sh" git inxi powertop edid-decode ethtool jq bc
else
# Fallback: install packages directly using apt
PACKAGES="git inxi powertop edid-decode ethtool jq bc"
MISSING_PACKAGES=""
for pkg in $PACKAGES; do
if ! dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -q "ok installed"; then
MISSING_PACKAGES="$MISSING_PACKAGES $pkg"
fi
done
if [ -n "$MISSING_PACKAGES" ]; then
echo "Installing missing packages: $MISSING_PACKAGES" >&2
sudo apt update
sudo apt install -y $MISSING_PACKAGES
fi
fi
cd $HOME
if [ -e system76-ee ]; then
rm -rvf system76-ee
fi
git clone https://github.com/system76/system76-ee
_t20_cosmic=0
[ "${XDG_SESSION_DESKTOP:-}" = COSMIC ] && _t20_cosmic=1
case ":${XDG_CURRENT_DESKTOP:-}:" in *:COSMIC:*) _t20_cosmic=1 ;; esac
if [ "$_t20_cosmic" = 0 ] && command -v gsettings >/dev/null 2>&1; then
gsettings set org.gnome.desktop.session idle-delay 900
gsettings set org.gnome.desktop.background picture-uri-dark "file://${HOME}/system76-ee/RGB130130130.svg"
gsettings set org.gnome.desktop.background picture-uri "file://${HOME}/system76-ee/RGB130130130.svg"
gsettings set org.gnome.settings-daemon.plugins.power idle-dim false
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 1800
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type "suspend"
fi
# COSMIC only: approximate GNOME idle-delay 900s and AC suspend after 1800s (cosmic-idle uses ms, RON Option)
if [ "$_t20_cosmic" = 1 ] && command -v cosmic-idle >/dev/null 2>&1; then
_t20_cv1="${XDG_CONFIG_HOME:-$HOME/.config}/cosmic/com.system76.CosmicIdle/v1"
mkdir -p "$_t20_cv1"
printf '%s\n' "Some($((900 * 1000)))" > "$_t20_cv1/screen_off_time"
printf '%s\n' "Some($((1800 * 1000)))" > "$_t20_cv1/suspend_on_ac_time"
fi
xrandr --verbose | edid-decode > monitor-info.txt
inxi -Fxxxrza > inxi.txt
echo "Energy Efficient Ethernet" > EEE-info.txt
for device in $(nmcli device | awk '$2=="ethernet" {print $1}'); do
ethtool --show-eee $device >> EEE-info.txt
echo "" >> EEE-info.txt
done
echo "$DMI_TYPE17" > mem-info.txt
# Function to collect system information for TEC score calculation
# Function to calculate CIELUV gamut percentage from RGB and white xy coordinates
# This calculates the coverage percentage relative to sRGB/Adobe RGB color spaces
# Formula: u' = 4x / (-2x + 12y + 3), v' = 9y / (-2x + 12y + 3)
# CIELUV percentage = (display gamut area / reference gamut area) * 100
calculate_cieluv_gamut() {
local red_x="$1"
local red_y="$2"
local green_x="$3"
local green_y="$4"
local blue_x="$5"
local blue_y="$6"
local white_x="$7"
local white_y="$8"
# Helper function to convert xy to u'v'
xy_to_uv() {
local x="$1"
local y="$2"
local denom=$(echo "scale=10; -2 * $x + 12 * $y + 3" | bc)
local up=$(echo "scale=10; 4 * $x / $denom" | bc)
local vp=$(echo "scale=10; 9 * $y / $denom" | bc)
echo "$up $vp"
}
# Helper function to calculate triangle area from three u'v' points
triangle_area() {
local u1="$1"
local v1="$2"
local u2="$3"
local v2="$4"
local u3="$5"
local v3="$6"
local area=$(echo "scale=10; 0.5 * ($u1 * ($v2 - $v3) + $u2 * ($v3 - $v1) + $u3 * ($v1 - $v2))" | bc)
# Get absolute value
if (( $(echo "$area < 0" | bc -l) )); then
area=$(echo "scale=10; -($area)" | bc)
fi
echo "$area"
}
# Convert display RGB primaries to u'v'
local red_uv=$(xy_to_uv "$red_x" "$red_y")
local red_up=$(echo "$red_uv" | awk '{print $1}')
local red_vp=$(echo "$red_uv" | awk '{print $2}')
local green_uv=$(xy_to_uv "$green_x" "$green_y")
local green_up=$(echo "$green_uv" | awk '{print $1}')
local green_vp=$(echo "$green_uv" | awk '{print $2}')
local blue_uv=$(xy_to_uv "$blue_x" "$blue_y")
local blue_up=$(echo "$blue_uv" | awk '{print $1}')
local blue_vp=$(echo "$blue_uv" | awk '{print $2}')
# Calculate display gamut triangle area
local display_area=$(triangle_area "$red_up" "$red_vp" "$green_up" "$green_vp" "$blue_up" "$blue_vp")
# Standard sRGB primaries (D65 white point, Rec. 709)
# Red: x=0.640, y=0.330
# Green: x=0.300, y=0.600
# Blue: x=0.150, y=0.060
local srgb_red_uv=$(xy_to_uv "0.640" "0.330")
local srgb_red_up=$(echo "$srgb_red_uv" | awk '{print $1}')
local srgb_red_vp=$(echo "$srgb_red_uv" | awk '{print $2}')
local srgb_green_uv=$(xy_to_uv "0.300" "0.600")
local srgb_green_up=$(echo "$srgb_green_uv" | awk '{print $1}')
local srgb_green_vp=$(echo "$srgb_green_uv" | awk '{print $2}')
local srgb_blue_uv=$(xy_to_uv "0.150" "0.060")
local srgb_blue_up=$(echo "$srgb_blue_uv" | awk '{print $1}')
local srgb_blue_vp=$(echo "$srgb_blue_uv" | awk '{print $2}')
# Calculate sRGB gamut triangle area
local srgb_area=$(triangle_area "$srgb_red_up" "$srgb_red_vp" "$srgb_green_up" "$srgb_green_vp" "$srgb_blue_up" "$srgb_blue_vp")
# Standard Adobe RGB primaries (D65 white point)
# Red: x=0.6400, y=0.3300
# Green: x=0.2100, y=0.7100
# Blue: x=0.1500, y=0.0600
local adobergb_red_uv=$(xy_to_uv "0.6400" "0.3300")
local adobergb_red_up=$(echo "$adobergb_red_uv" | awk '{print $1}')
local adobergb_red_vp=$(echo "$adobergb_red_uv" | awk '{print $2}')
local adobergb_green_uv=$(xy_to_uv "0.2100" "0.7100")
local adobergb_green_up=$(echo "$adobergb_green_uv" | awk '{print $1}')
local adobergb_green_vp=$(echo "$adobergb_green_uv" | awk '{print $2}')
local adobergb_blue_uv=$(xy_to_uv "0.1500" "0.0600")
local adobergb_blue_up=$(echo "$adobergb_blue_uv" | awk '{print $1}')
local adobergb_blue_vp=$(echo "$adobergb_blue_uv" | awk '{print $2}')
# Calculate Adobe RGB gamut triangle area
local adobergb_area=$(triangle_area "$adobergb_red_up" "$adobergb_red_vp" "$adobergb_green_up" "$adobergb_green_vp" "$adobergb_blue_up" "$adobergb_blue_vp")
# Calculate coverage percentages
# Standard method: coverage = (display_gamut_area / reference_gamut_area) * 100
local srgb_coverage_raw=$(echo "scale=4; ($display_area / $srgb_area) * 100" | bc)
local adobergb_coverage_raw=$(echo "scale=4; ($display_area / $adobergb_area) * 100" | bc)
# Cap sRGB coverage at 100% (can't cover more than 100% of sRGB)
local srgb_numeric=$(echo "$srgb_coverage_raw" | sed 's/^\./0./')
if (( $(echo "$srgb_numeric > 100.0" | bc -l) )); then
srgb_numeric="100.0"
fi
local srgb_coverage=$(echo "scale=2; $srgb_numeric" | bc)
# The issue: simple area ratio overestimates Adobe RGB coverage
# Panelook uses a more accurate method that calculates actual color space coverage
# For a 100% sRGB panel, Adobe RGB coverage is typically 74-88%, not the raw area ratio
# Use empirical relationship: Adobe RGB coverage ≈ sRGB_coverage * 0.88
# This matches the observed relationship: 100% sRGB → 88% Adobe RGB
# The factor 0.88 comes from Panelook's data showing 88% Adobe RGB for 100% sRGB panels
local adobergb_coverage=$(echo "scale=2; $srgb_numeric * 0.88" | bc)
# The empirical relationship is more accurate than raw area ratio for Adobe RGB
# Only use the raw calculation if it's significantly lower (indicates display is much smaller)
# Otherwise, trust the empirical relationship which matches Panelook's method
local adobergb_raw_numeric=$(echo "$adobergb_coverage_raw" | sed 's/^\./0./')
local adobergb_numeric=$(echo "$adobergb_coverage" | sed 's/^\./0./')
# If raw is more than 20% lower than empirical, use raw (display is genuinely smaller)
# Otherwise, use empirical (more accurate for typical displays)
local diff=$(echo "scale=2; $adobergb_numeric - $adobergb_raw_numeric" | bc)
if (( $(echo "$diff > 20.0" | bc -l) )); then
adobergb_coverage=$(echo "scale=2; $adobergb_raw_numeric" | bc)
fi
# Cap Adobe RGB coverage at 100%
local adobergb_numeric=$(echo "$adobergb_coverage" | sed 's/^\./0./')
if (( $(echo "$adobergb_numeric > 100.0" | bc -l) )); then
adobergb_coverage="100.0"
fi
# CIELUV percentage for Title 20 classification
# The CIELUV percentage thresholds (32.9% and 38.4%) correspond to:
# - 32.9% CIELUV ≈ 90% sRGB coverage
# - 38.4% CIELUV ≈ 90% Adobe RGB coverage
# We'll use the sRGB coverage as the base CIELUV percentage
local cieluv_percentage="$srgb_coverage"
# Output: CIELUV percentage, sRGB coverage, Adobe RGB coverage
echo "$cieluv_percentage|$srgb_coverage|$adobergb_coverage"
}
collect_tec_info() {
local output_file="t20-eut.txt"
local json_file="t20-eut.json"
local es_response_file="" # Will be set if expandability calculation is performed
local has_discrete_gpu_detected="false"
echo "Collecting system information for TEC score calculation..."
echo ""
# Prompt for motherboard model number
read -p "Enter motherboard model number (or press Enter to skip): " motherboard_model_number
echo ""
# Prompt for power supply model number
read -p "Enter power supply model number (or press Enter to skip): " psu_model_manual
echo ""
# Initialize JSON object
{
echo "{"
echo " \"timestamp\": \"$(date -Iseconds)\","
# System Information
echo " \"system\": {"
echo " \"manufacturer\": \"${SYSTEM_MANUFACTURER}\","
echo " \"product_name\": \"${PRODUCT_NAME}\","
echo " \"version\": \"${SYSTEM_VERSION}\","
# BIOS Information
local bios_vendor="$BIOS_VENDOR"
local bios_version="$BIOS_VERSION"
local bios_date="$BIOS_RELEASE_DATE"
echo " \"bios_vendor\": \"${bios_vendor}\","
echo " \"bios_version\": \"${bios_version}\","
echo " \"bios_date\": \"${bios_date}\","
# Get chassis type early (needed for expandability prompt logic)
local chassis_type="$CHASSIS_TYPE"
local is_notebook="$IS_NOTEBOOK"
# Get identifiers for expandability lookup
local lookup_identifier=""
if [ -n "$SYSTEM_VERSION" ]; then
lookup_identifier="$SYSTEM_VERSION"
fi
# Look up expandability score from lookup file using baseboard version
local expandability_score=""
local mobile_gaming_system="false"
# Use SCRIPT_DIR set at top of script (before any cd commands)
local current_dir=$(pwd)
local lookup_file=""
# Try SCRIPT_DIR first (where script is located), then current directory
if [ -f "${SCRIPT_DIR}/system-expandability-scores.json" ]; then
lookup_file="${SCRIPT_DIR}/system-expandability-scores.json"
elif [ -f "${current_dir}/system-expandability-scores.json" ]; then
lookup_file="${current_dir}/system-expandability-scores.json"
else
lookup_file="${SCRIPT_DIR}/system-expandability-scores.json"
fi
if [ -f "$lookup_file" ] && command -v jq &> /dev/null; then
local lookup_key=""
local lookup_result=""
# First try baseboard version
if [ -n "$lookup_identifier" ]; then
lookup_key=$(echo "$lookup_identifier" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g')
if [ -n "$lookup_key" ]; then
lookup_result=$(jq -r ".[\"$lookup_key\"] // empty" "$lookup_file" 2>/dev/null)
# Only use if it's a valid number (not "null" string or empty)
if [ -n "$lookup_result" ] && [ "$lookup_result" != "null" ] && [[ "$lookup_result" =~ ^[0-9]+$ ]]; then
expandability_score="$lookup_result"
fi
fi
fi
fi
# If notebook has an expandability score, it must be a mobile gaming system
if [ -n "$expandability_score" ] && [ "$is_notebook" = "true" ]; then
mobile_gaming_system="true"
fi
# If expandability score not found, prompt user
# Skip this entire block if we already have a score (especially for notebooks)
if [ -z "$expandability_score" ]; then
# Create response file for expandability calculation
local system_name_safe=$(echo "$PRODUCT_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//')
es_response_file="${system_name_safe}-es.txt" # Make it accessible outside this block
# Initialize response file
{
echo "Expandability Score Calculation Responses"
echo "========================================"
echo "System: ${PRODUCT_NAME}"
echo "Expandability Lookup Identifier: ${lookup_identifier}"
echo "Date: $(date -Iseconds)"
echo ""
} > "$es_response_file"
local should_calculate_es="false"
if [ "$is_notebook" = "true" ]; then
# Battery capacity should already be set from the prompt at the start of the function
# If not set (shouldn't happen for notebooks), prompt now
if [ -z "$battery_capacity_wh" ]; then
read -p "Enter battery capacity in Wh: " battery_capacity_wh
[ -n "$battery_capacity_wh" ] && battery_capacity_wh_numeric=$(echo "$battery_capacity_wh" | tr -dc '0-9.')
fi
local can_be_mobile_gaming="false"
# Minimum battery capacity threshold for mobile gaming systems (75Wh)
# Systems below this cannot qualify as mobile gaming systems
local min_battery_capacity=75
# Check for discrete GPU (NVIDIA or AMD)
local has_discrete_gpu="$has_discrete_gpu_detected"
if command -v nvidia-smi &> /dev/null && nvidia-smi &>/dev/null 2>/dev/null; then
# Check if NVIDIA GPU is present and not just integrated
local gpu_name=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1 | xargs)
if [ -n "$gpu_name" ] && [[ ! "$gpu_name" =~ "Intel|integrated" ]]; then
has_discrete_gpu="true"
has_discrete_gpu_detected="true"
fi
fi
# Also check for AMD GPU via lspci
if [ "$has_discrete_gpu" != "true" ]; then
if lspci 2>/dev/null | grep -qi "vga.*amd\|display.*amd\|radeon"; then
has_discrete_gpu="true"
has_discrete_gpu_detected="true"
fi
fi
echo "" >> "$es_response_file"
echo "Battery Capacity: ${battery_capacity_wh} Wh" >> "$es_response_file"
echo "Has Discrete GPU: ${has_discrete_gpu}" >> "$es_response_file"
echo "System Memory (GB): ${total_memory_gb_numeric:-unknown}" >> "$es_response_file"
# Check battery capacity
local battery_check_passed="false"
if [ -n "$battery_capacity_wh" ] && [ "$(echo "$battery_capacity_wh >= $min_battery_capacity" | bc 2>/dev/null || echo "0")" = "1" ]; then
battery_check_passed="true"
echo "Battery capacity check: PASSED (≥${min_battery_capacity}Wh)" >> "$es_response_file"
elif [ -n "$battery_capacity_wh" ]; then
echo "Battery capacity check: FAILED (<${min_battery_capacity}Wh)" >> "$es_response_file"
fi
# Check discrete GPU
local gpu_check_passed="false"
if [ "$has_discrete_gpu" = "true" ]; then
gpu_check_passed="true"
echo "Discrete GPU check: PASSED" >> "$es_response_file"
else
echo "Discrete GPU check: FAILED" >> "$es_response_file"
fi
# Check system memory capacity (>=16 GB)
local memory_check_passed="false"
if [ -n "$total_memory_gb_numeric" ] && [ "$(echo "$total_memory_gb_numeric >= 16" | bc 2>/dev/null || echo "0")" = "1" ]; then
memory_check_passed="true"
echo "System memory check: PASSED (≥16GB)" >> "$es_response_file"
elif [ -n "$total_memory_gb_numeric" ]; then
echo "System memory check: FAILED (<16GB)" >> "$es_response_file"
else
echo "System memory check: UNKNOWN" >> "$es_response_file"
fi
# System can be mobile gaming only if both checks pass
if [ "$battery_check_passed" = "true" ] && [ "$gpu_check_passed" = "true" ] && [ "$memory_check_passed" = "true" ]; then
can_be_mobile_gaming="true"
else
local disqualification_reasons=()
if [ "$battery_check_passed" != "true" ]; then
disqualification_reasons+=("battery capacity below ${min_battery_capacity}Wh")
fi
if [ "$gpu_check_passed" != "true" ]; then
disqualification_reasons+=("no discrete GPU")
fi
if [ "$memory_check_passed" != "true" ]; then
disqualification_reasons+=("system memory below 16GB")
fi
echo "System cannot qualify as mobile gaming system due to: $(IFS=', '; echo "${disqualification_reasons[*]}")" >> "$es_response_file"
fi
if [ "$can_be_mobile_gaming" = "true" ]; then
# For notebooks, check if it's a mobile gaming system
echo "" >&2
echo "═══════════════════════════════════════════════════════════════" >&2
echo "MOBILE GAMING SYSTEM DETERMINATION" >&2
echo "═══════════════════════════════════════════════════════════════" >&2
echo "" >&2
echo "System: ${PRODUCT_NAME} (${lookup_identifier})" >&2
echo "Battery Capacity: ${battery_capacity_wh} Wh" >&2
echo "System Memory (GB): ${total_memory_gb_numeric:-unknown}" >&2
echo "" >&2
echo "A mobile gaming system is defined as a notebook computer that" >&2
echo "meets ALL of the following requirements:" >&2
echo "" >&2
echo " 1. Discrete GPU: Frame buffer bandwidth of at least 128 gigabytes/second." >&2
echo " 2. System memory: At least 16 gigabytes." >&2
echo " 3. External power supply: A nameplate output power of at least 150 W." >&2
echo " 4. Total battery capacity: At least \(75\) Wh." >&2
echo "" >&2
echo "═══════════════════════════════════════════════════════════════" >&2
read -p "Is this system a mobile gaming system? (y/n): " is_mobile_gaming
echo "" >> "$es_response_file"
echo "Is Mobile Gaming System: ${is_mobile_gaming}" >> "$es_response_file"
if [[ "$is_mobile_gaming" =~ ^[Yy] ]]; then
mobile_gaming_system="true"
should_calculate_es="true"
else
echo "Not a mobile gaming system. No expandability score needed." >&2
echo "Result: Not a mobile gaming system" >> "$es_response_file"
fi
else
echo "" >&2
local disqualification_msg=""
if [ "$battery_check_passed" != "true" ]; then
disqualification_msg="Battery capacity (${battery_capacity_wh} Wh) is below the minimum threshold (${min_battery_capacity}Wh)"
fi
if [ "$gpu_check_passed" != "true" ]; then
if [ -n "$disqualification_msg" ]; then
disqualification_msg="${disqualification_msg} and no discrete GPU detected"
else
disqualification_msg="No discrete GPU detected"
fi
fi
if [ "$memory_check_passed" != "true" ]; then
if [ -n "$disqualification_msg" ]; then
disqualification_msg="${disqualification_msg} and system memory below 16GB"
else
disqualification_msg="System memory below 16GB"
fi
fi
echo "System disqualified: ${disqualification_msg}" >&2
echo "Skipping mobile gaming system determination." >&2
echo "Result: Disqualified - ${disqualification_msg}" >> "$es_response_file"
fi
else
# For desktops/workstations, always calculate expandability score
should_calculate_es="true"
fi
# Calculate expandability score based on interface prompts
if [ "$should_calculate_es" = "true" ]; then
echo "" >&2
echo "═══════════════════════════════════════════════════════════════" >&2
echo "EXPANDABILITY SCORE CALCULATION" >&2
echo "═══════════════════════════════════════════════════════════════" >&2
echo "" >&2
echo "System: ${PRODUCT_NAME} (${lookup_identifier})" >&2
echo "" >&2
echo "Please enter the count for each interface on the mainboard:" >&2
echo "" >&2
echo "" >> "$es_response_file"
echo "Interface Counts:" >> "$es_response_file"
echo "-----------------" >> "$es_response_file"
# Define interface prompts and their scores
local total_score=100
# USB 2.0 or less
read -p "1. USB 2.0 or less (score: 5): " usb2_count
usb2_count=${usb2_count:-0}
echo "USB 2.0 or less: ${usb2_count}" >> "$es_response_file"
total_score=$((total_score + usb2_count * 5))
# USB 3.0 or 3.1 Gen 1
read -p "2. USB 3.0 or 3.1 Gen 1 (score: 10): " usb3_gen1_count
usb3_gen1_count=${usb3_gen1_count:-0}
echo "USB 3.0 or 3.1 Gen 1: ${usb3_gen1_count}" >> "$es_response_file"
total_score=$((total_score + usb3_gen1_count * 10))
# USB 3.1 Gen 2
read -p "3. USB 3.1 Gen 2 (score: 15): " usb3_gen2_count
usb3_gen2_count=${usb3_gen2_count:-0}
echo "USB 3.1 Gen 2: ${usb3_gen2_count}" >> "$es_response_file"
total_score=$((total_score + usb3_gen2_count * 15))
# USB/Thunderbolt 3.0+ that can provide 100W+
read -p "4. USB/Thunderbolt 3.0+ (100W+ power delivery) (score: 100): " tb_100w_count
tb_100w_count=${tb_100w_count:-0}
echo "USB/Thunderbolt 3.0+ (100W+): ${tb_100w_count}" >> "$es_response_file"
total_score=$((total_score + tb_100w_count * 100))
# USB/Thunderbolt 3.0+ that can provide 60-100W
read -p "5. USB/Thunderbolt 3.0+ (60-100W power delivery) (score: 60): " tb_60_100w_count
tb_60_100w_count=${tb_60_100w_count:-0}
echo "USB/Thunderbolt 3.0+ (60-100W): ${tb_60_100w_count}" >> "$es_response_file"
total_score=$((total_score + tb_60_100w_count * 60))
# USB/Thunderbolt 3.0+ that can provide 30-60W
read -p "6. USB/Thunderbolt 3.0+ (30-60W power delivery) (score: 30): " tb_30_60w_count
tb_30_60w_count=${tb_30_60w_count:-0}
echo "USB/Thunderbolt 3.0+ (30-60W): ${tb_30_60w_count}" >> "$es_response_file"
total_score=$((total_score + tb_30_60w_count * 30))
# Thunderbolt 3.0+ or USB ports (not otherwise addressed, can't provide 30W+)
read -p "7. Thunderbolt 3.0+ or USB (can't provide 30W+, not otherwise addressed) (score: 20): " tb_other_count
tb_other_count=${tb_other_count:-0}
echo "Thunderbolt 3.0+ or USB (other): ${tb_other_count}" >> "$es_response_file"
total_score=$((total_score + tb_other_count * 20))
# Unconnected USB 2.0 motherboard header
read -p "8. Unconnected USB 2.0 motherboard headers (score: 10 per header): " usb2_header_count
usb2_header_count=${usb2_header_count:-0}
echo "Unconnected USB 2.0 headers: ${usb2_header_count}" >> "$es_response_file"
total_score=$((total_score + usb2_header_count * 10))
# Unconnected USB 3.0 or 3.1 Gen 1 motherboard header
read -p "9. Unconnected USB 3.0 or 3.1 Gen 1 motherboard headers (score: 20 per header): " usb3_header_count
usb3_header_count=${usb3_header_count:-0}
echo "Unconnected USB 3.0 or 3.1 Gen 1 headers: ${usb3_header_count}" >> "$es_response_file"
total_score=$((total_score + usb3_header_count * 20))
# PCI slot other than PCIe x16 (mechanical slots only)
read -p "10. PCI slots (other than PCIe x16, mechanical only) (score: 25): " pci_other_count
pci_other_count=${pci_other_count:-0}
echo "PCI slots (other than PCIe x16): ${pci_other_count}" >> "$es_response_file"
total_score=$((total_score + pci_other_count * 25))
# PCIe x16 (mechanical slots only)
read -p "11. PCIe x16 slots (mechanical only) (score: 75): " pcie_x16_count
pcie_x16_count=${pcie_x16_count:-0}
echo "PCIe x16 slots: ${pcie_x16_count}" >> "$es_response_file"
total_score=$((total_score + pcie_x16_count * 75))
# Thunderbolt 2.0 or less
read -p "12. Thunderbolt 2.0 or less (score: 20): " tb2_count
tb2_count=${tb2_count:-0}
echo "Thunderbolt 2.0 or less: ${tb2_count}" >> "$es_response_file"
total_score=$((total_score + tb2_count * 20))
# M.2 (except key M)
read -p "13. M.2 slots (except key M) (score: 10): " m2_other_count
m2_other_count=${m2_other_count:-0}
echo "M.2 (except key M): ${m2_other_count}" >> "$es_response_file"
total_score=$((total_score + m2_other_count * 10))
# IDE, SATA, eSATA
read -p "14. IDE, SATA, or eSATA ports (score: 15): " sata_count
sata_count=${sata_count:-0}
echo "IDE, SATA, eSATA: ${sata_count}" >> "$es_response_file"
total_score=$((total_score + sata_count * 15))
# M.2, key M, SATA express, U.2
read -p "15. M.2 key M, SATA express, or U.2 ports (score: 25): " m2_keym_count
m2_keym_count=${m2_keym_count:-0}
echo "M.2 key M, SATA express, U.2: ${m2_keym_count}" >> "$es_response_file"
total_score=$((total_score + m2_keym_count * 25))
# Integrated liquid cooling
read -p "16. Integrated liquid cooling (score: 50): " liquid_cooling_count
liquid_cooling_count=${liquid_cooling_count:-0}
echo "Integrated liquid cooling: ${liquid_cooling_count}" >> "$es_response_file"
total_score=$((total_score + liquid_cooling_count * 50))
# Memory interface bonus: Either 1) CPU and motherboard support 4+ channels AND 8GB+ installed, OR 2) 8GB+ on 256-bit+ interface
echo "" >&2
echo "Memory Interface Bonus (score: 100):" >&2
echo " Either:" >&2
echo " 1) CPU and motherboard support for 4+ channels of system memory" >&2
echo " AND at least 8GB of installed compatible system memory; OR" >&2
echo " 2) At least 8GB of system memory installed on a 256-bit or" >&2
echo " greater memory interface" >&2
read -p "17. Does this system qualify for the memory interface bonus? (y/n): " memory_bonus
if [[ "$memory_bonus" =~ ^[Yy] ]]; then
echo "Memory Interface Bonus: Yes" >> "$es_response_file"
total_score=$((total_score + 100))
else
echo "Memory Interface Bonus: No" >> "$es_response_file"
fi
# Review/edit loop
local calculation_confirmed="false"
while [ "$calculation_confirmed" != "true" ]; do
# Recalculate total score
total_score=100
total_score=$((total_score + usb2_count * 5))
total_score=$((total_score + usb3_gen1_count * 10))
total_score=$((total_score + usb3_gen2_count * 15))
total_score=$((total_score + tb_100w_count * 100))
total_score=$((total_score + tb_60_100w_count * 60))
total_score=$((total_score + tb_30_60w_count * 30))
total_score=$((total_score + tb_other_count * 20))
total_score=$((total_score + usb2_header_count * 10))
total_score=$((total_score + usb3_header_count * 20))
total_score=$((total_score + pci_other_count * 25))
total_score=$((total_score + pcie_x16_count * 75))
total_score=$((total_score + tb2_count * 20))
total_score=$((total_score + m2_other_count * 10))
total_score=$((total_score + sata_count * 15))
total_score=$((total_score + m2_keym_count * 25))
total_score=$((total_score + liquid_cooling_count * 50))
if [[ "$memory_bonus" =~ ^[Yy] ]]; then
total_score=$((total_score + 100))
fi
expandability_score=$total_score
# Display summary of calculation
echo "" >&2
echo "═══════════════════════════════════════════════════════════════" >&2
echo "EXPANDABILITY SCORE CALCULATION SUMMARY" >&2
echo "═══════════════════════════════════════════════════════════════" >&2
echo "" >&2
printf "%-5s %-55s %5s %10s\n" "Num" "Interface Type" "Count" "Score" >&2
echo "─────────────────────────────────────────────────────────────────────────────────" >&2
printf "%-5s %-55s %5d %10d\n" " 1" "USB 2.0 or less" "$usb2_count" "$((usb2_count * 5))" >&2
printf "%-5s %-55s %5d %10d\n" " 2" "USB 3.0 or 3.1 Gen 1" "$usb3_gen1_count" "$((usb3_gen1_count * 10))" >&2
printf "%-5s %-55s %5d %10d\n" " 3" "USB 3.1 Gen 2" "$usb3_gen2_count" "$((usb3_gen2_count * 15))" >&2
printf "%-5s %-55s %5d %10d\n" " 4" "USB/Thunderbolt 3.0+ (100W+)" "$tb_100w_count" "$((tb_100w_count * 100))" >&2
printf "%-5s %-55s %5d %10d\n" " 5" "USB/Thunderbolt 3.0+ (60-100W)" "$tb_60_100w_count" "$((tb_60_100w_count * 60))" >&2
printf "%-5s %-55s %5d %10d\n" " 6" "USB/Thunderbolt 3.0+ (30-60W)" "$tb_30_60w_count" "$((tb_30_60w_count * 30))" >&2
printf "%-5s %-55s %5d %10d\n" " 7" "Thunderbolt 3.0+ or USB (other)" "$tb_other_count" "$((tb_other_count * 20))" >&2
printf "%-5s %-55s %5d %10d\n" " 8" "Unconnected USB 2.0 headers" "$usb2_header_count" "$((usb2_header_count * 10))" >&2
printf "%-5s %-55s %5d %10d\n" " 9" "Unconnected USB 3.0/3.1 Gen 1 headers" "$usb3_header_count" "$((usb3_header_count * 20))" >&2
printf "%-5s %-55s %5d %10d\n" "10" "PCI slots (other than PCIe x16)" "$pci_other_count" "$((pci_other_count * 25))" >&2
printf "%-5s %-55s %5d %10d\n" "11" "PCIe x16 slots" "$pcie_x16_count" "$((pcie_x16_count * 75))" >&2
printf "%-5s %-55s %5d %10d\n" "12" "Thunderbolt 2.0 or less" "$tb2_count" "$((tb2_count * 20))" >&2
printf "%-5s %-55s %5d %10d\n" "13" "M.2 (except key M)" "$m2_other_count" "$((m2_other_count * 10))" >&2
printf "%-5s %-55s %5d %10d\n" "14" "IDE, SATA, eSATA" "$sata_count" "$((sata_count * 15))" >&2
printf "%-5s %-55s %5d %10d\n" "15" "M.2 key M, SATA express, U.2" "$m2_keym_count" "$((m2_keym_count * 25))" >&2
printf "%-5s %-55s %5d %10d\n" "16" "Integrated liquid cooling" "$liquid_cooling_count" "$((liquid_cooling_count * 50))" >&2
if [[ "$memory_bonus" =~ ^[Yy] ]]; then
printf "%-5s %-55s %5s %10d\n" "17" "Memory Interface Bonus" "Yes" "100" >&2
else
printf "%-5s %-55s %5s %10d\n" "17" "Memory Interface Bonus" "No" "0" >&2
fi
echo "─────────────────────────────────────────────────────────────────────────────────" >&2
printf "%-5s %-55s %5s %10d\n" "" "Base Score (all systems)" "" "100" >&2
printf "%-5s %-55s %5s %10d\n" "" "Interface Contributions" "" "$((expandability_score - 100))" >&2
echo "─────────────────────────────────────────────────────────────────────────────────" >&2
printf "%-5s %-55s %5s %10d\n" "" "TOTAL EXPANDABILITY SCORE" "" "$expandability_score" >&2
echo "" >&2
echo "═══════════════════════════════════════════════════════════════" >&2
# Prompt for modification or acceptance
echo ""
read -p "Enter number to modify (1-17), or press Enter to accept [Current ES: ${expandability_score}]: " modify_choice
if [ -z "$modify_choice" ]; then
# User accepted, break out of loop
calculation_confirmed="true"
# Write final summary to response file
{
echo ""
echo "Final Calculation Summary:"
echo "─────────────────────────────────────────────────────────────────────"
echo "1. USB 2.0 or less: ${usb2_count} × 5 = $((usb2_count * 5))"
echo "2. USB 3.0 or 3.1 Gen 1: ${usb3_gen1_count} × 10 = $((usb3_gen1_count * 10))"
echo "3. USB 3.1 Gen 2: ${usb3_gen2_count} × 15 = $((usb3_gen2_count * 15))"
echo "4. USB/Thunderbolt 3.0+ (100W+): ${tb_100w_count} × 100 = $((tb_100w_count * 100))"
echo "5. USB/Thunderbolt 3.0+ (60-100W): ${tb_60_100w_count} × 60 = $((tb_60_100w_count * 60))"
echo "6. USB/Thunderbolt 3.0+ (30-60W): ${tb_30_60w_count} × 30 = $((tb_30_60w_count * 30))"
echo "7. Thunderbolt 3.0+ or USB (other): ${tb_other_count} × 20 = $((tb_other_count * 20))"
echo "8. Unconnected USB 2.0 headers: ${usb2_header_count} × 10 = $((usb2_header_count * 10))"
echo "9. Unconnected USB 3.0/3.1 Gen 1 headers: ${usb3_header_count} × 20 = $((usb3_header_count * 20))"
echo "10. PCI slots (other than PCIe x16): ${pci_other_count} × 25 = $((pci_other_count * 25))"
echo "11. PCIe x16 slots: ${pcie_x16_count} × 75 = $((pcie_x16_count * 75))"
echo "12. Thunderbolt 2.0 or less: ${tb2_count} × 20 = $((tb2_count * 20))"
echo "13. M.2 (except key M): ${m2_other_count} × 10 = $((m2_other_count * 10))"
echo "14. IDE, SATA, eSATA: ${sata_count} × 15 = $((sata_count * 15))"
echo "15. M.2 key M, SATA express, U.2: ${m2_keym_count} × 25 = $((m2_keym_count * 25))"
echo "16. Integrated liquid cooling: ${liquid_cooling_count} × 50 = $((liquid_cooling_count * 50))"
if [[ "$memory_bonus" =~ ^[Yy] ]]; then
echo "17. Memory Interface Bonus: Yes × 100 = 100"
else
echo "17. Memory Interface Bonus: No × 100 = 0"
fi
echo "─────────────────────────────────────────────────────────────────────"
echo "Base Score (all systems): 100"
echo "Interface Contributions: $((expandability_score - 100))"
echo "TOTAL EXPANDABILITY SCORE: ${expandability_score}"
} >> "$es_response_file"
echo "Calculation confirmed. Expandability Score: ${expandability_score}" >&2
else
# User wants to modify a specific entry
case "$modify_choice" in
1)
read -p "USB 2.0 or less (score: 5): " usb2_count
usb2_count=${usb2_count:-0}
echo "Updated: USB 2.0 or less: ${usb2_count}" >> "$es_response_file"
;;
2)
read -p "USB 3.0 or 3.1 Gen 1 (score: 10): " usb3_gen1_count
usb3_gen1_count=${usb3_gen1_count:-0}
echo "Updated: USB 3.0 or 3.1 Gen 1: ${usb3_gen1_count}" >> "$es_response_file"
;;
3)
read -p "USB 3.1 Gen 2 (score: 15): " usb3_gen2_count
usb3_gen2_count=${usb3_gen2_count:-0}
echo "Updated: USB 3.1 Gen 2: ${usb3_gen2_count}" >> "$es_response_file"
;;
4)
read -p "USB/Thunderbolt 3.0+ (100W+ power delivery) (score: 100): " tb_100w_count
tb_100w_count=${tb_100w_count:-0}
echo "Updated: USB/Thunderbolt 3.0+ (100W+): ${tb_100w_count}" >> "$es_response_file"
;;
5)
read -p "USB/Thunderbolt 3.0+ (60-100W power delivery) (score: 60): " tb_60_100w_count
tb_60_100w_count=${tb_60_100w_count:-0}
echo "Updated: USB/Thunderbolt 3.0+ (60-100W): ${tb_60_100w_count}" >> "$es_response_file"
;;
6)
read -p "USB/Thunderbolt 3.0+ (30-60W power delivery) (score: 30): " tb_30_60w_count
tb_30_60w_count=${tb_30_60w_count:-0}
echo "Updated: USB/Thunderbolt 3.0+ (30-60W): ${tb_30_60w_count}" >> "$es_response_file"
;;
7)
read -p "Thunderbolt 3.0+ or USB (can't provide 30W+, not otherwise addressed) (score: 20): " tb_other_count
tb_other_count=${tb_other_count:-0}
echo "Updated: Thunderbolt 3.0+ or USB (other): ${tb_other_count}" >> "$es_response_file"
;;
8)
read -p "Unconnected USB 2.0 motherboard headers (score: 10 per header): " usb2_header_count
usb2_header_count=${usb2_header_count:-0}
echo "Updated: Unconnected USB 2.0 headers: ${usb2_header_count}" >> "$es_response_file"
;;
9)
read -p "Unconnected USB 3.0 or 3.1 Gen 1 motherboard headers (score: 20 per header): " usb3_header_count
usb3_header_count=${usb3_header_count:-0}
echo "Updated: Unconnected USB 3.0 or 3.1 Gen 1 headers: ${usb3_header_count}" >> "$es_response_file"
;;
10)
read -p "PCI slots (other than PCIe x16, mechanical only) (score: 25): " pci_other_count
pci_other_count=${pci_other_count:-0}
echo "Updated: PCI slots (other than PCIe x16): ${pci_other_count}" >> "$es_response_file"
;;
11)
read -p "PCIe x16 slots (mechanical only) (score: 75): " pcie_x16_count
pcie_x16_count=${pcie_x16_count:-0}
echo "Updated: PCIe x16 slots: ${pcie_x16_count}" >> "$es_response_file"
;;
12)
read -p "Thunderbolt 2.0 or less (score: 20): " tb2_count
tb2_count=${tb2_count:-0}
echo "Updated: Thunderbolt 2.0 or less: ${tb2_count}" >> "$es_response_file"
;;
13)
read -p "M.2 slots (except key M) (score: 10): " m2_other_count
m2_other_count=${m2_other_count:-0}
echo "Updated: M.2 (except key M): ${m2_other_count}" >> "$es_response_file"
;;
14)
read -p "IDE, SATA, or eSATA ports (score: 15): " sata_count
sata_count=${sata_count:-0}
echo "Updated: IDE, SATA, eSATA: ${sata_count}" >> "$es_response_file"
;;
15)
read -p "M.2 key M, SATA express, or U.2 ports (score: 25): " m2_keym_count
m2_keym_count=${m2_keym_count:-0}
echo "Updated: M.2 key M, SATA express, U.2: ${m2_keym_count}" >> "$es_response_file"
;;
16)
read -p "Integrated liquid cooling (score: 50): " liquid_cooling_count
liquid_cooling_count=${liquid_cooling_count:-0}
echo "Updated: Integrated liquid cooling: ${liquid_cooling_count}" >> "$es_response_file"
;;
17)
echo "" >&2
echo "Memory Interface Bonus (score: 100):" >&2
echo " Either:" >&2
echo " 1) CPU and motherboard support for 4+ channels of system memory" >&2
echo " AND at least 8GB of installed compatible system memory; OR" >&2
echo " 2) At least 8GB of system memory installed on a 256-bit or" >&2
echo " greater memory interface" >&2
read -p "Does this system qualify for the memory interface bonus? (y/n): " memory_bonus
if [[ "$memory_bonus" =~ ^[Yy] ]]; then
echo "Updated: Memory Interface Bonus: Yes" >> "$es_response_file"
else
echo "Updated: Memory Interface Bonus: No" >> "$es_response_file"
fi
;;
*)
echo "Invalid choice. Please enter a number from 1-17."
;;
esac
# Recalculate expandability score after modification
if [ "$modify_choice" -ge 1 ] && [ "$modify_choice" -le 17 ]; then
total_score=100
total_score=$((total_score + usb2_count * 5))
total_score=$((total_score + usb3_gen1_count * 10))
total_score=$((total_score + usb3_gen2_count * 15))
total_score=$((total_score + tb_100w_count * 100))
total_score=$((total_score + tb_60_100w_count * 60))
total_score=$((total_score + tb_30_60w_count * 30))
total_score=$((total_score + tb_other_count * 20))
total_score=$((total_score + usb2_header_count * 10))
total_score=$((total_score + usb3_header_count * 20))
total_score=$((total_score + pci_other_count * 25))
total_score=$((total_score + pcie_x16_count * 75))
total_score=$((total_score + tb2_count * 20))
total_score=$((total_score + m2_other_count * 10))
total_score=$((total_score + sata_count * 15))
total_score=$((total_score + m2_keym_count * 25))
total_score=$((total_score + liquid_cooling_count * 50))
if [[ "$memory_bonus" =~ ^[Yy] ]]; then
total_score=$((total_score + 100))
fi
expandability_score=$total_score
echo "Updated Expandability Score: ${expandability_score}" >&2
fi
fi
done
# Write confirmation to response file
echo "" >> "$es_response_file"
echo "Calculation Confirmed: Yes" >> "$es_response_file"
# Offer to save to lookup file
if [ -n "$expandability_score" ] && [ -n "$lookup_identifier" ] && [ -f "$lookup_file" ] && command -v jq &> /dev/null; then
local lookup_key=$(echo "$lookup_identifier" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g')
if [ -n "$lookup_key" ]; then
read -p "Save this score to lookup file for future use? (y/n): " save_score
if [[ "$save_score" =~ ^[Yy] ]]; then
local temp_file=$(mktemp)
jq ". + {\"$lookup_key\": $expandability_score}" "$lookup_file" > "$temp_file" && mv "$temp_file" "$lookup_file"
echo "Score saved to lookup file."
echo "Saved to lookup file: Yes" >> "$es_response_file"
else
echo "Saved to lookup file: No" >> "$es_response_file"
fi
fi
fi
fi
fi
# Get baseboard information for system object
local baseboard_manufacturer="$BASEBOARD_MANUFACTURER"
local baseboard_product="$BASEBOARD_PRODUCT"
local baseboard_version="$BASEBOARD_VERSION"
echo " \"baseboard_manufacturer\": \"${baseboard_manufacturer}\","
echo " \"baseboard_product\": \"${baseboard_product}\","
echo " \"baseboard_version\": \"${baseboard_version}\","
if [ -n "$lookup_identifier" ]; then
echo " \"expandability_lookup_identifier\": \"${lookup_identifier}\","
else
echo " \"expandability_lookup_identifier\": null,"
fi
if [ -n "$motherboard_model_number" ]; then
echo " \"motherboard_model_number\": \"${motherboard_model_number}\","
else
echo " \"motherboard_model_number\": null,"
fi
echo " \"is_notebook\": ${is_notebook},"
# Determine system classification
local system_classification="Desktop"
if [[ "$chassis_type" == "Notebook" || "$chassis_type" == "Laptop" ]]; then
system_classification="Notebook"
elif [[ "$chassis_type" == "Tower" || "$chassis_type" == "Desktop" ]]; then
# Check if it's a workstation (typically has professional GPU or ECC memory)
if command -v nvidia-smi &> /dev/null && nvidia-smi &>/dev/null; then
local gpu_name=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -1)
if [[ "$gpu_name" =~ "Quadro|Tesla|RTX.*A|RTX.*Pro" ]]; then
system_classification="Workstation"
fi
fi
# Check for ECC memory (typically indicates workstation/server)
if echo "$DMI_TYPE17" | grep -qi "Error Correction Type.*ECC\|Single-bit ECC"; then
system_classification="Workstation"
fi
fi
echo " \"classification\": \"${system_classification}\""