-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy patheasel-driver.sh
executable file
·207 lines (173 loc) · 6.2 KB
/
easel-driver.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/sh -x
# Move previous out of way if exists
if [ -e 'easel-driver' ]; then mv easel-driver easel-driver.bak.`date +%s`; fi &&
# Create dir to work in
mkdir -p easel-driver &&
cd easel-driver &&
# Download latest Easel Driver for Mac (which we'll extract necessary components from)
curl -L https://easel.inventables.com/downloads | perl -ne 'print $1 if /href="([^"]+EaselDriver\S*\.pkg[^"]*)/' | xargs curl -o EaselDriver.pkg &&
# Install p7zip to unpack xar archive, avrdude for firmware upgrades, screen to run in background
sudo apt-get install -y p7zip-full avrdude screen &&
# Unpack Easel Driver
7z x EaselDriver.pkg &&
# Unpack the primary Easel files
cd IrisLib*.pkg &&
zcat Payload | cpio -idv &&
# Grab the necessary files
cp -r lib iris.js package.json ssl avrdude/etc/avrdude.conf ../ &&
cd .. &&
# Move avrdude.conf into lib/etc as that's where the easel driver will look
mkdir lib/etc &&
mv avrdude.conf lib/etc &&
ln -s lib/etc etc &&
# Modify the firmware uploader to support Linux
perl -pi -e 'if (/var PLATFORMS/) { $x = chr(39); print; $_ = "\t${x}Linux${x}: {\n\t\troot: ${x}/usr/bin/avrdude${x},\n\t\texecutable: ${x}/usr/bin/avrdude${x},\n\t\tconfig: path.join(__dirname, ${x}etc/avrdude.conf${x})\n\t},\n"; }' lib/firmware_uploader.js &&
# Modify the serial port code to support CP210x/CH340/CH341-based serial devices by spoofing an FTDI chip
perl -pi -e 'if (/callback\(ports/) { print << "EOF"
ports.forEach(function(part, i) {
if (this[i].manufacturer === "1a86")
this[i].manufacturer = "FTDI";
if (this[i].manufacturer === "Silicon Labs")
this[i].manufacturer = "FTDI";
if (this[i].vendorId === "1a86")
this[i].vendorId = "0403";
if (this[i].vendorId === "10c4")
this[i].vendorId = "0403";
}, ports);
EOF
}' lib/serial_port_controller.js &&
# Modify the machine.js to watch for an unknown message received, then trigger a FluidNC connection
# perl search string is temp
perl -pi -e 'if (/that\.dispatchEvent\(.unknown.\, message/) { print << "EOF"
if (message.includes(\x{027}FluidNC\x{027}) && !isMachineConnected){
onMachineConnected(\x{027}Grbl 1.1g [\\\x{027}\$\\\x{027} for help]\x{027});
}
EOF
}' lib/machine.js &&
# Install nodejs using nvm
# The installation script will clone the nvm repository from Github to the ~/.nvm directory
# and add the nvm path to your Bash profile.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash - &&
# Rerun Profile script to start NVM
if [ ! -e "$NVM_DIR" ]; then
if [ -e "$HOME/.nvm" ]; then
export NVM_DIR="$HOME/.nvm"
else
if [ -e "$HOME/.config/nvm" ]; then
export NVM_DIR="$HOME/.config/nvm"
else
echo "Can't find NVM directory!"
fi
fi
fi &&
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && # This loads nvm bash_completion
. ~/.bashrc &&
# Ensure screen also respects the bashrc
echo 'shell -$SHELL' >> ~/.screenrc &&
# install nodejs v18
nvm install v18.20.4 &&
nvm use v18.20.4 &&
# Install the necessary node modules
npm install &&
echo "\n\n\n" &&
# Create a startup script
#echo '. ~/.bashrc ; . ~/.nvm/nvm.sh ; nvm use' \'v18.4.0\' '; cd ~/easel-driver ; node iris.js' > run.sh &&
#chmod 755 run.sh &&
# Allow installing on reboot
check_init() {
# Per sd_booted(8), the way to check if systemd is running is to check if this directory exists.
if [ -d /run/systemd/system/ ]; then
# set if systemd is in use on this system.
SYSD=1
else
SYSD=0
fi
}
# Create simple start script and save in easel driver folder
create_start_script() {
driverdir=$(pwd)
touch ${driverdir}/run.sh
chmod +x ${driverdir}/run.sh
cat <<EOF > run.sh
#!/bin/bash
. ~/.bashrc
. ${NVM_DIR}/nvm.sh
nvm use 'v18.20.4'
cd ${driverdir}
echo "Starting easel-driver"
node iris.js
EOF
}
# Installs system specific service
install_service() {
if [ "${SYSD}" = "1" ]; then
touch ${driverdir}/EaselDriver.service
cat <<EOF > ${driverdir}/EaselDriver.service
[Unit]
Description=EaselDriver systemd service unit file.
[Service]
User=$(whoami)
# use screen -D to keep 'screen' alive but detached so that systemd sees it is running.
ExecStart=screen -DmS easel /bin/bash ${driverdir}/run.sh
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo mv ${driverdir}/EaselDriver.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable EaselDriver.service
else # if init.d create start/stop script enable with chkconfig
touch ${driverdir}/EaselDriver
cat <<EOF > ${driverdir}/EaselDriver
#!/bin/bash
# chkconfig: 2345 20 80
# description: Serv
# Source function library.
. /etc/init.d/functions
start() {
cd ${driverdir}
chroot --userspec "$(whoami)": / screen -dmS easel ${driverdir}/run.sh
}
stop() {
chroot --userspec "$(whoami): / /usr/bin/screen -X -S "easel" quit
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage: $0 {start|stop}"
esac
exit 0
EOF
sudo mv ${driverdir}/EaselDriver /etc/init.d/
sudo chkconfig --add EaselDriver
sudo chkconfig --level 2345 EaselDriver on
fi
}
while true; do
echo "Almost done! Do you want Easel driver to run on startup (will install system service) [yn]: "
# It's important to use `read` like this so that we can be piped into `| sh`
read yn <&1
case $yn in
[Yy]* )
check_init
create_start_script
install_service
break;;
[Nn]* ) break;;
* ) echo "Please answer yes/no";;
esac
done &&
# Profit (run driver in the background)
screen -L -dmS easel node iris.js &&
# Output the screen log so we can see if it was successful
sleep 3 &&
echo "\n\n\n" &&
tail screenlog.0 &&
# Run `screen -r easel` to access the driver, and Ctrl+A (Cmd+A on macOS) followed by 'd' to detach)
echo '\n\nDone! Easel driver running in background. Run `screen -r` to bring it to foreground.'