fix prepare

This commit is contained in:
paukstelis
2022-01-22 11:05:59 -05:00
parent 3c3f541614
commit 3c0f99352e
2 changed files with 396 additions and 400 deletions

View File

@@ -29,17 +29,17 @@ log () {
new_instance () { new_instance () {
echo "$(date) starting instance installation" >> $logfile echo "$(date) starting instance installation" | log
if [ $SUDO_USER ]; then user=$SUDO_USER; fi if [ $SUDO_USER ]; then user=$SUDO_USER; fi
SCRIPTDIR=$(dirname $(readlink -f $0)) 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=""
PS3='Installation type: ' PS3='Installation type: '
options=("OctoPi" "OctoBuntu" "Other" "Quit") options=("OctoPi" "OctoBuntu" "Other" "Quit")
select opt in "${options[@]}" select opt in "${options[@]}"
do do
case $opt in case $opt in
"OctoPi") "OctoPi")
DAEMONPATH=$PIDEFAULT DAEMONPATH=$PIDEFAULT
@@ -60,24 +60,24 @@ do
;; ;;
*) echo "invalid option $REPLY";; *) echo "invalid option $REPLY";;
esac esac
done done
echo "UNPLUG PRINTER YOU ARE INSTALLING NOW (other printers can remain)" echo "UNPLUG PRINTER YOU ARE INSTALLING NOW (other printers can remain)"
echo "Enter the name for new printer/instance (no spaces):" 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" | log echo "No instance given. Exiting" | log
exit 1 exit 1
fi fi
if test -f "/etc/systemd/system/$INSTANCE.service"; then if test -f "/etc/systemd/system/$INSTANCE.service"; then
echo "Already have an entry for $INSTANCE. Exiting." | log echo "Already have an entry for $INSTANCE. Exiting." | log
exit 1 exit 1
fi fi
echo "Port on which this instance will run (ENTER will increment from last value in /etc/octoprint_instances):" echo "Port on which this instance will run (ENTER will increment from last value in /etc/octoprint_instances):"
read PORT read PORT
if [ -z "$PORT" ]; then if [ -z "$PORT" ]; then
PORT=$(tail -1 /etc/octoprint_instances | sed -n -e 's/^.*\(port:\)\(.*\)/\2/p') PORT=$(tail -1 /etc/octoprint_instances | sed -n -e 's/^.*\(port:\)\(.*\)/\2/p')
if [ -z "$PORT" ]; then if [ -z "$PORT" ]; then
@@ -87,62 +87,62 @@ if [ -z "$PORT" ]; then
PORT=$((PORT+1)) PORT=$((PORT+1))
echo Selected port is: $PORT | log echo Selected port is: $PORT | log
fi fi
if [ -f /etc/octoprint_instances ]; then if [ -f /etc/octoprint_instances ]; then
if grep -q $PORT /etc/octoprint_instances; then if grep -q $PORT /etc/octoprint_instances; then
echo "Port may be in use! Check /etc/octoprint_instances and select a different port. Exiting." | log echo "Port may be in use! Check /etc/octoprint_instances and select a different port. Exiting." | log
exit 1 exit 1
fi fi
fi fi
#collect user, basedir path, daemon path #collect user, basedir path, daemon path
echo "Octoprint Daemon User [$user]:" echo "Octoprint Daemon User [$user]:"
read OCTOUSER read OCTOUSER
if [ -z "$OCTOUSER" ]; then if [ -z "$OCTOUSER" ]; then
OCTOUSER=$user OCTOUSER=$user
fi fi
echo "Octoprint Executable Daemon Path [$DAEMONPATH]:" echo "Octoprint Executable Daemon Path [$DAEMONPATH]:"
read OCTOPATH read OCTOPATH
if [ -z "$OCTOPATH" ]; then if [ -z "$OCTOPATH" ]; then
OCTOPATH=$DAEMONPATH OCTOPATH=$DAEMONPATH
fi fi
if [ -f "$OCTOPATH" ]; then if [ -f "$OCTOPATH" ]; then
echo "Executable path is valid" | log echo "Executable path is valid" | log
else else
echo "Exectuable path is not valid! Aborting" | log echo "Exectuable path is not valid! Aborting" | log
exit 1 exit 1
fi fi
echo "Octoprint Config Path (where the hidden instance directory will be) [/home/$user/]:" echo "Octoprint Config Path (where the hidden instance directory will be) [/home/$user/]:"
read OCTOCONFIG read OCTOCONFIG
if [ -z "$OCTOCONFIG" ]; then if [ -z "$OCTOCONFIG" ]; then
OCTOCONFIG="/home/$user/" OCTOCONFIG="/home/$user/"
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 path [/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 "Template path is valid" | log echo "Template path is valid" | log
else else
echo "Template path is not valid! Aborting" | log echo "Template path is not valid! Aborting" | log
exit 1 exit 1
fi fi
#check to make sure first run is complete #check to make sure first run is complete
if grep -q 'firstRun: true' $BFOLD/config.yaml; then if grep -q 'firstRun: true' $BFOLD/config.yaml; then
echo "WARNING!! You must setup the base profile and admin user before continuing" | log echo "WARNING!! You must setup the base profile and admin user before continuing" | log
exit 1 exit 1
fi fi
if prompt_confirm "Begin auto-detect printer serial number for udev entry?" if prompt_confirm "Begin auto-detect printer serial number for udev entry?"
then then
echo echo
#clear out journalctl - probably a better way to do this #clear out journalctl - probably a better way to do this
@@ -155,37 +155,35 @@ if prompt_confirm "Begin auto-detect printer serial number for udev entry?"
TEMPUSB=$(timeout 1s journalctl -kf | sed -n -e 's/^.*\(cdc_acm\|ftdi_sio\|ch341\) \([0-9].*[0-9]\): \(tty.*\|FTD.*\|ch341-uart.*\).*/\2/p') TEMPUSB=$(timeout 1s journalctl -kf | sed -n -e 's/^.*\(cdc_acm\|ftdi_sio\|ch341\) \([0-9].*[0-9]\): \(tty.*\|FTD.*\|ch341-uart.*\).*/\2/p')
counter=$(( $counter + 1 )) counter=$(( $counter + 1 ))
done done
else else
echo "OK. Restart when you are ready" | log; exit 0 echo "OK. Restart when you are ready" | log; exit 0
fi fi
if [ -z "$UDEV" ]; then if [ -z "$UDEV" ]; then
echo "Printer Serial Number not detected" echo "Printer Serial Number not detected"
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" || exit 0 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" || exit 0
#if [[ $REPLY =~ ^[Yy]$ ]]; then
echo echo
USB=$TEMPUSB USB=$TEMPUSB
echo "Your printer will be setup at the following usb address:" echo "Your printer will be setup at the following usb address: $USB" | log
echo $USB | log
echo echo
else else
echo "Serial number detected as: $UDEV" | log echo "Serial number detected as: $UDEV" | log
fi fi
echo echo
#USB cameras #USB cameras
if [[ -n $INSTALL ]]; then if [[ -n $INSTALL ]]; then
if prompt_confirm "Would you like to auto detect an associated USB camera (experimental)?" if prompt_confirm "Would you like to auto detect an associated USB camera (experimental)?"
then then
add_camera add_camera
fi fi
fi fi
echo echo
if prompt_confirm "Ready to write all changes. Do you want to proceed?" if prompt_confirm "Ready to write all changes. Do you want to proceed?"
then then
cat $SCRIPTDIR/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#" \
@@ -282,17 +280,17 @@ then
#restart haproxy #restart haproxy
sudo systemctl restart haproxy.service sudo systemctl restart haproxy.service
fi fi
fi fi
} }
add_camera() { add_camera() {
#INSTANCE must be set for this to work #INSTANCE must be set for this to work
echo 'Adding camera' | log echo 'Adding camera' | log
if [ -z "$INSTANCE" ]; then if [ -z "$INSTANCE" ]; then
PS3='Select instance to add camera to: ' PS3='Select instance to add camera to: '
readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p') readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p')
#Not yet check to see if instance already has a camera
select opt in "${options[@]}" select opt in "${options[@]}"
do do
echo "Selected instance for camera: $opt" | log echo "Selected instance for camera: $opt" | log
@@ -352,19 +350,19 @@ add_camera() {
} }
remove_instance() { remove_instance() {
if [ $SUDO_USER ]; then user=$SUDO_USER; fi if [ $SUDO_USER ]; then user=$SUDO_USER; fi
echo 'Do not remove the generic instance!' | log #Check to see that octoprint_instances exists before continuing
PS3='Select instance to remove: ' echo 'Do not remove the generic instance!' | log
readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p') PS3='Select instance to remove: '
select opt in "${options[@]}" readarray -t options < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p')
do select opt in "${options[@]}"
do
echo "Selected instance to remove: $opt" | log echo "Selected instance to remove: $opt" | log
break break
done done
read -p "Do you want to remove everything associated with this instance?" -n 1 -r if prompt_confirm "Do you want to remove everything associated with this instance?"
echo #new line then
if [[ $REPLY =~ ^[Yy]$ ]]; then
#disable and remove service file #disable and remove service file
if [ -f /etc/systemd/system/$opt.service ]; then if [ -f /etc/systemd/system/$opt.service ]; then
systemctl stop $opt.service systemctl stop $opt.service
@@ -384,16 +382,16 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf /home/$user/.$opt rm -rf /home/$user/.$opt
#remove from octoprint_instances #remove from octoprint_instances
sed -i "/$opt/d" /etc/octoprint_instances sed -i "/$opt/d" /etc/octoprint_instances
fi fi
} }
usb_testing() { usb_testing() {
echo 'USB testing' | log echo 'USB testing' | log
journalctl --rotate > /dev/null 2>&1 journalctl --rotate > /dev/null 2>&1
journalctl --vacuum-time=1seconds > /dev/null 2>&1 journalctl --vacuum-time=1seconds > /dev/null 2>&1
echo "Plug your printer in via USB now (detection time-out in 1 min)" echo "Plug your printer in via USB now (detection time-out in 1 min)"
counter=0 counter=0
while [[ -z "$UDEV" ]] && [[ $counter -lt 30 ]]; do while [[ -z "$UDEV" ]] && [[ $counter -lt 30 ]]; do
UDEV=$(timeout 1s journalctl -kf | sed -n -e 's/^.*SerialNumber: //p') UDEV=$(timeout 1s journalctl -kf | sed -n -e 's/^.*SerialNumber: //p')
TEMPUSB=$(timeout 1s journalctl -kf | sed -n -e 's/^.*\(cdc_acm\|ftdi_sio\|ch341\) \([0-9].*[0-9]\): \(tty.*\|FTD.*\|ch341-uart.*\).*/\2/p') TEMPUSB=$(timeout 1s journalctl -kf | sed -n -e 's/^.*\(cdc_acm\|ftdi_sio\|ch341\) \([0-9].*[0-9]\): \(tty.*\|FTD.*\|ch341-uart.*\).*/\2/p')
counter=$(( $counter + 1 )) counter=$(( $counter + 1 ))
@@ -403,7 +401,7 @@ while [[ -z "$UDEV" ]] && [[ $counter -lt 30 ]]; do
if [ -n "$UDEV" ]; then if [ -n "$UDEV" ]; then
echo "Serial Number detected: $UDEV" | log echo "Serial Number detected: $UDEV" | log
fi fi
done done
} }
prepare () { prepare () {
@@ -412,8 +410,6 @@ prepare () {
echo 'Run this setup and then connect to octopi.local through your browser to setup your admin user.' echo 'Run this setup and then connect to octopi.local through your browser to setup your admin user.'
if prompt_confirm "Ready to begin?" if prompt_confirm "Ready to begin?"
then then
echo #new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo 'Adding instance records' echo 'Adding instance records'
if [ -f "/etc/octoprint_instances" ]; then if [ -f "/etc/octoprint_instances" ]; then
echo "octoprint_instances already exists. Trying to run prepare a second time? Exiting" | log echo "octoprint_instances already exists. Trying to run prepare a second time? Exiting" | log
@@ -430,7 +426,6 @@ prepare () {
echo 'Modifying config.yaml' echo 'Modifying config.yaml'
cp -p $SCRIPTDIR/config.basic /home/pi/.octoprint/config.yaml cp -p $SCRIPTDIR/config.basic /home/pi/.octoprint/config.yaml
fi fi
fi
} }
# initiate logging # initiate logging
@@ -442,6 +437,7 @@ select opt in "${options[@]}"
do do
case $opt in case $opt in
"Prepare system (OctoPi)") "Prepare system (OctoPi)")
prepare
break break
;; ;;
"New instance") "New instance")

View File

@@ -6,7 +6,7 @@ Wants=network.online.target
[Service] [Service]
User=OCTOUSER User=OCTOUSER
Environment="LD_LIBRARY_PATH=/home/OCTOUSER/mjpg-streamer" Environment="LD_LIBRARY_PATH=/home/OCTOUSER/mjpg-streamer"
ExecStart=/home/OCTOUSER/mjpg-streamer/mjpg_streamer -i "input_uvc.so -d /dev/OCTOCAM -f 5" -o "output_http.so -p CAMPORT" ExecStart=/home/OCTOUSER/mjpg-streamer/mjpg_streamer -i "input_uvc.so -d /dev/OCTOCAM -r RESOLUTION -f FRAMERATE" -o "output_http.so -p CAMPORT"
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target