Created
January 13, 2017 15:28
-
-
Save UmbrielSecurity/2a085da2c2f1e7d5330540904426db2b to your computer and use it in GitHub Desktop.
Register an RHEL6 or RHEL7 server to an in-house RHN Satellite server
This file contains 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 | |
# register the RHN satellite server | |
# @UmbrielSecurity | |
ACTIVATION_KEY="X-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
SATELLITE_SERVER="satellite.example.com" | |
TOOLCHECK=0 | |
# Validate necessary tools | |
echo Ensuring we have the necessary tools... | |
CAT=`which cat 2> /dev/null` | |
TOOLCHECK=$(expr ${TOOLCHECK} + $?) | |
AWK=`which awk 2> /dev/null` | |
TOOLCHECK=$(expr ${TOOLCHECK} + $?) | |
WGET=`which wget 2> /dev/null` | |
TOOLCHECK=$(expr ${TOOLCHECK} + $?) | |
CUT=`which cut 2> /dev/null` | |
TOOLCHECK=$(expr ${TOOLCHECK} + $?) | |
SUDO=`which sudo 2> /dev/null` | |
TOOLCHECK=$(expr ${TOOLCHECK} + $?) | |
YUM=`which yum 2> /dev/null` | |
TOOLCHECK=$(expr ${TOOLCHECK} + $?) | |
if [ ${TOOLCHECK} -ne 0 ]; then | |
echo ERROR: One or more tools cannot be found, Aborting... Check tools. | |
exit 1; | |
else | |
echo Found tools: | |
echo ----------------- | |
echo cat : ${CAT} | |
echo cut : ${CUT} | |
echo awk : ${AWK} | |
echo yum : ${YUM} | |
echo wget : ${WGET} | |
echo sudo : ${SUDO} | |
echo ------------------ | |
echo | |
read -p "Press [Enter] to proceed, or CTRL-C to quit." < /dev/tty | |
fi | |
# ID what version of redhat | |
if [ -f /etc/redhat-release ]; then | |
osversion=`${CAT} /etc/redhat-release | ${AWK} '{ print $7 }' | ${CUT} -d. -f1` | |
fi | |
if [ ! -z ${osversion} ]; then | |
echo Found OS version: ${osversion} | |
## version specific code | |
# rhel 7 specific commands | |
rhel_7() { | |
echo "Installing RHEL 7 Config..." | |
# disable rhsmcertd.service | |
${SUDO} /bin/systemctl stop rhsmcertd.service | |
${SUDO} /bin/systemctl disable rhsmcertd.service | |
# install the epel cert | |
${SUDO} rpm --import http://${SATELLITE_SERVER}/pub/RPM-GPG-KEY-EPEL-7 | |
} | |
# rhel 6 specific commands | |
rhel_6() { | |
echo "Installing RHEL 6 Config..." | |
# install the epel cert | |
${SUDO} rpm --import http://${SATELLITE_SERVER}/pub/RPM-GPG-KEY-EPEL-6 | |
} | |
# select the right version and run the install | |
if [ $osversion -eq 7 ]; then | |
rhel_7 | |
elif [ $osversion -eq 6 ]; then | |
rhel_6 | |
fi | |
else | |
echo Could not determine OS version, Aborting. | |
exit 1; | |
fi | |
echo Installing RPM key... | |
# install RPM-GPG-KEY-redhat-release cert | |
${SUDO} rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release | |
echo Installing Satellite Server certificate... | |
# install Adobe satelite ssl cert file${SUDO} ${WGET} -O /usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT http://${SATELLITE_SERVER}/pub/RHN-ORG-TRUSTED-SSL-CERT | |
echo Installing u2pdate... | |
# install up2date file from satelite server${SUDO} ${WGET} -O /etc/sysconfig/rhn/up2date http://${SATELLITE_SERVER}/pub/up2date | |
echo Registering with Satellite server... | |
# register the host with satelite server | |
${SUDO} /usr/sbin/rhnreg_ks --activationkey ${ACTIVATION_KEY} --force | |
${SUDO} ${YUM} repolist | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment