From d33db3096df4c589cd440a9c3e7a1f365ca629e0 Mon Sep 17 00:00:00 2001 From: "oz.nu" Date: Thu, 28 Apr 2022 12:29:30 +0000 Subject: [PATCH] homebridge raspberry pi image override --- deb/debian/postinst | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/deb/debian/postinst b/deb/debian/postinst index 21c4fc8..374d23a 100755 --- a/deb/debian/postinst +++ b/deb/debian/postinst @@ -49,6 +49,27 @@ if [ "$1" = "configure" ]; then # fix permissions on homebridge user home chown -R homebridge: /home/homebridge/.bashrc + # source /etc/os-release to get OS ID + . /etc/os-release + + # add user to default groups if running on raspbian + if [ "$ID" = "raspbian" ]; then + for groupName in udio bluetooth dialout gpio video input i2c spi audio render; do + usermod -a -G $groupName homebridge 2> /dev/null + done + fi + + # if running on Offical Homebridge Raspberry Pi, run as the "pi" user instead + if [ -z $2 ] && [ "$ID" = "raspbian" ] && [ -f /etc/hb-release ] && [ ! -f /etc/systemd/system/homebridge.service.d/override.conf ]; then + getent passwd pi > /dev/null + if [ "$?" -eq 0 ]; then + mkdir -p /etc/systemd/system/homebridge.service.d + echo "[Service]" > /etc/systemd/system/homebridge.service.d/override.conf + echo "User=pi" >> /etc/systemd/system/homebridge.service.d/override.conf + echo "Environment=\"UIX_CAN_SHUTDOWN_RESTART_HOST=1\"" >> /etc/systemd/system/homebridge.service.d/override.conf + fi + fi + # clear any masks on the homebridge service systemctl unmask homebridge.service 2> /dev/null @@ -64,14 +85,6 @@ if [ "$1" = "configure" ]; then # create symlink to hb-shell ln -fs /opt/homebridge/hb-shell /usr/local/bin/hb-shell - - # add user to default groups if running on raspbian - . /etc/os-release - if [ "$ID" = "raspbian" ]; then - for groupName in udio bluetooth dialout gpio video input i2c spi audio render; do - usermod -a -G $groupName homebridge 2> /dev/null - done - fi fi # post-install only