Skip to content

Instantly share code, notes, and snippets.

@vinzent
Created February 19, 2016 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinzent/4bba600573bc9eeb33c4 to your computer and use it in GitHub Desktop.
Save vinzent/4bba600573bc9eeb33c4 to your computer and use it in GitHub Desktop.
#!/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
@DRN88
Copy link

DRN88 commented Jun 14, 2016

Thanks for this. I filed a feature request: https://bugzilla.redhat.com/show_bug.cgi?id=1346373

@DRN88
Copy link

DRN88 commented Jun 24, 2016

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