Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sensible to run as user #21

Open
newhinton opened this issue Jun 2, 2023 · 2 comments · May be fixed by #17
Open

Allow sensible to run as user #21

newhinton opened this issue Jun 2, 2023 · 2 comments · May be fixed by #17
Labels
enhancement New feature or request v0.3.0

Comments

@newhinton
Copy link

Currently the settingsfile is hardcoded to be in /etc.

var settingsFile string = "/etc/sensible/settings.yaml"

this forces this app to be run as root. With small changes, it can be run from the user context:

//settings/settings.go
var settingsFolder string =  os.Getenv("HOME")+"/.config/sensible/"
var settingsFile string = settingsFolder + "settings.yaml"
var logFile string = settingsFolder + "logs.txt"
...


//utility/fileutil.go
// CreateFolder Create a folder and check if creation was successful
func CreateFolder(path string) {
        err := os.MkdirAll(path, os.ModePerm)
...

This will need to be adjusted so that it autodetects the context, and changes back to the original path's when run as root.

@TheTinkerDad
Copy link
Owner

This is a great idea, thank you! I will definitely add it into the next release!

@TheTinkerDad TheTinkerDad linked a pull request Jun 19, 2023 that will close this issue
@TheTinkerDad
Copy link
Owner

This was quite easy to implement indeed - also, made it so that the setup/reset CLI parameter (-r, added in v0.2.0) also considers the current user:

$ cd ~
$ ./sensible -r
time=2023-06-19T23:47:25Z level=info msg=Setting up defaults...
time=2023-06-19T23:47:25Z level=info msg=Creating default folders...
time=2023-06-19T23:47:25Z level=info msg=Successfully created /home/thetinkerdad/.sensible/scripts!
time=2023-06-19T23:47:25Z level=info msg=Successfully created /home/thetinkerdad/.sensible/log!
time=2023-06-19T23:47:25Z level=info msg=Successfully written default config file as /home/thetinkerdad/.sensible/settings.yaml!
$ ls -la .sensible
total 20
drwx------ 4 thetinkerdad thetinkerdad 4096 Jun 19 23:47 .
drwxr-xr-x 3 thetinkerdad thetinkerdad 4096 Jun 19 23:47 ..
drwx------ 2 thetinkerdad thetinkerdad 4096 Jun 19 23:47 log
drwx------ 2 thetinkerdad thetinkerdad 4096 Jun 19 23:47 scripts
-rw------- 1 thetinkerdad thetinkerdad 1885 Jun 19 23:47 settings.yaml

Since the settings file can contain MQTT username and password, made its permissions much stricter by default.

@TheTinkerDad TheTinkerDad added enhancement New feature or request v0.3.0 labels Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v0.3.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants