#!/bin/bash do { #//////////////////////////////////// # DietPi Bug Report Script # #//////////////////////////////////// # Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com # #//////////////////////////////////// # # Info: # - filename /DietPi/dietpi/dietpi-bugreport # - Generates MACADDRESS_BUGNUMBER.zip and uploads to dietpi.com #//////////////////////////////////// #Import DietPi-Globals --------------------------------------------------------------- source /DietPi/dietpi/func/dietpi-globals G_CHECK_ROOT_USER G_CHECK_ROOTFS_RW export G_PROGRAM_NAME='DietPi-Bugreport' #Import DietPi-Globals --------------------------------------------------------------- # - byte setglobal UPLOAD_FILESIZE_LIMIT = '83886080' setglobal UPLOAD_FILESIZE = '0' setglobal DATE_CURRENT = $[date +"%d-%m-%Y] setglobal ONLINE_BUG_REPORT = '1' setglobal CREATE_BUG_REPORT = '0' setglobal BUG_REPORT_COMPLETED = '0' setglobal UNIQUE_ID_HW = $[sed -n 5p /DietPi/dietpi/.hw_model] setglobal UNIQUE_ID_BUGNUMBER = '0' setglobal INTERNET_AVAILABLE = '0' setglobal FTP_ADDR = '"dietpi.com'" setglobal FTP_USER = '"dietpi-survey'" setglobal FTP_PASS = '"raspberry13'" setglobal FILEPATH_TEMP = '"/tmp/dietpi-bugreport'" setglobal FILE_GENERATED_ZIP = '"bugreport.zip'" setglobal FILE_BUGREPORT_TEXT = '"bugreport.txt'" setglobal FILE_BUG_NUMBER = '"/DietPi/dietpi/.bug_id'" proc Generate_Template_Doc{ cat << """ > "$FILE_BUGREPORT_TEXT" ---------------------------------------------------------------- DietPi : Bug Report #Date ---------------------------------------------------------------- Please fill out the information regarding your issue. When completed, save and exit nano: - Press CTRL+X - Press Y - Press Enter ---------------------------------------------------------------- Your contact information ---------------------------------------------------------------- Email address = Name = ---------------------------------------------------------------- Short Description of the issue (eg: Desktop wont start): ---------------------------------------------------------------- ---------------------------------------------------------------- When does the issue occur? (eg: I tried to run startx): ---------------------------------------------------------------- ---------------------------------------------------------------- Error Codes (if applicable): ---------------------------------------------------------------- ---------------------------------------------------------------- Additional Notes: ---------------------------------------------------------------- End of Line ;) """ > $FILE_BUGREPORT_TEXT ---------------------------------------------------------------- DietPi : Bug Report #Date ---------------------------------------------------------------- Please fill out the information regarding your issue. When completed, save and exit nano: - Press CTRL+X - Press Y - Press Enter ---------------------------------------------------------------- Your contact information ---------------------------------------------------------------- Email address = Name = ---------------------------------------------------------------- Short Description of the issue (eg: Desktop wont start): ---------------------------------------------------------------- ---------------------------------------------------------------- When does the issue occur? (eg: I tried to run startx): ---------------------------------------------------------------- ---------------------------------------------------------------- Error Codes (if applicable): ---------------------------------------------------------------- ---------------------------------------------------------------- Additional Notes: ---------------------------------------------------------------- End of Line ;) _EOF_ #Set date inside bugreport text sed -i "/#Date/c\ $DATE_CURRENT" $FILE_BUGREPORT_TEXT } proc Generate_Zip_File{ #---------------------------------------------------------------- #Define zip settings (level 9 compression etc) local zip_settings="-9" #Online - Update file name format to send if sh-expr ' $ONLINE_BUG_REPORT == 1 ' { setglobal FILE_GENERATED_ZIP = ""bugreport-$UNIQUE_ID_HW-$UNIQUE_ID_BUGNUMBER.zip"" #Offline } else { setglobal FILE_GENERATED_ZIP = '"bugreport.zip'" } #---------------------------------------------------------------- #Add User's text document zip $zip_settings $FILE_GENERATED_ZIP $FILE_BUGREPORT_TEXT #list of files and/or folders we want to zip local afile_list=( # - logs "/var/log/*" # - DietPi scripts / logs "/DietPi/*" "/boot/dietpi.txt" "/boot/config.txt" "/boot/dietpi/*" "/var/tmp/dietpi/logs/*" # - /var/lib/dietpi "/var/lib/dietpi/*" # - confs "/etc/X11/xorg.conf" "/etc/bash.bashrc" "/etc/rc.local" "/etc/asound.conf" "/etc/network/interfaces" "/etc/fstab" "/etc/dphys-swapfile" "/etc/sysctl.conf" "/etc/sysctl.d/*" "/root/.bashrc" # - Services "/etc/init.d/*" "/etc/systemd/*" # - Locale "/etc/apt/sources.list" "/etc/apt/sources.list.d/*" ) for ((i=0; i<${#afile_list[@]}; i++)) do zip -r "$zip_settings" "$FILE_GENERATED_ZIP" ${afile_list[$i]} done unset afile_list #List of commands we want to run and redirect to zip local acommand_list=( "ls -lha /var/log" "dpkg -l" "ifconfig -a" "iwconfig" "ip a" "lsusb" "cat /proc/cpuinfo" "ps aux" "blkid" "mount" "df -h" "ls /etc/rc*.d/" "cut -d: -f1 /etc/passwd" "locale" "ls -lha /mnt" #dietpi userdata location "dmesg" "lsmod" "systemctl status *.service -l" "systemctl status *.mount -l" "/DietPi/dietpi/dietpi-services status" ) for ((i=0; i<${#acommand_list[@]}; i++)) do ${acommand_list[$i]} > command_output_$i.txt zip -r "$zip_settings" "$FILE_GENERATED_ZIP" command_output_$i.txt rm command_output_$i.txt done unset acommand_list } #///////////////////////////////////////////////////////////////////////////////////// # Main Loop #///////////////////////////////////////////////////////////////////////////////////// #---------------------------------------------------------------- #Make Directory #we need to work inside the directory as Wput cant accept /paths mkdir -p $FILEPATH_TEMP cd $FILEPATH_TEMP #---------------------------------------------------------------- #Check if we have a working internet connection beforehand G_CHECK_URL $FTP_ADDR if sh-expr ' $? == 0 ' { setglobal INTERNET_AVAILABLE = '1' } # - Prompt user if they wish to continue. Offline mode. No Network. if sh-expr ' $INTERNET_AVAILABLE == 0 ' { clear whiptail --title "Offline" --yesno "Error: Unable to connect to $FTP_ADDR\n- Make sure a network device is installed.\n- Check your network connection is functional.\n- $FTP_ADDR may be offline.\n\n Would you like to generate an offline bug report?\n - /DietPi/bugreport.zip" --yes-button "Ok" --no-button "Exit" --defaultno --backtitle "DietPi Bug Report" 14 70 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal ONLINE_BUG_REPORT = '0' setglobal CREATE_BUG_REPORT = '1' } # - Prompt user if they wish to continue. Online Upload. } else { whiptail --title "Send DietPi Bug Report?" --yesno "DietPi will generate and upload a bug report for your system.\n\nThis file will contain:\n- Your description of the bug/issue.\n- DietPi settings.\n- Log files.\n- Config files specific to DietPi.\n\nDo you wish to continue?" --yes-button "Ok" --no-button "Exit" --defaultno --backtitle "DietPi Bug Report" 15 70 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal ONLINE_BUG_REPORT = '1' setglobal CREATE_BUG_REPORT = '1' } } #---------------------------------------------------------------- #Create Bug Report if sh-expr ' $CREATE_BUG_REPORT == 1 ' { #---------------------------------------------------------------- #Copy template if a previous bugreport.txt file does not exists. if test ! -f $FILE_BUGREPORT_TEXT { Generate_Template_Doc } #Load up template text file for user to input information nano $FILE_BUGREPORT_TEXT #---------------------------------------------------------------- #Load .bug_id if test -f $FILE_BUG_NUMBER { setglobal UNIQUE_ID_BUGNUMBER = $[cat $FILE_BUG_NUMBER] } #---------------------------------------------------------------- #Generate our zipped bugreport file Generate_Zip_File #---------------------------------------------------------------- #Offline Mode - store zip to /DietPi/bugreport.zip if sh-expr ' $ONLINE_BUG_REPORT == 0 ' { #copy offline bug report to /boot rm /DietPi/bugreport.zip &> /dev/null cp $FILE_GENERATED_ZIP /DietPi/bugreport.zip &> /dev/null setglobal BUG_REPORT_COMPLETED = '1' #Online Mode, Upload .zip to server. } else { #Check upload location is online G_CHECK_URL $FTP_ADDR if sh-expr ' $? == 0 ' { #Limit filesize to 10MB setglobal UPLOAD_FILESIZE = $[stat -c%s $FILE_GENERATED_ZIP] # - File too big if sh-expr ' $UPLOAD_FILESIZE > $UPLOAD_FILESIZE_LIMIT ' { setglobal BUG_REPORT_COMPLETED = '-2' # - upload to server } else { G_DIETPI-NOTIFY 2 "Uploading bug report, please wait..." wput --timeout=10th-4 --tries=1 --waitretry=2 -B -u $FILE_GENERATED_ZIP ftp://"$FTP_USER":"$FTP_PASS"@"$FTP_ADDR" setglobal BUG_REPORT_COMPLETED = '1' } } else { setglobal BUG_REPORT_COMPLETED = '-1' } } } #---------------------------------------------------------------- #Bug report generated / sent. Inform user if sh-expr ' $BUG_REPORT_COMPLETED == 1 ' { #Inform user if sh-expr ' $ONLINE_BUG_REPORT == 0 ' { whiptail --title "Bug Report Created" --msgbox "Your offline bug report has been generated:\n - /DietPi/bugreport.zip\n\nContact DietPi for support using one of the below:\n- Github Issue : https://github.com/Fourdee/DietPi/issues\n- RPi Forum : https://goo.gl/QzyTVm\n- Odroid Forum : http://goo.gl/26owYc\n- DietPi Forum : http://dietpi.com/phpbb/viewforum.php?f=9" --backtitle "DietPi Bug Report" 16 70 /DietPi/dietpi/dietpi-banner 1 echo -e "\n Bug report generated. /DietPi/bugreport.zip \n " } else { #inform user of their unique ID that can be used to track issue whiptail --title "Bug Report Sent" --msgbox "Your bug report has been sent.\nPlease make note of your reference code below. This will need to be used when contacting DietPi for support.\n\n Reference CODE: $UNIQUE_ID_HW-$UNIQUE_ID_BUGNUMBER \n\nContact DietPi for support using one of the below:\n- Github Issue : https://github.com/Fourdee/DietPi/issues\n- RPi Forum : https://goo.gl/QzyTVm\n- Odroid Forum : http://goo.gl/26owYc\n- DietPi Forum : http://dietpi.com/phpbb/viewforum.php?f=9" --backtitle "DietPi Bug Report" 18 70 #Print to terminal aswell /DietPi/dietpi/dietpi-banner 1 echo -e "\n Bug report Sent. Thank you.\n Your reference code: $UNIQUE_ID_HW-$UNIQUE_ID_BUGNUMBER \n" } #Update local Bug number Id sh-expr 'UNIQUE_ID_BUGNUMBER++' echo -e $UNIQUE_ID_BUGNUMBER > $FILE_BUG_NUMBER #Failed to upload - Connection error } elif sh-expr ' $BUG_REPORT_COMPLETED == -1 ' { whiptail --title "Upload failed" --msgbox "Error: Unable to upload Bug report.\n\nConnection to $FTP_ADDR has failed:\n- Check your network connection is functional.\n- Please try again later." --backtitle "DietPi Bug Report" 12 70 /DietPi/dietpi/dietpi-banner 1 #Failed to upload - Filesize too big } elif sh-expr ' $BUG_REPORT_COMPLETED == -2 ' { whiptail --title "Bug report upload failed" --msgbox "Error: Bug report file exceeds size limit\n - Max size = $shExpr(' $UPLOAD_FILESIZE_LIMIT / 1024 / 1024 ')MB\n - Bug report size = $shExpr(' $UPLOAD_FILESIZE / 1024 / 1024 ')MB\n\nThis bug report has NOT been sent." --backtitle "DietPi Bug Report" 12 60 /DietPi/dietpi/dietpi-banner 1 #Aborted } elif sh-expr ' $CREATE_BUG_REPORT == 0 ' { /DietPi/dietpi/dietpi-banner 1 echo -e "\nBug report aborted by user.\n" } #---------------------------------------------------------------- #remove temp folder and all generated temp files cd $HOME rm -R $FILEPATH_TEMP &> /dev/null #----------------------------------------------------------------------------------- exit 0 #----------------------------------------------------------------------------------- }