forked from MichaIng/DietPi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdietpi-survey
133 lines (105 loc) · 3.54 KB
/
dietpi-survey
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
#!/bin/bash
{
#////////////////////////////////////
# DietPi Survey Script
#
#////////////////////////////////////
# Created by Daniel Knight / [email protected] / dietpi.com
#
#////////////////////////////////////
#
# Info:
# - http://dietpi.com/phpbb/viewtopic.php?f=8&t=20
# - Sends DietPi statistics to FTP server (eg: what programs are installed, hardware model)
# - Allows the DietPi project to focus on areas based on popularity.
# - No private data is sent. Noone can indentify you.
# - Runs when user installs software using dietpi-software
#
# You can opt out of dietpi-survey by running:
# sed -i "1s/.*/0/" /DietPi/dietpi/.dietpi-survey
#
# File Sent format:
# $FILENAME_FORMAT.txt
#////////////////////////////////////
#Import DietPi-Globals ---------------------------------------------------------------
. /DietPi/dietpi/func/dietpi-globals
export G_PROGRAM_NAME='DietPi-Survey'
G_CHECK_ROOT_USER
G_INIT
#Import DietPi-Globals ---------------------------------------------------------------
SURVEY_VERSION=4
SURVEY_SENTCOUNT=1
OPTED_IN=1
DIETPI_VERSION="$(sed -n 1p /DietPi/dietpi/.version).$(sed -n 2p /DietPi/dietpi/.version)"
G_HW_MODEL=$(sed -n 1p /DietPi/dietpi/.hw_model)
UNIQUE_ID=$(sed -n 5p /DietPi/dietpi/.hw_model)
FTP_ADDR="dietpi.com"
FTP_USER="dietpi-survey"
FTP_PASS="raspberry13"
Update_FileName_Format(){
FILENAME_FORMAT="$SURVEY_VERSION-$UNIQUE_ID-$DIETPI_VERSION-$G_HW_MODEL.txt"
}
FP_SETTINGS="/DietPi/dietpi/.dietpi-survey"
Write_Settings(){
cat << _EOF_ > "$FP_SETTINGS"
$OPTED_IN
$SURVEY_SENTCOUNT
_EOF_
}
Read_Settings(){
OPTED_IN=$(sed -n 1p "$FP_SETTINGS")
SURVEY_SENTCOUNT=$(sed -n 2p "$FP_SETTINGS")
}
#/////////////////////////////////////////////////////////////////////////////////////
# Main Loop
#/////////////////////////////////////////////////////////////////////////////////////
#Read data from .dietpi-survey file
if [ -f "$FP_SETTINGS" ]; then
Read_Settings
#Create new file + generate UUID
else
Write_Settings
fi
#-----------------------------------------------------------------------------------
#Opted in - Setup and send
if (( $OPTED_IN == 1 )); then
#Check if we have a working internet connection beforehand
G_CHECK_URL "$FTP_ADDR"
#Grab filename to use
Update_FileName_Format
#Generate text file for upload
# - wput does not work with a filepath, so we must enter the directory and use a filename only.
cd /tmp
cat << _EOF_ > "$FILENAME_FORMAT"
-------------------------
DietPi-Survey v$SURVEY_VERSION
-------------------------
Upload Count : $SURVEY_SENTCOUNT
DietPi Version : $DIETPI_VERSION
Hardware Index : $G_HW_MODEL
Hardware Name : $G_HW_MODEL_DESCRIPTION
Distro Index : $G_DISTRO
Autoboot Index : $(cat /DietPi/dietpi/.dietpi-autostart_index)
Country : $(curl --max-time 4 -s http://whatismycountry.com/ | sed -n 's|.*,\(.*\)</h3>|\1|p')
Hostname : $(cat /etc/hostname)
-------------------------
DietPi-Software Installed
-------------------------
$(cat /DietPi/dietpi/.installed | grep ' =2 ')
-------------------------
FileSystem
-------------------------
$(df -h)
_EOF_
#upload to server
wput --timeout=10th-4 --tries=1 --waitretry=4 -q -B -u "$FILENAME_FORMAT" ftp://"$FTP_USER":"$FTP_PASS"@"$FTP_ADDR"
#clear generated temp file
rm "$FILENAME_FORMAT"
#Update .dietpi-survey file
((SURVEY_SENTCOUNT++))
Write_Settings
fi
#-----------------------------------------------------------------------------------
exit 0
#-----------------------------------------------------------------------------------
}