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

View File

@@ -6,7 +6,7 @@ Wants=network.online.target
[Service]
User=OCTOUSER
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]
WantedBy=multi-user.target