Skip to content

Commit

Permalink
Add an automatic PrusaLink image builder script
Browse files Browse the repository at this point in the history
  • Loading branch information
TojikCZ committed Aug 1, 2023
1 parent c58387d commit 3621767
Show file tree
Hide file tree
Showing 8 changed files with 595 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Hold the STOPPED and FINISHED state for at least 11s
* Fix MK2(.5)S SN being broken on multi-instance images
* Implemented UPGRADE high lvl Connect command
* Add an automatic PrusaLink image builder script

0.7.0 (2023-05-19)
* Fixed printer sends info about api key change to Connect after change
Expand Down
9 changes: 9 additions & 0 deletions prusa/link/data/image_builder/boot-message.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Boot message

[Service]
Type=simple
ExecStart=/bin/sh -c 'stty -F /dev/ttyAMA0 115200; printf \'M117 RPi booting...\n\' > /dev/ttyAMA0'

[Install]
WantedBy=basic.target
24 changes: 24 additions & 0 deletions prusa/link/data/image_builder/first-boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set_up_port () {
# Sets the baudrate and cancels the hangup at the end of a connection
stty -F "$1" 115200 -hupcl;
}

message() {
printf "M117 $2\n" > "$1"
}

set_up_port "/dev/ttyAMA0"
message "/dev/ttyAMA0" "Please wait < 10min";

for i in {0..5}; do
set_up_port "/dev/ttyACM$i"
done

sleep 8

for i in {0..5}; do
message "/dev/ttyACM$i" "Please wait < 10min"
done

# This generates the host keys for the ssh server to work
ssh-keygen -A
24 changes: 24 additions & 0 deletions prusa/link/data/image_builder/manager-start-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Forward the port 80 to 8080 even on the loopback, so we van ping ourselves
iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -I OUTPUT -p tcp -o lo -d localhost --dport 80 -j REDIRECT --to-ports 8080

set_up_port () {
# Sets the baudrate and cancels the hangup at the end of a connection
stty -F "$1" 115200 -hupcl;
}

message() {
printf "M117 $2\n" > "$1"
}

username=$(id -nu 1000)
user_site=$(su $username -c "python -m site --user-site")

set_up_port "/dev/ttyAMA0"
message "/dev/ttyAMA0" "Starting PrusaLink";

/home/$username/.local/bin/prusalink-boot
rm -f /run/prusalink/manager.pid
export PYTHONOPTIMIZE=2
PYTHONPATH=$user_site /home/$username/.local/bin/prusalink-manager -p "PYTHONPATH=$user_site /home/$username/.local/bin/" start
23 changes: 23 additions & 0 deletions prusa/link/data/image_builder/prusalink-start-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Forward the port 80 to 8080 even on the loopback, so we van ping ourselves
iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -I OUTPUT -p tcp -o lo -d localhost --dport 80 -j REDIRECT --to-ports 8080

set_up_port () {
# Sets the baudrate and cancels the hangup at the end of a connection
stty -F "$1" 115200 -hupcl;
}

message() {
printf "M117 $2\n" > "$1"
}

username=$(id -nu 1000)

set_up_port "/dev/ttyAMA0"
message "/dev/ttyAMA0" "Starting PrusaLink";

/home/$username/.local/bin/prusalink-boot
rm -f /home/$username/prusalink.pid
export PYTHONOPTIMIZE=2
su $username -c "/home/$username/.local/bin/prusalink -i start"
Empty file.
Loading

0 comments on commit 3621767

Please sign in to comment.