Skip to content

Commit ac6e77e

Browse files
committed
v8.0
+ DietPi-Survey | Add an info whether an SD card or eMMC module is used as root filesystem. This is useful for us to estimate how much filesystem write reduction needs to be weighted. Actually it would be better to detect SD card exclusively, since eMMC modules are designed to be used as OS drives and are hence expected to survive longer in average, but I don't know any simple method to do so currently. + DietPi-Survey/BugReport | Add a check whether our SSH host key is present on the system, else offer to have it re-added to allow proceeding with the survey/bug report upload/purge.
1 parent 08b27f2 commit ac6e77e

File tree

3 files changed

+62
-29
lines changed

3 files changed

+62
-29
lines changed

.meta/dietpi-survey_report

+10-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ shopt -s extglob
158158
declare -A aGIT_BRANCH
159159
# v6.31 addition
160160
aRASPBIAN=(0 0)
161+
# v8.0 addition
162+
aMMC=(0 0)
161163

162164
# Convert autostart index to name array
163165
# shellcheck disable=SC2034
@@ -595,7 +597,7 @@ shopt -s extglob
595597
# $1 = File name
596598
Process_File()
597599
{
598-
local file=$1 version branch device arch cpu_count distro autostart automated iface raspbian software asoftware=()
600+
local file=$1 version branch device arch cpu_count distro autostart automated iface raspbian software asoftware=() mmc
599601
local BENCH_VERSION BENCH_HW_MODEL BENCH_CPU BENCH_ROOTFS_WRITE BENCH_ROOTFS_READ BENCH_RAM_WRITE BENCH_RAM_READ BENCH_CUSTOMFS_WRITE BENCH_CUSTOMFS_READ BENCH_CPU_TEMP_START BENCH_CPU_TEMP_END BENCH_NET_LAN_SPEED
600602
while read -r line
601603
do
@@ -615,6 +617,7 @@ shopt -s extglob
615617
'((aAUTO_SETUP_AUTOMATED['[01]']++))') automated=${line#*'['} automated=${automated%']'*};;
616618
'((aNETWORK_INTERFACE['+([[:graph:]])']++))') iface=${line#*'['} iface=${iface%']'*};;
617619
'((aRASPBIAN['[01]']++))') raspbian=${line#*'['} raspbian=${raspbian%']'*};; # since v6.31
620+
'MMC='[01]) mmc=${line#*'='};;
618621
'((aSOFTWARE[${aSOFTWARE_NAME'${version/./_}'['+([[:digit:]])']:='+([[:digit:]])'}]++))') software=${line##*'['} software=${software%%']'*};;
619622
'((aSOFTWARE[${aSOFTWARE_NAME'${version/./_}'['+([[:digit:]])']}]++))') software=${line##*'['} software=${software%%']'*};; # Pre-v6.17
620623
'BENCH_VERSION='[12]) BENCH_VERSION=${line#*'='};; # 1 until v6.23, 2 afterwards
@@ -684,6 +687,7 @@ shopt -s extglob
684687
((aAUTO_SETUP_AUTOMATED["$automated"]++))
685688
((aNETWORK_INTERFACE["$iface"]++))
686689
[[ $raspbian ]] && ((aRASPBIAN["$raspbian"]++))
690+
[[ $mmc ]] && ((aMMC["$mmc"]++))
687691
for i in "${asoftware[@]}"
688692
do
689693
((aSOFTWARE["$i"]++))
@@ -1114,6 +1118,11 @@ shopt -s extglob
11141118
<tr><td>Debian is used by</td><td align="right">${aRASPBIAN[0]} of $(( ${aRASPBIAN[0]} + ${aRASPBIAN[1]} )) RPi systems</td><td align=\"right\">$(( ${aRASPBIAN[0]} * 100 / ( ${aRASPBIAN[0]} + ${aRASPBIAN[1]} ) ))%</td></tr>
11151119
</table>
11161120
1121+
<h2 id="mmc"><a href="#mmc">SD card/eMMC used &para</a></h2>
1122+
<table>
1123+
<tr><td>SD card or eMMC used as rootfs by</td><td align="right">${aMMC[1]} of $(( ${aMMC[0]} + ${aMMC[1]} )) systems</td><td align=\"right\">$(( ${aMMC[1]} * 100 / ( ${aMMC[0]} + ${aMMC[1]} ) ))%</td></tr>
1124+
</table>
1125+
11171126
<h2 id="autostart"><a href="#autostart">Autostart options &para</a></h2>
11181127
<table>
11191128
$(for i in "${!aAUTOSTART_OPTION[@]}"; do echo "<tr><td>$i</td><td align=\"right\"> ${aAUTOSTART_OPTION[$i]}</td><td align=\"right\">$(( ${aAUTOSTART_OPTION[$i]} * 100 / $SURVEY_COUNT_OPTIN ))%</td></tr>"; done | sort -nrk 2 -t ' ')

dietpi/dietpi-bugreport

+15
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ Available commands:
160160

161161
Upload_Bug_Report(){
162162

163+
# Check if our ssh.dietpi.com SSH host key is present
164+
if [[ ! -f '/root/.ssh/known_hosts' ]] || ! grep -q '^ssh.dietpi.com[[:blank:]]' /root/.ssh/known_hosts
165+
then
166+
# If missing, offer to re-add it
167+
if G_WHIP_YESNO '[WARNING] ssh.dietpi.com SSH host key is missing\nOur ssh.dietpi.com SSH host key, required to send or purge survey data and bug reports, is missing in /root/.ssh/known_hosts. Shall we re-create it to proceed with sending/purging the bug report?'
168+
then
169+
[[ -d '/root/.ssh' ]] || G_EXEC mkdir /root/.ssh
170+
[[ -f '/root/.ssh/known_hosts' ]] || > /root/.ssh/known_hosts
171+
G_CONFIG_INJECT 'ssh.dietpi.com[[:blank:]]' 'ssh.dietpi.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDE6aw3r6aOEqendNu376iiCHr9tGBIWPgfrLkzjXjEsHGyVSUFNnZt6pftrDeK7UX+qX4FxOwQlugG4fymOHbimRCFiv6cf7VpYg1Ednquq9TLb7/cIIbX8a6AuRmX4fjdGuqwmBq3OG7ZksFcYEFKt5U4mAJIaL8hXiM2iXjgY02LqiQY/QWATsHI4ie9ZOnwrQE+Rr6mASN1BVFuIgyHIbwX54jsFSnZ/7CdBMkuAd9B8JkxppWVYpYIFHE9oWNfjh/epdK8yv9Oo6r0w5Rb+4qaAc5g+RAaknHeV6Gp75d2lxBdCm5XknKKbGma2+/DfoE8WZTSgzXrYcRlStYN' /root/.ssh/known_hosts
172+
else
173+
G_DIETPI-NOTIFY 1 'Skipping sending/purging the bug report as our ssh.dietpi.com SSH host key is missing in /root/.ssh/known_hosts...'
174+
exit 1
175+
fi
176+
fi
177+
163178
[[ $INPUT == 1 ]] && G_EXEC_DESC='Sending bug report' || G_EXEC_DESC='Purging bug report'
164179

165180
G_EXEC curl --key '' --connect-timeout 8 --retry 1 --retry-delay 4 -sSvT "$UPLOAD_FILENAME" "sftp://$SFTP_USER:$SFTP_PASS@$SFTP_ADDR/bugreport/"

dietpi/dietpi-survey

+37-28
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Info:
1212
# - Allows to send DietPi usage info via SFTP to DietPi server
1313
# - Includes hardware info, DietPi version+branch, installed software, benchmark results and some setup info
14-
# - No private data is sent, no one can indentify you.
14+
# - No private data is sent, no one can identify you.
1515
# - Runs after every dietpi-update and dietpi-software install, if user opted in
1616
# - Summary can be visited at: https://dietpi.com/survey/
1717
# - Allows the DietPi project to focus development based on popularity
@@ -31,8 +31,6 @@
3131
G_INIT
3232
# Import DietPi-Globals --------------------------------------------------------------
3333

34-
EXIT_CODE=1
35-
3634
# Grab input
3735
[[ $1 == 1 ]] && INPUT=1 || INPUT=0
3836

@@ -50,14 +48,18 @@
5048
local gitbranch="$G_GITOWNER/$G_GITBRANCH"
5149

5250
# Active network interface
53-
local network_interface=$(G_GET_NET iface)
51+
local network_interface=$(G_GET_NET -q iface)
5452
[[ $network_interface ]] || network_interface='NONE'
5553

5654
# Autostart index
5755
local autostart_index
5856
[[ -f '/boot/dietpi/.dietpi-autostart_index' ]] && autostart_index=$(</boot/dietpi/.dietpi-autostart_index)
5957
[[ $autostart_index ]] || autostart_index=0
6058

59+
# rootfs on SD card/eMMC?
60+
local mmc=0
61+
[[ $G_ROOTFS_DEV == '/dev/mmcblk'* ]] && mmc=1
62+
6163
cat << _EOF_ > "$FP_UPLOAD"
6264
#!/bin/bash
6365
((aDIETPI_VERSION[$version]++))
@@ -69,14 +71,15 @@
6971
((aAUTOSTART_OPTION[\${aAUTOSTART_NAME[$autostart_index]:=$autostart_index}]++))
7072
((aAUTO_SETUP_AUTOMATED[$(grep -cm1 '^[[:blank:]]*AUTO_SETUP_AUTOMATED=1' /boot/dietpi.txt)]++))
7173
((aNETWORK_INTERFACE[$network_interface]++))
74+
MMC=$mmc
7275
_EOF_
7376

74-
# RPi: Raspbian/Raspberry Pi OS (32-bt) or Debian/Raspberry Pi OS (64-bit)?
77+
# RPi: Raspbian/Raspberry Pi OS (32-bit) or Debian/Raspberry Pi OS (64-bit)?
7578
(( $G_HW_MODEL < 10 )) && echo "((aRASPBIAN[$G_RASPBIAN]++))" >> "$FP_UPLOAD"
7679

7780
# DietPi-Software installs
78-
if [[ -f '/boot/dietpi/.installed' ]]; then
79-
81+
if [[ -f '/boot/dietpi/.installed' ]]
82+
then
8083
echo -e '# -------------------------\n# DietPi-Software installs\n# -------------------------' >> "$FP_UPLOAD"
8184

8285
while read -r software
@@ -86,7 +89,6 @@ _EOF_
8689
disable_error=1 G_CHECK_VALIDINT "$software" && echo "((aSOFTWARE[\${aSOFTWARE_NAME${G_DIETPI_VERSION_CORE}_${G_DIETPI_VERSION_SUB}[$software]:=$software}]++))" >> "$FP_UPLOAD"
8790

8891
done < <(grep ']=2$' /boot/dietpi/.installed)
89-
9092
fi
9193

9294
# DietPi-Benchmark results
@@ -96,23 +98,35 @@ _EOF_
9698

9799
Send_File(){
98100

99-
if (( $OPTED_IN )); then
101+
# Check if our ssh.dietpi.com SSH host key is present
102+
if [[ ! -f '/root/.ssh/known_hosts' ]] || ! grep -q '^ssh.dietpi.com[[:blank:]]' /root/.ssh/known_hosts
103+
then
104+
# If missing, offer to re-add it
105+
if G_WHIP_YESNO '[WARNING] ssh.dietpi.com SSH host key is missing\nOur ssh.dietpi.com SSH host key, required to send or purge survey data and bug reports, is missing in /root/.ssh/known_hosts. Shall we re-create it to proceed with sending/purging the bug report?'
106+
then
107+
[[ -d '/root/.ssh' ]] || G_EXEC mkdir /root/.ssh
108+
[[ -f '/root/.ssh/known_hosts' ]] || > /root/.ssh/known_hosts
109+
G_CONFIG_INJECT 'ssh.dietpi.com[[:blank:]]' 'ssh.dietpi.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDE6aw3r6aOEqendNu376iiCHr9tGBIWPgfrLkzjXjEsHGyVSUFNnZt6pftrDeK7UX+qX4FxOwQlugG4fymOHbimRCFiv6cf7VpYg1Ednquq9TLb7/cIIbX8a6AuRmX4fjdGuqwmBq3OG7ZksFcYEFKt5U4mAJIaL8hXiM2iXjgY02LqiQY/QWATsHI4ie9ZOnwrQE+Rr6mASN1BVFuIgyHIbwX54jsFSnZ/7CdBMkuAd9B8JkxppWVYpYIFHE9oWNfjh/epdK8yv9Oo6r0w5Rb+4qaAc5g+RAaknHeV6Gp75d2lxBdCm5XknKKbGma2+/DfoE8WZTSgzXrYcRlStYN' /root/.ssh/known_hosts
110+
else
111+
G_DIETPI-NOTIFY 1 'Skipping sending/purging survey data as our ssh.dietpi.com SSH host key is missing in /root/.ssh/known_hosts...'
112+
return 1
113+
fi
114+
fi
100115

116+
if (( $OPTED_IN ))
117+
then
101118
[[ -f $FP_UPLOAD ]] || Generate_File
102-
103119
else
104-
105-
# Send empty file to overwrite existing data, rm is not possible due to missing file list permissions
120+
# Send empty file to overwrite existing data, "rm" is not possible due to missing file list permissions
106121
> "$FP_UPLOAD"
107-
108122
fi
109123

110124
# Upload to server
111125
local timeout=$(sed -n '/^[[:blank:]]*CONFIG_G_CHECK_URL_TIMEOUT=/{s/^[^=]*=//p;q}' /boot/dietpi.txt) G_EXEC_DESC='Sending survey data'
112126
(( $OPTED_IN )) || G_EXEC_DESC='Purging survey data'
113-
# - Timeout times 2 for DNS resolving + connection, upload itself is done in no time
114-
G_EXEC_NOHALT=1 G_EXEC curl --key '' -m $(( ${timeout:-5} * 2 )) -sT "$FP_UPLOAD" sftp://$SFTP_USER:$SFTP_PASS@$SFTP_ADDR/survey/
115-
EXIT_CODE=$?
127+
# - Timeout x2 for DNS resolving + connection, upload itself is done in no time
128+
G_EXEC_NOHALT=1 G_EXEC curl --key '' -m $(( ${timeout:-5} * 2 )) -sT "$FP_UPLOAD" "sftp://$SFTP_USER:$SFTP_PASS@$SFTP_ADDR/survey/"
129+
return $?
116130

117131
}
118132

@@ -122,13 +136,12 @@ _EOF_
122136
# Read opt in/out choice: 1=yes and send data | 0=no and purge data
123137
OPTED_IN=$(sed -n '/^[[:blank:]]*SURVEY_OPTED_IN=[01]$/{s/^[^=]*=//p;q}' /boot/dietpi.txt)
124138
# - No (valid) choice done yet
125-
if [[ $OPTED_IN != [01] ]]; then
126-
139+
if [[ $OPTED_IN != [01] ]]
140+
then
127141
# Do not send data without user interactively opted in!
128142
OPTED_IN=0
129143
# Ask for choice, if interactive
130144
(( $G_INTERACTIVE )) && INPUT=0
131-
132145
fi
133146

134147
# Interactive menu
@@ -149,21 +162,17 @@ This allows us to focus development based on popularity.
149162
- The data is sent via secured SFTP connection, stored unreadable to the public upload user.
150163
- If you agree, your uploaded data will be updated after each DietPi-Update and DietPi-Software install.
151164
- Current survey statistics can be reviewed at: https://dietpi.com/survey/
152-
\nWould you like to join DietPi-Survey?'; then
153-
154-
if [[ $G_WHIP_RETURNED_VALUE == 'Show' ]]; then
155-
165+
\nWould you like to join DietPi-Survey?'
166+
then
167+
if [[ $G_WHIP_RETURNED_VALUE == 'Show' ]]
168+
then
156169
Generate_File
157170
G_WHIP_VIEWFILE "$FP_UPLOAD"
158171
continue # Stay in loop
159-
160172
else
161-
162173
OPTED_IN=$G_WHIP_RETURNED_VALUE
163174
G_CONFIG_INJECT 'SURVEY_OPTED_IN=' "SURVEY_OPTED_IN=$OPTED_IN" /boot/dietpi.txt
164-
165175
fi
166-
167176
fi
168177

169178
break
@@ -173,6 +182,6 @@ This allows us to focus development based on popularity.
173182
Send_File
174183

175184
#-----------------------------------------------------------------------------------
176-
exit $EXIT_CODE
185+
exit $?
177186
#-----------------------------------------------------------------------------------
178187
}

0 commit comments

Comments
 (0)