From 31096506e40e4d1178e35eb358727dd0343f035e Mon Sep 17 00:00:00 2001 From: Stephan Pauxberger Date: Thu, 9 Feb 2023 20:37:52 +0100 Subject: [PATCH] chore: fix issues with service user change (#6164) * Fix #6162: Always stop before preinstall Also: if creating a new user, chown the home directory just to be on the safe side (if /var/lib/evcc already exists but belongs to someone else) * Add the evcc user to the dialout group This allows evcc to access /dev/tty. Fix #6140 --- packaging/scripts/preinstall.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packaging/scripts/preinstall.sh b/packaging/scripts/preinstall.sh index e97e96bec..1da63b771 100644 --- a/packaging/scripts/preinstall.sh +++ b/packaging/scripts/preinstall.sh @@ -20,10 +20,6 @@ copyDbToUserDir() { CURRENT_HOME=$(getent passwd "$CURRENT_USER" | cut -d: -f6) COPIED_FLAG="$CURRENT_HOME/.evcc/.copiedToEvccUser" if [ -f "$CURRENT_HOME/.evcc/evcc.db" ] && [ ! -f "$COPIED_FLAG" ]; then - if [ -d /run/systemd/system ] && /bin/systemctl status evcc.service > /dev/null 2>&1; then - deb-systemd-invoke stop evcc.service >/dev/null || true - touch "$RESTART_FLAG_FILE" - fi if [ -f "$EVCC_HOME/evcc.db" ]; then echo "Not copying $CURRENT_HOME/.evcc/evcc.db to $EVCC_HOME/evcc.db, since there is already a database there" echo "Either delete one of the databases or run 'touch $COPIED_FLAG' to keep both." @@ -50,6 +46,10 @@ copyDbToUserDir() { } if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then + if [ -d /run/systemd/system ] && /bin/systemctl status evcc.service > /dev/null 2>&1; then + deb-systemd-invoke stop evcc.service >/dev/null || true + touch "$RESTART_FLAG_FILE" + fi if ! getent group "$EVCC_GROUP" > /dev/null 2>&1 ; then addgroup --system "$EVCC_GROUP" --quiet fi @@ -57,7 +57,10 @@ if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then adduser --quiet --system --ingroup "$EVCC_GROUP" \ --disabled-password --shell /bin/false \ --gecos "evcc runtime user" --home "$EVCC_HOME" "$EVCC_USER" + chown -R "$EVCC_USER:$EVCC_GROUP" "$EVCC_HOME" + adduser --quiet "$EVCC_USER" dialout else + adduser --quiet "$EVCC_USER" dialout homedir=$(getent passwd "$EVCC_USER" | cut -d: -f4) if [ "$homedir" != "$EVCC_HOME" ]; then mkdir -p "$EVCC_HOME"