#!/bin/sh #Credit to @bolliostu for the original idea and script #Credit to @dormouse for a whole lot, including making the script not look like hot garbage #Credit to @esoterical, from whom i stole this # ideas: # https://coderus.openrepos.net/klipper_logs/ # https://doctor-klipper.clmntw.fr/ # Klippylizer # Directories and files KATAPULTDIR="$HOME/katapult" CANBOOTDIR="$HOME/CanBoot" KLIPPERDIR="$HOME/klipper" KLIPPYLOG="$HOME/printer_data/logs/klippy.log" # Default responses MODEL="Unknown" DISTRO="Unknown" KERNEL="Unknown" UPTIME="Unknown" IFACESERVICE="Directory Not Found" SYSTEMD="Directory Not Found" IPA="Interfaces Not Found" CAN0STATUS="Unknown" CAN0IFACE="/etc/network/interfaces.d/can0 Not Found" CAN0STATS="No can0 interface" CAN0QUERY="No can0 interface" RCLOCAL="/etc/rc.local Not Found" BYID="/dev/serial/by-id Not Found" BOOTLOADERDIRFND="Not Found" BOOTLOADERFND="Not Found" BOOTLOADERVER="Unknown" KLIPPERDIRFND="Not Found" KLIPPERFND="Not Found" KLIPPERVER="Unknown" KLIPPERCFG="Not Found" KLIPPYMSGS="Not Found" MCUCONFIGS="Not Found" ADC="Klipper Log Not Found" disclaimer() { echo "*************" echo "* Attention *" echo "*************" echo echo "This script will run a series of diagnostic commands to gather configuration" echo "information about this host and upload it to a public site where it may be" echo "viewed by others. It will contain no personal information and will be deleted in 3 days." echo "" echo "This script is available for review at: " echo "https://debug.mikestammer.com/" echo while true; do read -p "Do you wish to run this script? (yes/no) " yn < /dev/tty case $yn in [Yy]* ) break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done } # Formatting function for output sections # Usage: prepout
[SUBSECTION...] prepout() { echo echo "================================================================"; echo $1; echo "================================================================\n"; # shift the first array entry $1 (Header) and iterate through remaining shift for var in "$@"; do echo "$var\n"; done } ####################################### disclaimer; echo "\nGathering Data...\n" # Definition of commands to be be run to obtain relevant information regarding CAN bus configuration. if [ -f /sys/firmware/devicetree/base/model ]; then MODEL="$(cat /sys/firmware/devicetree/base/model)" fi if [ ! -z "$(ls /etc/*-release)" ]; then DISTRO="$(cat /etc/*-release)" fi KERNEL="$(uname -a)" UPTIME="$(uptime)" if [ -d /etc/network ]; then IFACESERVICE="$(ls /etc/network)" fi if [ -d /etc/systemd/network ]; then if [ ! -z "$(ls /etc/systemd/network)" ]; then SYSTEMD="$(ls /etc/systemd/network)" else SYSTEMD="Empty Directory" fi fi IPA="$(ip a)" # Checking can0 interface configuration. if [ -f /etc/network/interfaces.d/can0 ]; then CAN0IFACE=$(cat /etc/network/interfaces.d/can0) fi if ip l l can0 > /dev/null 2>&1; then CAN0STATS="$(ip -d -s l l can0)" CAN0UPDOWN="$(echo "$CAN0STATS" | grep -m 1 -o 'state [A-Z]*')" CAN0STATE="$(echo "$CAN0STATS" | grep -m 1 -o 'can state [A-Z-]*')" CAN0BITRATE="$(echo "$CAN0STATS" | grep -m 1 -o 'bitrate [0-9]*')" CAN0QLEN="$(echo "$CAN0STATS" | grep -m 1 -o 'qlen [0-9]*')" CAN0STATUS="$(echo " $CAN0UPDOWN"; echo " $CAN0STATE"; echo " $CAN0BITRATE"; echo " $CAN0QLEN";)" if [ "$CAN0UPDOWN" = "state UP" ]; then CAN0QUERY="$(~/klippy-env/bin/python ~/klipper/scripts/canbus_query.py can0)" else CAN0QUERY="Unable to query can0 - DOWN" fi fi # Contents of rc.local if [ -f /etc/rc.local ]; then RCLOCAL="$(cat /etc/rc.local)" fi LSUSB="$(lsusb)" if [ -d /dev/serial/by-id ]; then BYID="$(ls -l /dev/serial/by-id | tail -n +2 | awk '{print $9,$10,$11}')" fi # Retrieving katapult bootloader compilation configuration. if [ -d ${KATAPULTDIR} ]; then BOOTLOADERDIRFND="${KATAPULTDIR}"; if [ -f ${KATAPULTDIR}/.config ]; then BOOTLOADERFND="\n$(cat ${KATAPULTDIR}/.config)" cd ${KATAPULTDIR} BOOTLOADERVER="$(git describe --tags)" fi # Retrieving CanBoot bootloader compilation configuration if katapult not there. elif [ -d ${CANBOOTDIR} ]; then BOOTLOADERDIRFND="${CANBOOTDIR}" if [ -f ${CANBOOTDIR}/.config ]; then BOOTLOADERFND="\n$(cat ${CANBOOTDIR}/.config)" cd ${CANBOOTDIR} BOOTLOADERVER="$(git describe --tags)" fi fi; # Retrieving klipper firmware compilation configuration. if [ -d ${KLIPPERDIR} ]; then KLIPPERDIRFND="${KLIPPERDIR}"; if [ -f ${KLIPPERDIR}/.config ]; then KLIPPERFND="\n$(cat ${KLIPPERDIR}/.config)" if command -v git > /dev/null 2>&1; then cd ${KLIPPERDIR} KLIPPERVER="$(git describe --tags)" fi fi fi # Retrieving info from klippy.log if [ -f $KLIPPYLOG ]; then SESSIONLOG=$(tac $KLIPPYLOG | sed '/Start printer at /q' | tac) KLIPPERCFG=$(echo "$SESSIONLOG" | awk '/^===== Config file/{m=1;next}/^[=]+$/{m=0}m') KLIPPYMSGS=$(echo "$SESSIONLOG" | awk '/^[=]+$/,EOF' | tail +2) MCUCONFIGS=$(echo "$SESSIONLOG" | awk '/^Loaded MCU/,/^MCU/') STARTUPMSGS=$(echo "$KLIPPYMSGS" | grep -E -v '^MCU|^Loaded MCU|^Stats' | head -100) # ADC temp check MIN_TEMP=-10 MAX_TEMP=400 ADC=$(echo "$SESSIONLOG" | tac | grep -m 1 "^Stats" | sed 's/\([a-zA-Z0-9_.]*\)\:/\n\1:/g' | awk -v mintemp="$MIN_TEMP" -v maxtemp="$MAX_TEMP" '/temp=/ { printf "%18s ", $1; j=0; for (i=2; i<=split($0, stat, " "); i++) { if (sub(/^.*temp=/, "", stat[i])) { printf "%6s", stat[i]; if (stat[i] + 0 < mintemp ) { printf "%s", " *** Check Sensor ***"; } else if (stat[i] + 0 > maxtemp) { printf "%s", " *** Check Sensor ***"; } j++; break; } } printf "\n"; } END { if (j == 0) { printf "No Temperature Data Available\n"; } }' ) fi LOG="$(prepout "Klippy Messages" "$KLIPPYMSGS")\n$(prepout "Klipper Config" "$KLIPPERCFG")" DEBUG="$(prepout "OS" "Model:\n${MODEL}" "Distro:\n${DISTRO}" "Kernel:\n${KERNEL}" "Uptime:\n${UPTIME}") $(prepout "Network" "Interface Services:\n${IFACESERVICE}" "Systemd Network Files:\n${SYSTEMD}" "ip a:\n${IPA}") $(prepout "can0" "status:\n${CAN0STATUS}" "file:\n${CAN0IFACE}" "ifstats:\n${CAN0STATS}" "Query:\n${CAN0QUERY}") $(prepout "rc.local contents" "${RCLOCAL}") $(prepout "USB / Serial" "lsusb:\n${LSUSB}" "/dev/serial/by-id:\n${BYID}") $(prepout "MCU Configs" "${MCUCONFIGS}") $(prepout "Temperature Check" "${ADC}") $(prepout "Startup Messages" "${STARTUPMSGS}") $(prepout "Bootloader" "Directory: ${BOOTLOADERDIRFND}" "Version: ${BOOTLOADERVER}" "Make Config: ${BOOTLOADERFND}") $(prepout "Klipper" "Directory: ${KLIPPERDIRFND}" "Version: ${KLIPPERVER}" "Make Config: $KLIPPERFND")" # Output locally, so the user can share as needed, and it makes curl happier if [ -d $HOME/printer_data/config ]; then LOGPATH=$HOME/printer_data/config else LOGPATH=/tmp fi TIMESTAMP=$(date "+%Y%m%d-%H%M%S") DEBUGFILE="$LOGPATH/Helper_debug-$TIMESTAMP.txt" LOGFILE="$LOGPATH/Helper_log-$TIMESTAMP.txt" echo "Data has been generated!" echo "You can find these files for download in your config folder if needed, available in Mainsail or Fluidd:" echo "$DEBUG" > $DEBUGFILE echo "$LOG" > $LOGFILE echo "\nDebug log: $DEBUGFILE" echo "Klippy log: $LOGFILE" isUp="$(curl -Is https://termpad.mikestammer.com | head -n 1)" if [ -n "$isUp" ]; then echo "\nUploading...\n" LOGURL=$(curl --data-binary "@$LOGFILE" https://termpad.mikestammer.com) echo "\n" # Append LogUrl to end of debug echo "\nKlippy log URL: $LOGURL" >> $DEBUGFILE DEBUGURL=$( curl --data-binary "@$DEBUGFILE" https://termpad.mikestammer.com) #LOGURL=$(curl -d @"'$LOGFILE'" https://termpad.mikestammer.com) #DEBUGURL=$(curl -d "'$DEBUG'" https://termpad.mikestammer.com) echo "\n\nInformation available at the following URL:\n" echo "Debug URL: $DEBUGURL" #echo "Klippy URL: $LOGURL" echo "\nPlease share this URL with the person who requested it.\n\n" else echo "\nUnable to connect to https://termpad.mikestammer.com. Please download these files and share manually via Discord" fi