Guest User

Untitled

a guest
May 21st, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #------------------------------------------------------------------------------
  3. # PURPOSE: Moving from 'Classic' to RHSM (Red Hat Subscription Management
  4. # basically happens in 2 steps:
  5. # 1) Registration: to RHSM
  6. # 2) Subscription: to Virtual or Physical
  7. # a) Physical is for ESXi Servers (physical host systems)
  8. # b) Virtual is for Guest VMs
  9. # We only care about Virtual subscriptions.
  10. # Classic is going away in 2017.
  11. # -------------------------------------------------------------------
  12. # AUTHORS: Todd E Thomas
  13. # DATE: 2015/06/23
  14. # MODIFIED: 2015/08/10
  15. #------------------------------------------------------------------------------
  16. #set -x
  17.  
  18.  
  19. ###----------------------------------------------------------------------------
  20. ### VARIABLES
  21. ###----------------------------------------------------------------------------
  22. # PREREQUISITES
  23. #: ${backupDir?"required backup directory not set in environment"}
  24. hostName="$(hostname -s)"
  25. userName='RHEL_ACCESS_UN'
  26. passWord='RHEL_ACCESS_PW'
  27.  
  28.  
  29. ###----------------------------------------------------------------------------
  30. ### FUNCTIONS
  31. ###----------------------------------------------------------------------------
  32. #source "lib/start.sh"
  33. #source "lib/finish.sh"
  34. #source "lib/printfmsg.sh"
  35.  
  36.  
  37. ###---
  38. ### Reregister The System to RHSM (subscription manager)
  39. ###---
  40. registerSystem() {
  41. printInfo "Registering $hostName with RHSM..."
  42. subscription-manager register --auto-attach --force --username "$userName" --password "$passWord"
  43. }
  44.  
  45.  
  46.  
  47. ###---
  48. ### Get Current Registration Status
  49. ### It's either: 'Unknown' or 'Current'
  50. ###---
  51. registrationStatus() {
  52. printInfo "Getting current registration status..."
  53. subscriptStatus="$(subscription-manager status | grep 'Overall')"
  54. subscriptStatus="${subscriptStatus##*:}"
  55. if [[ "${subscriptStatus##*\ }" = 'Unknown' ]]; then
  56. # If System Status: Overall Status: Unknown
  57. registerSystem
  58. else
  59. # continue to subscription
  60. printSStat "$hostName is already registered."
  61. fi
  62. }
  63.  
  64. ###---
  65. ### Subscribe VM by linking it with a Pool ID
  66. ###---
  67. susbscribeSystem() {
  68. printInfo "Subscribing to RHEL for Datacenters, Standard: Virtual"
  69. poolID="$(subscription-manager list --available | grep 'Virtual' -B7 | grep 'Pool')"
  70. poolID="${poolID##*:}"
  71. subscription-manager attach --pool="${poolID##*\ }"
  72. }
  73.  
  74.  
  75. ###---
  76. ### Check for new updates
  77. ###---
  78. checkSystemStatus() {
  79. printInfo "Check for updates with new subscription..."
  80. yum clean all
  81. yum check-update
  82. print1Line
  83. # OUPTUT:
  84. # Loaded plugins: product-id, rhnplugin, security, subscription-manager
  85. }
  86.  
  87.  
  88. ###----------------------------------------------------------------------------
  89. ### MAIN PROGRAM
  90. ###----------------------------------------------------------------------------
  91. ### What time is it?
  92. ###---
  93. start
  94.  
  95. printReq "Registration: Switching from Classic to RHSM..."
  96.  
  97.  
  98. ###---
  99. ### Get Program Status: subscription-manager
  100. ###---
  101. if [[ ! -x "$(type -P subscription-manager)" ]]; then
  102. printInfo "Installing subscription-manager..."
  103. yum -y install subscription-manager
  104. print1Line
  105. else
  106. printSStat "subscription-manager is installed"
  107. fi
  108.  
  109.  
  110. ###---
  111. ### Get the Registration Status
  112. ###---
  113. registrationStatus
  114.  
  115.  
  116. ###---
  117. ### Get Current Subscription Status
  118. ### It's either subscribed or it isn't.
  119. ###---
  120. printInfo "Getting current subscription status..."
  121. quantityNo="$(subscription-manager list --consumed | grep 'Quantity')"
  122. quantityNo="${quantityNo##*:}"
  123. if [[ "$quantityNo" -ne '1' ]]; then
  124. # If system is not subscribed
  125. susbscribeSystem
  126. else
  127. printSStat "$hostName is already subscribed."
  128. subscription-manager list --consumed
  129. # Clean the RPM db and pull new data
  130. checkSystemStatus
  131. fi
  132.  
  133. ###---
  134. ### Get New Subscription Status
  135. ###---
  136. printInfo "Refresh and get current subscription status..."
  137. subscription-manager refresh
  138. registrationStatus
  139. # OUPTUT:
  140. # +-------------------------------------------+
  141. # System Status Details
  142. # --------------------------------------------+
  143. # Overall Status: Current
  144.  
  145.  
  146. ###---
  147. ### fin~
  148. ###---
  149. finish
  150. exit 0
Add Comment
Please, Sign In to add comment