[Spacewalk-list] Scripted creation of initial user
Thomas Mueller
thomas at chaschperli.ch
Fri Feb 19 21:37:36 UTC 2016
Thanks a lot! Did not thought about just curl the form. Ugly, but works.
I've rewritten it a bit.
- Thomas
https://gist.github.com/vinzent/4bba600573bc9eeb33c4
#!/bin/bash
########################################
# create the first spacewalk account
# satwho requires it
LANG=C
tempfile=$(mktemp /tmp/$(basename $0).XXXXXX)
trap cleanup EXIT
cleanup() {
exitcode=$?
test -f "$tempfile" && rm -f "$tempfile"
exit $exitcode
}
if [ "$(satwho | wc -l)" = "0" ]; then
curl --silent https://localhost/rhn/newlogin/CreateFirstUser.do --insecure -D - >$tempfile
cookie=$(egrep -o 'JSESSIONID=[^ ]+' $tempfile)
csrf=$(egrep csrf_token $tempfile | egrep -o 'value=[^ ]+' | egrep -o '[0-9]+')
curl --noproxy '*' \
--cookie "$cookie" \
--insecure \
--data "login=admin&desiredpassword=TEMPPASS&desiredpasswordConfirm=TEMPPASS&firstNames=NAME&lastName=SURNAME&email=root at localhost&prefix=Mr.&account_type=create_sat&csrf_token=-$csrf" \
https://localhost/rhn/newlogin/CreateFirstUserSubmit.do
if [ "$(satwho | wc -l)" = "0" ]; then
echo "Error: user creation failed" >&2
fi
else
echo "Error: There is already a user. Check with satwho. No user created." >&2
exit 1
fi
Am 19.02.2016 um 21:49 schrieb Andy Seed:
> I've used the following code in my Spacewalk automated installs script
>
> ########################################
>
> # Lets Create the admin account
>
> echo-e
>
> echo-ne '\n'| readconti
>
> curl https://localhost/rhn/newlogin/CreateFirstUser.do--insecure -D-
> |egrep-i"cookie|csrf_token"|sed's/.*="/\&csrf_token=/ ;s/".*//;s/^.*: //'
>
> echo-ne '\n'|readcookie
>
> echo-ne '\n'|readcsrf
>
>
> curl --noproxy '*'--cookie "$cookie"--data
> "login=admin&desiredpassword=TEMPPASS&desiredpasswordConfirm=TEMPPASS&firstNames=NAME&lastName=SURNAME&email=ADMIN_EMAIL&prefix=Mr.&account_type=create_sat&csrf_token=-$csrf"https://localhost/rhn/newlogin/CreateFirstUserSubmit.do--insecure
> -D-
>
> Hope it helps
>
>
> On 19 February 2016 at 20:20, Thomas Mueller <thomas at chaschperli.ch
> <mailto:thomas at chaschperli.ch>> wrote:
>
> Hi
>
> I'm trying to fully automate the installation of spacewalk 2.4
> with puppet.
>
> I'm struggeling to add the first user by script. I now how to add
> users
> by API. But this requires that some user already exists to login with.
>
> Is there some shell command to add a user with organisation admin
> role?
> Or is it somehow possible with spacewalk-sql ? I've seen that there is
> some create_new_user postgresql function with lots of params - but I
> don't know how to use it.
>
> Any help appreciated!
>
> - Thomas
>
> _______________________________________________
> Spacewalk-list mailing list
> Spacewalk-list at redhat.com <mailto:Spacewalk-list at redhat.com>
> https://www.redhat.com/mailman/listinfo/spacewalk-list
>
>
>
>
> _______________________________________________
> Spacewalk-list mailing list
> Spacewalk-list at redhat.com
> https://www.redhat.com/mailman/listinfo/spacewalk-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/spacewalk-list/attachments/20160219/061e6595/attachment.htm>
More information about the Spacewalk-list
mailing list