Koozali.org: home of the SME Server

[SOLVED] how to create an ibay from bash

guest22

Re: [SOLVED] how to create an ibay from bash
« Reply #15 on: March 09, 2017, 01:04:22 AM »
RequestedDeletion

The script works OK for me, log files look good.

Something new for the wiki !
An often requested task over the years.


In a busy environment one should also take into consideration any racing conditions to get and update MinUid.... Although very slim chance, it is there.

guest22

Re: [SOLVED] how to create an ibay from bash
« Reply #16 on: March 09, 2017, 01:09:02 AM »
Something new for the wiki !

Please see https://wiki.contribs.org/Create_an_ibay_manually

The integrity check if the ibay name already exists should be added tho.


Offline Jean-Philippe Pialasse

  • *
  • 2,912
  • +11/-0
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: how to create an ibay from bash
« Reply #18 on: March 09, 2017, 06:42:23 AM »

Ok, got it, the last ID +1 is save automatically by server manager actions in the property MinUid. So adding an ibay manually, one must:
1. Get the value of MinUid to a shell variable e.g. new_id
2. Store a new value to MinUid of new_id + 1
3. Use the variable new_id in the manual create new ibay parameters where Gid is new_id and Uid is new_id
4. signal-event ibay-create


Done. Thanks all.

Well this is when all works good and no rpm has messed up there.
If you check the code you have a loop to test if it is free.

So i suggest you not only assuming the minuid +1 is free and use the function or recreate the same in bash. A search in google will show some.

And conside it not as last uid but minimal uid. Letting lower uid reserved for system. So updating it to get last uid is not the way to do.
Also as you pointed race situation might occurs. And duplicate name if not tested.

So as asked Stefano what is the purpose, as it should need more code around.
« Last Edit: March 09, 2017, 06:47:52 AM by Jean-Philippe Pialasse »

guest22

Re: how to create an ibay from bash
« Reply #19 on: March 09, 2017, 08:45:12 AM »
Code: [Select]
ibayname='myibay'
uid=`perl -Mesmith::AccountsDB -e 'my  $accountdb = esmith::AccountsDB->open(); print $accountdb->get_next_uid();'`
db accounts set $ibayname ibay Name "bash created $ibayname" Group admin UserAccess wr-group-rd-everyone CgiBin disabled PasswordSet no SSL disabled PublicAccess none Uid $uid Gid $uid
signal-event ibay-create $ibayname

The above works, BUT it needs to check if the ibay name already exists, for the config MinUid get's raised every time the code is run, even if the ibay name already exists. So I guess another perl function/parameter has to be called/passed that checks if the accountname already exists.