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`
* 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
* Camera settings written to separate env file. This can be found and edited at `/etc/cam_instancename.env`.
* Fixes for shared uploads function.
* Command-line function injection. Will be useful in some cases.
* Allow first instance creation without udev rule

View File

@@ -32,6 +32,7 @@ remove_camera() {
systemctl stop $1.service
systemctl disable $1.service
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/octoprint_cameras
if [ "$HAPROXY" == true ]; then
@@ -53,7 +54,7 @@ write_camera() {
else
CAMDEVICE=cam${INUM}_$INSTANCE
fi
OUTFILE=cam${INUM}_$INSTANCE
#mjpg-streamer
if [ "$STREAMER" == mjpg-streamer ]; then
cat $SCRIPTDIR/octocam_mjpg.service | \
@@ -68,14 +69,15 @@ write_camera() {
if [ "$STREAMER" == ustreamer ]; then
cat $SCRIPTDIR/octocam_ustream.service | \
sed -e "s/OCTOUSER/$OCTOUSER/" \
-e "s/OCTOCAM/$CAMDEVICE/" \
-e "s/RESOLUTION/$RESOLUTION/" \
-e "s/FRAMERATE/$FRAMERATE/" \
-e "s/CAMPORT/$CAMPORT/" > $SCRIPTDIR/cam${INUM}_$INSTANCE.service
-e "s/OCTOCAM/cam${INUM}_$INSTANCE/" > $SCRIPTDIR/$OUTFILE.service
fi
cp $SCRIPTDIR/cam${INUM}_$INSTANCE.service /etc/systemd/system/
mv $SCRIPTDIR/cam${INUM}_$INSTANCE.service $SCRIPTDIR/cam${INUM}_$INSTANCE.attempt
sudo -u $user echo "DEVICE=$CAMDEVICE" >> /etc/$OUTFILE.env
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
#config.yaml modifications - only if INUM not set
@@ -269,7 +271,7 @@ add_camera() {
write_camera
#Pi Cam setup, replace cam_INSTANCE with /dev/video0
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
systemctl start cam${INUM}_$INSTANCE.service

View File

@@ -1,6 +1,11 @@
#!/bin/bash
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
if [ -f /etc/octoprint_instances ]; then
firstrun=false
@@ -99,7 +104,14 @@ new_instance() {
echo
echo
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
if [ -n "$TEMPLATE" ]; then
@@ -115,13 +127,18 @@ new_instance() {
if prompt_confirm "Begin printer auto-detection for udev entry?"; then
detect_printer
else
echo "${magenta}Instance has not been created. Restart and do detection when you are ready.${white}"
main_menu
if [ "$firstrun" == "true" ]; then
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
#Detection phase
printer_udev false
#USB cameras
if [ "$firstrun" != "true" ]; then
if prompt_confirm "Would you like to auto detect an associated USB camera (experimental)?"; then
@@ -141,10 +158,12 @@ new_instance() {
-e "s/NEWPORT/$PORT/" > /etc/systemd/system/$INSTANCE.service
#write phase
printer_udev true
if [ -n "$UDEV" ] || [ -n "$USB" ]; then
printer_udev true
fi
#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
else
echo "instance:$INSTANCE port:$PORT udev:true" >> /etc/octoprint_instances
@@ -284,15 +303,13 @@ printer_udev() {
else
#No serial number
if [ -z "$UDEV" ] && [ -n "$TEMPUSB" ]; then
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
USB=$TEMPUSB
echo "Your printer will be setup at the following usb address: ${cyan}$USB${white}"
echo
else
main_menu
fi
echo "Printer Serial Number not detected."
echo "The physical USB port will be used."
echo "USB hubs and printers detected this way must stay plugged into the same USB positions on your machine."
echo
USB=$TEMPUSB
echo "Your printer will be setup at the following usb address: ${cyan}$USB${white}"
echo
else
echo -e "Serial number detected as: ${cyan}$UDEV${white}"
check_sn "$UDEV"
@@ -300,15 +317,15 @@ printer_udev() {
fi
#Failed state. Nothing detected
if [ -z "$UDEV" ] && [ -z "$TEMPUSB" ]; then
echo
echo "${red}No printer was detected during the detection period.${white}"
echo "Check your USB cable (power only?) and try again."
echo
echo
if [ "$firstrun" == "true" ]; then
echo "You can attempt adding a udev rule later from the Utilities menu."
else
if [ "$firstrun" == "false" ]; then
echo
echo "${red}No printer was detected during the detection period.${white}"
echo "Check your USB cable (power only?) and try again."
echo
echo
main_menu
else
echo "You can add a udev rule later from the Utilities menu."
fi
fi
fi

View File

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

View File

@@ -4,8 +4,9 @@ After=network.online.target
Wants=network.online.target
[Service]
EnvironmentFile=/etc/OCTOCAM.env
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]
WantedBy=multi-user.target

View File

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