Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- #------------------------------------------------------------------------------
- # PURPOSE: Moving from 'Classic' to RHSM (Red Hat Subscription Management
- # basically happens in 2 steps:
- # 1) Registration: to RHSM
- # 2) Subscription: to Virtual or Physical
- # a) Physical is for ESXi Servers (physical host systems)
- # b) Virtual is for Guest VMs
- # We only care about Virtual subscriptions.
- # Classic is going away in 2017.
- # -------------------------------------------------------------------
- # AUTHORS: Todd E Thomas
- # DATE: 2015/06/23
- # MODIFIED: 2015/08/10
- #------------------------------------------------------------------------------
- #set -x
- ###----------------------------------------------------------------------------
- ### VARIABLES
- ###----------------------------------------------------------------------------
- # PREREQUISITES
- #: ${backupDir?"required backup directory not set in environment"}
- hostName="$(hostname -s)"
- userName='RHEL_ACCESS_UN'
- passWord='RHEL_ACCESS_PW'
- ###----------------------------------------------------------------------------
- ### FUNCTIONS
- ###----------------------------------------------------------------------------
- #source "lib/start.sh"
- #source "lib/finish.sh"
- #source "lib/printfmsg.sh"
- ###---
- ### Reregister The System to RHSM (subscription manager)
- ###---
- registerSystem() {
- printInfo "Registering $hostName with RHSM..."
- subscription-manager register --auto-attach --force --username "$userName" --password "$passWord"
- }
- ###---
- ### Get Current Registration Status
- ### It's either: 'Unknown' or 'Current'
- ###---
- registrationStatus() {
- printInfo "Getting current registration status..."
- subscriptStatus="$(subscription-manager status | grep 'Overall')"
- subscriptStatus="${subscriptStatus##*:}"
- if [[ "${subscriptStatus##*\ }" = 'Unknown' ]]; then
- # If System Status: Overall Status: Unknown
- registerSystem
- else
- # continue to subscription
- printSStat "$hostName is already registered."
- fi
- }
- ###---
- ### Subscribe VM by linking it with a Pool ID
- ###---
- susbscribeSystem() {
- printInfo "Subscribing to RHEL for Datacenters, Standard: Virtual"
- poolID="$(subscription-manager list --available | grep 'Virtual' -B7 | grep 'Pool')"
- poolID="${poolID##*:}"
- subscription-manager attach --pool="${poolID##*\ }"
- }
- ###---
- ### Check for new updates
- ###---
- checkSystemStatus() {
- printInfo "Check for updates with new subscription..."
- yum clean all
- yum check-update
- print1Line
- # OUPTUT:
- # Loaded plugins: product-id, rhnplugin, security, subscription-manager
- }
- ###----------------------------------------------------------------------------
- ### MAIN PROGRAM
- ###----------------------------------------------------------------------------
- ### What time is it?
- ###---
- start
- printReq "Registration: Switching from Classic to RHSM..."
- ###---
- ### Get Program Status: subscription-manager
- ###---
- if [[ ! -x "$(type -P subscription-manager)" ]]; then
- printInfo "Installing subscription-manager..."
- yum -y install subscription-manager
- print1Line
- else
- printSStat "subscription-manager is installed"
- fi
- ###---
- ### Get the Registration Status
- ###---
- registrationStatus
- ###---
- ### Get Current Subscription Status
- ### It's either subscribed or it isn't.
- ###---
- printInfo "Getting current subscription status..."
- quantityNo="$(subscription-manager list --consumed | grep 'Quantity')"
- quantityNo="${quantityNo##*:}"
- if [[ "$quantityNo" -ne '1' ]]; then
- # If system is not subscribed
- susbscribeSystem
- else
- printSStat "$hostName is already subscribed."
- subscription-manager list --consumed
- # Clean the RPM db and pull new data
- checkSystemStatus
- fi
- ###---
- ### Get New Subscription Status
- ###---
- printInfo "Refresh and get current subscription status..."
- subscription-manager refresh
- registrationStatus
- # OUPTUT:
- # +-------------------------------------------+
- # System Status Details
- # --------------------------------------------+
- # Overall Status: Current
- ###---
- ### fin~
- ###---
- finish
- exit 0
Add Comment
Please, Sign In to add comment