Camsettings/firstrun (#144)

* cam variables to env file

* fix heredoc

* fix env filename

* ustreamer dev

* simplify echos

* readme

* cansettings plus much more

* else fix

* more else fixes

* remove env fix

* first run instance creation
This commit is contained in:
paukstelis
2024-01-15 10:45:56 -05:00
committed by GitHub
parent 99bb76874c
commit a1176318e3
6 changed files with 62 additions and 36 deletions

View File

@@ -62,6 +62,7 @@ Need help with octoprint_deploy? Ask on Discord: https://discord.gg/6vgSjgvR6u
* Restart all instances from the command line: `sudo octoprint_deploy/octoprint_deploy.sh restart_all` * Restart all instances from the command line: `sudo octoprint_deploy/octoprint_deploy.sh restart_all`
* You can inject any function at start using the command line with the first argument `f` and the second argument the function name. * You can inject any function at start using the command line with the first argument `f` and the second argument the function name.
# Recent Changes # Recent Changes
* Camera settings written to separate env file. This can be found and edited at `/etc/cam_instancename.env`.
* Fixes for shared uploads function. * Fixes for shared uploads function.
* Command-line function injection. Will be useful in some cases. * Command-line function injection. Will be useful in some cases.
* Allow first instance creation without udev rule * Allow first instance creation without udev rule

View File

@@ -32,6 +32,7 @@ remove_camera() {
systemctl stop $1.service systemctl stop $1.service
systemctl disable $1.service systemctl disable $1.service
rm /etc/systemd/system/$1.service 2>/dev/null rm /etc/systemd/system/$1.service 2>/dev/null
rm /etc/$1.env 2>/dev/null
sed -i "/$1/d" /etc/udev/rules.d/99-octoprint.rules sed -i "/$1/d" /etc/udev/rules.d/99-octoprint.rules
sed -i "/$1/d" /etc/octoprint_cameras sed -i "/$1/d" /etc/octoprint_cameras
if [ "$HAPROXY" == true ]; then if [ "$HAPROXY" == true ]; then
@@ -53,7 +54,7 @@ write_camera() {
else else
CAMDEVICE=cam${INUM}_$INSTANCE CAMDEVICE=cam${INUM}_$INSTANCE
fi fi
OUTFILE=cam${INUM}_$INSTANCE
#mjpg-streamer #mjpg-streamer
if [ "$STREAMER" == mjpg-streamer ]; then if [ "$STREAMER" == mjpg-streamer ]; then
cat $SCRIPTDIR/octocam_mjpg.service | \ cat $SCRIPTDIR/octocam_mjpg.service | \
@@ -68,14 +69,15 @@ write_camera() {
if [ "$STREAMER" == ustreamer ]; then if [ "$STREAMER" == ustreamer ]; then
cat $SCRIPTDIR/octocam_ustream.service | \ cat $SCRIPTDIR/octocam_ustream.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \ sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/$CAMDEVICE/" \ -e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service
-e "s/RESOLUTION/$RESOLUTION/" \
-e "s/FRAMERATE/$FRAMERATE/" \
-e "s/CAMPORT/$CAMPORT/" > $SCRIPTDIR/cam${INUM}_$INSTANCE.service
fi fi
cp $SCRIPTDIR/cam${INUM}_$INSTANCE.service /etc/systemd/system/ sudo -u $user echo "DEVICE=$CAMDEVICE" >> /etc/$OUTFILE.env
mv $SCRIPTDIR/cam${INUM}_$INSTANCE.service $SCRIPTDIR/cam${INUM}_$INSTANCE.attempt sudo -u $user echo "RES=$RESOLUTION" >> /etc/$OUTFILE.env
sudo -u $user echo "FRAMERATE=$FRAMERATE" >> /etc/$OUTFILE.env
sudo -u $user echo "PORT=$CAMPORT" >> /etc/$OUTFILE.env
cp $SCRIPTDIR/$OUTFILE.service /etc/systemd/system/
echo "camera:cam${INUM}_$INSTANCE port:$CAMPORT udev:true" >> /etc/octoprint_cameras echo "camera:cam${INUM}_$INSTANCE port:$CAMPORT udev:true" >> /etc/octoprint_cameras
#config.yaml modifications - only if INUM not set #config.yaml modifications - only if INUM not set
@@ -269,7 +271,7 @@ add_camera() {
write_camera write_camera
#Pi Cam setup, replace cam_INSTANCE with /dev/video0 #Pi Cam setup, replace cam_INSTANCE with /dev/video0
if [ -n "$PI" ]; then if [ -n "$PI" ]; then
echo SUBSYSTEM==\"video4linux\", ATTRS{name}==\"camera0\", SYMLINK+=\"cam${INUM}_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules echo SUBSYSTEM==\"video4linux\", ATTRS{name}==\"video0\", SYMLINK+=\"cam${INUM}_$INSTANCE\" >> /etc/udev/rules.d/99-octoprint.rules
fi fi
systemctl start cam${INUM}_$INSTANCE.service systemctl start cam${INUM}_$INSTANCE.service

View File

@@ -1,6 +1,11 @@
#!/bin/bash #!/bin/bash
new_instance() { new_instance() {
#reset detection info
UDEV=''
TEMPUSB=''
USB=''
#It is possible to not create an instance after preparing,so check if this is the first #It is possible to not create an instance after preparing,so check if this is the first
if [ -f /etc/octoprint_instances ]; then if [ -f /etc/octoprint_instances ]; then
firstrun=false firstrun=false
@@ -99,7 +104,14 @@ new_instance() {
echo echo
echo echo
else else
main_menu if [ "$firstrun" == "true" ]; then
echo "${red}You will need to restart your installation.${white}"
echo "${red}Answer Y and re-run octoprint_deploy${white}"
remove_everything
exit
else
main_menu
fi
fi fi
if [ -n "$TEMPLATE" ]; then if [ -n "$TEMPLATE" ]; then
@@ -115,8 +127,13 @@ new_instance() {
if prompt_confirm "Begin printer auto-detection for udev entry?"; then if prompt_confirm "Begin printer auto-detection for udev entry?"; then
detect_printer detect_printer
else else
echo "${magenta}Instance has not been created. Restart and do detection when you are ready.${white}" if [ "$firstrun" == "true" ]; then
main_menu echo "${magenta}First instance setup in progress, continuing${white}"
else
echo "${magenta}Instance has not been created. Restart and do detection when you are ready.${white}"
main_menu
fi
fi fi
#Detection phase #Detection phase
@@ -141,10 +158,12 @@ new_instance() {
-e "s/NEWPORT/$PORT/" > /etc/systemd/system/$INSTANCE.service -e "s/NEWPORT/$PORT/" > /etc/systemd/system/$INSTANCE.service
#write phase #write phase
printer_udev true if [ -n "$UDEV" ] || [ -n "$USB" ]; then
printer_udev true
fi
#Append instance name to list for removal tool #Append instance name to list for removal tool
if [ -z "$UDEV" ] && [ -z "$TEMPUSB" ]; then if [ -z "$UDEV" ] && [ -z "$USB" ]; then
echo "instance:$INSTANCE port:$PORT udev:false" >> /etc/octoprint_instances echo "instance:$INSTANCE port:$PORT udev:false" >> /etc/octoprint_instances
else else
echo "instance:$INSTANCE port:$PORT udev:true" >> /etc/octoprint_instances echo "instance:$INSTANCE port:$PORT udev:true" >> /etc/octoprint_instances
@@ -284,15 +303,13 @@ printer_udev() {
else else
#No serial number #No serial number
if [ -z "$UDEV" ] && [ -n "$TEMPUSB" ]; then if [ -z "$UDEV" ] && [ -n "$TEMPUSB" ]; then
echo "Printer Serial Number not detected" echo "Printer Serial Number not detected."
if prompt_confirm "Do you want to use the physical USB port to assign the udev entry? If you use this any USB hubs and printers detected this way must stay plugged into the same USB positions on your machine as they are right now"; then echo "The physical USB port will be used."
echo echo "USB hubs and printers detected this way must stay plugged into the same USB positions on your machine."
USB=$TEMPUSB echo
echo "Your printer will be setup at the following usb address: ${cyan}$USB${white}" USB=$TEMPUSB
echo echo "Your printer will be setup at the following usb address: ${cyan}$USB${white}"
else echo
main_menu
fi
else else
echo -e "Serial number detected as: ${cyan}$UDEV${white}" echo -e "Serial number detected as: ${cyan}$UDEV${white}"
check_sn "$UDEV" check_sn "$UDEV"
@@ -300,15 +317,15 @@ printer_udev() {
fi fi
#Failed state. Nothing detected #Failed state. Nothing detected
if [ -z "$UDEV" ] && [ -z "$TEMPUSB" ]; then if [ -z "$UDEV" ] && [ -z "$TEMPUSB" ]; then
echo if [ "$firstrun" == "false" ]; then
echo "${red}No printer was detected during the detection period.${white}" echo
echo "Check your USB cable (power only?) and try again." echo "${red}No printer was detected during the detection period.${white}"
echo echo "Check your USB cable (power only?) and try again."
echo echo
if [ "$firstrun" == "true" ]; then echo
echo "You can attempt adding a udev rule later from the Utilities menu."
else
main_menu main_menu
else
echo "You can add a udev rule later from the Utilities menu."
fi fi
fi fi
fi fi

View File

@@ -8,7 +8,7 @@ cyan=$(echo -en "\e[96m")
yellow=$(echo -en "\e[93m") yellow=$(echo -en "\e[93m")
main_menu() { main_menu() {
VERSION=1.0.5 VERSION=1.0.6
#reset #reset
UDEV='' UDEV=''
TEMPUSB='' TEMPUSB=''

View File

@@ -4,8 +4,9 @@ After=network.online.target
Wants=network.online.target Wants=network.online.target
[Service] [Service]
EnvironmentFile=/etc/OCTOCAM.env
User=OCTOUSER User=OCTOUSER
ExecStart=/home/OCTOUSER/ustreamer/ustreamer -d /dev/OCTOCAM -s 0.0.0.0 -m MJPEG -r RESOLUTION -f FRAMERATE -p CAMPORT --device-timeout 8 --device-error-delay 8 ExecStart=/home/OCTOUSER/ustreamer/ustreamer -d /dev/${DEVICE} -s 0.0.0.0 -m MJPEG -r ${RES} -f ${FRAMERATE} -p ${PORT} --device-timeout 8 --device-error-delay 8
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@@ -47,6 +47,9 @@ detect_installs() {
octopresent=$(find /home/$user/ -type f -executable -print | grep "bin/octoprint") octopresent=$(find /home/$user/ -type f -executable -print | grep "bin/octoprint")
if [ -n "$octopresent" ]; then if [ -n "$octopresent" ]; then
echo "OctoPrint binary found at $octopresent" echo "OctoPrint binary found at $octopresent"
echo "Did you try and setup OctoPrint in another way?"
echo "${red}This may cause issues!${white}"
: '
PS3="${green}Select option number: ${white}" PS3="${green}Select option number: ${white}"
options=("Use existing binary" "Install most recent OctoPrint" "More information") options=("Use existing binary" "Install most recent OctoPrint" "More information")
select opt in "${options[@]}" select opt in "${options[@]}"
@@ -66,10 +69,12 @@ detect_installs() {
*) echo "invalid option $REPLY";; *) echo "invalid option $REPLY";;
esac esac
done done
'
else else
echo "No OctoPrint binary found in the current user's home directory. Doing complete install." echo "No OctoPrint binary found in the current user's home directory. Doing complete install."
FULLINSTALL=1 FULLINSTALL=1
fi fi
FULLINSTALL=1
echo "Looking for existing OctoPrint systemd files....." echo "Looking for existing OctoPrint systemd files....."
#get any service files that have bin/octoprint #get any service files that have bin/octoprint
readarray -t syspresent < <(fgrep -l bin/octoprint /etc/systemd/system/*.service) readarray -t syspresent < <(fgrep -l bin/octoprint /etc/systemd/system/*.service)
@@ -404,7 +409,7 @@ streamer_install() {
sed -i "/streamer/d" /etc/octoprint_deploy sed -i "/streamer/d" /etc/octoprint_deploy
if [ $VID -eq 1 ]; then if [ $VID -eq 1 ]; then
rm -rf /home/$user/mjpg_streamer 2>/dev/null
#install mjpg-streamer, not doing any error checking or anything #install mjpg-streamer, not doing any error checking or anything
echo 'Installing mjpeg-streamer' echo 'Installing mjpeg-streamer'
sudo -u $user git -C /home/$user/ clone https://github.com/jacksonliam/mjpg-streamer.git mjpeg sudo -u $user git -C /home/$user/ clone https://github.com/jacksonliam/mjpg-streamer.git mjpeg
@@ -426,7 +431,7 @@ streamer_install() {
fi fi
if [ $VID -eq 2 ]; then if [ $VID -eq 2 ]; then
rm -rf /home/$user/ustreamer 2>/dev/null
#install ustreamer #install ustreamer
sudo -u $user git -C /home/$user clone --depth=1 https://github.com/pikvm/ustreamer sudo -u $user git -C /home/$user clone --depth=1 https://github.com/pikvm/ustreamer
sudo -u $user make -C /home/$user/ustreamer > /dev/null sudo -u $user make -C /home/$user/ustreamer > /dev/null
@@ -443,7 +448,7 @@ streamer_install() {
fi fi
if [ $VID -eq 4 ]; then if [ $VID -eq 4 ]; then
rm -rf /home/$user/camera-streamer 2>/dev/null
#install camera-streamer #install camera-streamer
sudo -u $user git -C /home/$user clone https://github.com/ayufan-research/camera-streamer.git --recursive sudo -u $user git -C /home/$user clone https://github.com/ayufan-research/camera-streamer.git --recursive
sudo -u $user make -C /home/$user/camera-streamer > /dev/null sudo -u $user make -C /home/$user/camera-streamer > /dev/null