refactor: fluidd installer
Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
@@ -41,14 +41,32 @@ function install_fluidd(){
|
|||||||
fluidd_port_check
|
fluidd_port_check
|
||||||
|
|
||||||
### ask user to install mjpg-streamer
|
### ask user to install mjpg-streamer
|
||||||
if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then
|
local install_mjpg_streamer
|
||||||
get_user_selection_mjpg-streamer
|
if [ ! -f "${SYSTEMD}/webcamd.service" ]; then
|
||||||
|
while true; do
|
||||||
|
echo
|
||||||
|
top_border
|
||||||
|
echo -e "| Install MJGP-Streamer for webcam support? |"
|
||||||
|
bottom_border
|
||||||
|
read -p "${cyan}###### Please select (Y/n):${white} " yn
|
||||||
|
case "${yn}" in
|
||||||
|
Y|y|Yes|yes|"")
|
||||||
|
select_msg "Yes"
|
||||||
|
install_mjpg_streamer="true"
|
||||||
|
break;;
|
||||||
|
N|n|No|no)
|
||||||
|
select_msg "No"
|
||||||
|
install_mjpg_streamer="false"
|
||||||
|
break;;
|
||||||
|
*)
|
||||||
|
error_msg "Invalid command!";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
### ask user to install the recommended webinterface macros
|
### ask user to install the recommended webinterface macros
|
||||||
if ! ls "${KLIPPER_CONFIG}/kiauh_macros.cfg" 2>/dev/null 1>&2 || ! ls "${KLIPPER_CONFIG}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then
|
install_fluidd_macros
|
||||||
get_user_selection_kiauh_macros "Fluidd "
|
|
||||||
fi
|
|
||||||
### create /etc/nginx/conf.d/upstreams.conf
|
### create /etc/nginx/conf.d/upstreams.conf
|
||||||
set_upstream_nginx_cfg
|
set_upstream_nginx_cfg
|
||||||
### create /etc/nginx/sites-available/<interface config>
|
### create /etc/nginx/sites-available/<interface config>
|
||||||
@@ -57,14 +75,11 @@ function install_fluidd(){
|
|||||||
### symlink nginx log
|
### symlink nginx log
|
||||||
symlink_webui_nginx_log "fluidd"
|
symlink_webui_nginx_log "fluidd"
|
||||||
|
|
||||||
### copy the kiauh_macros.cfg to the config location
|
|
||||||
install_kiauh_macros
|
|
||||||
|
|
||||||
### install mainsail/fluidd
|
### install mainsail/fluidd
|
||||||
fluidd_setup
|
fluidd_setup
|
||||||
|
|
||||||
### install mjpg-streamer
|
### install mjpg-streamer
|
||||||
[ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer
|
[ "${install_mjpg_streamer}" = "true" ] && install_mjpg-streamer
|
||||||
|
|
||||||
fetch_webui_ports #WIP
|
fetch_webui_ports #WIP
|
||||||
|
|
||||||
@@ -72,55 +87,138 @@ function install_fluidd(){
|
|||||||
print_confirm "Fluidd has been set up!"
|
print_confirm "Fluidd has been set up!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function install_fluidd_macros(){
|
||||||
|
while true; do
|
||||||
|
echo
|
||||||
|
top_border
|
||||||
|
echo -e "| It is recommended to have some important macros in |"
|
||||||
|
echo -e "| your printer configuration to have Mainsail fully |"
|
||||||
|
echo -e "| functional and working. |"
|
||||||
|
blank_line
|
||||||
|
echo -e "| The recommended macros for Fluidd can be found here: |"
|
||||||
|
echo -e "| https://docs.fluidd.xyz/configuration/initial_setup |"
|
||||||
|
blank_line
|
||||||
|
echo -e "| If you already have these macros in your config file, |"
|
||||||
|
echo -e "| skip this step and answer with 'no'. |"
|
||||||
|
echo -e "| Otherwise you should consider to answer with 'yes' to |"
|
||||||
|
echo -e "| add the recommended example macros to your config. |"
|
||||||
|
bottom_border
|
||||||
|
read -p "${cyan}###### Add the recommended macros? (Y/n):${white} " yn
|
||||||
|
case "${yn}" in
|
||||||
|
Y|y|Yes|yes|"")
|
||||||
|
select_msg "Yes"
|
||||||
|
download_fluidd_macros
|
||||||
|
break;;
|
||||||
|
N|n|No|no)
|
||||||
|
select_msg "No"
|
||||||
|
break;;
|
||||||
|
*)
|
||||||
|
print_error "Invalid command!";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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 configs
|
||||||
|
configs=$(find "${KLIPPER_CONFIG}" -type f -name "printer.cfg")
|
||||||
|
if [ -n "${configs}" ]; then
|
||||||
|
### create a backup of the config folder
|
||||||
|
backup_klipper_config_dir
|
||||||
|
|
||||||
|
for config in ${configs}; do
|
||||||
|
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||||
|
if [ ! -f "${path}/fluidd.cfg" ]; then
|
||||||
|
status_msg "Downloading fluidd.cfg to ${path} ..."
|
||||||
|
log_info "downloading fluidd.cfg to: ${path}"
|
||||||
|
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'
|
||||||
|
log_info "modify 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
|
||||||
|
if ! grep -Eq "^[include fluidd.cfg]$" "${path}/printer.cfg"; then
|
||||||
|
log_info "modify printer.cfg"
|
||||||
|
sed -i "1 i [include fluidd.cfg]" "${path}/printer.cfg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ok_msg "Done!"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
log_error "execution stopped! reason: no printer.cfg found"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function fluidd_setup(){
|
function fluidd_setup(){
|
||||||
### get fluidd download url
|
local url
|
||||||
FLUIDD_DL_URL=$(curl -s "${FLUIDD_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1)
|
url=$(get_fluidd_download_url)
|
||||||
|
status_msg "Downloading Fluidd ..."
|
||||||
### remove existing and create fresh fluidd folder, then download fluidd
|
if [ -d "${FLUIDD_DIR}" ]; then
|
||||||
[ -d "${FLUIDD_DIR}" ] && rm -rf "${FLUIDD_DIR}"
|
rm -rf "${FLUIDD_DIR}"
|
||||||
|
fi
|
||||||
mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}"
|
mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}"
|
||||||
status_msg "Downloading Fluidd ${FLUIDD_VERSION} ..."
|
wget "${url}" && ok_msg "Download complete!"
|
||||||
wget "${FLUIDD_DL_URL}" && ok_msg "Download complete!"
|
|
||||||
|
|
||||||
### extract archive
|
|
||||||
status_msg "Extracting archive ..."
|
status_msg "Extracting archive ..."
|
||||||
unzip -q -o *.zip && ok_msg "Done!"
|
unzip -q -o ./*.zip && ok_msg "Done!"
|
||||||
|
|
||||||
### delete downloaded zip
|
|
||||||
status_msg "Remove downloaded archive ..."
|
status_msg "Remove downloaded archive ..."
|
||||||
rm -rf *.zip && ok_msg "Done!"
|
rm -rf ./*.zip && ok_msg "Done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
#===================================================#
|
#===================================================#
|
||||||
#================== REMOVE FLUIDD ==================#
|
#================== REMOVE FLUIDD ==================#
|
||||||
#===================================================#
|
#===================================================#
|
||||||
|
|
||||||
function remove_fluidd(){
|
function remove_fluidd_dir(){
|
||||||
### remove fluidd dir
|
[ ! -d "${FLUIDD_DIR}" ] && return
|
||||||
if [ -d "${FLUIDD_DIR}" ]; then
|
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!"
|
}
|
||||||
fi
|
|
||||||
|
|
||||||
### remove fluidd config for nginx
|
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
|
||||||
### remove fluidd symlink for nginx
|
|
||||||
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
|
||||||
|
}
|
||||||
|
|
||||||
### remove mainsail nginx logs and log symlinks
|
function remove_fluidd_logs(){
|
||||||
for log in $(find /var/log/nginx -name "fluidd*"); do
|
local files
|
||||||
sudo rm -f "${log}"
|
files=$(find /var/log/nginx -name "fluidd*")
|
||||||
done
|
if [ -n "${files}" ]; then
|
||||||
for log in $(find ${HOME}/klipper_logs -name "fluidd*"); do
|
for file in ${files}; do
|
||||||
rm -f "${log}"
|
status_msg "Removing ${file} ..."
|
||||||
done
|
sudo rm -f "${file}"
|
||||||
|
ok_msg "${file} removed!"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_fluidd_log_symlinks(){
|
||||||
|
local files
|
||||||
|
files=$(find "${HOME}/klipper_logs" -name "fluidd*")
|
||||||
|
if [ -n "${files}" ]; then
|
||||||
|
for file in ${files}; do
|
||||||
|
status_msg "Removing ${file} ..."
|
||||||
|
rm -f "${file}"
|
||||||
|
ok_msg "${file} removed!"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_fluidd(){
|
||||||
|
remove_fluidd_dir
|
||||||
|
remove_fluidd_config
|
||||||
|
remove_fluidd_logs
|
||||||
|
remove_fluidd_log_symlinks
|
||||||
|
|
||||||
### remove fluidd_port from ~/.kiauh.ini
|
### remove fluidd_port from ~/.kiauh.ini
|
||||||
sed -i "/^fluidd_port=/d" "${INI_FILE}"
|
sed -i "/^fluidd_port=/d" "${INI_FILE}"
|
||||||
@@ -144,14 +242,8 @@ function update_fluidd(){
|
|||||||
#================== FLUIDD STATUS ==================#
|
#================== FLUIDD STATUS ==================#
|
||||||
#===================================================#
|
#===================================================#
|
||||||
|
|
||||||
function get_fluidd_ver(){
|
|
||||||
FLUIDD_VERSION=$(curl -s "${FLUIDD_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
function fluidd_status(){
|
function fluidd_status(){
|
||||||
local status
|
local status
|
||||||
|
|
||||||
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
|
||||||
local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd")
|
local data_arr=("${FLUIDD_DIR}" "${NGINX_SA}/fluidd" "${NGINX_SE}/fluidd")
|
||||||
|
|
||||||
### count+1 for each found data-item from array
|
### count+1 for each found data-item from array
|
||||||
|
|||||||
Reference in New Issue
Block a user