Skip to content

Instantly share code, notes, and snippets.

@drolfe
Last active December 19, 2017 03:47
Show Gist options
  • Save drolfe/488647f06982b70bbcd8 to your computer and use it in GitHub Desktop.
Save drolfe/488647f06982b70bbcd8 to your computer and use it in GitHub Desktop.
FirstBoot Script
#!/bin/bash
#Values set by foreman finish scritp..
H_NAME=
OS_NAME=
OS_MAJOR=
OS_MINOR=
IPV4=
NMASK=
GWAY=
RAIDSET=
#dist=`lsb_release -s -d | sed 's|[()]| |g' | awk '{ print $4 }'`
#dist_ver=`lsb_release -s -d | sed 's|[()]| |g' | awk '{ print $3 }'`
if [ ${OS_NAME} = "Ubuntu" ]
then
cat << EOF1 >/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
bond-master bond0
auto eth1
iface eth1 inet manual
bond-master bond0
auto bond0
iface bond0 inet static
address ${IPV4}
netmask ${NMASK}
gateway ${GWAY}
bond-mode 6
bond-miimon 100
bond_downdelay 200
bond_updelay 200
bond-slaves eth0 eth1
dns-nameservers 8.8.8.8 8.8.4.4
EOF1
cat << EOF2 >>/etc/modules
bonding
EOF2
cat << EOF3 >/etc/apt/sources.list.d/mcp.list
deb http://downloads.linux.hp.com/SDR/repo/mcp precise/current non-free
EOF3
update-rc.d firstboot disable
else
cat << EOF1 >/etc/network/interfaces
auto lo
iface lo inet loopback
auto bond0
iface bond0 inet static
address ${IPV4}
netmask ${NMASK}
gateway ${GWAY}
bond-mode 6
bond-miimon 100
bond_downdelay 200
bond_updelay 200
bond-slaves eth0 eth1
dns-nameserver 8.8.8.8 8.8.4.4
EOF1
cat << EOF2 >/etc/apt/sources.list.d/mcp.list
deb http://downloads.linux.hp.com/SDR/repo/mcp wheezy/current non-free
EOF2
update-rc.d firstboot disable
fi
#gpg --keyserver subkeys.pgp.net --recv-keys 2689B887 && gpg --export -a 2689B887 | apt-key add -
wget -O- http://downloads.linux.hp.com/SDR/repo/mcp/GPG-KEY-mcp | apt-key add -
apt-get update && apt-get -y install hpacucli hponcfg
reboot
#!/bin/bash
# chkconfig: 345 99 01
# description: firstboot script
#ipv4=`grep -i ipaddr /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F'"' '{print $2}'`
#mask=`grep -i netmask /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F'"' '{print $2}'`
#gateway=`grep -i gateway /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F'"' '{print $2}'`
#hname=`hostname`
dist=`cat /etc/redhat-release | awk '{ print $1 }'`
dist_ver=`cat /etc/redhat-release | awk '{ print $3 }'`
raidset=0
#Values set by foreman finish scritp..
H_NAME=
OS_NAME=
OS_MAJOR=
OS_MINOR=
IPV4=
NMASK=
GWAY=
#RAIDSET=
cat << EOF1 >/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
IPADDR="${IPV4}"
NETMASK="${NMASK}"
GATEWAY="${GWAY}"
HOSTNAME="${H_NAME}"
BONDING_OPTS="miimon=100 mode=balance-alb"
TYPE=Unknown
IPV6INIT=no
MTU="1500"
DNS1="8.8.8.8"
DNS2="8.8.4.4"
EOF1
cat << EOF2 >/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
EOF2
cat << EOF3 >/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
EOF3
echo 'alias bond0 bonding' >> /etc/modprobe.d/bonding.conf
service network stop
sleep 3
service network start
cat << EOF4 >/etc/yum.repos.d/mcp.repo
[mcp]
name=Management Component Pack
baseurl=http://downloads.linux.hp.com/repo/mcp/CentOS/6.5/x86_64/current/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/GPG-KEY-mcp
EOF4
yum -t -y -e 0 update
yum -t -y -e 0 install hpacucli hponcfg
/sbin/chkconfig --level 345 firstboot off
FindDisk=`hpacucli ctrl slot=1 pd all show | grep -i physical | awk '{print $2}'`
FindLv=`hpacucli ctrl slot=1 ld all show | grep logicaldrive | awk '{print $2}'`
Drives=()
for i in ${FindDisk}
do
Drives+=($i)
done
DiskNum=${#Drives[@]}
if [ ! -z ${FindLv} ]
then
hpacucli ctrl slot=1 ld all delete forced
fi
if [ ${#Drives[@]} -eq 1 ]
then
hpacucli ctrl slot=1 create type=ld drives=${Drives[0]} raid=0
elif [ ${raidset} -eq 0 ]
then
hpacucli ctrl slot=1 create type=ld drives=all raid=0
elif [ ${raidset} -eq 1 ]
then
hpacucli ctrl slot=1 create type=ld drives=all raid=1
else
for i in ${Drives[@]}
do
hpacucli ctrl slot=1 create type=ld drives=$i raid=0
done
fi
Lvols=`fdisk -l | grep cciss | sed 's|[/:]| |g' | awk '{ print $4 }'`
num=1
for i in ${Lvols}
do
pvcreate /dev/cciss/$i
vgcreate disk${num}_vg /dev/cciss/$i
lvcreate -l 100%FREE -n disk${num}_lv disk${num}_vg
mkfs -t ext4 /dev/disk${num}_vg/disk${num}_lv
cat << EOF5 >>/etc/fstab
/dev/disk${num}_vg/disk${num}_lv /disk${num} ext4 defaults 0 1
EOF5
mkdir /disk${num}
((num++))
done
mount -a
#!/bin/bash
# Tested on Centos 6.5 and Centos 6.6
cat << EOF4 >/etc/yum.repos.d/mcp.repo
[mcp]
name=Management Component Pack
baseurl=http://downloads.linux.hp.com/repo/mcp/CentOS/6.5/x86_64/current/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/GPG-KEY-mcp
EOF4
yum -t -y -e 0 update
yum -t -y -e 0 install hp-health-* hpacucli-* hponcfg-* hpsmh-* hp-snmp-agents-* hp-smh-templates-* cpqacuxe-* hpdiags-*
cat << EOF1 >/etc/snmp/snmpd.conf
# First, map the community name "public" into a "security name"
# sec.name source community
com2sec localRO 127.0.0.1 public
com2sec localRW 127.0.0.1 private
com2sec hpsim_ro x.x.x.x public
####
# Second, map the security name into a group name:
# groupName securityModel securityName
group group_localRO v1 localRO
group group_localRO v2c localRO
group group_localRW v1 localRW
group group_localRW v2c localRW
group group_hpsimro v1 hpsim_ro
####
# Third, create a view for us to let the group have rights to:
# Make at least snmpwalk -v 1 localhost -c public system fast again.
# name incl/excl subtree mask(optional)
view all included .1
####
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
access group_localRO "" any noauth exact all none none
access group_localRW "" any noauth exact all all none
access group_hpsimro "" any noauth exact all none none
## Extra's
dlmod cmaX /usr/lib64/libcmaX64.so
dontLogTCPWrappersConnects 1
trapcommunity public
trapsink x.x.x.x public
syscontact someone@localhost
syslocation DATACENTER
EOF1
service hp-asrd restart
service hp-health restart
service snmpd restart
service hp-snmp-agents restart
%post
logger "Starting anaconda <%= @host %> postinstall"
exec < /dev/tty3 > /dev/tty3
#changing to VT 3 so that we can see whats going on....
/usr/bin/chvt 3
(
echo "Grab Firstboot script"
sleep 5
wget -q -O- https://gist.githubusercontent.com/drolfe/488647f06982b70bbcd8/raw/firstboot-script | sed 's/raidset=0/raidset=<%= @host.params['RAID'] %>/' > /etc/init.d/firstboot
chmod +x /etc/init.d/firstboot
sync
) 2>&1 | tee /root/install.post.log
exit 0
#!/bin/bash
FindDisk=`hpacucli ctrl slot=1 pd all show | grep -i physical | awk '{print $2}'`
FindLv=`hpacucli ctrl slot=1 ld all show | grep logicaldrive | awk '{print $2}'`
Drives=()
for i in ${FindDisk}
do
Drives+=($i)
done
DiskNum=${#Drives[@]}
if [ ! -z ${FindLv} ]
then
hpacucli ctrl slot=1 ld all delete forced
fi
if [ ${#Drives[@]} -eq 1 ]
then
hpacucli ctrl slot=1 create type=ld drives=${Drives[0]} raid=0
elif [ ${RAID} -eq 0 ]
then
hpacucli ctrl slot=1 create type=ld drives=all raid=0
elif [ ${RAID} -eq 1 ]
then
hpacucli ctrl slot=1 create type=ld drives=all raid=1
else
for i in ${Drives[@]}
do
hpacucli ctrl slot=1 create type=ld drives=$i raid=0
done
fi
Lvols=`fdisk -l | grep cciss | sed 's|[/:]| |g' | awk '{ print $4 }'`
num=1
for i in ${Lvols}
do
pvcreate /dev/cciss/$i
vgcreate disk${num}_vg /dev/cciss/$i
lvcreate -l 100%FREE -n disk${num}_lv disk${num}_vg
mkfs -t ext4 /dev/disk${num}_vg/disk${num}_lv
cat << EOF5 >>/etc/fstab
/dev/disk${num}_vg/disk${num}_lv /disk${num} ext4 defaults 0 1
EOF5
mkdir /disk${num}
((num++))
done
mount -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment