style(fluidd.sh): improve code-style and fix some shellcheck warnings
Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
@@ -17,10 +17,11 @@ set -e
|
|||||||
|
|
||||||
function install_fluidd() {
|
function install_fluidd() {
|
||||||
### exit early if moonraker not found
|
### exit early if moonraker not found
|
||||||
if [ -z "$(moonraker_systemd)" ]; then
|
if [[ -z $(moonraker_systemd) ]]; then
|
||||||
local error="Moonraker not installed! Please install Moonraker first!"
|
local error="Moonraker not installed! Please install Moonraker first!"
|
||||||
print_error "${error}" && return
|
print_error "${error}" && return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### checking dependencies
|
### checking dependencies
|
||||||
local dep=(wget nginx)
|
local dep=(wget nginx)
|
||||||
dependency_check "${dep[@]}"
|
dependency_check "${dep[@]}"
|
||||||
@@ -41,7 +42,7 @@ function install_fluidd() {
|
|||||||
|
|
||||||
### ask user to install mjpg-streamer
|
### ask user to install mjpg-streamer
|
||||||
local install_mjpg_streamer
|
local install_mjpg_streamer
|
||||||
if [ ! -f "${SYSTEMD}/webcamd.service" ]; then
|
if [[ ! -f "${SYSTEMD}/webcamd.service" ]]; then
|
||||||
while true; do
|
while true; do
|
||||||
echo
|
echo
|
||||||
top_border
|
top_border
|
||||||
@@ -81,7 +82,7 @@ function install_fluidd() {
|
|||||||
patch_fluidd_update_manager
|
patch_fluidd_update_manager
|
||||||
|
|
||||||
### install mjpg-streamer
|
### install mjpg-streamer
|
||||||
[ "${install_mjpg_streamer}" = "true" ] && install_mjpg-streamer
|
[[ ${install_mjpg_streamer} == "true" ]] && install_mjpg-streamer
|
||||||
|
|
||||||
fetch_webui_ports #WIP
|
fetch_webui_ports #WIP
|
||||||
|
|
||||||
@@ -122,29 +123,30 @@ function install_fluidd_macros() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function download_fluidd_macros() {
|
function download_fluidd_macros() {
|
||||||
log_info "executing: download_fluidd_macros"
|
|
||||||
local fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg"
|
local fluidd_cfg="https://raw.githubusercontent.com/fluidd-core/FluiddPI/master/src/modules/fluidd/filesystem/home/pi/klipper_config/fluidd.cfg"
|
||||||
local configs
|
local configs path
|
||||||
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort)
|
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg" | sort)
|
||||||
if [ -n "${configs}" ]; then
|
|
||||||
|
if [[ -n ${configs} ]]; then
|
||||||
### create a backup of the config folder
|
### create a backup of the config folder
|
||||||
backup_klipper_config_dir
|
backup_klipper_config_dir
|
||||||
|
|
||||||
for config in ${configs}; do
|
for config in ${configs}; do
|
||||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||||
if [ ! -f "${path}/fluidd.cfg" ]; then
|
if [[ ! -f "${path}/fluidd.cfg" ]]; then
|
||||||
status_msg "Downloading fluidd.cfg to ${path} ..."
|
status_msg "Downloading fluidd.cfg to ${path} ..."
|
||||||
log_info "downloading fluidd.cfg to: ${path}"
|
log_info "downloading fluidd.cfg to: ${path}"
|
||||||
wget "${fluidd_cfg}" -O "${path}/fluidd.cfg"
|
wget "${fluidd_cfg}" -O "${path}/fluidd.cfg"
|
||||||
|
|
||||||
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
|
### replace user 'pi' with current username to prevent issues in cases where the user is not called 'pi'
|
||||||
log_info "modify fluidd.cfg"
|
log_info "modify fluidd.cfg"
|
||||||
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/fluidd.cfg"
|
sed -i "/^path: \/home\/pi\/gcode_files/ s/\/home\/pi/\/home\/${USER}/" "${path}/fluidd.cfg"
|
||||||
### write the include to the very first line of the printer.cfg
|
|
||||||
|
### write include to the very first line of the printer.cfg
|
||||||
if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then
|
if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then
|
||||||
log_info "modify printer.cfg"
|
log_info "modify printer.cfg"
|
||||||
sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg"
|
sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ok_msg "Done!"
|
ok_msg "Done!"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -157,16 +159,17 @@ function download_fluidd_macros() {
|
|||||||
function fluidd_setup() {
|
function fluidd_setup() {
|
||||||
local url
|
local url
|
||||||
url=$(get_fluidd_download_url)
|
url=$(get_fluidd_download_url)
|
||||||
|
|
||||||
status_msg "Downloading Fluidd ..."
|
status_msg "Downloading Fluidd ..."
|
||||||
if [ -d "${FLUIDD_DIR}" ]; then
|
|
||||||
|
if [[ -d ${FLUIDD_DIR} ]]; then
|
||||||
rm -rf "${FLUIDD_DIR}"
|
rm -rf "${FLUIDD_DIR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}"
|
mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}"
|
||||||
wget "${url}" && ok_msg "Download complete!"
|
wget "${url}" && ok_msg "Download complete!"
|
||||||
|
|
||||||
status_msg "Extracting archive ..."
|
status_msg "Extracting archive ..."
|
||||||
unzip -q -o ./*.zip && ok_msg "Done!"
|
unzip -q -o ./*.zip && ok_msg "Done!"
|
||||||
|
|
||||||
status_msg "Remove downloaded archive ..."
|
status_msg "Remove downloaded archive ..."
|
||||||
rm -rf ./*.zip && ok_msg "Done!"
|
rm -rf ./*.zip && ok_msg "Done!"
|
||||||
}
|
}
|
||||||
@@ -176,17 +179,18 @@ function fluidd_setup() {
|
|||||||
#===================================================#
|
#===================================================#
|
||||||
|
|
||||||
function remove_fluidd_dir() {
|
function remove_fluidd_dir() {
|
||||||
[ ! -d "${FLUIDD_DIR}" ] && return
|
[[ ! -d ${FLUIDD_DIR} ]] && return
|
||||||
|
|
||||||
status_msg "Removing Fluidd directory ..."
|
status_msg "Removing Fluidd directory ..."
|
||||||
rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!"
|
rm -rf "${FLUIDD_DIR}" && ok_msg "Directory removed!"
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_fluidd_config() {
|
function remove_fluidd_config() {
|
||||||
if [ -e "/etc/nginx/sites-available/fluidd" ]; then
|
if [[ -e "/etc/nginx/sites-available/fluidd" ]]; then
|
||||||
status_msg "Removing Fluidd configuration for Nginx ..."
|
status_msg "Removing Fluidd configuration for Nginx ..."
|
||||||
sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!"
|
sudo rm "/etc/nginx/sites-available/fluidd" && ok_msg "File removed!"
|
||||||
fi
|
fi
|
||||||
if [ -L "/etc/nginx/sites-enabled/fluidd" ]; then
|
if [[ -L "/etc/nginx/sites-enabled/fluidd" ]]; then
|
||||||
status_msg "Removing Fluidd Symlink for Nginx ..."
|
status_msg "Removing Fluidd Symlink for Nginx ..."
|
||||||
sudo rm "/etc/nginx/sites-enabled/fluidd" && ok_msg "File removed!"
|
sudo rm "/etc/nginx/sites-enabled/fluidd" && ok_msg "File removed!"
|
||||||
fi
|
fi
|
||||||
@@ -195,7 +199,8 @@ function remove_fluidd_config() {
|
|||||||
function remove_fluidd_logs() {
|
function remove_fluidd_logs() {
|
||||||
local files
|
local files
|
||||||
files=$(find /var/log/nginx -name "fluidd*")
|
files=$(find /var/log/nginx -name "fluidd*")
|
||||||
if [ -n "${files}" ]; then
|
|
||||||
|
if [[ -n ${files} ]]; then
|
||||||
for file in ${files}; do
|
for file in ${files}; do
|
||||||
status_msg "Removing ${file} ..."
|
status_msg "Removing ${file} ..."
|
||||||
sudo rm -f "${file}"
|
sudo rm -f "${file}"
|
||||||
@@ -206,8 +211,9 @@ function remove_fluidd_logs() {
|
|||||||
|
|
||||||
function remove_fluidd_log_symlinks() {
|
function remove_fluidd_log_symlinks() {
|
||||||
local files
|
local files
|
||||||
files=$(find "${KLIPPER_LOGS}" -name "fluidd*")
|
files=$(find "${KLIPPER_LOGS}" -name "fluidd*" 2> /dev/null | sort)
|
||||||
if [ -n "${files}" ]; then
|
|
||||||
|
if [[ -n ${files} ]]; then
|
||||||
for file in ${files}; do
|
for file in ${files}; do
|
||||||
status_msg "Removing ${file} ..."
|
status_msg "Removing ${file} ..."
|
||||||
rm -f "${file}"
|
rm -f "${file}"
|
||||||
@@ -251,10 +257,10 @@ function get_fluidd_status() {
|
|||||||
### count+1 for each found data-item from array
|
### count+1 for each found data-item from array
|
||||||
local filecount=0
|
local filecount=0
|
||||||
for data in "${data_arr[@]}"; do
|
for data in "${data_arr[@]}"; do
|
||||||
[ -e "${data}" ] && filecount=$(("${filecount}" + 1))
|
[[ -e ${data} ]] && filecount=$(( filecount + 1 ))
|
||||||
done
|
done
|
||||||
|
|
||||||
if (( filecount == ${#data_arr[*]})); then
|
if (( filecount == ${#data_arr[*]} )); then
|
||||||
status="Installed!"
|
status="Installed!"
|
||||||
elif ((filecount == 0)); then
|
elif ((filecount == 0)); then
|
||||||
status="Not installed!"
|
status="Not installed!"
|
||||||
@@ -265,15 +271,17 @@ function get_fluidd_status() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_local_fluidd_version() {
|
function get_local_fluidd_version() {
|
||||||
|
[[ ! -f "${FLUIDD_DIR}/.version" ]] && return
|
||||||
|
|
||||||
local version
|
local version
|
||||||
[ ! -f "${FLUIDD_DIR}/.version" ] && return
|
|
||||||
version=$(head -n 1 "${FLUIDD_DIR}/.version")
|
version=$(head -n 1 "${FLUIDD_DIR}/.version")
|
||||||
echo "${version}"
|
echo "${version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_remote_fluidd_version() {
|
function get_remote_fluidd_version() {
|
||||||
local version
|
|
||||||
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
|
[[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return
|
||||||
|
|
||||||
|
local version
|
||||||
version=$(get_fluidd_download_url | rev | cut -d"/" -f2 | rev)
|
version=$(get_fluidd_download_url | rev | cut -d"/" -f2 | rev)
|
||||||
echo "${version}"
|
echo "${version}"
|
||||||
}
|
}
|
||||||
@@ -283,7 +291,8 @@ function compare_fluidd_versions() {
|
|||||||
local versions local_ver remote_ver
|
local versions local_ver remote_ver
|
||||||
local_ver="$(get_local_fluidd_version)"
|
local_ver="$(get_local_fluidd_version)"
|
||||||
remote_ver="$(get_remote_fluidd_version)"
|
remote_ver="$(get_remote_fluidd_version)"
|
||||||
if [ "${local_ver}" != "${remote_ver}" ]; then
|
|
||||||
|
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
||||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
||||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||||
# add fluidd to the update all array for the update all function in the updater
|
# add fluidd to the update all array for the update all function in the updater
|
||||||
@@ -293,6 +302,7 @@ function compare_fluidd_versions() {
|
|||||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
||||||
FLUIDD_UPDATE_AVAIL="false"
|
FLUIDD_UPDATE_AVAIL="false"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${versions}"
|
echo "${versions}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +311,7 @@ function compare_fluidd_versions() {
|
|||||||
#================================================#
|
#================================================#
|
||||||
|
|
||||||
function get_fluidd_download_url() {
|
function get_fluidd_download_url() {
|
||||||
local latest_tag latest_url stable_tag stable_url url
|
local tags latest_tag latest_url stable_tag stable_url url
|
||||||
tags=$(curl -s "${FLUIDD_TAGS}" | grep "name" | cut -d'"' -f4)
|
tags=$(curl -s "${FLUIDD_TAGS}" | grep "name" | cut -d'"' -f4)
|
||||||
|
|
||||||
### latest download url including pre-releases (alpha, beta, rc)
|
### latest download url including pre-releases (alpha, beta, rc)
|
||||||
@@ -313,7 +323,7 @@ function get_fluidd_download_url() {
|
|||||||
stable_url="https://github.com/fluidd-core/fluidd/releases/download/${stable_tag}/fluidd.zip"
|
stable_url="https://github.com/fluidd-core/fluidd/releases/download/${stable_tag}/fluidd.zip"
|
||||||
|
|
||||||
read_kiauh_ini "${FUNCNAME[0]}"
|
read_kiauh_ini "${FUNCNAME[0]}"
|
||||||
if [ "${fluidd_install_unstable}" == "true" ]; then
|
if [[ ${fluidd_install_unstable} == "true" ]]; then
|
||||||
url="${latest_url}"
|
url="${latest_url}"
|
||||||
echo "${url}"
|
echo "${url}"
|
||||||
else
|
else
|
||||||
@@ -323,12 +333,18 @@ function get_fluidd_download_url() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fluidd_port_check() {
|
function fluidd_port_check() {
|
||||||
if [ "${FLUIDD_ENABLED}" = "false" ]; then
|
if [[ ${FLUIDD_ENABLED} == "false" ]]; then
|
||||||
if [ "${SITE_ENABLED}" = "true" ]; then
|
|
||||||
|
if [[ ${SITE_ENABLED} == "true" ]]; then
|
||||||
status_msg "Detected other enabled interfaces:"
|
status_msg "Detected other enabled interfaces:"
|
||||||
[ "${OCTOPRINT_ENABLED}" = "true" ] && echo " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${white}"
|
|
||||||
[ "${MAINSAIL_ENABLED}" = "true" ] && echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${white}"
|
[[ ${OCTOPRINT_ENABLED} == "true" ]] && \
|
||||||
if [ "${MAINSAIL_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then
|
echo " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${white}"
|
||||||
|
|
||||||
|
[[ ${MAINSAIL_ENABLED} == "true" ]] && \
|
||||||
|
echo " ${cyan}● Mainsail - Port: ${MAINSAIL_PORT}${white}"
|
||||||
|
|
||||||
|
if [[ ${MAINSAIL_PORT} == "80" ]] || [[ ${OCTOPRINT_PORT} == "80" ]]; then
|
||||||
PORT_80_BLOCKED="true"
|
PORT_80_BLOCKED="true"
|
||||||
select_fluidd_port
|
select_fluidd_port
|
||||||
fi
|
fi
|
||||||
@@ -337,21 +353,23 @@ function fluidd_port_check() {
|
|||||||
SET_LISTEN_PORT=${DEFAULT_PORT}
|
SET_LISTEN_PORT=${DEFAULT_PORT}
|
||||||
fi
|
fi
|
||||||
SET_NGINX_CFG="true"
|
SET_NGINX_CFG="true"
|
||||||
|
|
||||||
else
|
else
|
||||||
SET_NGINX_CFG="false"
|
SET_NGINX_CFG="false"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_fluidd_port() {
|
function select_fluidd_port() {
|
||||||
if [ "${PORT_80_BLOCKED}" = "true" ]; then
|
local new_port
|
||||||
|
if [[ ${PORT_80_BLOCKED} == "true" ]]; then
|
||||||
echo
|
echo
|
||||||
top_border
|
top_border
|
||||||
echo -e "| ${red}!!!WARNING!!!${white} |"
|
echo -e "| ${red}!!!WARNING!!!${white} |"
|
||||||
echo -e "| ${red}You need to choose a different port for Fluidd!${white} |"
|
echo -e "| ${red}You need to choose a different port for Fluidd!${white} |"
|
||||||
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
|
echo -e "| ${red}The following web interface is listening at port 80:${white} |"
|
||||||
blank_line
|
blank_line
|
||||||
[ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |"
|
[[ ${OCTOPRINT_PORT} == "80" ]] && echo "| ● OctoPrint |"
|
||||||
[ "${MAINSAIL_PORT}" = "80" ] && echo "| ● Mainsail |"
|
[[ ${MAINSAIL_PORT} == "80" ]] && echo "| ● Mainsail |"
|
||||||
blank_line
|
blank_line
|
||||||
echo -e "| Make sure you don't choose a port which was already |"
|
echo -e "| Make sure you don't choose a port which was already |"
|
||||||
echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${white} |"
|
echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${white} |"
|
||||||
@@ -361,10 +379,11 @@ function select_fluidd_port() {
|
|||||||
echo -e "| input. So make sure to choose a valid port! |"
|
echo -e "| input. So make sure to choose a valid port! |"
|
||||||
bottom_border
|
bottom_border
|
||||||
while true; do
|
while true; do
|
||||||
read -p "${cyan}Please enter a new Port:${white} " NEW_PORT
|
#TODO implement regex input validation for numbers only
|
||||||
if [ "${NEW_PORT}" != "${MAINSAIL_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then
|
read -p "${cyan}Please enter a new Port:${white} " new_port
|
||||||
echo "Setting port ${NEW_PORT} for Fluidd!"
|
if [[ ${new_port} != "${MAINSAIL_PORT}" ]] && [[ ${new_port} != "${OCTOPRINT_PORT}" ]]; then
|
||||||
SET_LISTEN_PORT=${NEW_PORT}
|
echo "Setting port ${new_port} for Mainsail!"
|
||||||
|
SET_LISTEN_PORT=${new_port}
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo "That port is already taken! Select a different one!"
|
echo "That port is already taken! Select a different one!"
|
||||||
@@ -376,10 +395,12 @@ function select_fluidd_port() {
|
|||||||
function patch_fluidd_update_manager() {
|
function patch_fluidd_update_manager() {
|
||||||
local moonraker_configs
|
local moonraker_configs
|
||||||
moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf" | sort)
|
moonraker_configs=$(find "$(get_klipper_cfg_dir)" -type f -name "moonraker.conf" | sort)
|
||||||
|
|
||||||
for conf in ${moonraker_configs}; do
|
for conf in ${moonraker_configs}; do
|
||||||
if ! grep -Eq "[update_manager fluidd]" "${conf}"; then
|
if ! grep -Eq "[update_manager fluidd]" "${conf}"; then
|
||||||
### add new line to conf if it doesn't end with one
|
### add new line to conf if it doesn't end with one
|
||||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
||||||
|
|
||||||
### add Fluidds update manager section to moonraker.conf
|
### add Fluidds update manager section to moonraker.conf
|
||||||
status_msg "Adding Fluidd to update manager in file:\n ${conf}"
|
status_msg "Adding Fluidd to update manager in file:\n ${conf}"
|
||||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
||||||
@@ -390,6 +411,7 @@ channel: stable
|
|||||||
repo: fluidd-core/fluidd
|
repo: fluidd-core/fluidd
|
||||||
path: ~/fluidd
|
path: ~/fluidd
|
||||||
MOONRAKER_CONF
|
MOONRAKER_CONF
|
||||||
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user