docker code conversions

This commit is contained in:
2024-07-27 18:16:59 -05:00
parent 5afb76db3f
commit 812266b26c
5 changed files with 43 additions and 287 deletions

View File

@@ -7,7 +7,7 @@ serial:
- /dev/octo_INSTANCE - /dev/octo_INSTANCE
server: server:
commands: commands:
serverRestartCommand: sudo systemctl restart INSTANCE serverRestartCommand: s6-svc -r /var/run/s6/services/octoprint
systemRestartCommand: sudo reboot # systemRestartCommand: ssh root@172.18.0.1 reboot
systemShutdownCommand: sudo shutdown -n now # systemShutdownCommand: ssh root@172.18.0.1 poweroff
firstRun: true firstRun: true

View File

@@ -38,7 +38,7 @@ new_instance() {
done done
if [ "$firstrun" != "true" ]; then if [ "$firstrun" != "true" ]; then
if test -f "/etc/systemd/system/$INSTANCE.service"; then if [ -d "/opt/octoprint/$INSTANCE" ]; then
echo "Already have an entry for $INSTANCE. Exiting." echo "Already have an entry for $INSTANCE. Exiting."
main_menu main_menu
fi fi
@@ -143,7 +143,8 @@ new_instance() {
cat $SCRIPTDIR/docker-compose.yml | \ cat $SCRIPTDIR/docker-compose.yml | \
sed -e "s/NEWINSTANCE/$INSTANCE/" \ sed -e "s/NEWINSTANCE/$INSTANCE/" \
-e "s/NEWPORT/$PORT/" > /opt/octoprint/docker-compose.yml -e "s/CAMPORT/$CAMPORT/" > \
-e "s/NEWPORT/$PORT/" > $OCTOCONFIG/$INSTANCE/docker-compose.yml
#write phase #write phase
if [ -n "$UDEV" ] || [ -n "$USB" ]; then if [ -n "$UDEV" ] || [ -n "$USB" ]; then
@@ -174,6 +175,9 @@ new_instance() {
fi fi
fi fi
#build docker
docker compose -f $OCTOCONFIG/$INSTANCE/docker-compose.yml up -d
#uniquify instances #uniquify instances
echo 'Uniquifying instance...' echo 'Uniquifying instance...'
BASE=$OCTOCONFIG/$INSTANCE BASE=$OCTOCONFIG/$INSTANCE
@@ -236,8 +240,8 @@ new_instance() {
systemctl daemon-reload systemctl daemon-reload
sleep 1 sleep 1
#Start and enable system processes #restart docker
systemctl start $INSTANCE.service docker restart $INSTANCE
systemctl enable $INSTANCE.service systemctl enable $INSTANCE.service
if [[ -n $CAM || -n $USBCAM || -n $BYIDCAM ]]; then if [[ -n $CAM || -n $USBCAM || -n $BYIDCAM ]]; then
systemctl start cam_$INSTANCE.service systemctl start cam_$INSTANCE.service

View File

@@ -9,7 +9,7 @@ yellow=$(echo -en "\e[93m")
main_menu() { main_menu() {
VERSION=0.1 VERSION=0.2
#reset #reset
UDEV='' UDEV=''
TEMPUSB='' TEMPUSB=''
@@ -35,7 +35,7 @@ main_menu() {
do do
case $opt in case $opt in
"Prepare system") "Prepare system")
detect_installs prepare
break break
;; ;;
"Add instance") "Add instance")

285
prepare.sh Normal file → Executable file
View File

@@ -1,204 +1,5 @@
#!/bin/bash #!/bin/bash
detect_installs() {
#OctoPi will be the most common so do a search for that:
if [ -f "/etc/octopi_version" ]; then
echo "OctoPi installation detected."
echo "Adding standard OctoPi instance to instance list."
echo "instance:octoprint port:5000 udev:false" >> /etc/octoprint_instances
echo "octoexec: /opt/octoprint/oprint/bin/octoprint" >> /etc/octodocker_deploy
echo "octopip: /opt/octoprint/oprint/bin/pip" >> /etc/octodocker_deploy
echo "haproxy: true" >> /etc/octodocker_deploy
echo "octopi: true" >> /etc/octodocker_deploy
echo "Adding systemctl and reboot to sudo"
echo "$user ALL=NOPASSWD: /usr/bin/systemctl" > /etc/sudoers.d/octoprint_systemctl
echo "$user ALL=NOPASSWD: /usr/sbin/reboot" > /etc/sudoers.d/octoprint_reboot
INSTANCE=octoprint
apt-get update
deb_packages
#rename
#detect
echo "If you plan to have multiple printers on your Pi it is helpful to assign printer udev rules."
echo "This will make sure the correct printer is associated with each OctoPrint instance."
echo "This can also be done in the Utility menu at a later time."
get_settings
if prompt_confirm "${green}Would you like to generate a udev rule now?${white}"; then
echo "Unplug your printer from the USB connection now."
if prompt_confirm "${green}Ready to begin printer auto-detection?${white}"; then
detect_printer
printer_udev false
printer_udev true
udevadm control --reload-rules
udevadm trigger
docker exec -it $INSTANCE $OCTOEXEC config set serial.port /dev/octo_$INSTANCE
docker exec -it $INSTANCE $OCTOEXEC config append_value serial.additionalPorts "/dev/octo_$INSTANCE"
#convert UDEV to true
sed -i "s/udev:false/udev:true/" /etc/octoprint_instances
systemctl restart $INSTANCE
fi
fi
#streamer_install
echo "streamer: camera-streamer" >> /etc/octodocker_deploy
main_menu
fi
echo "Searching home directory for existing OctoPrint venv/binary....."
octopresent=$(find /opt/octoprint/ -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[@]}"
do
case $opt in
"Use existing binary")
OCTOEXEC=$octopresent
break
;;
"Install most recent OctoPrint")
OCTOEXEC=thing
break
;;
"More information")
exit 1
;;
*) 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)
prepare
}
#https://askubuntu.com/questions/39497
deb_packages() {
#All extra packages needed can be added here for deb based systems. Only available will be selected.
apt-cache --generate pkgnames \
| grep --line-regexp --fixed-strings \
-e make \
-e v4l-utils \
-e python-is-python3 \
-e python3-venv \
-e python3.9-venv \
-e python3.10-venv \
-e python3.11-venv \
-e python3.11-dev \
-e virtualenv \
-e python3-dev \
-e build-essential \
-e python3-setuptools \
-e libyaml-dev \
-e python3-pip \
-e cmake \
-e libjpeg8-dev \
-e libjpeg62-turbo-dev \
-e gcc \
-e g++ \
-e libevent-dev \
-e libjpeg-dev \
-e libbsd-dev \
-e ffmpeg \
-e uuid-runtime\
-e ssh\
-e libffi-dev\
-e haproxy\
-e libavformat-dev\
-e libavutil-dev\
-e libavcodec-dev\
-e libcamera-dev\
-e libcamera-tools\
-e libcamera-v4l2\
-e liblivemedia-dev\
-e v4l-utils\
-e pkg-config\
-e xxd\
-e build-essential\
-e libssl-dev\
-e rsync\
| xargs apt-get install -y
#pacakges to REMOVE go here
apt-cache --generate pkgnames \
| grep --line-regexp --fixed-strings \
-e brltty \
| xargs apt-get remove -y
}
dnf_packages() {
#untested
dnf install -y \
gcc \
python3-devel \
cmake \
libjpeg-turbo-devel \
libbsd-devel \
libevent-devel \
haproxy \
openssh \
openssh-server \
libffi-devel \
libcamera-devel \
v4l-utils \
xxd \
openssl-devel \
rsync
}
pacman_packages() {
pacman -S --noconfirm --needed \
make \
cmake \
python \
python-virtualenv \
libyaml \
python-pip \
libjpeg-turbo \
python-yaml \
python-setuptools \
libffi \
ffmpeg \
gcc \
libevent \
libbsd \
openssh \
haproxy \
v4l-utils \
rsync
}
zypper_packages() {
zypper in -y \
gcc \
python3-devel \
cmake \
libjpeg-devel \
libbsd-devel \
libevent-devel \
haproxy \
openssh \
openssh-server \
libffi-devel \
v4l-utils \
xxd \
libopenssl-devel \
rsync
}
user_groups() { user_groups() {
echo 'Adding current user to dialout and video groups.' echo 'Adding current user to dialout and video groups.'
@@ -210,6 +11,14 @@ user_groups() {
} }
prepare () { prepare () {
echo "Checking if Docker is installed....."
if command_exists docker; then
echo "Docker found at `which docker`"
else
echo "Docker not found, will install."
DOCKERINSTALL=1
fi
echo echo
echo echo
@@ -242,102 +51,42 @@ prepare () {
done done
if prompt_confirm "Ready to begin?"; then if prompt_confirm "Ready to begin?"; then
install
#CHOICE HERE between new_install or directly to haproxy/streamer based on if existing binary is used
if [ -n "$FULLINSTALL" ]; then
new_install
else
old_install
fi
fi fi
main_menu main_menu
} }
old_install() { install() {
echo "octoexec:$octopresent" >> /etc/octodocker_deploy
user_groups
haproxy_install
streamer_install
#add existing instance(s) to /etc/octoprint_instances
}
new_install() {
user_groups user_groups
OCTOEXEC=/usr/local/bin/octoprint OCTOEXEC=/usr/local/bin/octoprint
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, install OctoPrint and setup an instance." echo "This will install necessary packages, install OctoPrint and setup an instance."
#install packages
#All DEB based
PYVERSION="python3"
if [ $INSTALL -eq 2 ]; then
apt-get update > /dev/null
PYV=$(python3 -c"import sys; print(sys.version_info.minor)")
#if [ $PYV -gt 11 ]; then
# PYVERSION='python3.11'
#fi
deb_packages
fi
#Fedora35/CentOS #SELinux
if [ $INSTALL -eq 3 ]; then if command_exists getenforce && [ "$(getenforce)" == "Enforcing" ]; then
echo "Fedora and variants have SELinux enabled by default." echo "SELinux is enabled"
echo "This causes a fair bit of trouble for running OctoPrint." echo "This causes a fair bit of trouble for running OctoPrint."
echo "You have the option of disabling this now." echo "You have the option of disabling this now."
if prompt_confirm "${green}Disable SELinux?${white}"; then if prompt_confirm "${green}Disable SELinux?${white}"; then
sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config
echo "${magenta}You will need to reboot after system preparation.${white}" echo "${magenta}You will need to reboot after system preparation.${white}"
fi fi
systemctl enable sshd.service
PYV=$(python3 -c"import sys; print(sys.version_info.minor)")
if [ $PYV -gt 11 ]; then
dnf -y install python3.11-devel
PYVERSION='python3.11'
fi fi
dnf_packages if [ -n "$DOCKERINSTALL" ]; then
fi curl -sL https://get.docker.com | sh
#ArchLinux
if [ $INSTALL -eq 4 ]; then
pacman_packages
fi
if [ $INSTALL -eq 5 ]; then
zypper_packages
systemctl enable sshd.service
fi fi
echo "Enabling ssh server..." echo "Enabling ssh server..."
systemctl enable ssh.service systemctl enable ssh.service
echo "Installing OctoPrint virtual environment in /opt/octoprint/OctoPrint"
#make venv
$PYVERSION -m venv /opt/octoprint/OctoPrint
#update pip
/opt/octoprint/OctoPrint/bin/pip install --upgrade pip
#pre-install wheel
/opt/octoprint/OctoPrint/bin/pip install wheel
#install oprint
/opt/octoprint/OctoPrint/bin/pip install OctoPrint
#Check to verify that OctoPrint binary is installed
if [ -f "/opt/octoprint/OctoPrint/bin/octoprint" ]; then
echo "${cyan}OctoPrint apppears to have been installed successfully${white}"
else
echo "${red}WARNING! WARNING! WARNING!${white}"
echo "OctoPrint has not been installed correctly."
echo "Please answer Y to remove everything and try running prepare system again."
remove_everything
exit
fi
haproxy_install haproxy_install
streamer_install streamer_install
#These will retreived as settings #These will retreived as settings
echo "octoexec: /opt/octoprint/OctoPrint/bin/octoprint" >> /etc/octodocker_deploy echo "octoexec: /usr/local/bin/octoprint" >> /etc/octodocker_deploy
echo "octopip: /opt/octoprint/OctoPrint/bin/pip" >> /etc/octodocker_deploy echo "octopip: /usr/local/bin/pip" >> /etc/octodocker_deploy
#Create first instance #Create first instance
echo echo

View File

@@ -404,3 +404,6 @@ diagnostics() {
logfile='octodocker_deploy.log' logfile='octodocker_deploy.log'
main_menu main_menu
} }
command_exists() { command -v "$@" > /dev/null 2>&1 }
join_by() { local IFS="$1"; shift; echo "$*"; }