diff options
author | Justin chi <chigang@huawei.com> | 2015-08-11 02:56:44 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2015-08-11 02:56:44 +0000 |
commit | 7951b094df92c40417ec66c4be58871911bbed07 (patch) | |
tree | 04975ff2de818c2352eaa64e0650d3b2f2b175a5 | |
parent | 87612abc0e24cafd89a49e350165b08fe1608233 (diff) | |
parent | 0c7f73b0f2c9dbaef1645328439cef7cff037cc3 (diff) |
Merge "Provide a script for building compass install all-in-one ISO."
-rwxr-xr-x | ci/build.sh | 68 | ||||
-rw-r--r-- | ci/ks.cfg | 252 |
2 files changed, 320 insertions, 0 deletions
diff --git a/ci/build.sh b/ci/build.sh new file mode 100755 index 00000000..490aafe3 --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,68 @@ +#!/bin/bash +set -ex +SCRIPT_DIR=`cd ${BASH_SOURCE[0]%/*};pwd` +WORK_DIR=$SCRIPT_DIR/work + +sudo rm -rf $WORK_DIR +mkdir -p $WORK_DIR + +COMPASS_CORE=${COMPASS_CORE:-http://github.com/baigk/compass-core.git} +COMPASS_WEB=${COMPASS_WEB:-http://github.com/baigk/compass-web.git} +COMPASS_INSTALL=${COMPASS_INSTALL:-http://github.com/baigk/compass-install.git} +COMPASS_ADAPTERS=${COMPASS_ADAPTERS:-http://github.com/baigk/compass-adapters.git} +PACKAGE_URL=${PACKAGE_URL:-http://192.168.127.11:9999/xh/work/package} + +cd $WORK_DIR + +# get base iso +wget -O centos_base.iso $PACKAGE_URL/centos_base.iso + +# get ubuntu ppa package +wget -O ubuntu_ppa.tar.gz $PACKAGE_URL/ubuntu_ppa.tar.gz + +# get ubuntu iso +wget -O Ubuntu-14.04-x86_64.iso $PACKAGE_URL/Ubuntu-14.04-x86_64.iso + +# get centos iso +wget -O CentOS-7-x86_64-Minimal-1503-01.iso $PACKAGE_URL/CentOS-7-x86_64-Minimal-1503-01.iso + +# get cenos common ppa package +wget -O centos_7_1_common_ppa_repo.tar.gz $PACKAGE_URL/centos_7_1_common_ppa_repo.tar.gz + +# get centos openstack ppa package +wget -O centos_7_1_openstack_juno_ppa_repo.tar.gz $PACKAGE_URL/centos_7_1_openstack_juno_ppa_repo.tar.gz + +wget -O loaders.tar.gz $PACKAGE_URL/loaders.tar.gz +# mount base iso +mkdir -p base +sudo mount -o loop centos_base.iso base +cd base;find .|cpio -pd ../new;cd - +sudo umount base +chmod 755 ./new -R + +# main process +mkdir -p new/repos new/compass new/bootstrap new/pip new/guestimg +cp ubuntu_ppa.tar.gz new/repos +cp Ubuntu-14.04-x86_64.iso new/repos +cp CentOS-7-x86_64-Minimal-1503-01.iso new/repos +cp centos_7_1_common_ppa_repo.tar.gz new/repos +cp centos_7_1_openstack_juno_ppa_repo.tar.gz new/repos +cp loaders.tar.gz new +wget -O new/guestimg/cirros-0.3.3-x86_64-disk.img $PACKAGE_URL/cirros-0.3.3-x86_64-disk.img +wget -O new/pip/pexpect-3.3.tar.gz https://pypi.python.org/packages/source/p/pexpect/pexpect-3.3.tar.gz#md5=0de72541d3f1374b795472fed841dce8 + +cd new/compass +git clone ${COMPASS_CORE} +git clone ${COMPASS_INSTALL} +git clone ${COMPASS_ADAPTERS} +git clone ${COMPASS_WEB} + +find . -name ".git" |xargs rm -rf + +cd $WORK_DIR +cp -rf $SCRIPT_DIR/ks.cfg new/isolinux/ks.cfg +rm -rf new/.rr_moved +sudo mkisofs -quiet -r -J -R -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -hide-rr-moved -x "lost+found:" -o compass.iso new/ + +# delete tmp file +sudo rm -rf new base ubuntu_ppa.tar.gz centos_base.iso Ubuntu-14.04-x86_64.iso diff --git a/ci/ks.cfg b/ci/ks.cfg new file mode 100644 index 00000000..036a8d90 --- /dev/null +++ b/ci/ks.cfg @@ -0,0 +1,252 @@ +install +text +cdrom +reboot --eject +lang en_US.UTF-8 +keyboard us +rootpw root +timezone --utc Etc/UTC +firewall --disabled +selinux --disabled +unsupported_hardware +skipx + +# NEVER ever place zerombr here, it breaks automated installation +%include /tmp/bootloader.ks +%include /tmp/partition.ks + +# PREINSTALL SECTION +# HERE ARE COMMANDS THAT WILL BE LAUNCHED BEFORE +# INSTALLATION PROCESS ITSELF +%pre +#!/bin/sh + +# hard drives +drives=(`ls -1 /sys/block | grep "sd\|hd\|vd\|cciss"`) +default_drive=${drives[0]} + +for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done + +tgtdrive=$default_drive +format_confirmed="no" + +if [ ${#drives[@]} -lt 1 ]; then + exec < /dev/tty3 > /dev/tty3 2>&1 + chvt 3 + clear + echo + echo '********************************************************************' + echo '* E R R O R *' + echo '* *' + echo '* There is no suitable media available for installation. *' + echo '* Please attach a drive and try again. *' + echo '* *' + echo '********************************************************************' + echo + read -p "Press Enter to shut down the system: " _ + poweroff +fi + +# verify tgtdrive is at least 30GB +tgtdrivesize=$(( $(cat "/sys/class/block/${tgtdrive}/size") / 2 / 1024 )) +if [ $tgtdrivesize -lt 30720 ]; then + exec < /dev/tty3 > /dev/tty3 2>&1 + chvt 3 + clear + echo + echo '********************************************************************' + echo '* E R R O R *' + echo '* *' + echo '* Your disk is under 30GB in size. Installation cannot continue. *' + echo '* Restart installation with a larger disk. *' + echo '* *' + echo '********************************************************************' + echo + read -p "Press Enter to restart: " _ + reboot +fi + +vgremove -ff os +dd if=/dev/zero of=/dev/${tgtdrive} bs=10M count=10 +sleep 3 + +hdparm -z /dev/${tgtdrive} +parted -s /dev/${tgtdrive} mklabel gpt +parted -a none -s /dev/${tgtdrive} unit MiB mkpart primary 0 24 +parted -s /dev/${tgtdrive} set 1 bios_grub on +parted -a none -s /dev/${tgtdrive} unit MiB mkpart primary fat16 24 224 +parted -s /dev/${tgtdrive} set 2 boot on +parted -a none -s /dev/${tgtdrive} unit MiB mkpart primary 224 424 +sleep 3 +hdparm -z /dev/${tgtdrive} + +# partition +echo > /tmp/partition.ks +echo "partition /boot --onpart=/dev/${tgtdrive}3" >> /tmp/partition.ks +echo "partition pv.001 --ondisk=${tgtdrive} --size=30000 --grow" >> /tmp/partition.ks +echo "volgroup os pv.001" >> /tmp/partition.ks +echo "logvol swap --vgname=os --recommended --name=swap" >> /tmp/partition.ks +echo "logvol / --vgname=os --size=10000 --name=root --fstype=ext4" >> /tmp/partition.ks +echo "logvol /var --vgname=os --size=10000 --percent 60 --grow --name=var --fstype=ext4" >> /tmp/partition.ks +echo "logvol /var/log --vgname=os --size=4096 --percent 40 --grow --name=varlog --fstype=ext4" >> /tmp/partition.ks + +# bootloader setting +echo "bootloader --location=mbr --driveorder=${tgtdrive} --append=' biosdevname=0 crashkernel=none'" > /tmp/bootloader.ks +%end + +%packages --nobase --excludedocs +wget +git +yum +cobbler +cobbler-web +createrepo +mkisofs +syslinux +debmirror +pykickstart +cman +bind +rsync +dhcp +xinetd +tftp-server +gcc +httpd +libselinux-python +python-setuptools +python-devel +mysql-devel +mysql-server +mysql +MySQL-python +redis +mod_wsgi +rabbitmq-server +nfs-utils + +%post +echo -e "modprobe nf_conntrack_ipv4\nmodprobe nf_conntrack_ipv6\nmodprobe nf_conntrack_tftp\nmodprobe nf_nat_tftp" >> /etc/rc.modules +chmod +x /etc/rc.modules +echo -e "net.nf_conntrack_max=1048576" >> /etc/sysctl.conf +mkdir -p /var/log/coredump +echo -e "kernel.core_pattern=/var/log/coredump/core.%e.%p.%h.%t" >> /etc/sysctl.conf +chmod 777 /var/log/coredump +echo -e "* soft core unlimited\n* hard core unlimited" >> /etc/security/limits.conf + +########################### post install before chroot #################### +%post --nochroot --log=/mnt/sysimage/root/anaconda-post-before-chroot.log +#!/bin/sh +set -x +SOURCE="/mnt/sysimage/tmp/source" +for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done + +mkdir -p "${SOURCE}" +mount -o bind "/mnt/source" "${SOURCE}" + +########################### post install after chroot #################### +%post --log=/root/anaconda-post-after-chroot.log +#!/bin/bash +set -x + +function save_nic_cfg() { + scrFile="/etc/sysconfig/network-scripts/ifcfg-$1" + sed -i -e 's#^\(HOSTNAME=\).*$#\1'"$hostname"'#' /etc/sysconfig/network + grep -q "^\s*$2\s+$hostname" /etc/hosts || echo "$2 $hostname" >> /etc/hosts + + echo DEVICE=$1> $scrFile + echo ONBOOT=yes >> $scrFile + echo NM_CONTROLLED=no >> $scrFile + echo HWADDR=$4 >> $scrFile + echo USERCTL=no >> $scrFile + echo PEERDNS=no >> $scrFile + echo BOOTPROTO=static >> $scrFile + echo IPADDR=$2 >> $scrFile + echo NETMASK=$3 >> $scrFile +} + +function save_gateway() { + echo GATEWAY=$gw >> /etc/sysconfig/network + search="domain $domain\nsearch $domain" + echo -e "${search}\nnameserver 127.0.0.1" > /etc/resolv.conf + [ $dns1 ] && echo -e "${search}\nnameserver $dns1" > /etc/resolv.conf + [ $dns1 ] && echo -e "${search}\nnameserver $dns1" > /etc/dnsmasq.upstream + [ $dns2 ] && echo "nameserver $dns2" >> /etc/resolv.conf + [ $dns2 ] && echo "nameserver $dns2" >> /etc/dnsmasq.upstream + + if [[ -z "$dns1" && -z "$dns2" ]]; then + echo "nameserver $gw" >> /etc/resolv.conf + fi +} +# Default FQDN +hostname="compass" + +for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done +domain=$hostname +gw=$gw + +install_ip=$install_ip +install_netmask=$install_netmask +install_intf="eth1" +install_hwaddr=`ifconfig $install_intf | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'` + +mgmt_ip=$mgmt_ip +mgmt_netmask=$mgmt_netmask +mgmt_intf="eth0" +mgmt_hwaddr=`ifconfig $mgmt_intf | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'` + +save_nic_cfg $install_intf $install_ip $install_netmask $install_hwaddr +save_nic_cfg $mgmt_intf $mgmt_ip $mgmt_netmask $mgmt_hwaddr +save_gateway + +# already chroot +SOURCE=/tmp/source +FS=/tmp/fs + +echo +mkdir -p ${SOURCE} +mkdir -p ${FS} + +repodir="/var/lib/install_iso" + +# Copying Centos files +mkdir -p ${repodir} +cp -r ${SOURCE} ${repodir}/source + +cp -rf ${SOURCE} ${repodir}/source +rm -rf ${repodir}/source/bootstrap/ \ + ${repodir}/source/compass/ \ + ${repodir}/source/guestimg/ \ + ${repodir}/source/pip/ \ + ${repodir}/source/repos + +mkdir -p /root/.ssh +chmod 700 /root/.ssh + +cat ${SOURCE}/bootstrap/boot.rsa.pub >> /root/.ssh/authorized_keys +cp -rf ${SOURCE}/compass/* /opt +cp -rf ${SOURCE}/repos/* /opt +cp -rf ${SOURCE}/loaders.tar.gz /opt + +mkdir -p /var/www + +cp -rf ${SOURCE}/pip /var/www/pip +cp -rf ${SOURCE}/guestimg /var/www/guestimg + +# Prepare local repository specification +rm /etc/yum.repos.d/CentOS*.repo +cat > /etc/yum.repos.d/install_iso.repo << EOF +[install_iso] +name=local repo +baseurl=file:$repodir/source +gpgcheck=0 +EOF + +# Disable GSSAPI in ssh server config +sed -i -e "/^\s*GSSAPICleanupCredentials yes/d" -e "/^\s*GSSAPIAuthentication yes/d" /etc/ssh/sshd_config +sed -i 's/Defaults requiretty/#Defaults requiretty/g' /etc/sudoers +sed -i 's/^UseDNS/#UseDNS/g' /etc/ssh/sshd_config +echo "UseDNS no" >> /etc/ssh/sshd_config + +%end + |