refactor: log-upload functions

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-04-21 15:30:43 +02:00
parent 43ab12ed14
commit c8864ea09f
3 changed files with 65 additions and 63 deletions

View File

@@ -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: 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 the use of shellcheck during development
* feat: Implementing a simple logging mechanic * 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 * 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: 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) * refactor: Switch branch function has been removed (was replaced by the custom Klipper repo feature)

View File

@@ -15,7 +15,7 @@ function main_ui(){
top_border top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
hr hr
echo -e "| 0) [Upload Log] | Klipper: $(get_klipper_status)|" echo -e "| 0) [Log-Upload] | Klipper: $(get_klipper_status)|"
echo -e "| | |" echo -e "| | |"
echo -e "| 1) [Install] | |" echo -e "| 1) [Install] | |"
echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|" echo -e "| 2) [Update] | Moonraker: $(get_moonraker_status)|"

View File

@@ -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 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 read -p "${cyan}Do you accept? (Y/n):${white} " yn
case "$yn" in case "${yn}" in
Y|y|Yes|yes|"") 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 clear && print_header && upload_selection
;; ;;
N|n|No|no) N|n|No|no)
@@ -27,73 +27,74 @@ accept_upload_conditions(){
break break
;; ;;
*) *)
clear error_msg "Invalid command!";;
print_header
print_unkown_cmd
print_msg && clear_msg
accept_upload_conditions;;
esac esac
done done
} }
upload_selection(){ function upload_selection(){
source_kiauh_ini read_kiauh_ini
[ "$logupload_accepted" = "false" ] && accept_upload_conditions local upload_agreed="${logupload_accepted}"
[ "${upload_agreed}" = "false" ] && accept_upload_conditions
### find all suitable logfiles for klipper local logfiles
logfiles=() local klipper_logs="${HOME}/klipper_logs"
klipper_logs="${HOME}/klipper_logs/klippy*.log" local webif_logs="/var/log/nginx"
moonraker_logs="${HOME}/klipper_logs/moonraker*.log"
if ls $klipper_logs 2>/dev/null 1>&2; then function find_logfile(){
for kl_log in $(find $klipper_logs); do local name=${1} location=${2}
logfiles+=($kl_log) for log in $(find "${location}" -maxdepth 1 -type f -name "${name}" | sort -g); do
logfiles+=("${log}")
done done
fi }
if ls $moonraker_logs 2>/dev/null 1>&2; then
for mr_log in $(find $moonraker_logs); do find_logfile "kiauh.log" "/tmp"
logfiles+=($mr_log) find_logfile "klippy*.log" "${klipper_logs}"
done find_logfile "moonraker*.log" "${klipper_logs}"
fi 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 ### draw interface
i=0 local i=0
top_border top_border
echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |" echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${white} |"
hr hr
echo -e "| You can choose the following files for uploading: |" echo -e "| You can choose the following files for uploading: |"
for log in ${logfiles[@]}; do blank_line
printf "| $i) %-50s|\n" "${logfiles[$i]}" 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)) i=$((i + 1))
done done
blank_line
back_footer back_footer
while true; do while true; do
read -p "${cyan}Please select:${white} " choice read -p "${cyan}Please select:${white} " option
if [ $choice = "b" ] || [ $choice = "B" ]; then if [ -n "${option}" ] && ((option < ${#logfiles[@]})); then
clear && main_menu && break upload_log "${logfiles[${option}]}"
elif [ $choice -le ${#logfiles[@]} ]; then
upload_log "${logfiles[$choice]}"
upload_selection upload_selection
elif [[ "${option}" == "B" || "${option}" == "b" ]]; then
return
else else
clear && print_header error_msg "Invalid command!"
ERROR_MSG="File not found!" && print_msg && clear_msg
upload_selection
fi fi
done done
} }
upload_log(){ function upload_log(){
if [ -f "$1" ]; then local link
clear && print_header clear && print_header
status_msg "Uploading $1 ..." status_msg "Uploading ${1} ..."
LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/') link=$(curl -s --upload-file "${1}" 'http://paste.c-net.org/')
[ ! -z "$LINK" ] && ok_msg "$1 upload successfull!" if [ -n "${link}" ]; then
ok_msg "${1} upload successfull!"
echo -e "\n${cyan}###### Here is your link:${white}" echo -e "\n${cyan}###### Here is your link:${white}"
echo -e ">>>>>> $LINK\n" echo -e ">>>>>> ${link}\n"
unset LINK
else else
clear && print_header error_msg "Uploading failed!"
ERROR_MSG="File not found!" && print_msg && clear_msg
upload_selection
fi fi
} }