move toward more automation

This commit is contained in:
paukstelis
2022-05-27 16:05:02 -04:00
parent a43018b44c
commit ed41deef9e

View File

@@ -79,6 +79,21 @@ new_instance () {
main_menu main_menu
fi fi
if prompt_confirm "Use all default values?"; then
PORT=$(tail -1 /etc/octoprint_instances | sed -n -e 's/^.*\(port:\)\(.*\)/\2/p')
if [ -z "$PORT" ]; then
PORT=5000
fi
PORT=$((PORT+1))
echo Selected port is: $PORT | log
OCTOUSER=$user
OCTOPATH=$DAEMONPATH
OCTOCONFIG="/home/$user/"
BFOLD="/home/$user/.octoprint"
echo "Your OctoPrint instance will be installed at /home/$user/.$INSTANCE"
echo
echo
else
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
@@ -139,10 +154,11 @@ new_instance () {
echo "Template path is not valid! Aborting" | log echo "Template path is not valid! Aborting" | log
main_menu main_menu
fi 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 template profile and admin user before continuing" | log
main_menu main_menu
fi fi
@@ -169,7 +185,7 @@ new_instance () {
#Failed state. Nothing detected #Failed state. Nothing detected
if [ -z "$UDEV" ] && [ -z "$TEMPUSB" ]; then if [ -z "$UDEV" ] && [ -z "$TEMPUSB" ]; then
echo echo
echo -e "\033[0;31mNo printer was detected during the detection period.\033[0m Check your USB cable and try again." echo -e "\033[0;31mNo printer was detected during the detection period.\033[0m Check your USB cable (power only?) and try again."
echo echo
echo echo
main_menu main_menu
@@ -237,7 +253,7 @@ new_instance () {
#just to be on the safe side, add user to dialout and video #just to be on the safe side, add user to dialout and video
usermod -a -G dialout,video $OCTOUSER usermod -a -G dialout,video $OCTOUSER
echo 'User added to dialout and video groups. You may need to restart before connecting to printers/cameras'
#Append instance name to list for removal tool #Append instance name to list for removal tool
echo instance:$INSTANCE port:$PORT >> /etc/octoprint_instances echo instance:$INSTANCE port:$PORT >> /etc/octoprint_instances
@@ -260,16 +276,15 @@ new_instance () {
sleep 1 sleep 1
#Start and enable system processes #Start and enable system processes
systemctl start $INSTANCE systemctl start $INSTANCE.service
systemctl enable $INSTANCE systemctl enable $INSTANCE.service
if [[ -n $CAM || -n $USBCAM ]]; then if [[ -n $CAM || -n $USBCAM ]]; then
systemctl start cam_$INSTANCE.service systemctl start cam_$INSTANCE.service
systemctl enable cam_$INSTANCE.service systemctl enable cam_$INSTANCE.service
fi fi
#need to find a way to know if haproxy is being used
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
if [ "$HAPROXY" == true ]; then if [ "$HAPROXY" == true ]; then
HAversion=$(haproxy -v | sed -n 's/^.*version \([0-9]\).*/\1/p')
#find frontend line, do insert #find frontend line, do insert
sed -i "/option forwardfor except 127.0.0.1/a\ use_backend $INSTANCE if { path_beg /$INSTANCE/ }" /etc/haproxy/haproxy.cfg sed -i "/option forwardfor except 127.0.0.1/a\ use_backend $INSTANCE if { path_beg /$INSTANCE/ }" /etc/haproxy/haproxy.cfg
echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg echo "#$INSTANCE start" >> /etc/haproxy/haproxy.cfg
@@ -369,9 +384,14 @@ add_camera() {
done done
fi fi
if [ "$camopt" == generic] then;
echo "Don't add cameras to the generic instance."
main_menu
fi
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 CAMERA in via USB now (detection time-out in 1 min)" echo "Plug your camera in via USB now (detection time-out in 1 min)"
counter=0 counter=0
while [[ -z "$CAM" ]] && [[ $counter -lt 30 ]]; do while [[ -z "$CAM" ]] && [[ $counter -lt 30 ]]; do
CAM=$(timeout 1s journalctl -kf | sed -n -e 's/^.*SerialNumber: //p') CAM=$(timeout 1s journalctl -kf | sed -n -e 's/^.*SerialNumber: //p')
@@ -425,7 +445,6 @@ add_camera() {
fi fi
echo "Selected camera framerate: $FRAMERATE" | log echo "Selected camera framerate: $FRAMERATE" | log
#Need to check if this is a one-off install #Need to check if this is a one-off install
if [ -n "$camopt" ]; then if [ -n "$camopt" ]; then
write_camera write_camera
@@ -585,15 +604,14 @@ prepare () {
touch /etc/camera_ports touch /etc/camera_ports
echo 'Adding current user to dialout and video groups.' echo 'Adding current user to dialout and video groups.'
usermod -a -G dialout,video $user usermod -a -G dialout,video $user
echo 'type: octopi' >> /etc/octoprint_deploy
#service start/stop may fail on non-OctoPi instances, but that is probably Ok
if [ $INSTALL -eq 1 ]; then
if grep -q 'firstRun: false' /home/$user/.octoprint/config.yaml; then if grep -q 'firstRun: false' /home/$user/.octoprint/config.yaml; then
echo "It looks as though this OctoPi installation has already been in use." | log echo "It looks as though this installation has already been in use." | log
echo "In order to use the script, the files must be moved." echo "In order to use the script, the files must be moved."
echo "If you chose to continue with the installation these files will be moved (not erased)." echo "If you chose to continue with the installation these files will be moved (not erased)."
echo "They will be found at /home/$user/.old-octo" echo "They will be found at /home/$user/.old-octo"
echo "If you have generated service files for OctoPrint, please stop and disable them."
if prompt_confirm "Continue with installation?"; then if prompt_confirm "Continue with installation?"; then
echo "Continuing installation." | log echo "Continuing installation." | log
systemctl stop octoprint.service systemctl stop octoprint.service
@@ -605,6 +623,8 @@ prepare () {
fi fi
fi fi
if [ $INSTALL -eq 1 ]; then
echo 'type: octopi' >> /etc/octoprint_deploy
if prompt_confirm "Would you like to install and use ustreamer instead of mjpg-streamer?"; then if prompt_confirm "Would you like to install and use ustreamer instead of mjpg-streamer?"; then
echo 'streamer: ustreamer' >> /etc/octoprint_deploy echo 'streamer: ustreamer' >> /etc/octoprint_deploy
apt-get -y install libevent-dev libbsd-dev apt-get -y install libevent-dev libbsd-dev
@@ -625,11 +645,10 @@ prepare () {
echo "Adding systemctl and reboot to sudo" echo "Adding systemctl and reboot to sudo"
echo "$user ALL=NOPASSWD: /usr/bin/systemctl" >> /etc/sudoers.d/octoprint_systemctl echo "$user ALL=NOPASSWD: /usr/bin/systemctl" >> /etc/sudoers.d/octoprint_systemctl
echo "$user ALL=NOPASSWD: /usr/sbin/reboot" >> /etc/sudoers.d/octoprint_reboot echo "$user ALL=NOPASSWD: /usr/sbin/reboot" >> /etc/sudoers.d/octoprint_reboot
echo 'haproxy: true' >> /etc/octoprint_deploy echo 'haproxy: true' >> /etc/octoprint_deploy
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
echo 'Connect to your octoprint instance and setup admin user' echo 'Connect to your octoprint (octopi.local) instance and setup admin user'
fi fi
@@ -639,7 +658,7 @@ prepare () {
echo "Adding systemctl and reboot to sudo" echo "Adding systemctl and reboot to sudo"
echo "$user ALL=NOPASSWD: /usr/bin/systemctl" >> /etc/sudoers.d/octoprint_systemctl echo "$user ALL=NOPASSWD: /usr/bin/systemctl" >> /etc/sudoers.d/octoprint_systemctl
echo "$user ALL=NOPASSWD: /usr/sbin/reboot" >> /etc/sudoers.d/octoprint_reboot echo "$user ALL=NOPASSWD: /usr/sbin/reboot" >> /etc/sudoers.d/octoprint_reboot
echo "This will install necessary packages, download and install OctoPrint and setup a base instance on this machine." echo "This will install necessary packages, download and install OctoPrint and setup a template instance on this machine."
#install packages #install packages
#All DEB based #All DEB based
if [ $INSTALL -eq 2 ]; then if [ $INSTALL -eq 2 ]; then
@@ -756,6 +775,7 @@ prepare () {
fi fi
echo 'Starting generic service on port 5000' echo 'Starting generic service on port 5000'
echo 'Connect to your template instance and setup the admin user.'
systemctl start octoprint_default.service systemctl start octoprint_default.service
systemctl enable octoprint_default.service systemctl enable octoprint_default.service