-
Notifications
You must be signed in to change notification settings - Fork 3
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
Better way of adding the user to the group #1
Comments
Hi! Thank you for your feedback. As far as I know, when using Tommes |
You are right indeed. You can get the current list with a bit of regexp and add Log_Analysis to the current members:
|
Nice code snippet. I just tried it out and it works very well. Thank you very much for that. I'll see what I can do with it. But now you didn't hack the /etc/group with sed, but you hacked the synogroup command with sed. A little joke ;-) Just a note in case anyone else is reading this. Log_Analysis was the old package name to keep the packages for DSM6 and DSM7 apart. LogAnalysis (without underscore) is the current package name and should be used in the above code snippet. |
I find it better to use synogroup because I surmise its content is shadowed in a synology only file. The logic can be reused with something like that:
(I added TR at the end of the pipeline to avoid side effects with groups that already have several members) |
That definitely sounds plausible, better to use the synogroup here. I will test this out and probably implement it. Maybe I'll build a function to remove a user from the group again. That can sometimes be quite useful. Thanks again for this great tip. |
Nice solution, but users should be quoted, as spaces are also allowed in usernames.
Same to delete user:
|
Better than quotes: an array.
But I admit it starts to get noticeably longer. |
In return, it is also getting better and better. I'm going to get some popcorn and watch you perfect the code. It would have taken me days to implement it. Really great and thanks for helping |
I tested your script this morning and it works really well. When calling the function, you should at least put the user in quotes, especially if it contains a space. As far as I know, group names should not contain spaces, so the quotes can be omitted here. I have rewritten your function so that you can also delete a user again. It would then look like this...
The function call would then look like this...
I like this very much and will incorporate it into LogAnalysis (and BasicBackup) in the next few days and test it further. Until then, if you see further potential for improvement, let me know. |
I have almost no change for your synogroupdeluser, kudos for that. Just that small detail: "\n" is not needed for sed:
I noticed that my synogroupadduser could be a bit shorter, though:
Let it be kept in mind that I am by no means a Bash specialist. I script a lot, but in other languages, and I tend to see Bash as a collection of hacks. A true bash aficionado would surely do it better. |
I have revised the functions for adding and deleting a user again and secured them a little. It was possible to add a user to a group more than once. Also, when deleting a user, the synogroup command was executed even if no matching user was found.
@XPlantefeve |
Yes, there's no reason to get the userlist differently. Adding that \n will just add empty lines that will be ignored later. There's no need for it. |
Rather than hacking /etc/group with sed in app_permissions.sh, the official way of adding an user to a group in Synology can be used:
synogroup --member log Log_Analysis
The text was updated successfully, but these errors were encountered: