From 9eb183d206f34b89ae4805a5447ec7294eaa1676 Mon Sep 17 00:00:00 2001 From: mplogas Date: Tue, 20 Aug 2019 20:43:24 +0200 Subject: [PATCH 1/5] added uid/gid fixes --- scripts/iobroker_startup.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/iobroker_startup.sh b/scripts/iobroker_startup.sh index 3eb992c..db478af 100644 --- a/scripts/iobroker_startup.sh +++ b/scripts/iobroker_startup.sh @@ -3,6 +3,8 @@ # Reading env-variables packages=$PACKAGES avahi=$AVAHI +uid=$PUID +gid=$PGID # Getting date and time for logging dati=`date '+%Y-%m-%d %H:%M:%S'` @@ -12,6 +14,7 @@ echo '' echo '----------------------------------------' echo '----- Image-Version: 3.0.2beta -----' echo '----- '$dati' -----' +echo '----- uid: '$uid' gid: '$gid' -----' echo '----------------------------------------' echo '' echo 'Startupscript running...' @@ -39,6 +42,9 @@ then echo 'Restoring done...' fi +echo 'who am i' +whoami + # Backing up original iobroker-file and changing sudo to gosu cp -a /opt/iobroker/iobroker /opt/iobroker/iobroker.bak sed -i 's/sudo -H -u/gosu/g' /opt/iobroker/iobroker @@ -50,7 +56,7 @@ then echo 'This is the first run of an new installation...' echo 'Hostname given is' $(hostname)'...' echo 'Renaming ioBroker...' - iobroker host $(cat /opt/iobroker/.install_host) + /opt/iobroker/iobroker host $(cat /opt/iobroker/.install_host) rm -f /opt/iobroker/.install_host echo 'Renaming ioBroker done...' fi @@ -60,8 +66,8 @@ if [ -f /opt/.firstrun ] then echo '' echo 'Changing permissions upon first run (This might take a while! Please be patient!)...' - chown -R iobroker /opt/iobroker - chown -R iobroker /opt/scripts + chown -R $uid:$gid /opt/iobroker + chown -R $uid:$gid /opt/scripts rm -f /opt/.firstrun echo 'Changing permissions done...' fi From 575050d5a4af57eae8c5da7c914d3350cca55d9e Mon Sep 17 00:00:00 2001 From: mplogas Date: Tue, 20 Aug 2019 21:59:42 +0200 Subject: [PATCH 2/5] external uid is now correctly applied --- Dockerfile | 3 ++- scripts/iobroker_startup.sh | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8e56cc0..db7cf53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -70,7 +70,8 @@ ENV DEBIAN_FRONTEND="teletype" \ LC_ALL="de_DE.UTF-8" \ TZ="Europe/Berlin" \ PACKAGES="nano" \ - AVAHI="false" + AVAHI="false" \ + HOSTUID=1000 # Setting up EXPOSE for Admin EXPOSE 8081/tcp diff --git a/scripts/iobroker_startup.sh b/scripts/iobroker_startup.sh index db478af..4c69af4 100644 --- a/scripts/iobroker_startup.sh +++ b/scripts/iobroker_startup.sh @@ -3,8 +3,7 @@ # Reading env-variables packages=$PACKAGES avahi=$AVAHI -uid=$PUID -gid=$PGID +uid=$HOSTUID # Getting date and time for logging dati=`date '+%Y-%m-%d %H:%M:%S'` @@ -14,7 +13,7 @@ echo '' echo '----------------------------------------' echo '----- Image-Version: 3.0.2beta -----' echo '----- '$dati' -----' -echo '----- uid: '$uid' gid: '$gid' -----' +echo '----- uid: '$uid' -----' echo '----------------------------------------' echo '' echo 'Startupscript running...' @@ -45,8 +44,24 @@ fi echo 'who am i' whoami +echo 'whats my id' +id $(whoami) + +# Checking for first run and change permissions +if [ -f /opt/.firstrun ] +then + echo '' + echo 'Changing permissions upon first run (This might take a while! Please be patient!)...' + usermod -u $uid iobroker + chown -R $uid /opt/iobroker + chown -R $uid /opt/scripts + rm -f /opt/.firstrun + echo 'Changing permissions done...' +fi + # Backing up original iobroker-file and changing sudo to gosu cp -a /opt/iobroker/iobroker /opt/iobroker/iobroker.bak +chmod u+x /opt/iobroker/iobroker sed -i 's/sudo -H -u/gosu/g' /opt/iobroker/iobroker # Checking for first run of a new installation and renaming ioBroker @@ -61,22 +76,12 @@ then echo 'Renaming ioBroker done...' fi -# Checking for first run and change permissions -if [ -f /opt/.firstrun ] -then - echo '' - echo 'Changing permissions upon first run (This might take a while! Please be patient!)...' - chown -R $uid:$gid /opt/iobroker - chown -R $uid:$gid /opt/scripts - rm -f /opt/.firstrun - echo 'Changing permissions done...' -fi - # Checking for and setting up avahi-daemon if [ "$avahi" = "true" ] then echo '' echo 'Initializing Avahi-Daemon...' + chmod u+x /opt/scripts/setup_avahi.sh sh /opt/scripts/setup_avahi.sh echo 'Initializing Avahi-Daemon done...' fi From 0d775350c5278836a7ea1653fea434e2b24a19eb Mon Sep 17 00:00:00 2001 From: mplogas Date: Tue, 20 Aug 2019 22:05:09 +0200 Subject: [PATCH 3/5] README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d912e62..6d8f600 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ In v3.0.0 I added some new features. The following will give some short informat |LANG|de_DE.UTF-8|following locales are pre-generated: de_DE.UTF-8, en_US.UTF-8| |LC_ALL|de_DE|following locales are pre-generated: de_DE.UTF-8, en_US.UTF-8| |TZ|Europe/Berlin|all valid Linux-timezones| +|HOSTUID|1000|any new UID you need to match from host| ### Mounting Folder/ Volume @@ -44,6 +45,9 @@ I added some code for fixing permissions for new iobroker-user. Permission-fixin ## Changelog +### v3.0.3beta (2019-08-20) +* you can provide a userid from your host system. permissions will be applied. + ### v3.0.2beta (2019-06-13) * using gosu instead of sudo * changing output of ioBroker logging From 5b083a98bb2f7062e5f11c79e61fadd33905c987 Mon Sep 17 00:00:00 2001 From: mplogas Date: Tue, 20 Aug 2019 22:08:05 +0200 Subject: [PATCH 4/5] removed debug output --- scripts/iobroker_startup.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/iobroker_startup.sh b/scripts/iobroker_startup.sh index 4c69af4..1fd2c0a 100644 --- a/scripts/iobroker_startup.sh +++ b/scripts/iobroker_startup.sh @@ -41,12 +41,6 @@ then echo 'Restoring done...' fi -echo 'who am i' -whoami - -echo 'whats my id' -id $(whoami) - # Checking for first run and change permissions if [ -f /opt/.firstrun ] then From 78399ff13b259288b1b9d21205183aa184254bcd Mon Sep 17 00:00:00 2001 From: mplogas Date: Wed, 21 Aug 2019 00:45:27 +0200 Subject: [PATCH 5/5] added GID support as well --- Dockerfile | 3 ++- README.md | 5 +++-- scripts/iobroker_startup.sh | 22 ++++++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index db7cf53..47039eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,7 +71,8 @@ ENV DEBIAN_FRONTEND="teletype" \ TZ="Europe/Berlin" \ PACKAGES="nano" \ AVAHI="false" \ - HOSTUID=1000 + HOSTUID=1000 \ + HOSTGID=1000 # Setting up EXPOSE for Admin EXPOSE 8081/tcp diff --git a/README.md b/README.md index 6d8f600..df106c4 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ In v3.0.0 I added some new features. The following will give some short informat |LANG|de_DE.UTF-8|following locales are pre-generated: de_DE.UTF-8, en_US.UTF-8| |LC_ALL|de_DE|following locales are pre-generated: de_DE.UTF-8, en_US.UTF-8| |TZ|Europe/Berlin|all valid Linux-timezones| -|HOSTUID|1000|any new UID you need to match from host| +|HOSTUID|1000|new UID you need to match from host| +|HOSTGID|1000|new GID you need to match from host| ### Mounting Folder/ Volume @@ -46,7 +47,7 @@ I added some code for fixing permissions for new iobroker-user. Permission-fixin ## Changelog ### v3.0.3beta (2019-08-20) -* you can provide a userid from your host system. permissions will be applied. +* you can provide a userid and a groupid from your host system. permissions will be applied. ### v3.0.2beta (2019-06-13) * using gosu instead of sudo diff --git a/scripts/iobroker_startup.sh b/scripts/iobroker_startup.sh index 1fd2c0a..abd17b5 100644 --- a/scripts/iobroker_startup.sh +++ b/scripts/iobroker_startup.sh @@ -4,6 +4,7 @@ packages=$PACKAGES avahi=$AVAHI uid=$HOSTUID +gid=$HOSTGID # Getting date and time for logging dati=`date '+%Y-%m-%d %H:%M:%S'` @@ -11,9 +12,9 @@ dati=`date '+%Y-%m-%d %H:%M:%S'` # Information echo '' echo '----------------------------------------' -echo '----- Image-Version: 3.0.2beta -----' +echo '----- Image-Version: 3.0.3beta -----' echo '----- '$dati' -----' -echo '----- uid: '$uid' -----' +echo '----- uid: '$uid' gid: '$gid' -----' echo '----------------------------------------' echo '' echo 'Startupscript running...' @@ -46,16 +47,20 @@ if [ -f /opt/.firstrun ] then echo '' echo 'Changing permissions upon first run (This might take a while! Please be patient!)...' + echo 'Changing user and group ids' usermod -u $uid iobroker - chown -R $uid /opt/iobroker - chown -R $uid /opt/scripts + groupmod -g $gid iobroker + echo 'Done.' + echo 'Setting folder permissions' + chown -R $uid:$gid /opt/iobroker + chown -R $uid:$gid /opt/scripts rm -f /opt/.firstrun echo 'Changing permissions done...' fi # Backing up original iobroker-file and changing sudo to gosu cp -a /opt/iobroker/iobroker /opt/iobroker/iobroker.bak -chmod u+x /opt/iobroker/iobroker +chmod 755 /opt/iobroker/iobroker sed -i 's/sudo -H -u/gosu/g' /opt/iobroker/iobroker # Checking for first run of a new installation and renaming ioBroker @@ -65,7 +70,7 @@ then echo 'This is the first run of an new installation...' echo 'Hostname given is' $(hostname)'...' echo 'Renaming ioBroker...' - /opt/iobroker/iobroker host $(cat /opt/iobroker/.install_host) + sh /opt/iobroker/iobroker host $(cat /opt/iobroker/.install_host) rm -f /opt/iobroker/.install_host echo 'Renaming ioBroker done...' fi @@ -75,7 +80,7 @@ if [ "$avahi" = "true" ] then echo '' echo 'Initializing Avahi-Daemon...' - chmod u+x /opt/scripts/setup_avahi.sh + chmod 764 /opt/scripts/setup_avahi.sh sh /opt/scripts/setup_avahi.sh echo 'Initializing Avahi-Daemon done...' fi @@ -91,7 +96,8 @@ echo '------- ioBroker Logging -------' echo '----------------------------------------' echo '' -# gosu iobroker node node_modules/iobroker.js-controller/controller.js > /opt/scripts/iobroker.log 2>&1 & +#touch /opt/iobroker/iobroker.log +#gosu iobroker node --trace-warnings node_modules/iobroker.js-controller/controller.js > /opt/iobroker/iobroker.log 2>&1 & gosu iobroker node node_modules/iobroker.js-controller/controller.js # Preventing container restart by keeping a process alive even if iobroker will be stopped