Last active
November 7, 2016 15:46
-
-
Save jnikolak/5c0eba5453a7d4912b4a700399a59040 to your computer and use it in GitHub Desktop.
Install Satellite from Disconnected
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 | |
set -x # Comment this out for faster implementation. | |
#************************************************************** | |
## Version 0.1" | |
### Author: Jon Nikolakakis | |
#### change variable $dom if you don't want the domain china.com | |
##### This script will install and set up your hostname, then install Satellite of your choosing. | |
###### The goal is to do it quickly and without much interaction. | |
####### The installer requires that you have downloaded the disconnected satellite iso, | |
######## and places it into a folder called /source, the iso's are available to be downloaded from portal. | |
#************************************************************** | |
### isos | |
sat615='/source/satellite-6.1.5-rhel-7-x86_64-dvd.iso' | |
sat618='/source/satellite-6.1.8-rhel-7-x86_64-dvd.iso' | |
sat6110='/source/satellite-6.1.10-rhel-7-x86_64-dvd.iso' | |
sat622='/source/satellite-6.2.2-rhel-7-x86_64-dvd.iso' | |
rhel73dvd='/source/rhel-server-7.3-beta-1-x86_64-dvd.iso' | |
rhel7dvd='/source/rhel-server-7.2-x86_64-dvd.iso' | |
# setup some variables | |
dom='.china.com' | |
old=$(hostname -f) | |
intName=$(ip link | egrep -v "lo|link" | awk -F ':' '{print $2}') | |
oldip=$(sed '3!d' /etc/hosts | awk '{print $1}') | |
hostsfile='/etc/hosts' | |
newip=$(ip -o -4 addr show dev $intName | sed 's/.* inet \([^/]*\).*/\1/') | |
#setup a pause function, so that I can use it, anytime to debug script | |
#function pause(){ | |
# read -p "$*" | |
# } | |
rm -f /etc/yum.repos.d/*.repo | |
# This repos didnt build and needed the newer one. | |
#function repo { | |
# media='/media/rhel7dvd' | |
# mkdir -p $media | |
# mount -o loop $rhel7dvd $media | |
# cp $media/media.repo /etc/yum.repos.d/rhel7-server.repo | |
# echo baseurl=file://$media/ >> /etc/yum.repos.d/rhel7-server.repo | |
#} | |
#repo | |
function repo3 { | |
media3='/media/rhel7_3dvd' | |
mkdir -p $media3 | |
mount -o loop $rhel73dvd $media3 | |
cp $media3/media.repo /etc/yum.repos.d/rhel7_3-server.repo | |
sed -i "s/InstallMedia/rhel7_3dvd/g" /etc/yum.repos.d/rhel7_3-server.repo | |
echo baseurl=file://$media3/ >> /etc/yum.repos.d/rhel7_3-server.repo | |
} | |
repo3 | |
sleep 5 | |
#pause 'Press [Enter] key to continue...or [cntrl c] to finish' | |
#This is if you want random letters, I decided to prompt user instead. | |
#new2=$(tr -dc 'a-z0-9' < /dev/urandom | head -c12) | |
#### This prompts user for hostname and stores it as a variable | |
read -p "Type in your hostname and then press enter : " yourhostname | |
new=$yourhostname$dom | |
hostnamectl set-hostname "$new" | |
# Change hosts file if Exists or not | |
if egrep $old $hostsfile; then | |
sed -i "s/$old/$new/g" /etc/hosts | |
sed -i "s/$oldip/$newip/g" /etc/hosts | |
else | |
echo $newip $new >> /etc/hosts | |
fi | |
ping -c3 $(hostname -f) | |
## Check if directory exists, if not then create it | |
if [ -d /media/iso ];then | |
echo "Directory already exists, skipping" | |
else | |
mkdir -p /media/iso | |
fi | |
echo "Choose Satellite to install: " | |
echo "1) = Satellite 6.1.5" | |
echo "2) = Satellite 6.1.8" | |
echo "3) = Satellite 6.1.10" | |
echo "4) = Satellite 6.2.2" | |
read -p "Type a number 1 to 4: " sat | |
## Mount the Satellite Image | |
if [ $sat -eq 1 ]; then | |
mount -o loop $sat615 /media/iso | |
elif [ $sat -eq 2 ]; then | |
mount -o loop $sat618 /media/iso | |
elif [ $sat -eq 3 ]; then | |
mount -o loop $sat6110 /media/iso | |
elif [ $sat -eq 4 ]; then | |
mount -o loop $sat622 /media/iso | |
else | |
echo "error you didnt enter any correct value" | |
fi | |
sleep 5 | |
#pause 'Press [Enter] key to continue...or [cntrl c] to finish' | |
# Install the Satellite | |
cd /media/iso | |
./install_packages | |
#Satellite 6.1 and Satellite 6.2 have different install options | |
if [ $sat -eq 1 -o $sat -eq 2 -o $sat -eq 3 ] ; then | |
\cp -r /source/answers.katello-installer.yaml /etc/katello-installer | |
katello-installer | |
elif [ $sat -eq 4 ]; then | |
satellite-installer --scenario satellite --foreman-initial-organization "GSS" --foreman-initial-location "Brisbane" --foreman-admin-username admin --foreman-admin-password changeme | |
fi | |
sleep 5 | |
#pause 'Press [Enter] key to continue...or [cntrl c] to finish' | |
mkdir -p /var/www/html/pub/sat-import/ | |
# We mount the content isos with a loop, we do this process, to not overwrite the content. | |
for i in $(ls /source/sat-6-isos--rhel-7-server-x86_64*) | |
do | |
mkdir /mnt/iso | |
mount -o loop $i /mnt/iso | |
cp -ruv /mnt/iso/* /var/www/html/pub/sat-import/ | |
umount /mnt/iso | |
rmdir /mnt/iso | |
done | |
mount -o loop /source/rhel-server-7.2-x86_64-dvd.iso /media/rhel7dvd/ | |
shopt -s dotglob | |
### This kickstart code untested from initial install. | |
# Kickstart wont enable by default and requires this setup. | |
mkdir -p /var/www/html/pub/sat-import/content/dist/rhel/server/7/7.2/x86_64/kickstart/ | |
mkdir -p /var/www/html/pub/sat-import/content/dist/rhel/server/7/7.3/x86_64/kickstart/ | |
echo -e "\n7.2" >> /var/www/html/pub/sat-import/content/dist/rhel/server/7/listing | |
echo -e "\n7.3" >> /var/www/html/pub/sat-import/content/dist/rhel/server/7/listing | |
echo -e "x86_64" >> /var/www/html/pub/sat-import/content/dist/rhel/server/7/7.2/listing | |
echo -e "x86_64" >> /var/www/html/pub/sat-import/content/dist/rhel/server/7/7.3/listing | |
cp -rv /media/rhel7dvd/* /var/www/html/pub/sat-import/content/dist/rhel/server/7/7.2/x86_64/kickstart/ | |
cp -rv /media/rhel7_3dvd/* /var/www/html/pub/sat-import/content/dist/rhel/server/7/7.3/x86_64/kickstart/ | |
# one liner to check the results | |
for i in $(find /var/www/html/pub/sat-import/content/dist/rhel/server/7* -maxdepth 2 -type f -name listing | egrep -i "7.[1-3]|Server");done | |
umount /media/rhel* | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment