Created
February 19, 2016 21:36
-
-
Save vinzent/4bba600573bc9eeb33c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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@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 |
For Spacewalk 2.5
#!/bin/bash
# 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 "csrf_token=-${csrf}&submitted=true&orgName=DefaultOrganization&login=administrator&desiredpassword=Passw0rd&desiredpasswordConfirm=Passw0rd&email=root%40localhost&prefix=Mr.&firstNames=Administrator&lastName=Spacewalk&" \
https://localhost/rhn/newlogin/CreateFirstUser.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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. I filed a feature request: https://bugzilla.redhat.com/show_bug.cgi?id=1346373