-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes sure that IF the user decided decided to change the username, contrary to setup guide instructions, stuff will still work because the user name change also gets applied to anything OctoPi specific.
- Loading branch information
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
set -x | ||
set -e | ||
|
||
export LC_ALL=C | ||
|
||
source /common.sh | ||
install_cleanup_trap | ||
|
||
# we need to install virtualenv-tools3, so let's get pip and that | ||
apt install -y python3-pip | ||
sudo -u pi pip3 install --user virtualenv-tools3 | ||
|
||
cp /files/user-fix /root/bin/user-fix | ||
chmod +x /root/bin/user-fix | ||
|
||
cp /files/user-fix.service /etc/systemd/system/user-fix.service | ||
systemctl enable user-fix.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
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` | ||
|
||
if [ "$CURRENT" = "pi" -a "$FIRSTUSER" != "pi" ]; then | ||
# if we get here it means that the first user was renamed but we haven't yet | ||
# updated all of OctoPi's files that depend on that name, so let's do that now | ||
|
||
# first we need to figure out if we can use the new user name in systemd files | ||
# directly or if we need to use the UID - we do that by checking if the | ||
# escaped name differes from the plain name, if so something is non ASCII | ||
# and the UID is the safer bet | ||
FIRSTUSERESC=`systemd-escape "$FIRSTUSER"` | ||
if [ "$FIRSTUSER" != "$FIRSTUSERESC" ]; then | ||
SERVICEUSER=$USERID | ||
else | ||
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" /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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=Ensure that user name changes are applied as needed | ||
|
||
DefaultDependencies=no | ||
|
||
Before=network-pre.target | ||
Wants=network-pre.target | ||
|
||
After=local-fs.target | ||
Wants=local-fs.target | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/root/bin/user-fix | ||
|
||
[Install] | ||
WantedBy=multi-user.target |