linux_wiki:spacewalk_register

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux_wiki:spacewalk_register [2016/01/26 22:37]
billdozor [Spacewalk Register Script]
linux_wiki:spacewalk_register [2019/07/11 22:29] (current)
billdozor [The Script]
Line 3: Line 3:
 **General Information** **General Information**
  
-Registering a client system with a Spacewalk server. +Register or unregister a client system with a Spacewalk server. \\
  
 **Checklist** **Checklist**
-  * Enterprise Linux 6/7 +  * Distro(s): Enterprise Linux 6/7 
-  * Spacewalk Server Installed+  * Other: [[https://fedorahosted.org/spacewalk/wiki/HowToInstall|Spacewalk server]] setup
  
 ---- ----
  
-====== Spacewalk Register Script ======+====== The Script ======
  
-<code bash spacewalk_register.sh> +This Spacewalk register script has been moved to GitLab: https://gitlab.com/whowe/spacewalk
-############################################################################################ +
-#!/bin/bash +
-# Title: spacewalk_register.sh +
-# Description: Register a system with spacewalk +
-############################################################################################ +
- +
-#===================================== +
-# CUSTOMIZE HERE +
-#===================================== +
-Spacewalk server fqdn hostname +
-sw_server="spacewalk-server.local" +
- +
-# Spacewalk server's ssl ca rpm version and installed location +
-#(this is the package available at: https://${sw_server}/pub/${sw_server_ca}) +
-sw_server_ca="rhn-org-trusted-ssl-cert-1.0-2.noarch.rpm" +
-sw_server_ca_installed="/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT" +
- +
-#spacewalk server channel activation keys +
-sw_activation_key_centos6="1-centos6-x86-64-key" +
-sw_activation_key_centos7="1-centos7-x86-64-key" +
-sw_activation_key_oracle6="1-oracle6-x86-64-key" +
-sw_activation_key_oracle7="1-oracle7-x86-64-key" +
- +
-#spacewalk client repos +
-sw_client_repo_el6="http://yum.spacewalkproject.org/2.4-client/RHEL/6/x86_64/spacewalk-client-repo-2.4-3.el6.noarch.rpm" +
-sw_client_repo_el7="http://yum.spacewalkproject.org/2.4-client/RHEL/7/x86_64/spacewalk-client-repo-2.4-3.el7.noarch.rpm" +
- +
-#===================================== +
-# END OF CUSTOMIZATION +
-#===================================== +
- +
-#===================================== +
-# Functions; Main starts after +
-#===================================== +
-function show_usage +
-+
-  echo -e "\n####========== Spacewalk Registration ============####" +
-  echo -e "\nDescripton: Register a system with the Spacewalk server; ${sw_server}" +
-  echo -e "\n--Usage" +
-  echo -e "$0      => No arguments, normal registration." +
-  echo -e "$0 -f   => Force registration if this system believes it is already registered." +
-  echo -e "$0 -h   => Display usage." +
-+
- +
- +
-function check_os_type +
-+
-if [[ $(uname -i) != "x86_64" ]]; then +
-  echo -e "->Error: Only x86_64 architecture channels supported at this time." +
-  exit 1 +
-else +
-  ## Gather Distro and Major Version +
-  if [ -f /etc/system-release-cpe ];then +
-    distro=$(awk -F: '{printf "%s", $3}' /etc/system-release-cpe) +
-    major_version=$(awk -F: '{printf "%d", $5}' /etc/system-release-cpe) +
-  elif [ -f /etc/redhat-release ];then +
-    distro=$(awk '{printf "%s", $1}' /etc/redhat-release) +
-    major_version=$(awk -F. '{print $1}' /etc/redhat-release | awk '{printf "%d", $3}'+
-  fi +
- +
-  if [[ ${distro,,} == "centos" ]]; then +
-    case ${major_version} in +
-      7) +
-        # CentOS 7 register +
-        sw_client_repo=${sw_client_repo_el7} +
-        sw_activation_key=${sw_activation_key_centos7} +
-      ;; +
-      6) +
-        # CentOS 6 register +
-        sw_client_repo=${sw_client_repo_el6} +
-        sw_activation_key=${sw_activation_key_centos6} +
-      ;; +
-      *) +
-        echo -e "->Error: ${distro} ${major_version} not supported at this time." +
-        exit 1 +
-      ;; +
-    esac +
-  elif [[ ${distro,,} == "oracle" ]]; then +
-    case ${major_version} in +
-      7) +
-        # Oracle 7 register +
-        sw_client_repo=${sw_client_repo_el7} +
-        sw_activation_key=${sw_activation_key_oracle7} +
-      ;; +
-      6) +
-        # Oracle 6 register +
-        sw_client_repo=${sw_client_repo_el6} +
-        sw_activation_key=${sw_activation_key_oracle6} +
-      ;; +
-      *) +
-        echo -e "->Error: ${distro} ${major_version} not supported at this time." +
-        exit 1 +
-      ;; +
-    esac +
-  else +
-    echo -e "->Error: ${distro} not supported. Only CentOS and Oracle channels available at this time." +
-    exit 1 +
-  fi +
- +
-fi +
-+
- +
- +
-#===================================== +
-# Get Script Arguments +
-#===================================== +
-# Reset POSIX variable in case it has been used previously in this shell +
-OPTIND=1 +
- +
-# set default variable settings +
-force_register="no" +
- +
-while getopts "hf" opt; do +
-  case "${opt}" in +
-    h) # -h (help) argument +
-      show_usage +
-      exit 0 +
-    ;; +
-    f) # -f (force) argument +
-      force_register="yes" +
-    ;; +
-    *) # invalid argument +
-      show_usage +
-      exit 0 +
-    ;; +
-  esac +
-done +
- +
- +
-####================================== +
-#### Main Starts Here +
-####================================== +
- +
-echo -e "======================================================" +
-echo -e "####========== Spacewalk Registration ============####" +
-echo -e "======================================================" +
- +
-## Check OS type. set client repo, and spacewalk activation key variable +
-echo -e "\n>> Checking OS type, setting repo variable, and Spacewalk activation key..." +
-check_os_type +
- +
-#===================================== +
-# Confirm running the script +
-#===================================== +
-echo +
-echo -e "Warning: This script will install packages, register a system with Spacewalk, and disable system default repos." +
-echo -e "Detected Distro: ${distro} ${major_version}" +
-echo -e "Will Register to Spacewalk Server: https://${sw_server}/XMLRPC" +
-echo -e "Activation Key to Use: ${sw_activation_key}" +
-echo -e "=>Continue?[y/n]:\c" +
-read run_script +
- +
-if [[ ${run_script} != "y" ]]; then +
-  echo -e "\n>>Will not run the Spacewalk Registration script. Exiting..." +
-  exit 1 +
-fi +
- +
-## Add Repos ## +
-echo -e "\n>> Adding Spacewalk Client Repo..." +
-yum -y install ${sw_client_repo} +
- +
-echo -e "\n>> Caching DNS lookup for mirrors.fedoraproject.org..." +
-dig mirrors.fedoraproject.org &> /dev/null +
- +
-echo -e "\n>> Adding EPEL Repo..." +
-yum -y install epel-release +
- +
-echo -e "\n>> Enabling EPEL Repo..." +
-sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/epel.repo +
- +
-## Install Spacewalk's CA Cert ## +
-echo -e "\n>> Installing Spacewalk Server's trusted CA cert..." +
-rpm -ivh https://${sw_server}/pub/${sw_server_ca} +
- +
-## Install Client Packages ## +
-echo -e "\n>> Installing rhn client packages..." +
-yum -y install rhn-client-tools rhn-check rhn-setup rhnsd m2crypto yum-rhn-plugin +
- +
-echo -e "\n>> Installing rhn configuration client packages..." +
-yum -y install rhncfg rhncfg-actions rhncfg-client rhncfg-management +
- +
-## Register ## +
-if [[ ${force_register} == "yes" ]]; then +
-  echo -e "\n>> Registering with ${sw_server} using the rhnreg_ks --force option..." +
-  rhnreg_ks --force --serverUrl=https://${sw_server}/XMLRPC --sslCACert=${sw_server_ca_installed} --activationkey=${sw_activation_key} +
-  registration_return_code=$? +
- +
-else +
-  echo -e "\n>> Registering with ${sw_server}..." +
-  rhnreg_ks --serverUrl=https://${sw_server}/XMLRPC --sslCACert=${sw_server_ca_installed} --activationkey=${sw_activation_key} +
-  registration_return_code=$? +
-fi +
- +
-# Check if registration was successful # +
-if [[ ${registration_return_code} -eq 0 ]]; then +
-  echo -e "-> Registration successful." +
-  sleep 1 +
- +
-elif [[ ${registration_return_code} -eq 255 ]]; then +
-  echo -e "-> Registration encountered an error! (Return Code: ${registration_return_code})" +
-  echo -e "\n-> To manually force registration(if system is 'already registered'), re-run this script with the "-f" argument.($0 -f)" +
-  echo -e "\n--> WARNING: This may create duplicate systems in Spacewalk." +
-  exit 1 +
- +
-else +
-  echo -e "-> Registration encountered an error! (Return Code: ${registration_return_code})" +
-  echo -e "-> Will NOT install osad and disable default repos...exiting." +
-  exit 1 +
-fi +
- +
-# Setup spacewalk-checkin cron job to run rhn_check every 30 mins +
-echo -e "\n>> Setting up spacewalk-checkin job..." +
-echo "# Spacewalk Check-in job; executes rhn_check" > /etc/cron.d/spacewalk-checkin +
-echo 'MAILTO=""' >> /etc/cron.d/spacewalk-checkin +
-echo -e "\n# run rhn_check every 30 mins" >> /etc/cron.d/spacewalk-checkin +
-echo "*/30 * * * * root /usr/sbin/rhn_check" >> /etc/cron.d/spacewalk-checkin +
- +
-echo -e "\n>> Disabling rhnsd..." +
-if [[ ${major_version} == "7" ]]; then +
-  systemctl disable rhnsd +
-  systemctl stop rhnsd +
-else +
-  chkconfig rhnsd off +
-  service rhnsd stop +
-fi +
- +
-# Allow Spacewalk server to deploy config files +
-echo -e "\n>> Allowing Spacewalk server deploy control..." +
-rhn-actions-control --enable-all +
- +
-## Disable Old Repos ## +
- +
-if [[ ${distro,,} == "centos" ]]; then +
-# Disable CentOS default system repos +
-  echo -e "\n>> Disabling default CentOS repos..." +
-  for FILE in /etc/yum.repos.d/CentOS-*.repo; do  +
-    sed -i 's/enabled=1/enabled=0/' ${FILE} +
-    sed -i '/gpgcheck/a enabled=0' ${FILE} +
-  done +
-elif [[ ${distro,,} == "oracle" ]]; then +
-# Disable Oracle default system repos +
-  echo -e "\n>> Disabling default Oracle repos..." +
-  for FILE in /etc/yum.repos.d/public-yum-ol*.repo; do +
-    sed -i 's/enabled=1/enabled=0/' ${FILE} +
-    sed -i '/gpgcheck/a enabled=0' ${FILE} +
-  done +
-fi +
- +
-# Disable temporary epel repo +
-echo -e "\n>> Disabling default epel repos..." +
-sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo +
-sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/epel-testing.repo +
- +
-# Show repos +
-echo -e "\n>> Active repos are:" +
-yum repolist +
- +
-# Show website +
-echo -e "\n>> System should appear in the Spacewalk portal at: https://${sw_server}/rhn/systems/Registered.do" +
- +
-echo -e "\n\n#==================================================================" +
-echo "# Spacewalk Registration Completed." +
-echo "#==================================================================" +
-exit 0 +
-</code>+
  
 ---- ----
  
  • linux_wiki/spacewalk_register.1453865865.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)