This commit is contained in:
paukstelis
2023-04-06 19:55:03 -04:00
parent 9149a1b790
commit 5f6f5a81ce

View File

@@ -277,13 +277,13 @@ new_instance () {
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p') HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
#find frontend line, do insert #find frontend line, do insert
#Don't know how to do the formatting correctly here. This works, however. #Don't know how to do the formatting correctly here. This works, however.
SEDREPLACE="#$INSTANCE start\n\ SEDREPLACE="#$INSTANCE start\n\
acl is_$INSTANCE url_beg /$INSTANCE\n\ acl is_$INSTANCE url_beg /$INSTANCE\n\
http-request redirect scheme http drop-query append-slash if is_$INSTANCE ! { path_beg /$INSTANCE/ }\n\ http-request redirect scheme http drop-query append-slash if is_$INSTANCE ! { path_beg /$INSTANCE/ }\n\
use_backend $INSTANCE if { path_beg /$INSTANCE/ }\n\ use_backend $INSTANCE if { path_beg /$INSTANCE/ }\n\
#$INSTANCE stop" #$INSTANCE stop"
sed -i "/option forwardfor except 127.0.0.1/a $SEDREPLACE" /etc/haproxy/haproxy.cfg sed -i "/option forwardfor except 127.0.0.1/a $SEDREPLACE" /etc/haproxy/haproxy.cfg
echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg
echo "backend $INSTANCE" >> /etc/haproxy/haproxy.cfg echo "backend $INSTANCE" >> /etc/haproxy/haproxy.cfg
@@ -392,15 +392,15 @@ write_camera() {
#find frontend line, do insert #find frontend line, do insert
sed -i "/use_backend $INSTANCE if/a\ use_backend cam${INUM}_$INSTANCE if { path_beg /cam${INUM}_$INSTANCE/ }" /etc/haproxy/haproxy.cfg sed -i "/use_backend $INSTANCE if/a\ use_backend cam${INUM}_$INSTANCE if { path_beg /cam${INUM}_$INSTANCE/ }" /etc/haproxy/haproxy.cfg
if [ $HAversion -gt 1 ]; then if [ $HAversion -gt 1 ]; then
EXTRACAM="backend cam${INUM}_$INSTANCE\n\ EXTRACAM="backend cam${INUM}_$INSTANCE\n\
http-request replace-path /cam${INUM}_$INSTANCE/(.*) /|\1\n\ http-request replace-path /cam${INUM}_$INSTANCE/(.*) /|\1\n\
server webcam1 127.0.0.1:$CAMPORT" server webcam1 127.0.0.1:$CAMPORT"
else else
EXTRACAM="backend cam${INUM}_$INSTANCE\n\ EXTRACAM="backend cam${INUM}_$INSTANCE\n\
reqrep ^([^\ :]*)\ /cam${INUM}_$INSTANCE/(.*) \1\ /|\2 \n\ reqrep ^([^\ :]*)\ /cam${INUM}_$INSTANCE/(.*) \1\ /|\2 \n\
server webcam1 127.0.0.1:$CAMPORT" server webcam1 127.0.0.1:$CAMPORT"
fi fi
echo "#cam${INUM}_$INSTANCE start" >> /etc/haproxy/haproxy.cfg echo "#cam${INUM}_$INSTANCE start" >> /etc/haproxy/haproxy.cfg
sed -i "/#cam${INUM}_$INSTANCE start/a $EXTRACAM" /etc/haproxy/haproxy.cfg sed -i "/#cam${INUM}_$INSTANCE start/a $EXTRACAM" /etc/haproxy/haproxy.cfg
#these are necessary because sed append seems to have issues with escaping for the /\1 #these are necessary because sed append seems to have issues with escaping for the /\1
@@ -496,22 +496,22 @@ add_camera() {
if [ -z "$CAMPORT" ]; then if [ -z "$CAMPORT" ]; then
CAMPORT=$(tail -1 /etc/camera_ports) CAMPORT=$(tail -1 /etc/camera_ports)
fi fi
if [ -z "$CAMPORT" ]; then if [ -z "$CAMPORT" ]; then
CAMPORT=8000 CAMPORT=8000
fi fi
CAMPORT=$((CAMPORT+1)) CAMPORT=$((CAMPORT+1))
if [ $CAMPORT -gt 7000 ]; then if [ $CAMPORT -gt 7000 ]; then
break break
else else
echo "Camera Port must be greater than 7000" echo "Camera Port must be greater than 7000"
fi fi
fi
done done
echo "Settings can be modified after initial setup in /etc/systemd/system/cam${INUM}_$INSTANCE.service" echo "Settings can be modified after initial setup in /etc/systemd/system/cam${INUM}_$INSTANCE.service"
echo echo
while true; do while true; do
@@ -1024,7 +1024,7 @@ remove_instance() {
for camera in "${cameras[@]}"; do for camera in "${cameras[@]}"; do
remove_camera $camera remove_camera $camera
done done
#remove udev entry #remove udev entry
sed -i "/$opt/d" /etc/udev/rules.d/99-octoprint.rules sed -i "/$opt/d" /etc/udev/rules.d/99-octoprint.rules
#remove files #remove files