diff --git a/docs/changelog.md b/docs/changelog.md index 326baaa..4c96933 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -11,6 +11,7 @@ The majority of things that have been rewritten are mainly for internal reasons * feat: Multi-Instance OctoPrint installations now each have their own Virtualenv, allowing independent installation of Plugins * feat: Implementing the use of shellcheck during development * feat: Implementing a simple logging mechanic +* feat: Log-upload function allows uploading for several, other logfiles (kiauh.log, webcamd.log etc.) * fix: During Klipper installation checks for group membership of `tty` and `dialout` are made * refactor: Support for DWC and DWC-for-Klipper has been removed * refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 55b2aba..b5c786b 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -15,7 +15,7 @@ function main_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" hr - echo -e "| 0) [Upload Log] | Klipper: $(get_klipper_status)|" + echo -e "| 0) [Log-Upload] | Klipper: $(get_klipper_status)|" echo -e "| | |" echo -e "| 1) [Install] | |" echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|" diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index 5d27154..05185d4 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -1,24 +1,24 @@ -accept_upload_conditions(){ +function accept_upload_conditions(){ + top_border + echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |" + hr + echo -e "| The following function will help to quickly upload |" + echo -e "| logs for debugging purposes. With confirming this |" + echo -e "| dialog, you agree that during that process your logs |" + echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |" + hr + echo -e "| ${red}PLEASE NOTE:${white} |" + echo -e "| Be aware that logs can contain network information, |" + echo -e "| private data like usernames, filenames, or other |" + echo -e "| information you may not want to make public. |" + blank_line + echo -e "| Do ${red}NOT${white} use this function if you don't agree! |" + bottom_border while true; do - top_border - echo -e "| ${red}~~~~~~~~~~~ [ Upload Agreement ] ~~~~~~~~~~~~${white} |" - hr - echo -e "| The following function will help to quickly upload |" - echo -e "| logs for debugging purposes. With confirming this |" - echo -e "| dialog, you agree that during that process your logs |" - echo -e "| will be uploaded to: ${yellow}http://paste.c-net.org/${white} |" - hr - echo -e "| ${red}PLEASE NOTE:${white} |" - echo -e "| Be aware that logs can contain network information, |" - echo -e "| private data like usernames, filenames, or other |" - echo -e "| information you may not want to make public. |" - blank_line - echo -e "| Do ${red}NOT${white} use this function if you don't agree! |" - bottom_border read -p "${cyan}Do you accept? (Y/n):${white} " yn - case "$yn" in + case "${yn}" in Y|y|Yes|yes|"") - sed -i "/logupload_accepted=/s/false/true/" $INI_FILE + sed -i "/logupload_accepted=/s/false/true/" "${INI_FILE}" clear && print_header && upload_selection ;; N|n|No|no) @@ -27,73 +27,74 @@ accept_upload_conditions(){ break ;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - accept_upload_conditions;; + error_msg "Invalid command!";; esac done } -upload_selection(){ - source_kiauh_ini - [ "$logupload_accepted" = "false" ] && accept_upload_conditions +function upload_selection(){ + read_kiauh_ini + local upload_agreed="${logupload_accepted}" + [ "${upload_agreed}" = "false" ] && accept_upload_conditions - ### find all suitable logfiles for klipper - logfiles=() - klipper_logs="${HOME}/klipper_logs/klippy*.log" - moonraker_logs="${HOME}/klipper_logs/moonraker*.log" + local logfiles + local klipper_logs="${HOME}/klipper_logs" + local webif_logs="/var/log/nginx" - if ls $klipper_logs 2>/dev/null 1>&2; then - for kl_log in $(find $klipper_logs); do - logfiles+=($kl_log) + function find_logfile(){ + local name=${1} location=${2} + for log in $(find "${location}" -maxdepth 1 -type f -name "${name}" | sort -g); do + logfiles+=("${log}") done - fi - if ls $moonraker_logs 2>/dev/null 1>&2; then - for mr_log in $(find $moonraker_logs); do - logfiles+=($mr_log) - done - fi + } + + find_logfile "kiauh.log" "/tmp" + find_logfile "klippy*.log" "${klipper_logs}" + find_logfile "moonraker*.log" "${klipper_logs}" + find_logfile "telegram*.log" "${klipper_logs}" + find_logfile "mainsail*" "${webif_logs}" + find_logfile "fluidd*" "${webif_logs}" + find_logfile "KlipperScreen.log" "/tmp" + find_logfile "webcamd*" "/var/log" ### draw interface - i=0 + local i=0 top_border echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |" hr - echo -e "| You can choose the following files for uploading: |" - for log in ${logfiles[@]}; do - printf "| $i) %-50s|\n" "${logfiles[$i]}" + echo -e "| You can choose the following files for uploading: |" + blank_line + for log in "${logfiles[@]}"; do + log=${log//${HOME}/"~"} + ((i < 10)) && printf "| ${i}) %-50s|\n" "${log}" + ((i >= 10)) && printf "| ${i}) %-50s|\n" "${log}" i=$((i + 1)) done + blank_line back_footer while true; do - read -p "${cyan}Please select:${white} " choice - if [ $choice = "b" ] || [ $choice = "B" ]; then - clear && main_menu && break - elif [ $choice -le ${#logfiles[@]} ]; then - upload_log "${logfiles[$choice]}" + read -p "${cyan}Please select:${white} " option + if [ -n "${option}" ] && ((option < ${#logfiles[@]})); then + upload_log "${logfiles[${option}]}" upload_selection + elif [[ "${option}" == "B" || "${option}" == "b" ]]; then + return else - clear && print_header - ERROR_MSG="File not found!" && print_msg && clear_msg - upload_selection + error_msg "Invalid command!" fi done } -upload_log(){ - if [ -f "$1" ]; then - clear && print_header - status_msg "Uploading $1 ..." - LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/') - [ ! -z "$LINK" ] && ok_msg "$1 upload successfull!" +function upload_log(){ + local link + clear && print_header + status_msg "Uploading ${1} ..." + link=$(curl -s --upload-file "${1}" 'http://paste.c-net.org/') + if [ -n "${link}" ]; then + ok_msg "${1} upload successfull!" echo -e "\n${cyan}###### Here is your link:${white}" - echo -e ">>>>>> $LINK\n" - unset LINK + echo -e ">>>>>> ${link}\n" else - clear && print_header - ERROR_MSG="File not found!" && print_msg && clear_msg - upload_selection + error_msg "Uploading failed!" fi }