#!/bin/bash do { #//////////////////////////////////// # DietPi Survey Script # #//////////////////////////////////// # Created by Daniel Knight / daniel.knight@dietpi.com / 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 --------------------------------------------------------------- source /DietPi/dietpi/func/dietpi-globals export G_PROGRAM_NAME='DietPi-Survey' G_CHECK_ROOT_USER #Import DietPi-Globals --------------------------------------------------------------- setvar SURVEY_VERSION = '4' setvar SURVEY_SENTCOUNT = '1' setvar OPTED_IN = '1' setvar DIETPI_VERSION = ""$(sed -n 1p /DietPi/dietpi/.version).$(sed -n 2p /DietPi/dietpi/.version)"" setvar G_HW_MODEL = $(sed -n 1p /DietPi/dietpi/.hw_model) setvar UNIQUE_ID = $(sed -n 5p /DietPi/dietpi/.hw_model) setvar FTP_ADDR = ""dietpi.com"" setvar FTP_USER = ""dietpi-survey"" setvar FTP_PASS = ""raspberry13"" proc Update_FileName_Format { setvar FILENAME_FORMAT = ""$SURVEY_VERSION-$UNIQUE_ID-$DIETPI_VERSION-$G_HW_MODEL.txt"" } setvar FP_SETTINGS = ""/DietPi/dietpi/.dietpi-survey"" proc Write_Settings { cat <<< """ > "$FP_SETTINGS" $OPTED_IN $SURVEY_SENTCOUNT """ > "$FP_SETTINGS" $OPTED_IN $SURVEY_SENTCOUNT _EOF_ } proc Read_Settings { setvar OPTED_IN = $(sed -n 1p "$FP_SETTINGS") setvar SURVEY_SENTCOUNT = $(sed -n 2p "$FP_SETTINGS") } #///////////////////////////////////////////////////////////////////////////////////// # Main Loop #///////////////////////////////////////////////////////////////////////////////////// #Read data from .dietpi-survey file if test -f $FP_SETTINGS { Read_Settings #Create new file + generate UUID } else { Write_Settings } #----------------------------------------------------------------------------------- #Opted in - Setup and send if (( $OPTED_IN == 1 )) { #Check if we have a working internet connection beforehand G_CHECK_URL $FTP_ADDR if (( $? == 0 )) { #Obtain active network adapter. /DietPi/dietpi/func/obtain_network_details setvar active_network_adapter = $(sed -n 3p /DietPi/dietpi/.network) #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 <<< """ > "$FILENAME_FORMAT" ------------------------- DietPi-Survey v$SURVEY_VERSION ------------------------- Upload Count : $SURVEY_SENTCOUNT DietPi Version : $DIETPI_VERSION Mac Address : $( ifconfig -a | grep -m1 "$active_network_adapter" | awk '{print $NF}' | sed 's/://g') 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|.*,\(.*\)|\1|p') Hostname : $(cat /etc/hostname) ------------------------- DietPi-Software Installed ------------------------- $(cat /DietPi/dietpi/.installed | grep ' =2 ') ------------------------- FileSystem ------------------------- $(df -h) """ > "$FILENAME_FORMAT" ------------------------- DietPi-Survey v$SURVEY_VERSION ------------------------- Upload Count : $SURVEY_SENTCOUNT DietPi Version : $DIETPI_VERSION Mac Address : $( ifconfig -a | grep -m1 "$active_network_adapter" | awk '{print $NF}' | sed 's/://g') 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|.*,\(.*\)|\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 } } #----------------------------------------------------------------------------------- exit 0 #----------------------------------------------------------------------------------- }