Created
July 1, 2020 08:35
-
-
Save jirihnidek/dbb0cbad2f968a8d49b745e6c7215e0b to your computer and use it in GitHub Desktop.
Register system using D-Bus API
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 | |
echo "reseting config file..." | |
cp /etc/rhsm/rhsm.conf.default /etc/rhsm/rhsm.conf | |
echo "restarting rhsm.service..." | |
systemctl restart rhsm.service | |
# Set new variables using D-Bus API | |
echo "changing configuration..." | |
busctl call com.redhat.RHSM1 /com/redhat/RHSM1/Config com.redhat.RHSM1.Config Set svs "server.hostname" s "svice" "" | |
sleep 1 | |
busctl call com.redhat.RHSM1 /com/redhat/RHSM1/Config com.redhat.RHSM1.Config Set svs "server.prefix" s "/candlepin" "" | |
sleep 1 | |
busctl call com.redhat.RHSM1 /com/redhat/RHSM1/Config com.redhat.RHSM1.Config Set svs "server.port" s "8443" "" | |
sleep 1 | |
busctl call com.redhat.RHSM1 /com/redhat/RHSM1/Config com.redhat.RHSM1.Config Set svs "server.insecure" s "1" "" | |
sleep 1 | |
busctl call com.redhat.RHSM1 /com/redhat/RHSM1/Config com.redhat.RHSM1.Config Set svs "rhsm.baseurl" s "http://svice:8080" "" | |
echo "configuration changed" | |
# Create new unix socket used for registration | |
echo "starting RegisterServer..." | |
dbus-send --system --print-reply --dest='com.redhat.RHSM1' \ | |
'/com/redhat/RHSM1/RegisterServer' com.redhat.RHSM1.RegisterServer.Start string:"" > /root/register_server_output.txt | |
if [[ $? -eq 0 ]] | |
then | |
export my_addr=`cat /root/register_server_output.txt | gawk '/string/{ print $2 }' | sed 's/\"//g'` | |
fi | |
# Try to register | |
echo "registering..." | |
dbus-send --address=${my_addr} --print-reply --dest='com.redhat.RHSM1.Register' \ | |
'/com/redhat/RHSM1/Register' com.redhat.RHSM1.Register.Register string:"admin" \ | |
string:"admin" string:"admin" dict:string:string:"","" dict:string:string:"","" string:"" > /root/register_output.txt | |
if [[ $? -eq 0 ]] | |
then | |
echo "Registration sucess" | |
else | |
echo "Registration FAILED" | |
fi | |
echo "stoping RegisterServer..." | |
dbus-send --system --print-reply --dest='com.redhat.RHSM1' \ | |
'/com/redhat/RHSM1/RegisterServer' com.redhat.RHSM1.RegisterServer.Stop string:"" > /dev/null | |
# Unregister | |
echo "unregistering..." | |
dbus-send --system --print-reply --dest='com.redhat.RHSM1' '/com/redhat/RHSM1/Unregister' \ | |
com.redhat.RHSM1.Unregister.Unregister dict:string:string:"","" string:"" > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment