xsnrg / OpenHAB2-tools

various scripts and hacks to assist with OpenHAB2
19 stars 7 forks source link

Added a few new things to the makeHAB script #8

Open Rick-Jongbloed opened 7 years ago

Rick-Jongbloed commented 7 years ago

Hi,

i've added a few new things to my makeHAB script, which might be nice for the general script:

1: Check for root at the beginning of the script) if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi

2: Shutting down the openhab service after the files have been downloaded

# Shutting  down openhab2 service
service openhab2 stop

3: setting permissions correctly so the service runs correctly after all the files have been placed.

# Set permissions to user openhab
chown $SERVICEUSER:$SERVICEUSER  /opt/openhab2 -R

4: Starting the openhab service

# Starting openhab service
service openhab2 start

If you think these enhancements are too specific, please close this issue.

xsnrg commented 7 years ago

Hi, thanks for the ideas!

  1. I don't run openHAB as root, and I would recommend that nobody else ever run it as root either. If the permissions are set correctly on devices and on the openHAB filesystem stack, running as root is not needed. It is a security issue. If 3. below was the thought for running as root, an option would be to run it as a sudo command, then the user has an option of allowing it, or password entry prompt for elevated privs to run the chmod/chown. Same for the service handling in 2. and 4.

  2. This works only if you have installed openHAB to run as a service. I am okay with shutting it down, as it should not be running when this script is executed, but we should probably check to see if it is a service, then shut the service down, else shut it down with a simple kill for folk running it in the foreground, in screen, or nohup'd.

  3. Setting the owner is good. We can set a variable at the top for the user to run as. Also, see the comment in 1.

  4. How about setting a variable in the script that the user can set if they want to auto-restart?

Thoughts?

Rick-Jongbloed commented 7 years ago

Hi, you're welcome. I'll reply per item:

  1. I don't run openHAB as root, but i install openhab as root, and set the permissions later on. This way i never have permission issues when downloading or installing de new openhab binaries. To prevent myself accidentally running the script, while i didn't do a Sudo, i've implemented this line. We could make it optional of course.

  2. I do run openHAB as a service, maybe this should be optional as well?

  3. Yup, setting the owner is needed when running the makeHAB script as root.

  4. Thats also good. I also do a tail -f /opt/openhab2/userdata/logs/openhab.log, in the end.

Shall i have a look how to implement these changes?

xsnrg commented 7 years ago

Certainly. PRs are always welcome.

Rick-Jongbloed commented 7 years ago

I dídn't make a PR because i have to find out how that works. :-)

However one addition to get it working properly: You'll have to remove the file org.ops4j.pax.url.mvn.cfg, otherwise the repository changes won't be processed. (See https://community.openhab.org/t/karaf-console-bundle-uninstall-and-bundle-update-not-running-as-expected/27444/22)

xsnrg commented 7 years ago

also of note: https://github.com/openhab/openhab-distro/issues/299#issuecomment-309775581

It might be time to join forces and work with that one.

sihui62 commented 6 years ago

It might be time to join forces and work with that one.

Maybe, but would that (new) script work with manual installations? I can only see folder names related to an apt-get install ....