Compare commits

...

15 Commits

Author SHA1 Message Date
7c3bc51691 Gods fucking dammit 2024-09-16 21:09:05 -04:00
8ad9fb0e46 Add Taz base config 2024-09-16 21:07:49 -04:00
46da506ac7 Update Firmware Building 2024-09-16 21:07:32 -04:00
80ec5a75b6 Add todo 2024-08-19 20:26:03 -04:00
32d3020421 Fix port selection 2024-08-19 20:18:33 -04:00
837c10eb21 Add base config for Lulzbot Mini 2024-08-19 20:18:24 -04:00
6d046cd394 Avoid duplicate printer names 2024-08-08 09:36:39 -04:00
874e9d0871 Typo in symlink 2024-08-08 09:15:53 -04:00
05669ea4cd Restart correct service 2024-08-06 13:51:18 -04:00
df8fdc37cc Installs Mainsail, but buggy 2024-08-06 13:48:45 -04:00
475bc5df15 Poor forgotten moonraker environment 2024-08-06 10:17:33 -04:00
d49c50ae9a I need to go home awa 2024-08-05 22:39:32 -04:00
317a4c0a37 Finish knocking out bugs 2024-08-05 22:31:47 -04:00
065e262b0e Some finishing touches I hope 2024-08-05 22:15:04 -04:00
8983526714 Alternative to sed 2024-08-05 21:24:18 -04:00
14 changed files with 907 additions and 80 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/getoptions

3
add_nginx_camera.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
# TODO: add nginx configs for an additional camera streamer

216
club_configs/mini.cfg Normal file
View File

@@ -0,0 +1,216 @@
#This file contains pin mappings for the Lulzbot Mini 1 using RAMBo Mini and SingleExtruder
#To use this config, the firmware should be compiled for the AVR atmega2560.
# See docs/Config_Reference.md for a description of parameters.
#-------------------------------------------------------------------------------------------------
# LULZBOT Mini 1 SingleExtruder (RAMBoMini)
# defines are copied from Marlin pins_MINIRAMBO.h
# pin conversion was found in fastio_1280.h
#-------------------------------------------------------------------------------------------------
[stepper_x]
#define X_STEP_PIN 37
step_pin: PC0
#define X_DIR_PIN 48
dir_pin: PL1
#define X_ENABLE_PIN 29
enable_pin: !PA7
# 1/100
microsteps: 16
rotation_distance: 32
#define X_MIN_PIN 12
endstop_pin: ^!PB6
position_endstop: -3
position_min: -3
position_max: 159
homing_speed: 50
homing_retract_dist: 2.0
second_homing_speed: 5
[stepper_y]
#define Y_STEP_PIN 36
step_pin: PC1
#define Y_DIR_PIN 49
dir_pin: !PL0
#define Y_ENABLE_PIN 28
enable_pin: !PA6
# 1/100
microsteps: 16
rotation_distance: 32
#define Y_MIN_PIN 11
endstop_pin: ^!PB5
position_endstop: -7
position_min: -7
position_max: 173
homing_speed: 50
homing_retract_dist: 2.0
second_homing_speed: 5
[stepper_z]
#define Z_STEP_PIN 35
step_pin: PC2
#define Z_DIR_PIN 47
dir_pin: PL2
#define Z_ENABLE_PIN 27
enable_pin: !PA5
# 1/1600
microsteps: 16
rotation_distance: 2
#define Z_MAX_PIN 23
endstop_pin: ^!PA1
# I have replaced the original nozzle with
# a hardened steel one that make the extruder
# 1-1.5mm longer, so this may be a little too low
position_endstop: 161.5
position_max: 161.5
position_min: -2.0
homing_speed: 7
homing_retract_dist: 2.0
second_homing_speed: 2
[extruder]
#define E0_STEP_PIN 34
step_pin: PC3
#define E0_DIR_PIN 43
dir_pin: !PL6
#define E0_ENABLE_PIN 26
enable_pin: !PA4
# 1/833
microsteps: 16
rotation_distance: 3.842
nozzle_diameter: 0.400
filament_diameter: 2.850
#define HEATER_0_PIN 3
heater_pin: PE5
#The Extruder uses 100K thermistor - ATC Semitec 104GT-2 (#5) and PID control
sensor_type: ATC Semitec 104GT-2
# I can't explain this from Marlin
sensor_pin: PF0
control: pid
pid_Kp: 28.79
pid_Ki: 1.91
pid_Kd: 108.51
min_temp: 0
max_temp: 280
min_extrude_temp: 160
max_extrude_only_velocity: 500
max_extrude_only_accel: 2000
[heater_bed]
#define HEATER_BED_PIN 4
heater_pin: PG5
# The Heater Bed uses Honeywell 100K 135-104LAG-J01 temp sensor (#7) and PID control
sensor_type: Honeywell 100K 135-104LAG-J01
# I can't explain this from Marlin
sensor_pin: PF2
control: pid
pid_Kp: 294.0
pid_Ki: 65.0
pid_Kd: 382.0
min_temp: 0
max_temp: 130
[fan]
#define FAN_PIN 8
pin: PH5
[heater_fan heatbreak_cooling_fan]
#define FAN1_PIN 6
pin: PH3
[output_pin stepper_xy_current]
#define MOTOR_CURRENT_PWM_XY_PIN 46
pin: PL3
pwm: True
scale: 2.0
cycle_time: .000030
hardware_pwm: True
value: 1.300
[output_pin stepper_z_current]
pin: PL4
pwm: True
scale: 2.0
cycle_time: .000030
hardware_pwm: True
value: 1.630
[output_pin stepper_e_current]
pin: PL5
pwm: True
scale: 2.0
cycle_time: .000030
hardware_pwm: True
value: 1.250
[static_digital_output stepper_config]
# Microstepping pins
#define X_MS1_PIN 40
#define X_MS2_PIN 41
#define Y_MS1_PIN 69
#define Y_MS2_PIN 39
#define Z_MS1_PIN 68
#define Z_MS2_PIN 67
#define E0_MS1_PIN 65
#define E0_MS2_PIN 66
pins:
PG1, PG0,
PK7, PG2,
PK6, PK5,
PK3, PK4
[static_digital_output yellow_led]
#define LED_PIN 13
pins: !PB7
[mcu]
serial: /dev/ttyACM0
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 2000
max_z_velocity: 7
max_z_accel: 500
[homing_override]
gcode:
G91
G28 Z
G0 Z-5
G28 X Y
G0 X3 Y7
G90
[probe]
#define Z_MIN_PROBE_PIN 10
pin: ^!PB4
# z_offset equals washer thickness ~= 1.377
z_offset: 1.377
speed: 5.0
samples: 2
sample_retract_dist: 1.0
samples_result: average
samples_tolerance: 0.200
samples_tolerance_retries: 2
[bed_tilt]
# Enable bed tilt measurments using the probe we defined above
# Probe points using X0 Y0 offsets @ 0.01mm/step
points: -2, -6
156, -6
156, 158
-2, 158
speed: 75
horizontal_move_z: 2
[firmware_retraction]
retract_length: 2
retract_speed: 200
unretract_extra_length: 0
unretract_speed: 200
[gcode_macro G29]
# Preform the ABL by running G29 in the start GCODE script
gcode:
BED_TILT_CALIBRATE

214
club_configs/taz.cfg Normal file
View File

@@ -0,0 +1,214 @@
# This file contains common pin mappings for the BIGTREETECH SKR mini
# E3 v3.0. To use this config, the firmware should be compiled for the
# STM32G0B1 with a "8KiB bootloader" and USB communication.
# The "make flash" command does not work on the SKR mini E3. Instead,
# after running "make", copy the generated "out/klipper.bin" file to a
# file named "firmware.bin" on an SD card and then restart the SKR
# mini E3 with that SD card.
# See docs/Config_Reference.md for a description of parameters.
[gcode_macro CALIBRATE_NOZZLE_OFFSET]
description: Move to center of bed and calibrate nozzle offset
gcode:
G90
G0 X100 Y155 F1500
PROBE_CALIBRATE
[gcode_macro LEVEL_BED]
description: "Level the bed manually."
gcode:
BED_SCREWS_ADJUST
[gcode_macro CHECK_DEVIATION]
description: "Check the deviation of the bed from the last loaded mesh."
gcode:
SCREWS_TILT_CALCULATE MAX_DEVIATION=0.05
[gcode_macro LIZ_IS_A_BAKA]
description: "Liz is a baka, so here's her start G-Code >.<"
gcode:
BED_MESH_CALIBRATE
BED_MESH_PROFILE SAVE=default
[gcode_macro _START_GCODE]
description: "The gcode that should be called from your slicer at the beginning of a print."
gcode:
# Ender 3 Custom Start G-code
G90
G1 X2 Y30 Z30 F1500
G1 Z0.28 F240
G92 E0
G1 Y220 E10 F1500 ; prime the nozzle
G1 X2.3 F5000
G92 E0
G1 Y30 E10 F1200 ; prime the nozzle
G92 E0
G1 Z5 F1500 ; don't scratch the build plate
[gcode_macro _END_GCODE]
description: "The gcode that should be called from your slicer at the end of a print."
gcode:
G91 # Relative positioning
G1 E-2 F2700 # Retract a bit
G1 E-2 Z0.2 F2400 # Retract and raise Z
G1 X5 Y5 F3000 # Wipe out
G1 Z10 # Raise Z more
G90 # Absolute positioning
G1 X0 Y220 # Present print
M106 S0 # Turn-off fan
M104 S0 # Turn-off hotend
M140 S0 # Turn-off bed
M84 X Y E # Disable all steppers but Z
[stepper_x]
step_pin: PB13
dir_pin: !PB12
enable_pin: !PB14
microsteps: 16
rotation_distance: 40
endstop_pin: ^PC0
position_endstop: 0
position_max: 235
homing_speed: 50
[tmc2209 stepper_x]
uart_pin: PC11
tx_pin: PC10
uart_address: 0
run_current: 0.580
stealthchop_threshold: 999999
[stepper_y]
step_pin: PB10
dir_pin: !PB2
enable_pin: !PB11
microsteps: 16
rotation_distance: 40
endstop_pin: ^PC1
position_endstop: 0
position_max: 235
homing_speed: 50
[tmc2209 stepper_y]
uart_pin: PC11
tx_pin: PC10
uart_address: 2
run_current: 0.580
stealthchop_threshold: 999999
[stepper_z]
step_pin: PB0
dir_pin: PC5
enable_pin: !PB1
microsteps: 16
rotation_distance: 8
endstop_pin: ^PC2
position_endstop: 0.0
position_max: 250
[tmc2209 stepper_z]
uart_pin: PC11
tx_pin: PC10
uart_address: 1
run_current: 0.580
stealthchop_threshold: 999999
[bltouch]
sensor_pin: PC14
control_pin: PA1
x_offset: -44
y_offset: 8
probe_with_touch_mode: True
# pin_up_touch_mode_reports_triggered = False
# z_offset: 3.0
[bed_mesh]
speed: 120
horizontal_move_z: 7
mesh_min: 30, 40
mesh_max: 250, 230
probe_count: 5
mesh_pps: 3
algorithm: bicubic
[safe_z_home]
home_xy_position: 140, 140
speed: 50
z_hop: 10
z_hop_speed: 5
[extruder]
step_pin: PB3
dir_pin: !PB4
enable_pin: !PD1
microsteps: 16
rotation_distance: 7.9797
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PC8
# sensor_type: EPCOS 100K B57560G104F # Stock board config
sensor_type: NTC 100K MGB18-104F39050L32
sensor_pin: PA0
control: pid
pid_Kp: 21.527
pid_Ki: 1.063
pid_Kd: 108.982
min_temp: 0
max_temp: 300
[tmc2209 extruder]
uart_pin: PC11
tx_pin: PC10
uart_address: 3
run_current: 0.650
stealthchop_threshold: 999999
[heater_bed]
heater_pin: PC9
# sensor_type: ATC Semitec 104GT-2 # Stock board config
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC4
control: pid
pid_Kp: 54.027
pid_Ki: 0.770
pid_Kd: 948.182
min_temp: 0
max_temp: 130
[heater_fan heatbreak_cooling_fan]
pin: PC6
fan_speed: 1.0
heater: extruder
heater_temp: 50.0
[fan cooling]
pin: PC7 # Part cooling
# [heater_fan controller_fan]
# pin: PB15
# [fan]
# pin: PC6
[mcu]
serial: /dev/serial/by-id/usb-Klipper_Klipper_firmware_12345-if00
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
[board_pins]
aliases:
# EXP1 header
EXP1_1=PB5, EXP1_3=PA9, EXP1_5=PA10, EXP1_7=PB8, EXP1_9=<GND>,
EXP1_2=PA15, EXP1_4=<RST>, EXP1_6=PB9, EXP1_8=PD6, EXP1_10=<5V>
# See the sample-lcd.cfg file for definitions of common LCD displays.
[include mainsail.cfg]

View File

@@ -1,17 +1,20 @@
git
virtualenv
python-dev
libffi-dev
build-essential
libncurses-dev
libusb-dev
avrdude
gcc-avr
binutils-avr
avr-libc
stm32flash
dfu-util
libnewlib-arm-none-eabi
gcc-arm-none-eabi
avrdude
binutils-arm-none-eabi
libusb-1.0
binutils-avr
build-essential
dfu-util
gcc-arm-none-eabi
gcc-avr
git
libffi-dev
libncurses-dev
libnewlib-arm-none-eabi
libusb-1.0
libusb-dev
mariadb-server
python3-dev
stm32flash
virtualenv
nginx
lolcat

View File

@@ -0,0 +1,6 @@
# /etc/nginx/conf.d/common_vars.conf
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

View File

@@ -0,0 +1,14 @@
# location ~ ^/PRINTERNAMELC/(.*) {
# proxy_pass http://127.0.0.1:PORT/$1;
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection $connection_upgrade;
# proxy_set_header Host $host;
# proxy_buffering off;
# proxy_read_timeout 10800s;
# proxy_send_timeout 10800s;
# proxy_connect_timeout 30s;
# }
location ~ ^/PRINTERNAMELC/(.*) {
return 301 $scheme://$host:PORT/$1;
}

View File

@@ -0,0 +1,55 @@
# config file for a specific printer subdir
server {
listen PORT default_server;
rewrite_log on;
access_log /var/log/nginx/PRINTERNAME-mainsail-access.log;
error_log /var/log/nginx/PRINTERNAME-mainsail-error.log info;
# disable this section on smaller hardware like a pi zero
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 4;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/json application/xml;
index index.html;
# disable max upload size checks
client_max_body_size 0;
# disable proxy request buffering
proxy_request_buffering off;
root /home/pi/PRINTERNAME/mainsail;
location / {
try_files $uri $uri/ /index.html;
}
location = /index.html {
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
location /websocket {
proxy_pass http://PRINTERNAMELCapiserver/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 ~ ^/(printer|api|access|machine|server)/ {
proxy_pass http://PRINTERNAMELCapiserver$request_uri;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_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_set_header X-Scheme $scheme;
}
}

View File

@@ -0,0 +1,6 @@
# config file for a specific printer upstream
upstream PRINTERNAMELCapiserver {
ip_hash;
server 127.0.0.1:PORT;
}

92
config/nginx/site.conf Normal file
View File

@@ -0,0 +1,92 @@
# /etc/nginx/sites-available/site.conf
server {
listen 80 default_server;
rewrite_log on;
access_log /var/log/nginx/mainsail-access.log;
error_log /var/log/nginx/mainsail-error.log debug;
# disable this section on smaller hardware like a pi zero
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 4;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/json application/xml;
index index.html;
server_name _;
# disable max upload size checks
client_max_body_size 0;
# disable proxy request buffering
proxy_request_buffering off;
include /etc/nginx/mainsail/proxy/*.conf;
location /webcam/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer1/;
}
location /webcam2/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer2/;
}
location /webcam3/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer3/;
}
location /webcam4/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer4/;
}
location /webcam5/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer5/;
}
location /webcam6/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer6/;
}
location /webcam7/ {
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
access_log off;
error_log off;
proxy_pass http://mjpgstreamer7/;
}
}

View File

@@ -0,0 +1,38 @@
# /etc/nginx/conf.d/upstreams.conf
include /etc/nginx/mainsail/upstream/*.conf;
upstream mjpgstreamer1 {
ip_hash;
server 127.0.0.1:8080;
}
upstream mjpgstreamer2 {
ip_hash;
server 127.0.0.1:8081;
}
upstream mjpgstreamer3 {
ip_hash;
server 127.0.0.1:8082;
}
upstream mjpgstreamer4 {
ip_hash;
server 127.0.0.1:8083;
}
upstream mjpgstreamer5 {
ip_hash;
server 127.0.0.1:8084;
}
upstream mjpgstreamer6 {
ip_hash;
server 127.0.0.1:8085;
}
upstream mjpgstreamer7 {
ip_hash;
server 127.0.0.1:8086;
}

View File

@@ -1,6 +1,6 @@
[server]
host: 0.0.0.0
port: 7126
port: PORT
# The maximum size allowed for a file upload (in MiB). Default 1024 MiB
max_upload_size: 1024
# Path to klippy Unix Domain Socket

View File

@@ -1 +1 @@
KLIPPER_ARGS="/home/pi/PRINTERNAME/klipper/klippy/klippy.py /home/pi/PRINTERNAME/printer_data/onfig/printer.cfg -l /home/pi/taz/printer_data_taz/logs/klippy.log -I /home/pi/taz/printer_data_taz/comms/klippy.serial -a /home/pi/taz/printer_data_taz/comms/klippy.sock"
KLIPPER_ARGS="/home/pi/PRINTERNAME/klipper/klippy/klippy.py /home/pi/PRINTERNAME/printer_data/config/printer.cfg -l /home/pi/PRINTERNAME/printer_data/logs/klippy.log -I /home/pi/PRINTERNAME/printer_data/comms/klippy.serial -a /home/pi/PRINTERNAME/printer_data/comms/klippy.sock"

305
setup.sh
View File

@@ -1,7 +1,31 @@
#!/bin/bash
# TODO: CHANGE KLIPPER PORTS
# TODO: Add Crowsnest Support
# TODO: Dry run
# TODO: Printer Directory Page in NGINX
# TODO: Add mainsail GCODE if config not manually entered
# Handle arguments
ARG_HELP=0
ARG_SKIP_APT=0
ARG_NAME=0
ARG_CONFIG=0
ARG_PORT=0
ARG_FIRM=0
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--help) ARG_HELP=1 ;;
-a|--skip-apt) ARG_SKIP_APT=1 ;;
-n|--name) ARG_NAME="$2" ; shift ;;
-c|--config) ARG_CONFIG="$2" ; shift ;;
-p|--port) ARG_PORT="$2" ; shift ;;
-f|--skip-firmware) ARG_FIRM=1 ;;
*) echo "Unknown Parameter"; exit 3 ;;
esac
shift
done
# Prepare global variables
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do
TARGET=$(readlink "$SOURCE")
@@ -18,72 +42,143 @@ cd $ROOT_DIR
source ./ColorEchoForShell/dist/ColorEcho.bash
if [[ "$ARG_HELP" == 1 ]]; then
echo.Cyan "HacDC Printer Setup Script Usage"
echo.Yellow "./setup.sh [options]"
echo ""
echo.BoldPurple "Option Description"
echo.Rainbow "-h/--help Display this help msg"
echo.Rainbow "-a/--skip-apt Skip installing apt packages"
echo.Rainbow "-f/--skip-firmware Skip firmware build/install"
echo.Rainbow "-n/--name Specify printer name (skips popup)"
echo.Rainbow "-c/--config Specify printer config (skips popup)"
echo.Rainbow "-p/--port Specify printer port (skips popup)"
exit 0
fi
if [[ "$ARG_NAME" != 0 ]]; then
if [ -d $HOME/$ARG_NAME ]; then
echo.Red "UNABLE TO COMPLY: Printer name already exists"
exit 1
fi
fi
# Pull Klipper
git submodule update --init --recursive
# Install packages
if [[ "$ARG_SKIP_APT" == 1 ]]; then
echo.ICyan "Apt packagees skipped"
else
echo.Cyan "Installing required packageas"
for PACKAGE in `cat $ROOT_DIR/config/apt-packages`; do
sudo apt install -y $PACKAGE
done
fi
# Name Printer
# Todo: avoid duplications
NAME_NOT_VALID=true
while $NAME_NOT_VALID ; do
PRINTER_NAME=$(dialog --backtitle 'drwho@hackers.town' --inputbox 'Name This Printer' 8 40 "${PRINTER_NAME}" 3>&1 1>&2 2>&3)
if [[ $PRINTER_NAME =~ ^[a-zA-Z0-9_-]+$ ]]; then
NAME_NOT_VALID=false
fi
done
PRINTER_NAME=""
if [[ "$ARG_NAME" == 0 ]]; then
NAME_NOT_VALID=true
DISPLAY_MSG="Name This Printer"
while $NAME_NOT_VALID ; do
PRINTER_NAME=$(dialog --backtitle 'drwho@hackers.town' --inputbox "$DISPLAY_MSG" 8 40 "${PRINTER_NAME}" 3>&1 1>&2 2>&3)
if [[ $PRINTER_NAME =~ ^[a-zA-Z0-9_-]+$ ]]; then
NAME_NOT_VALID=false
fi
if [ -d $HOME/$PRINTER_NAME ]; then
DISPLAY_MSG="Printer name already exists"
NAME_NOT_VALID=true
fi
if [[ "$PRINTER_NAME" == "" ]]; then
echo ""
echo.Yellow "Cancelled or no input, closing script"
exit 4
fi
done
else
echo.ICyan "Using passed printer name: $ARG_NAME"
PRINTER_NAME="$ARG_NAME"
fi
cp -r $ROOT_DIR/dirs $ROOT_DIR/$PRINTER_NAME
# Select Klipper Config
cd $ROOT_DIR/$PRINTER_NAME/klipper
make menuconfig
CONFIG_FILES=(`ls config`)
CONFIG_FILES+=("Enter_Manually")
let i=0
C=()
for f in ${CONFIG_FILES[@]}; do
C+=($i $f)
let i+=1
done
CONFIG_INDEX=$(dialog --backtitle "drwho@hackers.town" --title "Printer Selection" --menu "Select Printer Config" --output-fd 1 40 0 1 ${C[@]})
CONFIG_FILE=${CONFIG_FILES[$CONFIG_INDEX]}
if [[ $CONFIG_FILE == "Enter_Manually" ]]; then
MANUAL_FILE=""
while [ ! -f "${MANUAL_FILE}" ]; do
MANUAL_FILE=$(dialog --backtitle "drwho@hackers.town" --title "Manual Config Selection" --inputbox "Enter Full Config File Path" 8 40 "${MANUAL_FILE}" 3>&1 1>&2 2>&3)
if [[ "$ARG_FIRM" == 0 ]]; then
make menuconfig
fi
CONFIG_FILE=""
if [[ "$ARG_CONFIG" == 0 ]]; then
CONFIG_FILES=(`ls config`)
CONFIG_FILES+=("Enter_Manually")
let i=0
C=()
for f in ${CONFIG_FILES[@]}; do
C+=($i $f)
let i+=1
done
CONFIG_FILE=$MANUAL_FILE
CONFIG_INDEX=$(dialog --backtitle "drwho@hackers.town" --title "Printer Selection" --menu "Select Printer Config" --output-fd 1 40 0 1 ${C[@]})
CONFIG_FILE=${CONFIG_FILES[$CONFIG_INDEX]}
if [[ $CONFIG_FILE == "Enter_Manually" ]]; then
MANUAL_FILE=""
while [ ! -f "${MANUAL_FILE}" ]; do
MANUAL_FILE=$(dialog --backtitle "drwho@hackers.town" --title "Manual Config Selection" --inputbox "Enter Full Config File Path" 8 40 "${MANUAL_FILE}" 3>&1 1>&2 2>&3)
done
CONFIG_FILE=$MANUAL_FILE
else
# TODO: maybe replace this with the full path?
CONFIG_FILE="./config/$CONFIG_FILE"
fi
else
CONFIG_FILE="./config/$CONFIG_FILE"
echo.ICyan "Using passed config file"
CONFIG_FILE="$ARG_CONFIG"
fi
# Select Serial Device
DEVICES=(`ls /dev/serial/by-id/`)
DEVICES+=("Enter_Manually")
let i=0
C=()
for f in ${DEVICES[@]}; do
C+=($i $f)
let i+=1
done
DEVICE_INDEX=$(dialog --backtitle "drwho@hackers.town" --title "USB Device Selection" --menu "Select USB Device" --output-fd 1 40 0 1 ${C[@]})
DEVICE=${DEVICES[$DEVICE_INDEX]}
if [[ $DEVICE == "Enter_Manually" ]]; then
MANUAL_FILE=""
while [ ! -f "${MANUAL_FILE}" ]; do
MANUAL_FILE=$(dialog --backtitle "drwho@hackers.town" --title "Manual Device Selection" --inputbox "Enter Full Device File Path" 8 40 "${MANUAL_FILE}" 3>&1 1>&2 2>&3)
DEVICE=""
if [[ "$ARG_PORT" == 0 ]]; then
DEVICES=(`ls /dev/serial/by-id/`)
DEVICES+=("Enter_Manually")
let i=0
C=()
for f in ${DEVICES[@]}; do
C+=($i $f)
let i+=1
done
DEVICE=$MANUAL_FILE
DEVICE_INDEX=$(dialog --backtitle "drwho@hackers.town" --title "USB Device Selection" --menu "Select USB Device" --output-fd 1 40 0 1 ${C[@]})
DEVICE=${DEVICES[$DEVICE_INDEX]}
if [[ $DEVICE == "Enter_Manually" ]]; then
MANUAL_FILE=""
while [ ! -f "${MANUAL_FILE}" ]; do
MANUAL_FILE=$(dialog --backtitle "drwho@hackers.town" --title "Manual Device Selection" --inputbox "Enter Full Device File Path" 8 40 "${MANUAL_FILE}" 3>&1 1>&2 2>&3)
done
DEVICE="$MANUAL_FILE"
else
DEVICE="/dev/serial/by-id/$DEVICE"
fi
else
echo.ICyan "Using passed serial port"
DEVICE="$ARG_PORT"
fi
# Build Klipper
cp $CONFIG_FILE $ROOT_DIR/$PRINTER_NAME/klipper/printer.cfg
sed -i -e "s/^serial: .\+$/serial: \/dev\/serial\/by-id\/${DEVICE}/g" "${ROOT_DIR}/$PRINTER_NAME/klipper/printer.cfg"
make -j$(nproc)
# Flash Firmware
make flash FLASH_DEVICE=/dev/serial/by-id/$DEVICE
if [[ "$ARG_FIRM" == 0 ]]; then
echo.Cyan "Compile Klipper Firmware"
cp $CONFIG_FILE $ROOT_DIR/$PRINTER_NAME/klipper/printer.cfg
sed -i -e "s/^serial: .\+$/LINEHERE/g" "$ROOT_DIR/$PRINTER_NAME/klipper/printer.cfg"
cat $ROOT_DIR/$PRINTER_NAME/klipper/printer.cfg | replace "LINEHERE" "serial: $DEVICE" > $ROOT_DIR/$PRINTER_NAME/klipper/tmp.cfg
rm $ROOT_DIR/$PRINTER_NAME/klipper/printer.cfg
mv $ROOT_DIR/$PRINTER_NAME/klipper/tmp.cfg $ROOT_DIR/$PRINTER_NAME/klipper/printer.cfg
make -j$(nproc)
# Flash Firmware
echo.Cyan "Flash Device"
make flash FLASH_DEVICE=$DEVICE
else
echo.ICyan "Skipping firmware build"
fi
# Copy over printer config file
echo.Cyan "Setup printer.cfg"
@@ -97,11 +192,19 @@ echo.Cyan "Setup Moonraker"
cd $ROOT_DIR/$PRINTER_NAME/printer_data/config
sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "moonraker.conf"
sed -i -e "s/pi/$USER/g" "moonraker.conf"
cat "moonraker.conf" | replace "~/" "$HOME/" > m.tmp
rm moonraker.conf
mv m.tmp moonraker.conf
NUM_OF_PRIOR_INSTALLS=`ls /etc/systemd/system/*-klipper.service | wc -l`
NEW_PORT=$((NUM_OF_PRIOR_INSTALLS + 7125))
echo.ICyan "Using port ${NEW_PORT} for Moonraker"
sed -i -e "s/PORT/$NEW_PORT/g" "moonraker.conf"
echo.Cyan "Setup Mainsail Config"
cd $ROOT_DIR/$PRINTER_NAME/mainsail-config
USABLE_HOME=`echo "$HOME" | sed -e 's/\//\\\//'`
sed -i -e "s/~\/printer_data/$USABLE_HOME\/$PRINTER_NAME\/printer_data/g" "client.cfg"
cat "client.cfg" | replace "~/printer_data" "$HOME/$PRINTER_NAME/printer_data" > tmp.client.cfg
rm client.cfg
mv tmp.client.cfg client.cfg
sed -i -e "s/pi/$USER/g" "client.cfg"
# Download Mainsail
@@ -111,28 +214,93 @@ wget -q -O mainsail.zip https://github.com/mainsail-crew/mainsail/releases/lates
unzip -o mainsail.zip -d $PRINTER_NAME/mainsail
rm mainsail.zip
echo.ICyan "Installing base nginx configs"
if [ ! -f /etc/nginx/conf.d/upstreams.conf ]; then
sudo cp $ROOT_DIR/config/nginx/upstreams.conf /etc/nginx/conf.d/upstreams.conf
sudo chown root:root /etc/nginx/conf.d/upstreams.conf
else
echo.ICyan "upstreams.conf already exists"
fi
if [ ! -f /etc/nginx/sites-available/site.conf ]; then
sudo cp $ROOT_DIR/config/nginx/site.conf /etc/nginx/sites-available/site.conf
sudo chown root:root /etc/nginx/sites-available/site.conf
else
echo.ICyan "site.conf already exists"
fi
if [ ! -f /etc/nginx/conf.d/common_vars.conf ]; then
sudo cp $ROOT_DIR/config/nginx/common_vars.conf /etc/nginx/conf.d/common_vars.conf
sudo chown root:root /etc/nginx/conf.d/common_vars.conf
else
echo.ICyan "common_vars.conf already exists"
fi
if [ ! -d /etc/nginx/mainsail/sites ]; then
sudo mkdir -p /etc/nginx/mainsail/sites
fi
if [ ! -d /etc/nginx/mainsail/upstream ]; then
sudo mkdir -p /etc/nginx/mainsail/upstream
fi
if [ ! -d /etc/nginx/mainsail/proxy ]; then
sudo mkdir -p /etc/nginx/mainsail/proxy
fi
echo.Cyan "Generate and Install $PRINTER_NAME nginx configs"
cat $ROOT_DIR/config/nginx/mainsail-upstream.conf | replace "PRINTERNAMELC" "${PRINTER_NAME,,}" | replace "PORT" "$NEW_PORT" > $ROOT_DIR/$PRINTER_NAME/upstream.conf
PROXY_PORT=$((NEW_PORT - 7000 + 8000))
cat $ROOT_DIR/config/nginx/mainsail-site.conf | replace "PRINTERNAMELC" "${PRINTER_NAME,,}" | replace "/home/pi" "$HOME" | replace "PRINTERNAME" "$PRINTER_NAME" | replace "PORT" "$PROXY_PORT" > $ROOT_DIR/$PRINTER_NAME/site.conf
cat $ROOT_DIR/config/nginx/mainsail-proxy.conf | replace "PRINTERNAMELC" "${PRINTER_NAME,,}" | replace "PORT" "$PROXY_PORT" > $ROOT_DIR/$PRINTER_NAME/proxy.conf
# add proxy
sudo cp $ROOT_DIR/$PRINTER_NAME/upstream.conf /etc/nginx/mainsail/upstream/$PRINTER_NAME.conf
sudo cp $ROOT_DIR/$PRINTER_NAME/site.conf /etc/nginx/sites-available/$PRINTER_NAME.conf
sudo cp $ROOT_DIR/$PRINTER_NAME/proxy.conf /etc/nginx/mainsail/proxy/$PRINTER_NAME.conf
sudo ln -s /etc/nginx/sites-available/$PRINTER_NAME.conf /etc/nginx/sites-enabled/$PRINTER_NAME.conf
sudo chown -R root:root /etc/nginx/mainsail
if [ -f /etc/nginx/sites-enabled/site.conf ]; then
echo.ICyan "Restart nginx if the site is already enabled"
sudo systemctl stop nginx
fi
# Setup klipper python env
echo.Cyan "Setup Klipper Python Virtual Environment"
cd $ROOT_DIR/$PRINTER_NAME
/usr/bin/virtualenv klippy-env
$ROOT_DIR/$PRINTER_NAME/klippy-env/bin/pip install -r $ROOT_DIR/$PRINTER_NAME/klipper/scripts/klippy-requirements.txt
touch $ROOT_DIR/$PRINTER_NAME/printer_data/comms/klippy.sock
# Setup moonraker python env
echo.Cyan "Setup Moonraker Python Virtual Environment"
cd $ROOT_DIR/$PRINTER_NAME
/usr/bin/virtualenv moonraker-env
$ROOT_DIR/$PRINTER_NAME/moonraker-env/bin/pip install -r $ROOT_DIR/$PRINTER_NAME/moonraker/scripts/moonraker-requirements.txt
# Configure Systemd Environment Files
echo.Cyan "Config Systemd Envs"
cd $ROOT_DIR/$PRINTER_NAME/printer_data/systemd
for ENV in *.env; do
cat "$ENV" | replace "/home/pi" "$HOME" | replace "PRINTERNAME" "$PRINTER_NAME" | replace "PRINTERDATA" "$PRINTER_NAME"> "$ENV.tmp"
rm "$ENV"
mv "$ENV.tmp" "$ENV"
done
# Copy To Final Location
echo.Cyan "Run Copy"
mkdir -p $HOME/$PRINTER_NAME
cp -r $PRINTER_NAME/* $HOME/$PRINTER_NAME
cp -r $ROOT_DIR/$PRINTER_NAME/* $HOME/$PRINTER_NAME
# Create Empty dirs
dirs=(logs gcodes certs backup mainsail-config)
dirs=(logs gcodes certs backup)
for d in ${dirs[@]}; do
mkdir -p "$HOME/$PRINTER_NAME/$d"
D="$HOME/$PRINTER_NAME/printer_data/$d"
echo.ICyan "make $D"
mkdir -p $D
done
touch $HOME/$PRINTER_NAME/printer_data/logs/klippy.log
# Configure System Services
# cd $ROOT_DIR/config/services
# TODO: Add Crowsnest Support
# FILES=(moonraker klipper)
# for f in ${FILES[@]}; do
# echo.ICyan "Configuring ${f}"
# sed -i -e "s/PRINTERNAME/$PRINTER_NAME/g" "${f}.service"
# sed -i -e "s/pi/$USER/g" "${f}.service"
# done
cd $ROOT_DIR/config/services
SERVICES=()
for f in *.service; do
@@ -153,3 +321,14 @@ for svc in ${SERVICES[@]}; do
done
# Cleanup
$HOME/$PRINTER_NAME/moonraker/scripts/set-policykit-rules.sh -z
ln -s $HOME/$PRINTER_NAME/mainsail-config/client.cfg $HOME/$PRINTER_NAME/printer_data/config/mainsail.cfg
sudo systemctl restart $PRINTER_NAME-klipper.service
sudo systemctl restart $PRINTER_NAME-moonraker.service
echo.BoldCyan "${PRINTER_NAME} is setup with moonraker on port ${NEW_PORT}"
sudo nginx -t
if [ ! -f /etc/nginx/sites-enabled/site.conf ]; then
echo.Red "NGINX config not enabled, don't forget to symlink the site.conf file from sites-available to sites-enabled"
else
sudo systemctl start nginx
fi