Prep for octopi
This commit is contained in:
@@ -6,7 +6,7 @@ if (( $EUID != 0 )); then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $SUDO_USER ]; then user=$SUDO_USER; fi
|
if [ $SUDO_USER ]; then user=$SUDO_USER; fi
|
||||||
|
SCRIPTDIR=$(dirname $(readlink -f $0))
|
||||||
PIDEFAULT="/home/$user/oprint/bin/octoprint"
|
PIDEFAULT="/home/$user/oprint/bin/octoprint"
|
||||||
BUDEFAULT="/home/$user/OctoPrint/bin/octoprint"
|
BUDEFAULT="/home/$user/OctoPrint/bin/octoprint"
|
||||||
OTHERDEFAULT=""
|
OTHERDEFAULT=""
|
||||||
@@ -17,6 +17,7 @@ do
|
|||||||
case $opt in
|
case $opt in
|
||||||
"OctoPi")
|
"OctoPi")
|
||||||
DAEMONPATH=$PIDEFAULT
|
DAEMONPATH=$PIDEFAULT
|
||||||
|
INSTALL=1
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"OctoBuntu")
|
"OctoBuntu")
|
||||||
@@ -36,7 +37,7 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "UNPLUG PRINTER FROM USB"
|
echo "UNPLUG PRINTER FROM USB"
|
||||||
echo "Enter the name for new printer/instance:"
|
echo "Enter the name for new printer/instance (no spaces):"
|
||||||
read INSTANCE
|
read INSTANCE
|
||||||
if [ -z "$INSTANCE" ]; then
|
if [ -z "$INSTANCE" ]; then
|
||||||
echo "No instance given. Exiting"
|
echo "No instance given. Exiting"
|
||||||
@@ -48,22 +49,22 @@ if test -f "/etc/systemd/system/$INSTANCE.service"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Port on which this instance will run (ENTER will increment last value in /etc/octoprint_ports):"
|
echo "Port on which this instance will run (ENTER will increment last value in /etc/octoprint_instances):"
|
||||||
read PORT
|
read PORT
|
||||||
if [ -z "$PORT" ]; then
|
if [ -z "$PORT" ]; then
|
||||||
PORT=$(tail -1 /etc/octoprint_ports)
|
PORT=$(tail -1 /etc/octoprint_instances | sed -n -e 's/^.*\(port:\)\(.*\)/\2/p')
|
||||||
|
|
||||||
if [ -z "$PORT" ]; then
|
if [ -z "$PORT" ]; then
|
||||||
PORT=4999
|
PORT=5000
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PORT=$((PORT+1))
|
PORT=$((PORT+1))
|
||||||
echo Selected port is: $PORT
|
echo Selected port is: $PORT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /etc/octoprint_ports ]; then
|
if [ -f /etc/octoprint_instances ]; then
|
||||||
if grep -q $PORT /etc/octoprint_ports; then
|
if grep -q $PORT /etc/octoprint_instances; then
|
||||||
echo "Port in use! Check /etc/octoprint_ports. Exiting."
|
echo "Port in use! Check /etc/octoprint_instances. Exiting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -81,7 +82,7 @@ if [ -z "$OCTOPATH" ]; then
|
|||||||
OCTOPATH=$DAEMONPATH
|
OCTOPATH=$DAEMONPATH
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f $OCTOPATH ]]; then
|
if [ -f "$OCTOPATH" ]; then
|
||||||
echo "Path is valid"
|
echo "Path is valid"
|
||||||
else
|
else
|
||||||
echo "Path is not valid! Aborting"
|
echo "Path is not valid! Aborting"
|
||||||
@@ -95,13 +96,13 @@ if [ -z "$OCTOCONFIG" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
#octoprint_base is the generic .octoprint folder that contains all configuration, upload, etc.
|
#octoprint_base is the generic .octoprint folder that contains all configuration, upload, etc.
|
||||||
echo "Octoprint instance template base folder [/home/$user/.octoprint]:"
|
echo "Octoprint instance template path [/home/$user/.octoprint]:"
|
||||||
read BFOLD
|
read BFOLD
|
||||||
if [ -z "$BFOLD" ]; then
|
if [ -z "$BFOLD" ]; then
|
||||||
BFOLD="/home/$user/.octoprint"
|
BFOLD="/home/$user/.octoprint"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -d $BFOLD ]]; then
|
if [ -d "$BFOLD" ]; then
|
||||||
echo "Path is valid"
|
echo "Path is valid"
|
||||||
else
|
else
|
||||||
echo "Path is not valid! Aborting"
|
echo "Path is not valid! Aborting"
|
||||||
@@ -142,14 +143,13 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Serial number detected as: $UDEV"
|
echo "Serial number detected as: $UDEV"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Octobuntu cameras
|
#Octobuntu cameras
|
||||||
if [[ $INSTALL = 2 ]]; then
|
if [[ $INSTALL = "2" ]]; then
|
||||||
read -p "Would you like to auto detect an associated USB camera (experimental)?" -n 1 -r
|
read -p "Would you like to auto detect an associated USB camera (experimental)?" -n 1 -r
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
if [[ $REPLY =~ ^[Yy]$ ]]
|
||||||
then
|
then
|
||||||
@@ -171,6 +171,18 @@ if [[ $INSTALL = 2 ]]; then
|
|||||||
else
|
else
|
||||||
echo "Camera detected with serial number: $CAM"
|
echo "Camera detected with serial number: $CAM"
|
||||||
fi
|
fi
|
||||||
|
echo "Camera Port (ENTER will increment last value in /etc/camera_ports):"
|
||||||
|
read CAMPORT
|
||||||
|
if [ -z "$CAMPORT" ]; then
|
||||||
|
CAMPORT=$(tail -1 /etc/camera_ports)
|
||||||
|
|
||||||
|
if [ -z "$CAMPORT" ]; then
|
||||||
|
CAMPORT=8000
|
||||||
|
fi
|
||||||
|
|
||||||
|
CAMPORT=$((CAMPORT+1))
|
||||||
|
echo Selected port is: $PORT
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -178,7 +190,7 @@ read -p "Ready to write all changes. Do you want to proceed? " -n 1 -r
|
|||||||
echo
|
echo
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]];
|
if [[ $REPLY =~ ^[Yy]$ ]];
|
||||||
then
|
then
|
||||||
cat octoprint_generic.service | \
|
cat $SCRIPTDIR/octoprint_generic.service | \
|
||||||
sed -e "s/OCTOUSER/$OCTOUSER/" \
|
sed -e "s/OCTOUSER/$OCTOUSER/" \
|
||||||
-e "s#OCTOPATH#$OCTOPATH#" \
|
-e "s#OCTOPATH#$OCTOPATH#" \
|
||||||
-e "s#OCTOCONFIG#$OCTOCONFIG#" \
|
-e "s#OCTOCONFIG#$OCTOCONFIG#" \
|
||||||
@@ -198,6 +210,15 @@ then
|
|||||||
|
|
||||||
#Octobuntu Cameras udev identifier - either Serial number or USB port
|
#Octobuntu Cameras udev identifier - either Serial number or USB port
|
||||||
#Serial Number
|
#Serial Number
|
||||||
|
if [[ -n $CAM || -n $USBCAM ]]; then
|
||||||
|
cat $SCRIPTDIR/octocam_generic.service | \
|
||||||
|
sed -e "s/OCTOUSER/$OCTOUSER/" \
|
||||||
|
-e "s/OCTOCAM/cam_$INSTANCE/" \
|
||||||
|
-e "s/CAMPORT/$CAMPORT/"
|
||||||
|
|
||||||
|
echo $CAMPORT >> /etc/camera_ports
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$CAM" ]; then
|
if [ -n "$CAM" ]; then
|
||||||
echo SUBSYSTEM==\"video4linux\", ATTRS{serial}==\"$CAM\", ATTR{index}==\"0\", SYMLINK+=\"cam_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules
|
echo SUBSYSTEM==\"video4linux\", ATTRS{serial}==\"$CAM\", ATTR{index}==\"0\", SYMLINK+=\"cam_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules
|
||||||
fi
|
fi
|
||||||
@@ -207,15 +228,18 @@ then
|
|||||||
echo KERNELS==\"$USBCAM\",SUBSYSTEMS==\"video4linux\", ATTR{index}==\"0\", SYMLINK+=\"cam_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules
|
echo KERNELS==\"$USBCAM\",SUBSYSTEMS==\"video4linux\", ATTR{index}==\"0\", SYMLINK+=\"cam_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#just to be on the safe side, add user to dialout
|
#just to be on the safe side, add user to dialout and video
|
||||||
usermod -a -G dialout $OCTOUSER
|
usermod -a -G dialout,video $OCTOUSER
|
||||||
|
|
||||||
#Open port to be on safe side
|
#Open port to be on safe side
|
||||||
ufw allow $PORT/tcp
|
#ufw allow $PORT/tcp
|
||||||
|
|
||||||
#Append port in the port list
|
#Append port in the port list
|
||||||
echo $PORT >> /etc/octoprint_ports
|
echo $PORT >> /etc/octoprint_ports
|
||||||
|
|
||||||
|
#Append instance name to list for removal tool
|
||||||
|
echo instance:$INSTANCE port:$PORT >> /etc/octoprint_instances
|
||||||
|
|
||||||
#copy all files to our new directory
|
#copy all files to our new directory
|
||||||
cp -rp $BFOLD $OCTOCONFIG/.$INSTANCE
|
cp -rp $BFOLD $OCTOCONFIG/.$INSTANCE
|
||||||
|
|
||||||
|
|||||||
9
octocam_generic.service
Normal file
9
octocam_generic.service
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=the OctoPi/buntu webcam daemon with the user specified config
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=OCTOUSER
|
||||||
|
ExecStart=mjpg_streamer -i "input_uvc.so -d /dev/OCTOCAM -y -f 5" -o "output_http.so -p CAMPORT"
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -4,12 +4,11 @@ After=network.online.target
|
|||||||
Wants=network.online.target
|
Wants=network.online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Environment="HOST=127.0.0.1"
|
|
||||||
Environment="PORT=NEWPORT"
|
Environment="PORT=NEWPORT"
|
||||||
Environment="BASEDIR=OCTOCONFIG/.NEWINSTANCE"
|
Environment="BASEDIR=OCTOCONFIG/.NEWINSTANCE"
|
||||||
Environment="CONFIGFILE=OCTOCONFIG/.NEWINSTANCE/config.yaml"
|
Environment="CONFIGFILE=OCTOCONFIG/.NEWINSTANCE/config.yaml"
|
||||||
User=OCTOUSER
|
User=OCTOUSER
|
||||||
ExecStart=OCTOPATH serve --config=${CONFIGFILE} --basedir=${BASEDIR} --host=${HOST} --port=${PORT}
|
ExecStart=OCTOPATH serve --config=${CONFIGFILE} --basedir=${BASEDIR} --port=${PORT}
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
Reference in New Issue
Block a user