################################################################################
#Version 2018.06.01.0001
################################################################################

################################################################################
#sat 6 - uses forman - hammercli
################################################################################
MYRPM=katello-ca-consumer-latest.noarch.rpm
MYORG="NAME OF ORG"
MYKEY="RHEL 7 PROD"

echo "ACTION: getting $MYRPM"
cd /tmp
wget http://satpdc/pub/$MYRPM

echo "ACTION: installing $MYRPM"
yum -y localinstall $MYRPM

MYFILE=/etc/sysconfig/rhn/systemid
rm $MYFILE

echo "ACTION: Registering $MYAGENT with $MYORG and $MYKEY"
eval subscription-manager register \
        --org="$MYORG" \
        --activationkey=\"TEMPVIRT,$MYKEY\"
		#TEMPVIRT is needed for "default" key - no matter what

#echo "ACTION: Attaching $MYAGENT"
#subscription-manager attach --auto

echo "ACTION: Refreshing $MYAGENT"
subscription-manager refresh

echo "INFO: Showing $MYAGENT registration"
subscription-manager registration

MYRPMS="katello-agent"
f_installpkgs

if (( $SYSTEMCTL ))
then
    MYAGENT=goferd.service
    echo "ACTION: Starting $MYAGENT"
    systemctl enable  $MYAGENT
    systemctl restart $MYAGENT
else
    MYAGENT=goferd
    echo "ACTION: Starting $MYAGENT"
    chkconfig $MYAGENT on
    service   $MYAGENT restart
fi

#
# enable a repo
#
subscription-manager repos --list-disabled
#Repo ID:   Johnson_Controls_Inc_EPEL_RHEL7_EPEL_RHEL7

subscription-manager repos --enable=Johnson_Controls_Inc_EPEL_RHEL7_EPEL_RHEL7

yum clean all

################################################################################
#sat 5 - uses spacewalk
################################################################################
Register client into satellite

   Rename the short hostname in Sat
   then
      rhncfg-client [verify | get]

   IF system is not registered:

   SATUSER=sspauto

      if (( $OSRELMAJ == 7 ))
			MYKEY=2-rhel7-released-virtual-ssp
																					  (( $OSRELMAJ == 6))
			MYKEY=2-rhel6-released-virtual-ssp

	 rhnreg_ks --force \
           --username=$SATUSER \
           --serverUrl=http://satellite/XMLRPC \
           --activationkey=$MYKEY

     yum -y install osad rhncfg rhncfg-actions rhncfg-client

       rhnreg_ks --force --profilename myservername --activationkey \
          1-development-vm,company_internal

	   rhnreg_ks --force --username=somename \
	   		--serverUrl=http://SATSERVER/XMLRPC \
		    --activationkey=somename

   
     or
       rhn_register    #walks you through a number of screens
			scp SOMESYSTEM:/etc/sysconfig/rhn/up2date \
				/etc/sysconfig/rhn/up2date
	  		rm /etc/sysconfig/rhn/systemid
		
       rhn_register    #walks you through a number of screens

	 to resync

	 	 rhn-profile-sync -vv 


##############################################################################
#Create profiles of the systems (for rollback if updates cause issues)
spacecmd "system_createpackageprofile HOSTNAME \
	-n HOSTNAME-DATE \
	-d \"backup profile DATE\""

#or interactive
spacecmd login

#or GUI: -System->Software->Profile ->Create System Profile

################################################################################
#IF bonded, kickstart w/ bond still in use
#use IP for satmdc/750 server in the kickstart string
	
	#map your kickstart ISO
	#boot off your kickstart ISO

	ksdevice=bond0 \
		bond=bond0:eth1,eth6:mode=802.3ad,miimon=100,lacp_rate=fast
	              #in this RAC env, bond0 is made up of eth1 and eth6

################################################################################
Reload a loaded system via PXE/kickstart/satellite

   On Satellite
      cobbler system edit --name=server1:2 --netboot-enabled=1

      # If the server is not in cobbler, then add it vi cobblersystemadd

   In VSphere
      Boot into BIOS (check BIOS in VM guest config, options tab)
      then when in BIOS mode, select network as first item


   Once you are done with the reload, change the BIOS to boot network last
   so we don't accidentally reload a system (if someone accidentally does 
   another reset on the client in satellite).


################################################################################
Push a pkg to a channel

	rhnpush -c "rhel6-xxxx"  somename.rpm

	#then compare channels, and update the particulars

################################################################################
Update a config file (via a channel)

   Exampe: sendmail.cf

   rhncfg-client list  | grep mail

   rhncfg-client diff /etc/mail/sendmail*

   rhncfg-client get /etc/mail/sendmail*

   service sendmail restart  #will create new sendmail.cf via m4 sendmail.mc

##############################################################################
#Satellite:

	locate snippet
		/var/lib/rhn/kickstarts/snippets/2; ls

	/var/satellite/config

		*.conf

		release grouping

			spacewalk-clone-by-date \
				-d 2017-07-01 \
				-c ./rhel7-initialrelease-matt.conf

#log
	/var/log/reposync
		channel name

#Validation/config tools:

	yum -y install system-config-kickstart
		#=>  
			GUI menu
				system tools -> kickstart
				/usr/bin/python2 /usr/bin/system-config-kickstart

	yum -y install pykickstart
		#=>  
			ksvalidator
				-e

				ks.cfg
				#or
				http://satellite/ks/dist/ks-rhel-x86_64-server-6-6.5 

################################################################################
#spacewalk

spacewalk-channel -L    #list possible channels
spacewalk-channel -l    #list subscribed to channels

#add a channel
spacewalk-channel -a -c CHANNEL-NAME


#Delete old system from Satellite
#Check for systems that can be deleted IF they have not connected in 3 days:
delete-old-systems-interactive --idle 3d \
	--username=$USERNAME
	--password=<PASSWORD> | grep delete

#“FORCE” delete systems that have not connected in more than 3 days:
delete-old-systems-interactive --idle 3d \
 	--username=$USERNAME
	--password=<PASSWORD>  --force

#Use spacecmd to report and duplicate systems:
spacecmd –u USERNAME report_ipaddresses
	#enter PASSWORD

	#INFO: Connected to https://localhost/rpc/api as <Your_Sat_Login_ID>
	#WARNING: Duplicate system profile names found!
	#WARNING: Please reference systems by ID or resolve the
	#WARNING: underlying issue with 'system_delete' or 'system_rename'
	#WARNING: 
	#WARNING: j051srhel7mb1 = 1000013458, 1000013477, 1000013483, 1000013488
	#
	#This this case, delete 1000013458, 1000013477 & 1000013483

#Delete the lowest GUIDs:
spacecmd system_delete 1000013458 1000013477 1000013483

#add via the repo
yum clean all; rm -rf /var/cache/yum

#There are no enabled repos.
# Run "yum repolist all" to see the repos you have.
     yum repolist all
# To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
# To enable custom repositories:
     yum-config-manager --enable <repo>


##############################################################################
satellite
   tcp ports: 
      I&O-80
      I&O-443
      O-4545 (rhnmd)
      I-5222 (push client)
      I-5269 (push to proxy)

##############################################################################
#stop satellite 6

katello-service stop/start

##############################################################################
##############################################################################
##############################################################################
