mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 18:44:29 +05:00
Upload v2.0
Uploading a complete rewrite of the original script.
This commit is contained in:
74
scripts/backup.sh
Normal file
74
scripts/backup.sh
Normal file
@@ -0,0 +1,74 @@
|
||||
backup_printer_cfg(){
|
||||
if [ ! -d $BACKUP_DIR ]; then
|
||||
status_msg "Create backup directory ..."
|
||||
mkdir -p $BACKUP_DIR && ok_msg "Directory created!"
|
||||
fi
|
||||
if [ -f $PRINTER_CFG ]; then
|
||||
get_date
|
||||
status_msg "Create backup of printer.cfg ..."
|
||||
cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup created!"
|
||||
else
|
||||
ok_msg "No printer.cfg found! Skipping backup ..."
|
||||
fi
|
||||
}
|
||||
|
||||
read_bb4u_stat(){
|
||||
source_ini
|
||||
if [ ! "$backup_before_update" = "true" ]; then
|
||||
BB4U_STATUS="${green}[Enable]${default} backups before updating "
|
||||
else
|
||||
BB4U_STATUS="${red}[Disable]${default} backups before updating "
|
||||
fi
|
||||
}
|
||||
|
||||
toggle_backups(){
|
||||
source_ini
|
||||
if [ "$backup_before_update" = "true" ]; then
|
||||
sed -i '/backup_before_update=/s/true/false/' ${HOME}/kiauh2/kiauh.ini
|
||||
BB4U_STATUS="${green}[Enable]${default} backups before updating "
|
||||
fi
|
||||
if [ "$backup_before_update" = "false" ]; then
|
||||
sed -i '/backup_before_update=/s/false/true/' ${HOME}/kiauh2/kiauh.ini
|
||||
BB4U_STATUS="${red}[Disable]${default} backups before updating "
|
||||
fi
|
||||
}
|
||||
|
||||
bb4u_klipper(){
|
||||
source_ini
|
||||
if [ -d $KLIPPER_DIR ] && [ "$backup_before_update" = "true" ]; then
|
||||
get_date
|
||||
status_msg "Creating Klipper backup ..."
|
||||
mkdir -p $BACKUP_DIR/klipper-backups/"$current_date"
|
||||
cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV_DIR $_ && ok_msg "Backup complete!"
|
||||
fi
|
||||
}
|
||||
|
||||
bb4u_dwc2fk(){
|
||||
source_ini
|
||||
if [ -d $DWC2FK_DIR ] && [ "$backup_before_update" = "true" ]; then
|
||||
get_date
|
||||
status_msg "Creating DWC2-for-Klipper backup ..."
|
||||
mkdir -p $BACKUP_DIR/dwc2-for-klipper-backups/"$current_date"
|
||||
cp -r $DWC2FK_DIR $_ && ok_msg "Backup complete!"
|
||||
fi
|
||||
}
|
||||
|
||||
bb4u_dwc2(){
|
||||
source_ini
|
||||
if [ -d $DWC2_DIR ] && [ "$backup_before_update" = "true" ]; then
|
||||
get_date
|
||||
status_msg "Creating DWC2 Web UI backup ..."
|
||||
mkdir -p $BACKUP_DIR/dwc2-backups/"$current_date"
|
||||
cp -r $DWC2_DIR $_ && ok_msg "Backup complete!"
|
||||
fi
|
||||
}
|
||||
|
||||
bb4u_mainsail(){
|
||||
source_ini
|
||||
if [ -d $MAINSAIL_DIR ] && [ "$backup_before_update" = "true" ]; then
|
||||
get_date
|
||||
status_msg "Creating Mainsail backup ..."
|
||||
mkdir -p $BACKUP_DIR/mainsail-backups/"$current_date"
|
||||
cp -r $MAINSAIL_DIR $_ && ok_msg "Backup complete!"
|
||||
fi
|
||||
}
|
||||
185
scripts/functions.sh
Normal file
185
scripts/functions.sh
Normal file
@@ -0,0 +1,185 @@
|
||||
# setting up some frequently used functions
|
||||
check_euid(){
|
||||
if [ "$EUID" -eq 0 ]
|
||||
then
|
||||
echo -e "${red}"
|
||||
echo -e "/=================================================\ "
|
||||
echo -e "| !!! THIS SCRIPT MUST NOT RAN AS ROOT !!! |"
|
||||
echo -e "\=================================================/ "
|
||||
echo -e "${default}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
source_ini(){
|
||||
source ${HOME}/kiauh2/kiauh.ini
|
||||
}
|
||||
|
||||
start_klipper(){
|
||||
if [ -e /etc/init.d/klipper ]; then
|
||||
status_msg "Starting klipper service ..."
|
||||
sudo /etc/init.d/klipper start && sleep 2 && ok_msg "Klipper service started!"
|
||||
fi
|
||||
}
|
||||
stop_klipper(){
|
||||
if [ -e /etc/init.d/klipper ]; then
|
||||
status_msg "Stopping klipper service ..."
|
||||
sudo /etc/init.d/klipper stop && sleep 2 && ok_msg "Klipper service stopped!"
|
||||
fi
|
||||
}
|
||||
|
||||
start_moonraker(){
|
||||
if [ -e /etc/init.d/moonraker ]; then
|
||||
status_msg "Starting moonraker service ..."
|
||||
sudo /etc/init.d/moonraker start && sleep 2 && ok_msg "Moonraker service started!"
|
||||
fi
|
||||
}
|
||||
|
||||
stop_moonraker(){
|
||||
if [ -e /etc/init.d/moonraker ]; then
|
||||
status_msg "Stopping moonraker service ..."
|
||||
sudo /etc/init.d/moonraker stop && sleep 2 && ok_msg "Moonraker service stopped!"
|
||||
fi
|
||||
}
|
||||
|
||||
dep_check(){
|
||||
for package in "${dep[@]}"
|
||||
do
|
||||
! command -v $package >&/dev/null 2>&1 && install+=($package)
|
||||
done
|
||||
if ! [ ${#install[@]} -eq 0 ]; then
|
||||
warn_msg "The following packages are missing but necessary:"
|
||||
echo ${install[@]}
|
||||
while true; do
|
||||
read -p "Do you want to install them now? (Y/n): " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
status_msg "Installing dependencies ..."
|
||||
sudo apt-get install ${install[@]} -y && ok_msg "Dependencies installed!"
|
||||
break;;
|
||||
N|n|No|no) break;;
|
||||
*) echo "Unknown parameter: $yn"; echo;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
print_error(){
|
||||
for data in "${data_arr[@]}"
|
||||
do
|
||||
if [ ! -e $data ]; then
|
||||
data_count+=(0)
|
||||
else
|
||||
data_count+=(1)
|
||||
fi
|
||||
done
|
||||
sum=$(IFS=+; echo "$((${data_count[*]}))")
|
||||
if [ $sum -eq 0 ]; then
|
||||
ERROR_MSG=" Looks like $1 was already removed!\n Skipping..."
|
||||
else
|
||||
ERROR_MSG=""
|
||||
fi
|
||||
}
|
||||
|
||||
pkg_check(){
|
||||
status_msg "Checking if nginx is installed"
|
||||
if [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]]; then
|
||||
echo "nginx found!"
|
||||
else
|
||||
echo "nginx was not found, installing..." 2>&1
|
||||
sudo apt-get -y install nginx 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
build_fw(){
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
cd $KLIPPER_DIR && make menuconfig
|
||||
status_msg "Building firmware ..."
|
||||
make clean && make && ok_msg "Firmware built!"
|
||||
else
|
||||
warn_msg "Can not build firmware without a Klipper directory!"
|
||||
fi
|
||||
}
|
||||
|
||||
### grab the printers id
|
||||
get_usb_id(){
|
||||
warn_msg "Make sure your printer is the only USB device connected!"
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Press any key to continue ... " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
*) break;;
|
||||
esac
|
||||
done
|
||||
status_msg "Identifying the correct USB port ..."
|
||||
USB_ID=$(ls /dev/serial/by-id/*)
|
||||
if [ -e /dev/serial/by-id/* ]; then
|
||||
status_msg "The ID of your printer is:"
|
||||
title_msg "$USB_ID"
|
||||
else
|
||||
warn_msg "Could not retrieve ID!"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
write_printer_id(){
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to write the ID to your printer.cfg? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
backup_printer_cfg
|
||||
cat <<PRINTERID >> $PRINTER_CFG
|
||||
|
||||
##########################
|
||||
### CREATED WITH KIAUH ###
|
||||
##########################
|
||||
[mcu]
|
||||
serial: $USB_ID
|
||||
##########################
|
||||
##########################
|
||||
PRINTERID
|
||||
ok_msg "Config written!"
|
||||
break;;
|
||||
N|n|No|no) break;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
flash_routine(){
|
||||
echo -e "/=================================================\ "
|
||||
echo -e "| ATTENTION! |"
|
||||
echo -e "| Flashing a Smoothie based board for the first |"
|
||||
echo -e "| time with this script will certainly fail. |"
|
||||
echo -e "| This applies to boards like the BTT SKR V1.3 or |"
|
||||
echo -e "| the newer SKR V1.4 (Turbo). You have to copy |"
|
||||
echo -e "| the firmware file to the microSD card manually |"
|
||||
echo -e "| and rename it to 'firmware.bin'. |"
|
||||
echo -e "| |"
|
||||
echo -e "| You find the file in: ~/klipper/out/klipper.bin |"
|
||||
echo -e "\=================================================/ "
|
||||
echo
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to continue? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
get_usb_id && flash_mcu && write_printer_id; break;;
|
||||
N|n|No|no) break;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
flash_mcu(){
|
||||
stop_klipper
|
||||
if ! make flash FLASH_DEVICE="$USB_ID" ; then
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the log above!"
|
||||
else
|
||||
ok_msg "Flashing successfull!"
|
||||
fi
|
||||
start_klipper
|
||||
}
|
||||
166
scripts/install_dwc2.sh
Normal file
166
scripts/install_dwc2.sh
Normal file
@@ -0,0 +1,166 @@
|
||||
#TODO:
|
||||
# - check for existing/running octoprint service
|
||||
# - ask for permission to disable octoprint service
|
||||
|
||||
dwc2_install_routine(){
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
# check for existing installation
|
||||
if [ -d ${HOME}/klippy-env/lib/python2.7/site-packages/tornado ]; then
|
||||
ERROR_MSG=" Looks like DWC2 is already installed!\n Skipping..."
|
||||
return
|
||||
fi
|
||||
stop_klipper
|
||||
install_tornado
|
||||
install_dwc2fk && dwc2fk_cfg
|
||||
install_dwc2
|
||||
start_klipper
|
||||
else
|
||||
ERROR_MSG=" Please install Klipper first!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
install_tornado(){
|
||||
#check for dependencies
|
||||
dep=(virtualenv)
|
||||
dep_check
|
||||
#execute operation
|
||||
status_msg "Installing Tornado 5.1.1 ..."
|
||||
cd ${HOME}
|
||||
PYTHONDIR="${HOME}/klippy-env"
|
||||
virtualenv ${PYTHONDIR}
|
||||
${PYTHONDIR}/bin/pip install tornado==5.1.1 && ok_msg "Tornado 5.1.1 successfully installed!"
|
||||
}
|
||||
|
||||
install_dwc2fk(){
|
||||
cd ${HOME}
|
||||
status_msg "Cloning dwc2-for-klipper repository ..."
|
||||
git clone $DWC2FK_REPO && ok_msg "dwc2-for-klipper successfully cloned!"
|
||||
#create a web_dwc2.py symlink if not already existing
|
||||
if [ -d $KLIPPER_DIR/klippy/extras ] && [ ! -e $KLIPPER_DIR/klippy/extras/web_dwc2.py ]; then
|
||||
status_msg "Creating web_dwc2.py symlink ..."
|
||||
ln -s $DWC2FK_DIR/web_dwc2.py $KLIPPER_DIR/klippy/extras/web_dwc2.py && ok_msg "Symlink created!"
|
||||
fi
|
||||
}
|
||||
|
||||
dwc2fk_cfg(){
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to create the config now? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"") create_dwc2fk_cfg; break;;
|
||||
N|n|No|no) break;;
|
||||
*) echo "Unknown parameter: $yn"; dwc2fk_cfg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
create_dwc2fk_cfg(){
|
||||
echo -e "/=================================================\ "
|
||||
echo -e "| 1) [Default configuration] | "
|
||||
echo -e "| 2) [Custom configuration] | "
|
||||
echo -e "| 3) [Skip] | "
|
||||
echo -e "\=================================================/ "
|
||||
while true; do
|
||||
read -p "Please select: " choice; echo
|
||||
case "$choice" in
|
||||
1) dwc2fk_default_cfg && ok_msg "Config written ..."; break;;
|
||||
2) create_dwc2fk_custom_cfg && ok_msg "Config written ..."; break;;
|
||||
3) echo "Skipping ..."; break;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
dwc2fk_default_cfg(){
|
||||
cat <<DWC2 >> $PRINTER_CFG
|
||||
|
||||
##########################
|
||||
### CREATED WITH KIAUH ###
|
||||
##########################
|
||||
[virtual_sdcard]
|
||||
path: ~/sdcard
|
||||
|
||||
[web_dwc2]
|
||||
printer_name: my_printer
|
||||
listen_adress: 0.0.0.0
|
||||
listen_port: 4750
|
||||
web_path: dwc2/web
|
||||
##########################
|
||||
##########################
|
||||
DWC2
|
||||
}
|
||||
|
||||
create_dwc2fk_custom_cfg(){
|
||||
echo -e "${cyan}"
|
||||
read -e -p "Printer name: " -i "my_printer" PRINTER_NAME
|
||||
read -e -p "Listen adress: " -i "0.0.0.0" LISTEN_ADRESS
|
||||
read -e -p "Listen port: " -i "4750" LISTEN_PORT
|
||||
read -e -p "Web path: " -i "dwc2/web" WEB_PATH
|
||||
echo -e "${default}"
|
||||
DWC2_CFG=$(cat <<DWC2
|
||||
|
||||
##########################
|
||||
### CREATED WITH KIAUH ###
|
||||
##########################
|
||||
[virtual_sdcard]
|
||||
path: ~/sdcard
|
||||
|
||||
[web_dwc2]
|
||||
printer_name: $PRINTER_NAME
|
||||
listen_adress: $LISTEN_ADRESS
|
||||
listen_port: $LISTEN_PORT
|
||||
web_path: $WEB_PATH
|
||||
##########################
|
||||
##########################
|
||||
DWC2
|
||||
)
|
||||
echo "The following lines will be written:"
|
||||
echo -e "$DWC2_CFG"
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Write now (Y) or start over (n)? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"") echo -e "$DWC2_CFG" >> $PRINTER_CFG; break;;
|
||||
N|n|No|no) create_dwc2fk_custom_cfg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
install_dwc2(){
|
||||
#needed packages for webcam
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to use a webcam? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
status_msg "Checking for dependencies ..."
|
||||
webcam_dep_check && ok_msg "Dependencies installed!"
|
||||
break;;
|
||||
N|n|No|no) break;;
|
||||
*) echo "Unknown parameter: $yn"; echo;;
|
||||
esac
|
||||
done
|
||||
#the update_dwc2 function does the same as installing dwc2
|
||||
update_dwc2 && ok_msg "DWC2 Web UI installed!"
|
||||
}
|
||||
|
||||
webcam_dep_check(){
|
||||
webcam_dep=(
|
||||
build-essential
|
||||
libjpeg8-dev
|
||||
imagemagick
|
||||
libv4l-dev
|
||||
cmake
|
||||
)
|
||||
for pkg in "${webcam_dep[@]}"
|
||||
do
|
||||
if ! [[ $(dpkg-query -f'${Status}' --show $pkg 2>/dev/null) = *\ installed ]]; then
|
||||
install+=($pkg)
|
||||
fi
|
||||
done
|
||||
if ! [ ${#install[@]} -eq 0 ]; then
|
||||
sudo apt-get install ${install[@]} -y
|
||||
fi
|
||||
}
|
||||
30
scripts/install_klipper.sh
Normal file
30
scripts/install_klipper.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
install_klipper(){
|
||||
if [ -e /etc/init.d/klipper ] && [ -e /etc/default/klipper ]; then
|
||||
ERROR_MSG=" Looks like klipper is already installed!\n Skipping ..."
|
||||
else
|
||||
#check for dependencies
|
||||
dep=(git)
|
||||
dep_check
|
||||
#execute operation
|
||||
cd ${HOME}
|
||||
status_msg "Cloning klipper repository ..."
|
||||
git clone $KLIPPER_REPO && ok_msg "Klipper successfully cloned!"
|
||||
status_msg "Installing klipper service ..."
|
||||
$KLIPPER_DIR/scripts/install-octopi.sh && sleep 2 && ok_msg "Klipper installation complete!"
|
||||
#create a klippy.log symlink in home-dir just for convenience
|
||||
if [ ! -e ${HOME}/klippy.log ]; then
|
||||
status_msg "Creating klippy.log symlink ..."
|
||||
ln -s /tmp/klippy.log ${HOME}/klippy.log && ok_msg "Symlink created!"
|
||||
fi
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to flash your MCU now? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"") build_fw && flash_routine; break;;
|
||||
N|n|No|no) break;;
|
||||
*) warn_msg "Unknown parameter: $yn"; echo;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
349
scripts/install_mainsail.sh
Normal file
349
scripts/install_mainsail.sh
Normal file
@@ -0,0 +1,349 @@
|
||||
mainsail_install_routine(){
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
#check for dependencies
|
||||
dep=(wget curl unzip)
|
||||
dep_check
|
||||
#execute operation
|
||||
install_moonraker
|
||||
disable_wrong_webserver
|
||||
remove_wrong_webserver
|
||||
install_nginx
|
||||
test_api
|
||||
test_nginx
|
||||
install_mainsail && ok_msg "Mainsail install complete!"; echo
|
||||
else
|
||||
ERROR_MSG=" Please install Klipper first!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
install_moonraker(){
|
||||
cd $KLIPPER_DIR
|
||||
if [[ $(git describe --all) = "remotes/Arksine/work-web_server-20200131" ]]; then
|
||||
status_msg "Installing Moonraker ..."
|
||||
$KLIPPER_DIR/scripts/install-moonraker.sh && ok_msg "Moonraker successfully installed!"
|
||||
if [ ! -d ${HOME}/sdcard ]; then
|
||||
mkdir ${HOME}/sdcard
|
||||
fi
|
||||
#create a moonraker.log symlink in home-dir just for convenience
|
||||
if [ ! -e ${HOME}/moonraker.log ]; then
|
||||
status_msg "Creating moonraker.log symlink ..."
|
||||
ln -s /tmp/moonraker.log ${HOME}/moonraker.log && ok_msg "Symlink created!"
|
||||
fi
|
||||
else
|
||||
warn_msg "You are not using Arksine/work-web_server-20200131."
|
||||
warn_msg "Please switch to the moonraker fork first!"
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to switch to it now? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"") switch_to_moonraker && install_moonraker; break;;
|
||||
N|n|No|no) break;;
|
||||
*) echo "Unknown parameter: $yn"; echo;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
check_printer_cfg(){
|
||||
if [ ! -e $PRINTER_CFG ]; then
|
||||
warn_msg "No printer.cfg found"
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to create a default config? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"") create_default_cfg; break;;
|
||||
N|n|No|no) break;;
|
||||
*) echo "Unknown parameter: $yn"; echo;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
check_vsdcard_section
|
||||
check_api_section
|
||||
fi
|
||||
}
|
||||
|
||||
disable_wrong_webserver(){
|
||||
if systemctl is-active haproxy ; then
|
||||
status_msg "Stopping haproxy service ..."
|
||||
sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!"
|
||||
fi
|
||||
if systemctl is-active lighttpd ; then
|
||||
status_msg "Stopping lighttpd service ..."
|
||||
sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_wrong_webserver(){
|
||||
rem=(haproxy lighttpd)
|
||||
for remove in "${rem[@]}"
|
||||
do
|
||||
if [[ $(dpkg-query -f'${Status}' --show $remove 2>/dev/null) = *\ installed ]]; then
|
||||
delete+=($remove)
|
||||
fi
|
||||
done
|
||||
if ! [ ${#delete[@]} -eq 0 ]; then
|
||||
sudo apt-get remove ${delete[@]} -y
|
||||
fi
|
||||
}
|
||||
|
||||
install_nginx(){
|
||||
if ! [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]]; then
|
||||
status_msg "Installing Nginx ..."
|
||||
sudo apt-get install nginx -y && ok_msg "Nginx successfully installed!"
|
||||
fi
|
||||
if [ ! -d $MAINSAIL_DIR ]; then
|
||||
mkdir $MAINSAIL_DIR
|
||||
fi
|
||||
status_msg "Configure Nginx ..."
|
||||
create_mainsail_cfgfile && sudo mv $MAINSAIL_DIR/mainsail /etc/nginx/sites-available/
|
||||
if [ -e /etc/nginx/sites-enabled/default ]; then
|
||||
sudo rm /etc/nginx/sites-enabled/default
|
||||
fi
|
||||
if [ ! -e /etc/nginx/sites-enabled/mainsail ]; then
|
||||
sudo ln -s /etc/nginx/sites-available/mainsail /etc/nginx/sites-enabled/
|
||||
fi
|
||||
ok_msg "Nginx configured!"
|
||||
}
|
||||
|
||||
test_api(){
|
||||
status_msg "Testing API ..."
|
||||
sleep 5
|
||||
status_msg "API response from http://localhost:7125/printer/info:"
|
||||
API_RESPONSE="$(curl -sG4 http://localhost:7125/printer/info)"
|
||||
echo -e "${cyan}$API_RESPONSE${default}"
|
||||
if [ $(curl -sG4 "http://localhost:7125/printer/info" | grep '^{"result"' -c) -eq 1 ]; then
|
||||
echo; ok_msg "Klipper API is working correctly!"; echo
|
||||
else
|
||||
echo; warn_msg "Klipper API not working correctly!"; echo
|
||||
fi
|
||||
}
|
||||
|
||||
test_nginx(){
|
||||
sudo /etc/init.d/nginx restart
|
||||
status_msg "Testing Nginx ..."
|
||||
sleep 5
|
||||
status_msg "API response from http://localhost/printer/info:"
|
||||
API_RESPONSE="$(curl -sG4 http://localhost/printer/info)"
|
||||
echo -e "${cyan}$API_RESPONSE${default}"
|
||||
if [ $(curl -sG4 "http://localhost/printer/info" | grep '^{"result"' -c) -eq 1 ]; then
|
||||
echo; ok_msg "Nginx is working correctly!"; echo
|
||||
else
|
||||
echo; warn_msg "Nginx is not working correctly!"; echo
|
||||
fi
|
||||
}
|
||||
|
||||
get_mainsail_ver(){
|
||||
MAINSAIL_VERSION=`curl -s https://api.github.com/repositories/240875926/tags | grep name | cut -d'"' -f4 | cut -d"v" -f2 | head -1`
|
||||
}
|
||||
|
||||
mainsail_dl_url(){
|
||||
get_mainsail_ver
|
||||
MAINSAIL_URL=https://github.com/meteyou/mainsail/releases/download/v"$MAINSAIL_VERSION"/mainsail-alpha-"$MAINSAIL_VERSION".zip
|
||||
}
|
||||
|
||||
install_mainsail(){
|
||||
mainsail_dl_url
|
||||
if [ ! -d $MAINSAIL_DIR ]; then
|
||||
mkdir $MAINSAIL_DIR
|
||||
fi
|
||||
cd $MAINSAIL_DIR
|
||||
status_msg "Downloading Mainsail v$MAINSAIL_VERSION ..."
|
||||
wget -q -O mainsail.zip $MAINSAIL_URL && status_msg "Extracting archive ..." && unzip -o mainsail.zip && rm mainsail.zip
|
||||
### write mainsail version to file for update check reasons
|
||||
echo "$MAINSAIL_VERSION" > $MAINSAIL_DIR/version
|
||||
}
|
||||
|
||||
create_mainsail_cfgfile(){
|
||||
cat <<MAINSAIL_CFG > $MAINSAIL_DIR/mainsail
|
||||
map \$http_upgrade \$connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
upstream apiserver {
|
||||
#edit your api port here
|
||||
ip_hash;
|
||||
server 127.0.0.1:7125;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
access_log /var/log/nginx/mainsail-access.log;
|
||||
error_log /var/log/nginx/mainsail-error.log;
|
||||
|
||||
#web_path from mainsail static files
|
||||
root /home/pi/mainsail;
|
||||
|
||||
index index.html;
|
||||
server_name _;
|
||||
|
||||
#max upload size for gcodes
|
||||
client_max_body_size 200M;
|
||||
|
||||
location / {
|
||||
try_files \$uri \$uri/ /index.html;
|
||||
}
|
||||
|
||||
location /printer {
|
||||
proxy_pass http://apiserver/printer;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme \$scheme;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://apiserver/api;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme \$scheme;
|
||||
}
|
||||
|
||||
location /access {
|
||||
proxy_pass http://apiserver/access;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme \$scheme;
|
||||
}
|
||||
|
||||
location /websocket {
|
||||
proxy_pass http://apiserver/websocket;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade \$http_upgrade;
|
||||
proxy_set_header Connection \$connection_upgrade;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
location /machine {
|
||||
proxy_pass http://apiserver/machine;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme \$scheme;
|
||||
}
|
||||
|
||||
location /server {
|
||||
proxy_pass http://apiserver/server;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme \$scheme;
|
||||
}
|
||||
}
|
||||
MAINSAIL_CFG
|
||||
}
|
||||
|
||||
check_vsdcard_section(){
|
||||
# check if virtual sdcard is present in printer.cfg
|
||||
if [ $(grep '^\[virtual_sdcard\]$' /home/pi/printer.cfg) ]; then
|
||||
echo "Virtual sdcard already configured"
|
||||
else
|
||||
echo "No virtual sdcard entry found..."
|
||||
echo "Configuring virtual sdcard..."
|
||||
# append the following lines to printer.cfg
|
||||
cat <<VSDCARD >> $PRINTER_CFG
|
||||
|
||||
##########################
|
||||
### CREATED WITH KIAUH ###
|
||||
##########################
|
||||
[virtual_sdcard]
|
||||
path: ~/sdcard
|
||||
##########################
|
||||
##########################
|
||||
VSDCARD
|
||||
fi
|
||||
}
|
||||
|
||||
check_api_section(){
|
||||
# check if api server is present in printer.cfg
|
||||
if [ $(grep '^\[api_server\]$' /home/pi/printer.cfg) ]; then
|
||||
echo "API server already configured"
|
||||
else
|
||||
echo "No API server entry found..."
|
||||
echo "Configuring API server..."
|
||||
# append the following lines to printer.cfg
|
||||
cat <<API >> $PRINTER_CFG
|
||||
|
||||
##########################
|
||||
### CREATED WITH KIAUH ###
|
||||
##########################
|
||||
[api_server]
|
||||
trusted_clients:
|
||||
192.168.0.0/24
|
||||
192.168.1.0/24
|
||||
127.0.0.0/24
|
||||
##########################
|
||||
##########################
|
||||
API
|
||||
fi
|
||||
}
|
||||
|
||||
create_default_cfg(){
|
||||
cat <<MAINSAIL_CFG >> $PRINTER_CFG
|
||||
|
||||
##########################
|
||||
### CREATED WITH KIAUH ###
|
||||
##########################
|
||||
[virtual_sdcard]
|
||||
path: ~/sdcard
|
||||
|
||||
[api_server]
|
||||
trusted_clients:
|
||||
192.168.0.0/24
|
||||
192.168.1.0/24
|
||||
127.0.0.0/24
|
||||
|
||||
[pause_resume]
|
||||
|
||||
[gcode_macro CANCEL]
|
||||
default_parameter_X: 230
|
||||
default_parameter_Y: 230
|
||||
default_parameter_Z: 10
|
||||
gcode:
|
||||
M104 S0
|
||||
M140 S0
|
||||
M141 S0
|
||||
M106 S0
|
||||
CLEAR_PAUSE
|
||||
RESET_SD
|
||||
|
||||
[gcode_macro CANCEL_PRINT]
|
||||
gcode:
|
||||
CANCEL
|
||||
|
||||
[gcode_macro PAUSE]
|
||||
rename_existing: BASE_PAUSE
|
||||
default_parameter_X: 230
|
||||
default_parameter_Y: 230
|
||||
default_parameter_Z: 10
|
||||
gcode:
|
||||
SAVE_GCODE_STATE NAME=PAUSE_state
|
||||
BASE_PAUSE
|
||||
G91
|
||||
G1 E-1.7 F2100
|
||||
G1 Z{Z}
|
||||
G90
|
||||
G1 X{X} Y{Y} F6000
|
||||
G91
|
||||
|
||||
[gcode_macro RESUME]
|
||||
rename_existing: BASE_RESUME
|
||||
gcode:
|
||||
G91
|
||||
G1 E1.7 F2100
|
||||
G91
|
||||
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1
|
||||
BASE_RESUME
|
||||
##########################
|
||||
##########################
|
||||
MAINSAIL_CFG
|
||||
}
|
||||
145
scripts/remove.sh
Normal file
145
scripts/remove.sh
Normal file
@@ -0,0 +1,145 @@
|
||||
remove_klipper(){
|
||||
data_arr=(
|
||||
/etc/init.d/klipper
|
||||
/etc/default/klipper
|
||||
$KLIPPER_DIR
|
||||
$KLIPPY_ENV_DIR
|
||||
${HOME}/klippy.log
|
||||
)
|
||||
print_error "Klipper" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
stop_klipper
|
||||
if [[ -e /etc/init.d/klipper || -e /etc/default/klipper ]]; then
|
||||
status_msg "Removing klipper service ..."
|
||||
sudo update-rc.d -f klipper remove
|
||||
sudo rm -rf /etc/init.d/klipper /etc/default/klipper && ok_msg "Klipper service removed!"
|
||||
fi
|
||||
if [[ -d $KLIPPER_DIR || -d $KLIPPY_ENV_DIR ]]; then
|
||||
status_msg "Removing klipper and klippy-env diretory ..."
|
||||
rm -rf $KLIPPER_DIR $KLIPPY_ENV_DIR && ok_msg "Directories removed!"
|
||||
fi
|
||||
if [[ -L ${HOME}/klippy.log || -e /tmp/klippy.log ]]; then
|
||||
status_msg "Removing klippy.log symlink ..."
|
||||
rm -rf ${HOME}/klippy.log /tmp/klippy.log && ok_msg "Symlink removed!"
|
||||
fi
|
||||
ok_msg "Klipper successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_dwc2(){
|
||||
data_arr=(
|
||||
$DWC2FK_DIR
|
||||
$TORNADO_DIR1
|
||||
$TORNADO_DIR2
|
||||
$WEB_DWC2
|
||||
$DWC2_DIR
|
||||
)
|
||||
print_error "DWC2-for-Klipper &\n DWC2 Web UI" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
if [ -d $DWC2FK_DIR ]; then
|
||||
status_msg "Removing dwc2-for-klipper directory ..."
|
||||
rm -rf $DWC2FK_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
if [ -d $TORNADO_DIR1 ]; then
|
||||
status_msg "Removing tornado from klippy-env ..."
|
||||
rm -rf $TORNADO_DIR1 $TORNADO_DIR2 && ok_msg "Tornado removed!"
|
||||
fi
|
||||
if [ -e $WEB_DWC2 ]; then
|
||||
status_msg "Removing web_dwc2.py symlink from klippy ..."
|
||||
rm -rf $WEB_DWC2 && ok_msg "File removed!"
|
||||
fi
|
||||
if [ -d $DWC2_DIR ]; then
|
||||
status_msg "Removing dwc2 directory ..."
|
||||
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
ok_msg "DWC2-for-Klipper & DWC2 Web UI successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_mainsail(){
|
||||
data_arr=(
|
||||
$MAINSAIL_SERVICE1
|
||||
$MAINSAIL_SERVICE2
|
||||
$MAINSAIL_DIR
|
||||
${HOME}/moonraker.log
|
||||
${HOME}/.klippy_api_key
|
||||
${HOME}/.moonraker_api_key
|
||||
${HOME}/moonraker-env
|
||||
/etc/nginx/sites-available/mainsail
|
||||
/etc/nginx/sites-enabled/mainsail
|
||||
/etc/init.d/nginx
|
||||
/etc/default/nginx
|
||||
)
|
||||
print_error "Mainsail" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
stop_moonraker
|
||||
#remove moonraker services
|
||||
if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then
|
||||
status_msg "Removing moonraker service ..."
|
||||
sudo update-rc.d -f moonraker remove
|
||||
sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker && ok_msg "Moonraker service removed!"
|
||||
fi
|
||||
#remove mainsail dir
|
||||
if [ -d $MAINSAIL_DIR ]; then
|
||||
status_msg "Removing mainsail directory ..."
|
||||
rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!"
|
||||
fi
|
||||
#remove moonraker-env
|
||||
if [ -d ${HOME}/moonraker-env ]; then
|
||||
status_msg "Removing moonraker virtualenv ..."
|
||||
rm -rf ${HOME}/moonraker-env && ok_msg "Directory removed!"
|
||||
fi
|
||||
#remove moonraker.log symlink
|
||||
if [[ -L ${HOME}/moonraker.log || -e /tmp/moonraker.log ]]; then
|
||||
status_msg "Removing moonraker.log symlink ..."
|
||||
rm -rf ${HOME}/moonraker.log /tmp/moonraker.log && ok_msg "Symlink removed!"
|
||||
fi
|
||||
#remove mainsail cfg
|
||||
if [ -e /etc/nginx/sites-available/mainsail ]; then
|
||||
status_msg "Removing mainsail configuration for nginx ..."
|
||||
sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!"
|
||||
fi
|
||||
#remove mainsail symlink
|
||||
if [ -L /etc/nginx/sites-enabled/mainsail ]; then
|
||||
status_msg "Removing mainsail symlink for nginx ..."
|
||||
sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!"
|
||||
fi
|
||||
#remove legacy api key
|
||||
if [ -e ${HOME}/.klippy_api_key ]; then
|
||||
status_msg "Removing legacy API Key ..."
|
||||
rm ${HOME}/.klippy_api_key && ok_msg "Done!"
|
||||
fi
|
||||
#remove api key
|
||||
if [ -e ${HOME}/.moonraker_api_key ]; then
|
||||
status_msg "Removing API Key ..."
|
||||
rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
|
||||
fi
|
||||
remove_nginx
|
||||
ok_msg "Mainsail successfully removed!"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_nginx(){
|
||||
#ask for complete removal of nginx if installed
|
||||
if [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]] ; then
|
||||
while true; do
|
||||
echo
|
||||
read -p "Do you want to completely remove (purge) nginx? (Y/n): " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
status_msg "Stopping and removing nginx service ..."
|
||||
if [ -e /etc/init.d/nginx ]; then
|
||||
sudo /etc/init.d/nginx stop && ok_msg "Nginx service stopped!"
|
||||
sudo rm /etc/init.d/nginx && ok_msg "Nginx service removed!"
|
||||
fi
|
||||
if [ -e /etc/default/nginx ]; then
|
||||
sudo rm /etc/default/nginx
|
||||
fi
|
||||
status_msg "Purging nginx from system ..."
|
||||
sudo apt-get purge nginx nginx-common -y && ok_msg "Nginx removed!"
|
||||
break;;
|
||||
N|n|No|no) break;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
226
scripts/status.sh
Normal file
226
scripts/status.sh
Normal file
@@ -0,0 +1,226 @@
|
||||
klipper_status(){
|
||||
kcount=0
|
||||
klipper_data=(
|
||||
$KLIPPER_DIR
|
||||
$KLIPPY_ENV_DIR
|
||||
$KLIPPER_SERVICE1
|
||||
$KLIPPER_SERVICE2
|
||||
)
|
||||
#count+1 for each found data-item from array
|
||||
for kd in "${klipper_data[@]}"
|
||||
do
|
||||
if [ -e $kd ]; then
|
||||
kcount=$(expr $kcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$kcount" == "${#klipper_data[*]}" ]; then
|
||||
KLIPPER_STATUS="${green}Installed!${default} "
|
||||
elif [ "$kcount" == 0 ]; then
|
||||
KLIPPER_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
KLIPPER_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
dwc2_status(){
|
||||
dcount=0
|
||||
dwc2_data=(
|
||||
$DWC2FK_DIR
|
||||
$WEB_DWC2
|
||||
$DWC2_DIR
|
||||
$TORNADO_DIR1
|
||||
$TORNADO_DIR2
|
||||
)
|
||||
#count+1 for each found data-item from array
|
||||
for dd in "${dwc2_data[@]}"
|
||||
do
|
||||
if [ -e $dd ]; then
|
||||
dcount=$(expr $dcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$dcount" == "${#dwc2_data[*]}" ]; then
|
||||
DWC2_STATUS="${green}Installed!${default} "
|
||||
elif [ "$dcount" == 0 ]; then
|
||||
DWC2_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
DWC2_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
mainsail_status(){
|
||||
mcount=0
|
||||
mainsail_data=(
|
||||
$MAINSAIL_SERVICE1
|
||||
$MAINSAIL_SERVICE2
|
||||
$MAINSAIL_DIR
|
||||
#${HOME}/.klippy_api_key
|
||||
#${HOME}/.moonraker_api_key
|
||||
#${HOME}/moonraker-env
|
||||
/etc/nginx/sites-available/mainsail
|
||||
/etc/nginx/sites-enabled/mainsail
|
||||
/etc/init.d/nginx
|
||||
/etc/default/nginx
|
||||
)
|
||||
#count+1 for each found data-item from array
|
||||
for md in "${mainsail_data[@]}"
|
||||
do
|
||||
if [ -e $md ]; then
|
||||
mcount=$(expr $mcount + 1)
|
||||
fi
|
||||
done
|
||||
if [ "$mcount" == "${#mainsail_data[*]}" ]; then
|
||||
MAINSAIL_STATUS="${green}Installed!${default} "
|
||||
elif [ "$mcount" == 0 ]; then
|
||||
MAINSAIL_STATUS="${red}Not installed!${default} "
|
||||
else
|
||||
MAINSAIL_STATUS="${yellow}Incomplete!${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
read_branch(){
|
||||
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPER_DIR/.git ]; then
|
||||
cd $KLIPPER_DIR
|
||||
GET_BRANCH=$(git branch -a | head -1 | cut -d " " -f5 | cut -d ")" -f1)
|
||||
#if reading the branch gives an empty string
|
||||
#we are on non-detached HEAD state on origin/master
|
||||
#and need to set GET_BRANCH to make a non-empty string
|
||||
if [ -z $GET_BRANCH ]; then
|
||||
GET_BRANCH="origin/master"
|
||||
fi
|
||||
else
|
||||
GET_BRANCH=""
|
||||
fi
|
||||
}
|
||||
|
||||
print_branch(){
|
||||
read_branch
|
||||
if [ "$GET_BRANCH" == "origin/master" ]; then
|
||||
PRINT_BRANCH="${cyan}$GET_BRANCH${default} "
|
||||
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-shaping" ]; then
|
||||
PRINT_BRANCH="${cyan}scurve-shaping${default} "
|
||||
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-smoothing" ]; then
|
||||
PRINT_BRANCH="${cyan}scurve-smoothing${default} "
|
||||
elif [ "$GET_BRANCH" == "Arksine/work-web_server-20200131" ]; then
|
||||
PRINT_BRANCH="${cyan}moonraker${default} "
|
||||
elif [ "$GET_BRANCH" == "Arksine/dev-moonraker-testing" ]; then
|
||||
PRINT_BRANCH="${cyan}dev-moonraker${default} "
|
||||
else
|
||||
PRINT_BRANCH="${red}----${default} "
|
||||
fi
|
||||
}
|
||||
|
||||
read_local_klipper_commit(){
|
||||
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPER_DIR/.git ]; then
|
||||
cd $KLIPPER_DIR
|
||||
LOCAL_COMMIT=$(git rev-parse --short=8 HEAD)
|
||||
else
|
||||
LOCAL_COMMIT=""
|
||||
fi
|
||||
}
|
||||
|
||||
read_remote_klipper_commit(){
|
||||
read_branch
|
||||
if [ ! -z $GET_BRANCH ];then
|
||||
REMOTE_COMMIT=$(git rev-parse --short=8 $GET_BRANCH)
|
||||
else
|
||||
REMOTE_COMMIT=""
|
||||
fi
|
||||
}
|
||||
|
||||
compare_klipper_versions(){
|
||||
read_local_klipper_commit
|
||||
read_remote_klipper_commit
|
||||
#echo "Local: $LOCAL_COMMIT"
|
||||
#echo "Remote: $REMOTE_COMMIT"
|
||||
if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then
|
||||
LOCAL_COMMIT="${yellow}$LOCAL_COMMIT${default}"
|
||||
REMOTE_COMMIT="${green}$REMOTE_COMMIT${default}"
|
||||
else
|
||||
LOCAL_COMMIT="${green}$LOCAL_COMMIT${default}"
|
||||
REMOTE_COMMIT="${green}$REMOTE_COMMIT${default}"
|
||||
fi
|
||||
}
|
||||
|
||||
read_dwc2fk_versions(){
|
||||
if [ -d $DWC2FK_DIR ] && [ -d $DWC2FK_DIR/.git ]; then
|
||||
cd $DWC2FK_DIR
|
||||
LOCAL_DWC2FK_COMMIT=$(git rev-parse --short=8 HEAD)
|
||||
REMOTE_DWC2FK_COMMIT=$(git rev-parse --short=8 origin/master)
|
||||
else
|
||||
LOCAL_DWC2FK_COMMIT=""
|
||||
REMOTE_DWC2FK_COMMIT=""
|
||||
fi
|
||||
}
|
||||
|
||||
compare_dwc2fk_versions(){
|
||||
read_dwc2fk_versions
|
||||
#echo "Local: $LOCAL_DWC2FK_COMMIT"
|
||||
#echo "Remote: $REMOTE_DWC2FK_COMMIT"
|
||||
if [ "$LOCAL_DWC2FK_COMMIT" != "$REMOTE_DWC2FK_COMMIT" ]; then
|
||||
LOCAL_DWC2FK_COMMIT="${yellow}$LOCAL_DWC2FK_COMMIT${default}"
|
||||
REMOTE_DWC2FK_COMMIT="${green}$REMOTE_DWC2FK_COMMIT${default}"
|
||||
else
|
||||
LOCAL_DWC2FK_COMMIT="${green}$LOCAL_DWC2FK_COMMIT${default}"
|
||||
REMOTE_DWC2FK_COMMIT="${green}$REMOTE_DWC2FK_COMMIT${default}"
|
||||
fi
|
||||
}
|
||||
|
||||
read_local_dwc2_version(){
|
||||
if [ -e $DWC2_DIR/web/version ]; then
|
||||
DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/web/version)
|
||||
else
|
||||
DWC2_LOCAL_VER=""
|
||||
fi
|
||||
}
|
||||
|
||||
read_remote_dwc2_version(){
|
||||
DWC2_REMOTE_VER=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep tag_name | cut -d'"' -f4)
|
||||
}
|
||||
|
||||
compare_dwc2_versions(){
|
||||
read_local_dwc2_version
|
||||
read_remote_dwc2_version
|
||||
#echo "Local: $DWC2_LOCAL_VER"
|
||||
#echo "Remote: $DWC2_REMOTE_VER"
|
||||
if [ "$DWC2_LOCAL_VER" != "$DWC2_REMOTE_VER" ]; then
|
||||
DWC2_LOCAL_VER="${yellow}$DWC2_LOCAL_VER${default}"
|
||||
DWC2_REMOTE_VER="${green}$DWC2_REMOTE_VER${default}"
|
||||
else
|
||||
DWC2_LOCAL_VER="${green}$DWC2_LOCAL_VER${default}"
|
||||
DWC2_REMOTE_VER="${green}$DWC2_REMOTE_VER${default}"
|
||||
fi
|
||||
}
|
||||
|
||||
read_local_mainsail_version(){
|
||||
if [ -e $MAINSAIL_DIR/version ]; then
|
||||
MAINSAIL_LOCAL_VER=$(head -n 1 $MAINSAIL_DIR/version)
|
||||
else
|
||||
MAINSAIL_LOCAL_VER=""
|
||||
fi
|
||||
}
|
||||
|
||||
read_remote_mainsail_version(){
|
||||
get_mainsail_ver
|
||||
MAINSAIL_REMOTE_VER=$MAINSAIL_VERSION
|
||||
}
|
||||
|
||||
compare_mainsail_versions(){
|
||||
read_local_mainsail_version
|
||||
read_remote_mainsail_version
|
||||
#echo "Local: $MAINSAIL_LOCAL_VER"
|
||||
#echo "Remote: $MAINSAIL_REMOTE_VER"
|
||||
if [ "$MAINSAIL_LOCAL_VER" != "$MAINSAIL_REMOTE_VER" ]; then
|
||||
MAINSAIL_LOCAL_VER="${yellow}$MAINSAIL_LOCAL_VER${default}"
|
||||
MAINSAIL_REMOTE_VER="${green}$MAINSAIL_REMOTE_VER${default}"
|
||||
else
|
||||
MAINSAIL_LOCAL_VER="${green}$MAINSAIL_LOCAL_VER${default}"
|
||||
MAINSAIL_REMOTE_VER="${green}$MAINSAIL_REMOTE_VER${default}"
|
||||
fi
|
||||
}
|
||||
|
||||
ui_print_versions(){
|
||||
compare_klipper_versions
|
||||
compare_dwc2fk_versions
|
||||
compare_dwc2_versions
|
||||
compare_mainsail_versions
|
||||
}
|
||||
41
scripts/switch_branch.sh
Normal file
41
scripts/switch_branch.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
switch_to_origin(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
git fetch origin -q && git checkout origin/master -q
|
||||
}
|
||||
|
||||
switch_to_scurve_shaping(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
if ! git remote | grep dmbutyugin -q; then
|
||||
git remote add dmbutyugin $DMBUTYUGIN_REPO
|
||||
fi
|
||||
git fetch dmbutyugin -q && git checkout $BRANCH_SCURVE_SHAPING -q
|
||||
}
|
||||
|
||||
switch_to_scurve_smoothing(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
if ! git remote | grep dmbutyugin -q; then
|
||||
git remote add dmbutyugin $DMBUTYUGIN_REPO
|
||||
fi
|
||||
git fetch dmbutyugin -q && git checkout $BRANCH_SCURVE_SMOOTHING -q
|
||||
}
|
||||
|
||||
switch_to_moonraker(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
if ! git remote | grep Arksine -q; then
|
||||
git remote add Arksine $ARKSINE_REPO
|
||||
fi
|
||||
git fetch Arksine -q && git checkout $BRANCH_MOONRAKER -q
|
||||
}
|
||||
|
||||
switch_to_dev_moonraker(){
|
||||
cd $KLIPPER_DIR
|
||||
status_msg "Switching...Please wait ..."; echo
|
||||
if ! git remote | grep Arksine -q; then
|
||||
git remote add Arksine $ARKSINE_REPO
|
||||
fi
|
||||
git fetch Arksine -q && git checkout $BRANCH_DEV_MOONRAKER -q
|
||||
}
|
||||
154
scripts/ui.sh
Normal file
154
scripts/ui.sh
Normal file
@@ -0,0 +1,154 @@
|
||||
### set up some UI stuff
|
||||
|
||||
#ui total width = 57 chars
|
||||
top_border(){
|
||||
echo -e "/=======================================================\ "
|
||||
}
|
||||
|
||||
bottom_border(){
|
||||
echo -e "\=======================================================/"
|
||||
}
|
||||
|
||||
hr(){
|
||||
echo -e "|-------------------------------------------------------|"
|
||||
}
|
||||
|
||||
quit_footer(){
|
||||
hr
|
||||
echo -e "| ${red}Q) Quit${default} | "
|
||||
bottom_border
|
||||
}
|
||||
|
||||
print_header(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |"
|
||||
echo -e "| $(title_msg " Klipper Installation And Update Helper ") |"
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |"
|
||||
bottom_border
|
||||
}
|
||||
|
||||
main_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
|
||||
hr
|
||||
echo -e "| 0) [System status] | |"
|
||||
echo -e "| | Klipper: $KLIPPER_STATUS|"
|
||||
echo -e "| 1) [Install] | Branch: $PRINT_BRANCH|"
|
||||
echo -e "| 2) [Update] | |"
|
||||
echo -e "| 3) [Remove] | DWC2: $DWC2_STATUS|"
|
||||
echo -e "| | Mainsail: $MAINSAIL_STATUS|"
|
||||
echo -e "| 4) [Advanced] | Octoprint: #### WIP #### |"
|
||||
echo -e "| 5) [Backup] | |"
|
||||
quit_footer
|
||||
}
|
||||
|
||||
install_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~") | "
|
||||
hr
|
||||
echo -e "| You need this menu usually only for installing | "
|
||||
echo -e "| all necessary dependencies for the various | "
|
||||
echo -e "| functions on a completely fresh system. | "
|
||||
hr
|
||||
echo -e "| Firmware: | | "
|
||||
echo -e "| 1) [Klipper] | | "
|
||||
echo -e "| | | "
|
||||
echo -e "| Webinterface: | | "
|
||||
echo -e "| 2) [DWC2] | | "
|
||||
echo -e "| 3) [Mainsail] | | "
|
||||
echo -e "| | | "
|
||||
quit_footer
|
||||
}
|
||||
|
||||
update_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~") | "
|
||||
hr
|
||||
echo -e "| It's a good idea to check the following website | "
|
||||
echo -e "| for important software changes to the config file | "
|
||||
echo -e "| BEFORE updating your klipper installation: | "
|
||||
echo -e "| | "
|
||||
echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | "
|
||||
bottom_border
|
||||
top_border
|
||||
echo -e "| 0) $BB4U_STATUS| "
|
||||
hr
|
||||
echo -e "| | Local Vers: | Remote Vers: | "
|
||||
echo -e "| Firmware: | | | "
|
||||
echo -e "| 1) [Klipper] | $(echo "$LOCAL_COMMIT") | $(echo "$REMOTE_COMMIT") | "
|
||||
echo -e "| | | | "
|
||||
echo -e "| Webinterface: | | | "
|
||||
echo -e "| 2) [DWC2-for-Klipper] | $(echo "$LOCAL_DWC2FK_COMMIT") | $(echo "$REMOTE_DWC2FK_COMMIT") | "
|
||||
echo -e "| 3) [DWC2 Web UI] | $(echo "$DWC2_LOCAL_VER") | $(echo "$DWC2_REMOTE_VER") | "
|
||||
echo -e "| 4) [Mainsail] | $(echo "$MAINSAIL_LOCAL_VER") | $(echo "$MAINSAIL_REMOTE_VER") | "
|
||||
echo -e "| | | | "
|
||||
quit_footer
|
||||
}
|
||||
|
||||
remove_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~") | "
|
||||
hr
|
||||
echo -e "| Files and directories which remain untouched: | "
|
||||
echo -e "| --> ~/printer.cfg | "
|
||||
echo -e "| --> ~/backup | "
|
||||
echo -e "| You need remove them manually if you wish so. | "
|
||||
hr
|
||||
echo -e "| 1) [Klipper] | | "
|
||||
echo -e "| 2) [DWC2-for-Klipper] | | "
|
||||
echo -e "| 3) [Mainsail] | | "
|
||||
echo -e "| | | "
|
||||
quit_footer
|
||||
}
|
||||
|
||||
advanced_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~") | "
|
||||
hr
|
||||
echo -e "| 1) [Switch Klipper version] | "
|
||||
echo -e "| | "
|
||||
echo -e "| 2) [Build Firmware] | "
|
||||
echo -e "| 3) [Flash MCU] | "
|
||||
echo -e "| 4) [Get Printer-ID] | "
|
||||
echo -e "| 5) [Write Printer-ID to printer.cfg] | "
|
||||
echo -e "| 6) [Write DWC2-for-klipper config] | "
|
||||
echo -e "| | "
|
||||
echo -e "| x) [Enable/Disable Octoprint service] | "
|
||||
echo -e "| | "
|
||||
quit_footer
|
||||
}
|
||||
|
||||
backup_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | "
|
||||
hr
|
||||
echo -e "| | "
|
||||
hr
|
||||
echo -e "| 1) [ ] | "
|
||||
echo -e "| 2) [ ] | "
|
||||
echo -e "| 3) [ ] | "
|
||||
echo -e "| 4) [ ] | "
|
||||
echo -e "| 5) [ ] | "
|
||||
echo -e "| 6) [ ] | "
|
||||
echo -e "| 7) [ ] | "
|
||||
echo -e "| | "
|
||||
quit_footer
|
||||
}
|
||||
|
||||
switch_ui(){
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |"
|
||||
bottom_border
|
||||
echo
|
||||
echo -e " $(title_msg "Active branch: ")${green}$GET_BRANCH${default}"
|
||||
echo
|
||||
top_border
|
||||
echo -e "| 1) [--> origin/master] | "
|
||||
echo -e "| | "
|
||||
echo -e "| 2) [--> scurve-shaping] | "
|
||||
echo -e "| 3) [--> scurve-smoothing] | "
|
||||
echo -e "| | "
|
||||
echo -e "| 4) [--> moonraker] | "
|
||||
echo -e "| 5) [--> dev-moonraker] | "
|
||||
quit_footer
|
||||
}
|
||||
77
scripts/update.sh
Normal file
77
scripts/update.sh
Normal file
@@ -0,0 +1,77 @@
|
||||
#TODO
|
||||
# - update the correct branch
|
||||
# - version checks before updating
|
||||
|
||||
#WIP
|
||||
update_check(){
|
||||
read_local_commit
|
||||
read_remote_commit
|
||||
}
|
||||
|
||||
update_klipper(){
|
||||
stop_klipper
|
||||
bb4u_klipper
|
||||
if [ ! -d $KLIPPER_DIR ]; then
|
||||
cd ${HOME} && git clone $KLIPPER_REPO
|
||||
else
|
||||
read_branch
|
||||
status_msg "Updating $GET_BRANCH"
|
||||
#fetching origin/master -> error
|
||||
#rewriting origin/master to origin
|
||||
if [ "$GET_BRANCH" == "origin/master" ]; then
|
||||
FETCH_BRANCH="origin"
|
||||
else
|
||||
FETCH_BRANCH=$(echo "$GET_BRANCH" | cut -d "/" -f1)
|
||||
fi
|
||||
status_msg "Fetching from $FETCH_BRANCH"
|
||||
git fetch $FETCH_BRANCH -q && ok_msg "Fetch successfull!"
|
||||
status_msg "Checking out $GET_BRANCH"
|
||||
git checkout $GET_BRANCH -q && ok_msg "Checkout successfull!" && echo; ok_msg "Update complete!"
|
||||
fi
|
||||
start_klipper; echo
|
||||
}
|
||||
|
||||
update_dwc2fk(){
|
||||
stop_klipper
|
||||
bb4u_dwc2fk
|
||||
if [ ! -d $DWC2FK_DIR ]; then
|
||||
cd ${HOME} && git clone $DWC2FK_REPO
|
||||
else
|
||||
cd $DWC2FK_DIR && git pull
|
||||
#create a web_dwc2.py symlink if not already existing
|
||||
if [ -d $KLIPPER_DIR/klippy/extras ] && [ ! -e $WEB_DWC2 ]; then
|
||||
status_msg "Creating web_dwc2.py symlink ..."
|
||||
ln -s $DWC2FK_DIR/web_dwc2.py $WEB_DWC2 && ok_msg "Symlink created!"
|
||||
fi
|
||||
fi
|
||||
start_klipper
|
||||
}
|
||||
|
||||
update_dwc2(){
|
||||
bb4u_dwc2
|
||||
#check dependencies
|
||||
dep=(wget gzip tar curl)
|
||||
dep_check
|
||||
#execute operation
|
||||
GET_DWC2_URL=`curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4`
|
||||
if [ ! -d $DWC2_DIR/web ]; then
|
||||
mkdir -p $DWC2_DIR/web
|
||||
fi
|
||||
cd $DWC2_DIR/web
|
||||
status_msg "Downloading DWC2 Web UI ..."
|
||||
wget -q $GET_DWC2_URL && ok_msg "Download complete!"
|
||||
status_msg "Unzipping archive ..."
|
||||
unzip -q -o *.zip && for f_ in $(find . | grep '.gz');do gunzip -f ${f_};done && ok_msg "Done!"
|
||||
status_msg "Writing version to file ..."
|
||||
echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/web/version && ok_msg "Done!"
|
||||
status_msg "Do a little cleanup ..."
|
||||
rm -rf DuetWebControl-SD.zip && ok_msg "Done!"
|
||||
}
|
||||
|
||||
update_mainsail(){
|
||||
stop_klipper
|
||||
bb4u_mainsail
|
||||
status_msg "Updating Mainsail ..."
|
||||
install_mainsail
|
||||
start_klipper
|
||||
}
|
||||
Reference in New Issue
Block a user