openhab / openhabian

openHABian - empowering the smart home, for Raspberry Pi and Debian systems
https://community.openhab.org/t/13379
ISC License
821 stars 252 forks source link

apply improvements -> fix file permissions fails #1613

Closed wrosenauer closed 2 years ago

wrosenauer commented 2 years ago

Issue information:

When I run the tool from openhabian-config: fix file permissions it results in an error

Debug information:

+ influxdb_is_installed
+ dpkg -s influxdb
+ [[ -d /var/lib/influxdb ]]
+ return 0
+ chmod +x /usr/lib/influxdb/scripts/influxd-systemd-start.sh
chmod: cannot access '/usr/lib/influxdb/scripts/influxd-systemd-start.sh': No such file or directory
+ zram_is_installed
+ [[ -s /etc/ztab ]]
+ return 1
+ echo OK
OK
+ homegear_is_installed
+ dpkg -s homegear
+ return 1
+ [[ -d /opt/habapp ]]
+ return 1
+ '[' 1 -ne 0 ']'
+ whiptail --msgbox 'There was an error or interruption during the execution of:\n  "10 | Apply Improvements"\n\nPlease try again. If the error persists, please read /opt/openhabian/docs/openhabian-DEBUG.md or https://github.com/openhab/openhabian/blob/main/docs/openhabian-DEBUG.md how to proceed.' 14 80
+ return 0

System information:

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
ecdye commented 2 years ago

Do you have InfluxDB installed? If not then I will look into the code that checks is InfluxDB is installed as it is likely incorrect.

wrosenauer commented 2 years ago

[16:05:22] root@smart-controller:~# dpkg -l | grep influx rc influxdb 1.8.2-1 armhf Distributed time-series database.

wrosenauer commented 2 years ago

I removed influxdb completely and the chmod error is gone. Still the script bails out:

$ fix_permissions /var/log/openhab openhab:openhabian 664 775 
+ fix_permissions /var/log/openhab openhab:openhabian 664 775
+ [[ -e /var/log/openhab ]]
+ chown openhab:openhabian /var/log/openhab
+ [[ -n 664 ]]
+ [[ -f /var/log/openhab ]]
+ [[ -n 775 ]]
+ [[ -d /var/log/openhab ]]
+ find /var/log/openhab -type d -print0
+ xargs -0 chmod 775
+ return 0
+ return 0
+ mosquitto_is_installed
+ dpkg -s mosquitto mosquitto-clients
+ return 1
+ influxdb_is_installed
+ dpkg -s influxdb
+ return 1
+ zram_is_installed
+ [[ -s /etc/ztab ]]
+ return 1
+ echo OK
OK
+ homegear_is_installed
+ dpkg -s homegear
+ return 1
+ [[ -d /opt/habapp ]]
+ return 1
+ '[' 1 -ne 0 ']'
+ whiptail --msgbox 'There was an error or interruption during the execution of:\n  "10 | Apply Improvements"\n\nPlease try again. If the error persists, please read /opt/openhabian/docs/openhabian-DEBUG.md or https://github.com/openhab/openhabian/blob/main/docs/openhabian-DEBUG.md how to proceed.' 14 80
+ return 0
ecdye commented 2 years ago

Probably a bug with the code, we recently changed the way it works, I'll look into it and try to figure out what is going on and it'll fix it.

ecdye commented 2 years ago

@wrosenauer Can you provide the full log, as I don't think that the issue is in the piece you provided.

mstormi commented 2 years ago

fyi when you change anything this line chmod +x /usr/lib/influxdb/scripts/influxd-systemd-start.sh can be removed, it was only temporarily needed until this was fixed in the InfluxDB pkg some weeks ago

wrosenauer commented 2 years ago
+ case "$choice2" in
+ permissions_corrections
+ local gpioDir=/sys/devices/platform/soc
+ groups=("audio" "bluetooth" "dialout" "gpio" "tty")
+ local groups
+ openhabFolders=("/etc/openhab" "/var/lib/openhab" "/var/log/openhab" "/usr/share/openhab")
+ local openhabFolders
+ local openhabHome=/var/lib/openhab
+ local backupsFolder=/var/lib/openhab/backups
+ local retval=0
++ timestamp
++ date +%F_%T_%Z
+ echo -n '2021-11-08_23:09:16_CET [openHABian] Applying file permissions recommendations... '
2021-11-08_23:09:16_CET [openHABian] Applying file permissions recommendations... + openhab_is_installed
+ openhab2_is_installed
++ dpkg -s openhab2
++ grep Status
++ cut '-d ' -f2
+ [[ deinstall == \i\n\s\t\a\l\l ]]
+ return 1
+ openhab3_is_installed
++ dpkg -s openhab
++ grep Status
++ cut '-d ' -f2
+ [[ install == \i\n\s\t\a\l\l ]]
+ return 0
+ return 0
+ cond_echo 'Setting Java and arping file capabilites'
+ [[ -z '' ]]
+ echo -e '\033[33;01mSetting Java and arping file capabilites\033[39;49;00m'
Setting Java and arping file capabilites
+++ command -v java
++ realpath /usr/bin/java
+ cond_redirect setcap 'cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep' /opt/jdk/zulu11.52.13-ca-jdk11.0.13-linux_aarch32hf/bin/java
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ setcap cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep /opt/jdk/zulu11.52.13-ca-jdk11.0.13-linux_aarch32hf/bin/java \033[39;49;00m'

$ setcap cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep /opt/jdk/zulu11.52.13-ca-jdk11.0.13-linux_aarch32hf/bin/java 
+ setcap 'cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep' /opt/jdk/zulu11.52.13-ca-jdk11.0.13-linux_aarch32hf/bin/java
+ return 0
+ cond_redirect setcap 'cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep' /usr/sbin/arping
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ setcap cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep /usr/sbin/arping \033[39;49;00m'

$ setcap cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep /usr/sbin/arping 
+ setcap 'cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep' /usr/sbin/arping
+ return 0
+ for pGroup in "${groups[@]}"
+ grep -qs '^[[:space:]]*audio:' /etc/group
+ cond_redirect usermod --append --groups audio openhab
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups audio openhab \033[39;49;00m'

$ usermod --append --groups audio openhab 
+ usermod --append --groups audio openhab
+ return 0
+ cond_redirect usermod --append --groups audio openhabian
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups audio openhabian \033[39;49;00m'

$ usermod --append --groups audio openhabian 
+ usermod --append --groups audio openhabian
+ return 0
+ for pGroup in "${groups[@]}"
+ grep -qs '^[[:space:]]*bluetooth:' /etc/group
+ cond_redirect usermod --append --groups bluetooth openhab
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups bluetooth openhab \033[39;49;00m'

$ usermod --append --groups bluetooth openhab 
+ usermod --append --groups bluetooth openhab
+ return 0
+ cond_redirect usermod --append --groups bluetooth openhabian
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups bluetooth openhabian \033[39;49;00m'

$ usermod --append --groups bluetooth openhabian 
+ usermod --append --groups bluetooth openhabian
+ return 0
+ for pGroup in "${groups[@]}"
+ grep -qs '^[[:space:]]*dialout:' /etc/group
+ cond_redirect usermod --append --groups dialout openhab
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups dialout openhab \033[39;49;00m'

$ usermod --append --groups dialout openhab 
+ usermod --append --groups dialout openhab
+ return 0
+ cond_redirect usermod --append --groups dialout openhabian
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups dialout openhabian \033[39;49;00m'

$ usermod --append --groups dialout openhabian 
+ usermod --append --groups dialout openhabian
+ return 0
+ for pGroup in "${groups[@]}"
+ grep -qs '^[[:space:]]*gpio:' /etc/group
+ cond_redirect usermod --append --groups gpio openhab
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups gpio openhab \033[39;49;00m'

$ usermod --append --groups gpio openhab 
+ usermod --append --groups gpio openhab
+ return 0
+ cond_redirect usermod --append --groups gpio openhabian
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups gpio openhabian \033[39;49;00m'

$ usermod --append --groups gpio openhabian 
+ usermod --append --groups gpio openhabian
+ return 0
+ for pGroup in "${groups[@]}"
+ grep -qs '^[[:space:]]*tty:' /etc/group
+ cond_redirect usermod --append --groups tty openhab
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups tty openhab \033[39;49;00m'

$ usermod --append --groups tty openhab 
+ usermod --append --groups tty openhab
+ return 0
+ cond_redirect usermod --append --groups tty openhabian
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups tty openhabian \033[39;49;00m'

$ usermod --append --groups tty openhabian 
+ usermod --append --groups tty openhabian
+ return 0
+ cond_redirect usermod --append --groups openhab openhabian
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ usermod --append --groups openhab openhabian \033[39;49;00m'

$ usermod --append --groups openhab openhabian 
+ usermod --append --groups openhab openhabian
+ return 0
+ cond_redirect chown --silent openhab:openhab /srv /opt
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ chown --silent openhab:openhab /srv /opt \033[39;49;00m'

$ chown --silent openhab:openhab /srv /opt 
+ chown --silent openhab:openhab /srv /opt
+ return 0
+ cond_redirect chmod --silent ugo+w /srv
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ chmod --silent ugo+w /srv \033[39;49;00m'

$ chmod --silent ugo+w /srv 
+ chmod --silent ugo+w /srv
+ return 0
+ cond_redirect chown --recursive openhab:openhab /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ chown --recursive openhab:openhab /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab \033[39;49;00m'

$ chown --recursive openhab:openhab /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab 
+ chown --recursive openhab:openhab /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab
+ return 0
+ cond_redirect chmod --recursive u+wX,g+wX /opt /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ chmod --recursive u+wX,g+wX /opt /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab \033[39;49;00m'

$ chmod --recursive u+wX,g+wX /opt /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab 
+ chmod --recursive u+wX,g+wX /opt /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab
+ return 0
+ [[ -d /var/lib/openhab/.ssh ]]
+ [[ -d /var/lib/openhab/backups ]]
+ cond_redirect chown openhab:openhab /var/lib/openhab/backups
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ chown openhab:openhab /var/lib/openhab/backups \033[39;49;00m'

$ chown openhab:openhab /var/lib/openhab/backups 
+ chown openhab:openhab /var/lib/openhab/backups
+ return 0
+ cond_redirect chmod g+s '/var/lib/openhab/backups /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab'
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ chmod g+s /var/lib/openhab/backups /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab \033[39;49;00m'

$ chmod g+s /var/lib/openhab/backups /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab 
+ chmod g+s '/var/lib/openhab/backups /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab'
chmod: cannot access '/var/lib/openhab/backups /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab': No such file or directory
+ return 1
+ echo 'FAILED (setgid backups folder)'
FAILED (setgid backups folder)
+ retval=1
+ cond_redirect fix_permissions /home/openhabian openhabian:openhabian
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ fix_permissions /home/openhabian openhabian:openhabian \033[39;49;00m'

$ fix_permissions /home/openhabian openhabian:openhabian 
+ fix_permissions /home/openhabian openhabian:openhabian
+ [[ -e /home/openhabian ]]
+ chown openhabian:openhabian /home/openhabian
+ [[ -n '' ]]
+ return 0
+ return 0
+ cond_redirect setfacl --recursive --remove-all /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ setfacl --recursive --remove-all /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab \033[39;49;00m'

$ setfacl --recursive --remove-all /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab 
+ setfacl --recursive --remove-all /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab
+ return 0
+ cond_redirect fix_permissions /var/log/unattended-upgrades root:root 644 755
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ fix_permissions /var/log/unattended-upgrades root:root 644 755 \033[39;49;00m'

$ fix_permissions /var/log/unattended-upgrades root:root 644 755 
+ fix_permissions /var/log/unattended-upgrades root:root 644 755
+ [[ -e /var/log/unattended-upgrades ]]
+ chown root:root /var/log/unattended-upgrades
+ [[ -n 644 ]]
+ [[ -f /var/log/unattended-upgrades ]]
+ [[ -n 755 ]]
+ [[ -d /var/log/unattended-upgrades ]]
+ find /var/log/unattended-upgrades -type d -print0
+ xargs -0 chmod 755
+ return 0
+ return 0
+ cond_redirect fix_permissions /var/log/samba root:root 640 750
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ fix_permissions /var/log/samba root:root 640 750 \033[39;49;00m'

$ fix_permissions /var/log/samba root:root 640 750 
+ fix_permissions /var/log/samba root:root 640 750
+ [[ -e /var/log/samba ]]
+ chown root:root /var/log/samba
+ [[ -n 640 ]]
+ [[ -f /var/log/samba ]]
+ [[ -n 750 ]]
+ [[ -d /var/log/samba ]]
+ find /var/log/samba -type d -print0
+ xargs -0 chmod 750
+ return 0
+ return 0
+ cond_redirect fix_permissions /var/log/openhab openhab:openhabian 664 775
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ fix_permissions /var/log/openhab openhab:openhabian 664 775 \033[39;49;00m'

$ fix_permissions /var/log/openhab openhab:openhabian 664 775 
+ fix_permissions /var/log/openhab openhab:openhabian 664 775
+ [[ -e /var/log/openhab ]]
+ chown openhab:openhabian /var/log/openhab
+ [[ -n 664 ]]
+ [[ -f /var/log/openhab ]]
+ [[ -n 775 ]]
+ [[ -d /var/log/openhab ]]
+ find /var/log/openhab -type d -print0
+ xargs -0 chmod 775
+ return 0
+ return 0
+ mosquitto_is_installed
+ dpkg -s mosquitto mosquitto-clients
+ return 1
+ influxdb_is_installed
+ dpkg -s influxdb
+ return 1
+ zram_is_installed
+ [[ -s /etc/ztab ]]
+ return 1
+ echo OK
OK
+ homegear_is_installed
+ dpkg -s homegear
+ return 1
+ [[ -d /opt/habapp ]]
+ return 1
+ '[' 1 -ne 0 ']'
+ whiptail --msgbox 'There was an error or interruption during the execution of:\n  "10 | Apply Improvements"\n\nPlease try again. If the error persists, please read /opt/openhabian/docs/openhabian-DEBUG.md or https://github.com/openhab/openhabian/blob/main/docs/openhabian-DEBUG.md how to proceed.' 14 80

Seeing this one:

Not exactly sure what the issue is though because: [23:14:08] root@smart-controller:~# ls -ld /var/lib/openhab/backups /etc/openhab /var/lib/openhab /var/log/openhab /usr/share/openhab drwxrwxr-x 15 openhab openhab 4096 Jul 4 20:15 /etc/openhab drwxrwxr-x 4 openhab openhab 4096 Nov 8 12:29 /usr/share/openhab drwxrwxr-x 15 openhab openhab 4096 Nov 8 12:38 /var/lib/openhab drwxrwxr-x 2 openhab openhab 4096 Jan 29 2021 /var/lib/openhab/backups drwxrwxr-x 2 openhab openhabian 4096 Nov 8 14:43 /var/log/openhab

mstormi commented 2 years ago

mmh, now openhab dirs are no longer setgid so that's no a proper fix

Is the issue because of the single quotes ?

ecdye commented 2 years ago

We don't need to do that. They are already being fixed in line 316 by doing it in that line as well we are overwriting the changes, are we not?

mstormi commented 2 years ago

I wasn't aware of l316 but now (like before this part you just removed was added) trouble is that not only the dirs are setgid but also all files are (which is unneeded and gives irritating output when you list the dir contents). So maybe better fix this line (as I said, it's maybe the quotes) and remove that part from l316?

ecdye commented 2 years ago

Not quite sure what you are going for with regards to line 316, do you want to create a PR for me to review?

mstormi commented 2 years ago

yes please, a PR that puts back the line (fixed of course) you deleted and removes the duplicate from l316