Koozali.org: home of the SME Server

[SOLVED] how to create an ibay from bash

guest22

[SOLVED] how to create an ibay from bash
« 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

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: how to create an ibay from bash
« Reply #1 on: March 08, 2017, 05:15:28 PM »

guest22

Re: how to create an ibay from bash
« Reply #2 on: March 08, 2017, 09:51:23 PM »
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?

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: how to create an ibay from bash
« Reply #3 on: March 08, 2017, 10:02:35 PM »
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
« Last Edit: March 08, 2017, 10:24:48 PM by janet »
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

guest22

Re: how to create an ibay from bash
« Reply #4 on: March 08, 2017, 10:17:13 PM »
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.

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: how to create an ibay from bash
« Reply #5 on: March 08, 2017, 10:31:36 PM »
RequestedDeletion

You did what ?

Please tell us the exact commands you issued, copied from your history rather than from other forum posts.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: how to create an ibay from bash
« Reply #6 on: March 08, 2017, 10:52:07 PM »
And, please, tell us your aim/problem, not your solution
Thank you

Offline Jean-Philippe Pialasse

  • *
  • 2,765
  • +11/-0
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: how to create an ibay from bash
« Reply #7 on: March 08, 2017, 11:00:57 PM »
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 :

Code: [Select]
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

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

guest22

Re: how to create an ibay from bash
« Reply #8 on: March 08, 2017, 11:01:25 PM »
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.

guest22

Re: how to create an ibay from bash
« Reply #9 on: March 08, 2017, 11:02:12 PM »
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.

guest22

Re: how to create an ibay from bash
« Reply #10 on: March 08, 2017, 11:07:31 PM »
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 :

Code: [Select]
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

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 config key MinUid does not get updated this way.

guest22

Re: [SOLVED] how to create an ibay from bash
« Reply #11 on: March 09, 2017, 12:02:01 AM »
Create an ibay (test) from a script:


Code: [Select]
#!/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

guest22

Re: [SOLVED] how to create an ibay from bash
« Reply #12 on: March 09, 2017, 12:10:12 AM »
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 ;-)

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: [SOLVED] how to create an ibay from bash
« Reply #13 on: March 09, 2017, 12:53:52 AM »
RequestedDeletion

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

Something new for the wiki !
An often requested task over the years.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: [SOLVED] how to create an ibay from bash
« Reply #14 on: March 09, 2017, 01:01:03 AM »
Fine
And the aim is? :-)