Koozali.org: home of the SME Server
Obsolete Releases => SME Server 9.x => Topic started by: guest22 on March 08, 2017, 03:23:20 PM
-
Hi,
is there anywhere documented how one can create an ibay from the shell/command line with all proper/wanted options please? If not documented does anybody know?
TIA
-
https://forums.contribs.org/index.php/topic,52730.msg271929.html#msg271929
HTH
(BTW, if you tell us the whole plot... ;-) )
-
Thanks. How about the Uid? The Uid is not added to /etc/passwd. A Uid IS however added when the ibay is created via the server manager. I guess it is adding the properti Uid, but how the extract the last Uid in /etc/passwd?
This for example is the last entry in /etc/passwd made via server manager (ibay test):
test:x:5001:5001:test:/home/e-smith/files/ibays/test/files:/bin/false
So I guess the format from left to right is: characters:x:Uid where :-x : seems always to be the separator. So some grep/sed/awk guru can extract the last Uid entry?
When deleting the manual created ibay (not test) the result is:
Operation status reportAn error occurred while deleting the i-bay.
The related entry is log messages is: userdel: user 'ibayname' does not exist. This is the ibay without Uid set AND (after a quick test) WITH a Uid set as property . Do we need to execute an extra signal event relating creating an ibay manually?
-
RequestedDeletion
Server manager is just a GUI to issue commands.
Whatever you can do in server manager has underlying commands.
Try creating an ibay in server manager (or do any other setting) & then review the /var/log/messages log file to see what commands were issued along with signal events.
Then you can use those same commands manually at the command prompt.
Read up the Howtos on db command tutorial & other related command Howtos & also review the output of
db configuration show
(for this command only it can be abbreviated to)
config show
& you will see many of the db settings & what can be used in the commands.
Ultimately all commands/options are listed in the code in templates, & under actions & events, just start reading them to discover.
Also see
https://wiki.contribs.org/DB_Variables_Configuration
&
https://wiki.contribs.org/SME_Server:Documentation:Developers_Manual:Section2#Standard_events_and_their_arguments
-
Thanks, did that. Both properties 'Gid' and 'Uid' are missing to the manual command. So last question remains, how to discover the last id used in /etc/passwd so the proper Gui and Uid can be set as values.
-
RequestedDeletion
You did what ?
Please tell us the exact commands you issued, copied from your history rather than from other forum posts.
-
And, please, tell us your aim/problem, not your solution
Thank you
-
if you check at the perl code behind the manager you get a clue:
file : /usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/ibays.pm
search for ibay_create
you will see : $uid=$accountdb->get_next_uid();
you can do the same this way : perl -Mesmith::AccountsDB -e 'my $accountdb = esmith::AccountsDB->open(); print $accountdb->get_next_uid();'
or to use for your bash script :
uid=`perl -Mesmith::AccountsDB -e 'my $accountdb = esmith::AccountsDB->open(); print $accountdb->get_next_uid();'`
echo $uid
now you can also be more curious and check at the content of AccountsDB get_next_uid() in /usr/share/perl5/vendor_perl/esmith/AccountsDB.pm
you can search for alternative using only bash awk and other things, but ultimately you will need to reinvente this function as you might want to keep the uid in sync with what returns config get MinUid
so the complete answer would be
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
-
RequestedDeletion
You did what ?
Please tell us the exact commands you issued, copied from your history rather than from other forum posts.
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.
-
And, please, tell us your aim/problem, not your solution
Thank you
The aim was to find out how to manually create a correct ibay from bash.
I will provide a sample code soonish.
-
if you check at the perl code behind the manager you get a clue:
file : /usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/ibays.pm
search for ibay_create
you will see : $uid=$accountdb->get_next_uid();
you can do the same this way : perl -Mesmith::AccountsDB -e 'my $accountdb = esmith::AccountsDB->open(); print $accountdb->get_next_uid();'
or to use for your bash script :
uid=`perl -Mesmith::AccountsDB -e 'my $accountdb = esmith::AccountsDB->open(); print $accountdb->get_next_uid();'`
echo $uid
now you can also be more curious and check at the content of AccountsDB get_next_uid() in /usr/share/perl5/vendor_perl/esmith/AccountsDB.pm
you can search for alternative using only bash awk and other things, but ultimately you will need to reinvente this function as you might want to keep the uid in sync with what returns config get MinUid
so the complete answer would be
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 config key MinUid does not get updated this way.
-
Create an ibay (test) from a script:
#!/bin/bash
#Configure the new ibay "test"
next_id=$(config get MinUid)
let "new_next_id = next_id + 1"
config set MinUid $new_next_id
#Populate the accounts db
db accounts set test ibay Name test \
Group admin UserAccess wr-group-rd-everyone \
Uid $next_id Gid $next_id CgiBin enabled PasswordSet no \
SSL enabled PublicAccess global \
#Create the "test" ibay
signal-event ibay-create test
exit
-
To complete the above script, one should add a routine above the code to check the accounts db if the new ibay name already exists. If so, the code should not be executed for it will lead to a bit off a mess ;-)
-
RequestedDeletion
The script works OK for me, log files look good.
Something new for the wiki !
An often requested task over the years.
-
Fine
And the aim is? :-)
-
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.
-
Something new for the wiki !
Please see https://wiki.contribs.org/Create_an_ibay_manually (https://wiki.contribs.org/Create_an_ibay_manually)
The integrity check if the ibay name already exists should be added tho.
-
Fine
And the aim is? :)
as explained here https://forums.contribs.org/index.php/topic,52938.msg273338.html#msg273338
-
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.
-
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.