Skip to content

Commit

Permalink
Move octoprint python virtualenv to /opt/custompios/oprint and add a …
Browse files Browse the repository at this point in the history
…symlink
  • Loading branch information
guysoft committed Jul 26, 2024
1 parent 7029650 commit e62bada
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/modules/octopi/filesystem/home/pi/OctoPrint/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ so OctoPi no longer goes that route either.
Feel free to manually create a git clone though if you need it (e.g. for
branch based updates or on board development):

~/scripts/add-octoprint-checkout
/opt/octopi/scripts/add-octoprint-checkout
19 changes: 3 additions & 16 deletions src/modules/octopi/filesystem/home/root/bin/user-fix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ USERID=1000
FIRSTUSER=`getent passwd $USERID | cut -d: -f1`
FIRSTUSERHOME=`getent passwd $USERID | cut -d: -f6`

CURRENT=`grep User= /etc/systemd/system/octoprint.service | cut -d= -f2`
CURRENT=$(grep "ALL\=NOPASSWD" /etc/sudoers.d/octoprint-service | cut -d\ -f1)

if [ "$CURRENT" = "pi" -a "$FIRSTUSER" != "pi" ]; then
# if we get here it means that the first user was renamed but we haven't yet
Expand All @@ -24,30 +24,17 @@ if [ "$CURRENT" = "pi" -a "$FIRSTUSER" != "pi" ]; then
SERVICEUSER=$FIRSTUSER
fi

# fix OctoPrint service file
echo "Fixing service file"
sed -i "s!User=pi!User=$SERVICEUSER!g" /etc/systemd/system/octoprint.service
sed -i "s!ExecStart=/home/pi/!ExecStart=$FIRSTUSERHOME/!g" /etc/systemd/system/octoprint.service
systemctl daemon-reload

# fix sudoers files
echo "Fixing sudoers"
sed -i "s!^pi!$FIRSTUSER!g" /etc/sudoers.d/octoprint-service
sed -i "s!^pi!$FIRSTUSER!g" /etc/sudoers.d/octoprint-shutdown

# fix scripts
echo "Fixing scripts"
sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" $FIRSTUSERHOME/scripts/add-octoprint-checkout
sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" $FIRSTUSERHOME/scripts/welcome
sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" $FIRSTUSERHOME/.bashrc
sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" /opt/octopi/scripts/add-octoprint-checkout
sed -i "s!/home/pi/!$FIRSTUSERHOME/!g" /root/bin/webcamd

# fix virtualenv
echo "Fixing paths in virtual environment"
cd $FIRSTUSERHOME/oprint
sudo -u $FIRSTUSER $FIRSTUSERHOME/.local/bin/virtualenv-tools --update-path $FIRSTUSERHOME/oprint

# finally, reboot for all of this to actually take affect
echo "Adjusted scripts to new user, restarting services..."
systemctl reboot
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Environment="HOST=127.0.0.1"
Environment="PORT=5000"
Environment="REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt"
Type=simple
User=pi
ExecStart=/home/pi/oprint/bin/octoprint serve --host=${HOST} --port=${PORT}
User=1000
ExecStart=/opt/octopi/oprint/bin/octoprint serve --host=${HOST} --port=${PORT}

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

OCTOPRINT_FOLDER=/home/pi/OctoPrint
OCTOPRINT_CONFIG=/home/pi/.octoprint/config.yaml
USER_NAME=$(id -nu 1000)'
OCTOPRINT_FOLDER=/home/"${USER_NAME}"/OctoPrint
OCTOPRINT_CONFIG=/home/"${USER_NAME}"/.octoprint/config.yaml
if [ "${PWD}" == "${OCTOPRINT_FOLDER}" ]; then
echo "Error: you are in the folder: "${OCTOPRINT_FOLDER}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

_NAME=$(hostname)
_IP=$(hostname -I)
_OCTOPRINT_VERSION=$(/home/pi/oprint/bin/python -c "from octoprint._version import get_versions; print(get_versions()['version'])" || echo "unknown")
_OCTOPRINT_VERSION=$(/opt/octopi/oprint/bin/python -c "from octoprint._version import get_versions; print(get_versions()['version'])" || echo "unknown")
_OCTOPI_VERSION=$(cat /etc/octopi_version || echo "unknown")

echo
Expand Down
15 changes: 11 additions & 4 deletions src/modules/octopi/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,24 @@ apt-get -y --allow-change-held-packages install python3 python3-virtualenv pytho
echo " - Reinstall iputils-ping"
apt-get -y --force-yes install --reinstall iputils-ping

pushd /home/"${BASE_USER}"
# Path is hardcoded systemd service, this is not configurable
OCTOPI_OPT_FOLDER=/opt/octopi
mkdir -p "${OCTOPI_OPT_FOLDER}"
chown "${BASE_USER}":"${BASE_USER}" "${OCTOPI_OPT_FOLDER}"
OCTOPI_OCTOPRINT_FOLDER="${OCTOPI_OPT_FOLDER}"/oprint
ln -s "${OCTOPI_OCTOPRINT_FOLDER}" /home/"${BASE_USER}"/oprint
PIP="${OCTOPI_OCTOPRINT_FOLDER}"/bin/pip
pushd "${OCTOPI_OPT_FOLDER}"

# build virtualenv
sudo -u "${BASE_USER}" python3 -m virtualenv --python=python3 oprint
sudo -u "${BASE_USER}" /home/"${BASE_USER}"/oprint/bin/pip install --upgrade pip
sudo -u "${BASE_USER}" "${PIP}" install --upgrade pip

# OctoPrint
if [ "$OCTOPI_INCLUDE_OCTOPRINT" == "yes" ]
then
echo "--- Installing OctoPrint"
PIP_DEFAULT_TIMEOUT=60 sudo -u "${BASE_USER}" /home/"${BASE_USER}"/oprint/bin/pip install $OCTOPI_OCTOPRINT_PACKAGE
PIP_DEFAULT_TIMEOUT=60 sudo -u "${BASE_USER}" "${PIP}" install $OCTOPI_OCTOPRINT_PACKAGE
fi

#mjpg-streamer
Expand Down Expand Up @@ -240,7 +247,7 @@ EOT
echo 'exit 0' >> /etc/rc.local

# add a longer welcome text to ~pi/.bashrc / ~${BASE_USER}/.bashrc
echo "source /home/${BASE_USER}/scripts/welcome" >> /home/${BASE_USER}/.bashrc
echo "source /opt/octopi/scripts/welcome" >> /home/${BASE_USER}/.bashrc

#unpack root in the end, so etc file are not overwritten, might need to add two roots int he future
unpack /filesystem/root /
Expand Down

0 comments on commit e62bada

Please sign in to comment.