Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
267b49a
more generic :D
prometheanfire May 18, 2015
0c22138
moving kernel config to files dir
prometheanfire May 18, 2015
2b3bff6
change stage3 getting to gkeys and stuff
prometheanfire Jun 1, 2015
2441a9c
more stuff
prometheanfire Jun 4, 2015
9504e74
final update to use gkeys to verify stages and snapshots
prometheanfire Jun 4, 2015
cbd52a0
make scripts exec
prometheanfire Jun 4, 2015
3ef30ae
updating catylst script
prometheanfire Jun 4, 2015
85ecaff
missed an old subshell thing
prometheanfire Jun 4, 2015
6f7ede9
switching to grub2
prometheanfire Jun 5, 2015
18054f0
fixing grub and allowing console
prometheanfire Jun 7, 2015
daa1c4a
more random fixes
prometheanfire Jun 7, 2015
3c3f552
moar
prometheanfire Jun 7, 2015
485c9bd
first pass at cloud-init
prometheanfire Jun 7, 2015
90cd923
more sed fixes
prometheanfire Jun 7, 2015
141f233
hopefully the last...
prometheanfire Jun 7, 2015
59499e9
updating kernel config
prometheanfire Jun 8, 2015
264b1fd
more kconfig stuff
prometheanfire Jun 8, 2015
442b568
let dhcpcd use normal slaac instead of private
prometheanfire Jun 8, 2015
1e9acfe
more profiles
prometheanfire Jun 20, 2015
5372ae7
missed an abstraction in 03
prometheanfire Jun 20, 2015
4719544
I think we can do parallel jobs now...
prometheanfire Jun 20, 2015
46d2267
more paralell
prometheanfire Jun 20, 2015
be8f383
more parallel kernel compilation
prometheanfire Jun 20, 2015
f383071
better name for default-nomultilib
prometheanfire Jun 20, 2015
8a8f8cf
now with dynamic network configs
prometheanfire Jun 22, 2015
45b3f4a
sliming down and cleaning up
prometheanfire Jun 22, 2015
cfc1fb9
better cleanup of tmp make.conf stuff
prometheanfire Jun 22, 2015
d4e0a38
hardened kconfig
prometheanfire Jun 22, 2015
db8d816
fixing kernel builds and better parallelism on 02
prometheanfire Jun 22, 2015
4243441
more betterer bash
prometheanfire Jun 22, 2015
2f2ce05
fixing kconfig naming
prometheanfire Jun 22, 2015
9155c94
yay
prometheanfire Jun 22, 2015
2f9dce7
more parallelism in 02
prometheanfire Jun 22, 2015
3e16bf0
spelling
prometheanfire Jun 22, 2015
e5898c6
clean up all of /usr/portage/* before making the tarball
prometheanfire Jun 22, 2015
402fad8
catalyst removes portage stuff autoatically
prometheanfire Jun 22, 2015
1fcf6f4
resize the root partition on first boot
prometheanfire Jun 22, 2015
4b5000d
yay spelling
prometheanfire Jun 23, 2015
6547858
fixing the last parallelization bug I hope
prometheanfire Jun 23, 2015
2397757
reduce that complexity
prometheanfire Jun 23, 2015
e4c1dce
removing a dangling symlink
prometheanfire Jul 20, 2015
09182c7
switch to static cloud config
prometheanfire Jul 20, 2015
1dbff5d
need bios_grub for gpt
prometheanfire Jul 20, 2015
1a2e74a
typo
prometheanfire Jul 20, 2015
2f2816c
disable domain name update in dhcpcd
prometheanfire Jul 20, 2015
a93e955
lock the root account as well
prometheanfire Jul 20, 2015
ee25e05
fixing the boot problem
prometheanfire Jul 20, 2015
28f91ee
correct cloud.cfg location, again...
prometheanfire Jul 20, 2015
47f6ba1
we are now on vda2 for the gpt stuff
prometheanfire Jul 20, 2015
e1157e4
we are using built in disk expansion :D
prometheanfire Jul 20, 2015
a0e4c34
smaller disk
prometheanfire Jul 20, 2015
83f7f2c
updating host working and resizing works now
prometheanfire Jul 20, 2015
d6b9d11
update the image before sending it out
prometheanfire Jul 20, 2015
f414673
move stuff into the cloud-init ebuild or prep
prometheanfire Jul 20, 2015
446555c
first fix and readme update
prometheanfire Jul 20, 2015
bf05931
second script update
prometheanfire Jul 20, 2015
20b9606
better fix
prometheanfire Jul 20, 2015
b2b344e
final hopefully?
prometheanfire Jul 21, 2015
0c7eeee
correcting portage overlay/confdir
prometheanfire Jul 21, 2015
e6ee6e9
don't set the build use flag
prometheanfire Jul 21, 2015
4f574a8
better tar
prometheanfire Jul 21, 2015
5b06eb0
fixing /etc/conf.d/hostname, subshell was executed, not placed in file
prometheanfire Jul 25, 2015
3a4365c
add acpid and move the rc-update stuff into catalyst
prometheanfire Jul 25, 2015
7d744b3
including /usr/portage in the image now
prometheanfire Jul 25, 2015
e9c504d
updating for better bash, also fixing dhcpcd
Sep 21, 2015
7b81111
increase image size because of inode count
prometheanfire Nov 18, 2015
9c6a687
alphabetize and reorder package/use flags
prometheanfire Dec 15, 2015
c25002c
don't hardcode multilib, let the profiles handle it
prometheanfire Dec 26, 2015
52a2a01
rc-add cronie, not vixie-cron
prometheanfire Dec 26, 2015
30c1ac5
use the default kernels
prometheanfire Dec 26, 2015
5624f52
use automode -5 (non-interactive) in etc-update
prometheanfire Dec 26, 2015
ee002cf
remove cloud-init from keywords (marked stable)
prometheanfire Dec 26, 2015
ec748f1
make rm recursive for /usr/src/linux
prometheanfire Dec 26, 2015
5e194fe
use a more generic sed
prometheanfire Dec 29, 2015
abfc79f
smaller stages?
prometheanfire Jan 11, 2016
56ffe25
shrank to under a gig :D
prometheanfire Jan 11, 2016
99ee853
don't use pt_pax
prometheanfire Jan 12, 2016
4a1463f
remove unneccessary quotes
prometheanfire Jan 12, 2016
f99adfe
switch to labels
prometheanfire Jan 13, 2016
e7fe57f
switch grub2-install to use root-directory
prometheanfire Jan 22, 2016
9f0f681
first pass at musl
prometheanfire Dec 30, 2016
ee2969e
more updates for musl
prometheanfire Jan 1, 2017
04cb42d
more musl changes
prometheanfire Jan 1, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 86 additions & 37 deletions 01-get-stage3.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,101 @@
# Note that I use this script to update all my current stages, and rootfs,
# but this repo is more specifically for Gentoo, so have some Gentoo.

##
## Vars
##
MIRROR="http://mirror.reenigne.net"
OUTDIR="/var/tmp/catalyst/builds"

mkdir -p ${OUTDIR}

##
## Gentoo
##

STAGE3_NAME="stage3-amd64-latest.tar.bz2"
STAGE3_FILE=$(curl -s "${MIRROR}/gentoo/releases/amd64/autobuilds/latest-stage3-amd64.txt" | awk '/stage3/ { print $1 }')
LIVE_SHA512=$(curl -s "${MIRROR}/gentoo/releases/amd64/autobuilds/${STAGE3_FILE}.DIGESTS" | awk '/SHA512 HASH/{getline;print}' | grep -iv 'contents' | awk {'print $1'})
OUR_SHA512=$(sha512sum "${OUTDIR}/${STAGE3_NAME}" | awk {'print $1'})

# download latest stage3 if not the newest
if [ "${LIVE_SHA512}" != "${OUR_SHA512}" ]
then
echo "Downloading new image - ${STAGE3_NAME}"
curl -s "${MIRROR}/gentoo/releases/amd64/autobuilds/${STAGE3_FILE}" > "${OUTDIR}/${STAGE3_NAME}"
set -e -u -x -o pipefail

# Vars
export MIRROR=${MIRROR:-"http://gentoo.osuosl.org"}
export OUTDIR=${OUTDIR:-"/var/tmp/catalyst/builds"}
export PORTAGE_DIR=${PORTAGE_DIR:-"/var/tmp/catalyst/snapshots"}
# profiles supported are as follows
# default/linux/amd64/13.0
# default/linux/amd64/13.0/no-multilib
# hardened/linux/amd64
# hardened/linux/amd64/no-multilib
# hardened/linux/amd64/selinux (eventually)
# hardened/linux/amd64/no-multilib/selinux (eventually)
export PROFILE=${PROFILE:-"default/linux/amd64/13.0"}

mkdir -p "${OUTDIR}"

if [[ "${PROFILE}" == "default/linux/amd64/13.0" ]]; then
STAGE3_NAME="stage3-amd64-current.tar.bz2"
STAGE3_REAL_PATH=$(curl -s "${MIRROR}/releases/amd64/autobuilds/latest-stage3-amd64.txt" | awk '/stage3/ { print $1 }')
STAGE3_REAL_NAME=$(echo -n "${STAGE3_REAL_PATH}" | awk -F/ '{ print $2}')
STAGE3_URL="${MIRROR}/releases/amd64/autobuilds/current-stage3-amd64/${STAGE3_REAL_NAME}"
elif [[ "${PROFILE}" == "default/linux/amd64/13.0/no-multilib" ]]; then
STAGE3_NAME="stage3-amd64-nomultilib-current.tar.bz2"
STAGE3_REAL_PATH=$(curl -s "${MIRROR}/releases/amd64/autobuilds/latest-stage3-amd64-nomultilib.txt" | awk '/stage3/ { print $1 }')
STAGE3_REAL_NAME=$(echo -n "${STAGE3_REAL_PATH}" | awk -F/ '{ print $2}')
STAGE3_URL="${MIRROR}/releases/amd64/autobuilds/current-stage3-amd64-nomultilib/${STAGE3_REAL_NAME}"
elif [[ "${PROFILE}" == "hardened/linux/amd64" ]]; then
STAGE3_NAME="stage3-amd64-hardened-current.tar.bz2"
STAGE3_REAL_PATH=$(curl -s "${MIRROR}/releases/amd64/autobuilds/latest-stage3-amd64-hardened.txt" | awk '/hardened/ { print $1 }')
STAGE3_REAL_NAME=$(echo -n "${STAGE3_REAL_PATH}" | awk -F/ '{ print $3}')
STAGE3_URL="${MIRROR}/releases/amd64/autobuilds/current-stage3-amd64-hardened/${STAGE3_REAL_NAME}"
elif [[ "${PROFILE}" == "hardened/linux/amd64/no-multilib" ]]; then
STAGE3_NAME="stage3-amd64-hardened-nomultilib-current.tar.bz2"
STAGE3_REAL_PATH=$(curl -s "${MIRROR}/releases/amd64/autobuilds/latest-stage3-amd64-hardened+nomultilib.txt" | awk '/hardened/ { print $1 }')
STAGE3_REAL_NAME=$(echo -n "${STAGE3_REAL_PATH}" | awk -F/ '{ print $3}')
STAGE3_URL="${MIRROR}/releases/amd64/autobuilds/current-stage3-amd64-hardened+nomultilib/${STAGE3_REAL_NAME}"
else
echo "${STAGE3_NAME} is up to date, skipping"
echo 'invalid profile, exiting'
exit 1
fi

# make sure latest stage3 is actually good
OUR_SHA512=$(sha512sum "${OUTDIR}/${STAGE3_NAME}" | awk {'print $1'})
if [ "${OUR_SHA512}" != "${OUR_SHA512}" ]; then
echo 'downloaded file did not match the sha512 sum'
curl -s "${STAGE3_URL}.DIGESTS.asc" -o "${OUTDIR}/${STAGE3_REAL_NAME}.DIGESTS.asc"
gkeys verify -F "${OUTDIR}/${STAGE3_REAL_NAME}.DIGESTS.asc"
STATUS=$?
if [[ ${STATUS} != 0 ]]; then
echo 'stage3 did not verify, removing badness'
rm "${OUTDIR}/${STAGE3_REAL_NAME}"
rm "${OUTDIR}/${STAGE3_REAL_NAME}.DIGESTS.asc"
exit 1
fi

SHA512=$(grep -A1 SHA512 "${OUTDIR}/${STAGE3_REAL_NAME}.DIGESTS.asc" | grep stage3 | grep -v CONTENTS | awk '{ print $1 }')
SHA512_REAL=$(sha512sum "${OUTDIR}/${STAGE3_NAME}" | awk '{ print $1 }')
if [[ "${SHA512}" != "${SHA512_REAL}" ]]; then
echo "Downloading new image - ${STAGE3_REAL_NAME}"
curl -s "${STAGE3_URL}" -o "${OUTDIR}/${STAGE3_REAL_NAME}"
SHA512=$(grep -A1 SHA512 "${OUTDIR}/${STAGE3_REAL_NAME}.DIGESTS.asc" | grep stage3 | grep -v CONTENTS | awk '{ print $1 }')
SHA512_REAL=$(sha512sum "${OUTDIR}/${STAGE3_REAL_NAME}" | awk '{ print $1 }')
if [[ "${SHA512}" != "${SHA512_REAL}" ]]; then
echo 'shasum did not match, removing badness'
rm "${OUTDIR}/${STAGE3_REAL_NAME}"
rm "${OUTDIR}/${STAGE3_REAL_NAME}.DIGESTS.asc"
exit 1
fi
# otherwise we cleanup and move on
if [[ -f "${OUTDIR}/${STAGE3_NAME}" ]]; then
rm "${OUTDIR}/${STAGE3_NAME}"
fi
rm "${OUTDIR}/${STAGE3_REAL_NAME}.DIGESTS.asc"
mv "${OUTDIR}/${STAGE3_REAL_NAME}" "${OUTDIR}/${STAGE3_NAME}"
fi


# get the latest portage
PORTAGE_DIR="/var/tmp/catalyst/snapshots"
PORTAGE_LIVE_MD5=$(curl -s "${MIRROR}/gentoo/snapshots/portage-latest.tar.bz2.md5sum" | awk '/portage-latest/ {print $1}')
OUR_MD5=$(md5sum "${PORTAGE_DIR}/portage-latest.tar.bz2" | awk {'print $1'})
PORTAGE_LIVE_MD5=$(curl -s "${MIRROR}/snapshots/portage-latest.tar.bz2.md5sum" | awk '/portage-latest/ {print $1}')
OUR_MD5=$(md5sum "${PORTAGE_DIR}/portage-current.tar.bz2" | awk {'print $1'})
if [[ "${PORTAGE_LIVE_MD5}" != "${OUR_MD5}" ]]; then
echo 'downloading new portage tarball'
curl -s "${MIRROR}/gentoo/snapshots/portage-latest.tar.bz2" > "${PORTAGE_DIR}/portage-latest.tar.bz2"
if [[ ! -d "${PORTAGE_DIR}" ]]; then
mkdir -p "${PORTAGE_DIR}"
fi
curl -s "${MIRROR}/snapshots/portage-latest.tar.bz2" -o "${PORTAGE_DIR}/portage-current.tar.bz2"
curl -s "${MIRROR}/snapshots/portage-latest.tar.bz2.gpgsig" -o "${PORTAGE_DIR}/portage-current.tar.bz2.gpgsig"
gkeys verify -F "${PORTAGE_DIR}/portage-current.tar.bz2"
STATUS=$?
if [[ ${STATUS} != 0 ]]; then
echo 'tarball did not verify, removing badness'
rm "${PORTAGE_DIR}/portage-current.tar.bz2"
rm "${PORTAGE_DIR}/portage-current.tar.bz2.gpgsig"
exit 1
elif [[ ${STATUS} == 0 ]]; then
echo 'tarball verified'
rm "${PORTAGE_DIR}/portage-current.tar.bz2.gpgsig"
fi
else
echo 'portage tarball is up to date'
fi

OUR_MD5=$(md5sum "${PORTAGE_DIR}/portage-latest.tar.bz2" | awk {'print $1'})
if [[ "${PORTAGE_LIVE_MD5}" != "${OUR_MD5}" ]]; then
echo 'downloaded file did not match the md5sum'
exit 1
fi
113 changes: 90 additions & 23 deletions 02-catalyst-that-shit.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,111 @@
# your own scenario. I have a VM that poops out images for me, and these
# are the fields I use.

##
## Vars
##
DATE=$(date +%Y%m%d)
SPECFILE=~/tmp/catalyst/stage4.spec
OUTDIR=~/tmp/catalyst/gentoo
OUTFILE="${OUTDIR}/stage4-${DATE}.tar.bz2"
set -e -u -x -o pipefail

# Vars
export DATE=${DATE:-"$(date +%Y%m%d)"}
export OUTDIR=${OUTDIR:-"/root/tmp/catalyst/gentoo"}
export GIT_BASE_DIR=${GIT_BASE_DIR:-$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )}
# profiles supported are as follows
# default/linux/amd64/13.0
# default/linux/amd64/13.0/no-multilib
# hardened/linux/amd64
# hardened/linux/amd64/no-multilib
# hardened/linux/amd64/selinux (eventually)
# hardened/linux/amd64/no-multilib/selinux (eventually)
export PROFILE=${PROFILE:-"default/linux/amd64/13.0"}


if [[ "${PROFILE}" == "default/linux/amd64/13.0" ]]; then
PROFILE_SHORTNAME="amd64-default"
SOURCE_SUBPATH="stage3-amd64-current"
KERNEL_SOURCES="gentoo-sources"
elif [[ "${PROFILE}" == "default/linux/amd64/13.0/no-multilib" ]]; then
PROFILE_SHORTNAME="amd64-default-nomultilib"
SOURCE_SUBPATH="stage3-amd64-nomultilib-current"
KERNEL_SOURCES="gentoo-sources"
elif [[ "${PROFILE}" == "hardened/linux/musl/amd64" ]]; then
PROFILE_SHORTNAME="amd64-hardened-musl"
SOURCE_SUBPATH="musl/hardened/amd64/stage3-amd64-musl-hardened"
KERNEL_SOURCES="hardened-sources"
elif [[ "${PROFILE}" == "hardened/linux/amd64" ]]; then
PROFILE_SHORTNAME="amd64-hardened"
SOURCE_SUBPATH="stage3-amd64-hardened-current"
KERNEL_SOURCES="hardened-sources"
elif [[ "${PROFILE}" == "hardened/linux/amd64/no-multilib" ]]; then
PROFILE_SHORTNAME="amd64-hardened-nomultilib"
SOURCE_SUBPATH="stage3-amd64-hardened-nomultilib-current"
KERNEL_SOURCES="hardened-sources"
else
echo 'invalid profile, exiting'
exit 1
fi
export OUTFILE=${OUTFILE:-"${OUTDIR}/stage4-${PROFILE_SHORTNAME}-${DATE}.tar.bz2"}
export SPECFILE=${SPECFILE:-"/root/tmp/catalyst/stage4-${PROFILE_SHORTNAME}.spec"}
mkdir -p "${OUTDIR}"

# Build the spec file, first
cat > "${SPECFILE}" << EOF
subarch: amd64
target: stage4
rel_type: default
profile: default/linux/amd64/13.0
source_subpath: stage3-amd64-latest
rel_type: ${PROFILE_SHORTNAME}
profile: ${PROFILE}
source_subpath: ${SOURCE_SUBPATH}
cflags: -O2 -pipe -march=core2

pkgcache_path: /tmp/packages
kerncache_path: /tmp/kernel
pkgcache_path: /tmp/packages-${PROFILE_SHORTNAME}
kerncache_path: /tmp/kernel-${PROFILE_SHORTNAME}
portage_confdir: ${GIT_BASE_DIR}/portage_overlay
portage_overlay: /opt/overlays/musl

# Probably best made as parameters
snapshot: latest
snapshot: current
version_stamp: ${DATE}

# Stage 4 stuff
stage4/use: bash-completion bzip2 idm urandom ipv6 mmx sse sse2 abi_x86_32 abi_x86_64
stage4/packages: eix dev-vcs/git tmux vim sys-devel/bc cloud-init syslog-ng logrotate vixie-cron dhcpcd net-misc/curl sudo gentoolkit iproute2 grub:0
stage4/fsscript: /root/gentoo-catalyst/prep.sh
stage4/root_overlay: /root/gentoo-catalyst/root-overlay
stage4/rcadd: syslog-ng|default sshd|default vixie-cron|default cloud-config|default cloud-init-local|default cloud-init|default cloud-final|default netmount|default
stage4/use: bash-completion bzip2 idm ipv6 mmx sse sse2 urandom -nls -fortran
stage4/packages: app-admin/logrotate app-admin/sudo app-admin/syslog-ng app-editors/vim app-portage/eix app-portage/gentoolkit net-misc/dhcpcd sys-apps/dmidecode sys-apps/gptfdisk sys-apps/iproute2 sys-apps/lsb-release sys-boot/grub:2 sys-devel/bc sys-power/acpid sys-process/cronie
stage4/fsscript: files/prep.sh
stage4/root_overlay: root-overlay
stage4/rcadd: syslog-ng|default sshd|default cronie|default netmount|default acpid|default dhcpcd|default net.lo|default

boot/kernel: gentoo
boot/kernel/gentoo/sources: gentoo-sources
boot/kernel/gentoo/config: /root/gentoo-catalyst/kernel.config
boot/kernel/gentoo/extraversion: reenigne
boot/kernel/gentoo/gk_kernargs: --all-ramdisk-modules
boot/kernel/gentoo/sources: ${KERNEL_SOURCES}
boot/kernel/gentoo/config: files/kernel-${PROFILE_SHORTNAME}.config
boot/kernel/gentoo/extraversion: openstack
boot/kernel/gentoo/gk_kernargs: --all-ramdisk-modules --makeopts=-j6

# all of the cleanup...
stage4/unmerge:
sys-kernel/genkernel
sys-kernel/gentoo-sources
sys-kernel/hardened-sources

stage4/empty:
/root/.ccache
/tmp
/usr/portage/distfiles
/usr/src
/var/cache/edb/dep
/var/cache/genkernel
/var/empty
/var/run
/var/state
/var/tmp

stage4/rm:
/etc/*-
/etc/*.old
/etc/ssh/ssh_host_*
/root/.*history
/root/.lesshst
/root/.ssh/known_hosts
/root/.viminfo
# Remove any generated stuff by genkernel
/usr/share/genkernel
# This is 3MB of crap for each copy
/usr/lib64/python*/site-packages/gentoolkit/test/eclean/testdistfiles.tar.gz
EOF

# Run catalyst
Expand All @@ -55,4 +122,4 @@ catalyst -f "${SPECFILE}"
rm "${SPECFILE}"

# Move the outputted image
mv "/var/tmp/catalyst/builds/default/stage4-amd64-${DATE}.tar.bz2" "${OUTFILE}"
mv "/var/tmp/catalyst/builds/${PROFILE_SHORTNAME}/stage4-amd64-${DATE}.tar.bz2" "${OUTFILE}"
96 changes: 56 additions & 40 deletions 03-prep-that-image.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,64 +1,80 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Okay, so here's some real meat. We take a drive (as 02 said, I use a VM),
# and we spray that stage4 all over it. Then we rub some grub (0.97) all over
# it to make it feel better, and then we box it up and ship it out.

##
## Vars
##
TARGET_DISK=vdd
TEMP_DIR=/image-prep/gentoo
TARGET_IMAGE=/var/www/reenigne-gentoo-`date +%Y-%m-%d`
MOUNT_DIR=/mnt
ORIG_DIR=`pwd`
TARBALL=/image-prep/gentoo/stage4.tar.bz2
set -e -u -x -o pipefail

# Vars
export TEMP_DIR=${TEMP_DIR:-'/root/tmp/catalyst/gentoo'}
export MOUNT_DIR=${MOUNT_DIR:-'/mnt'}
export DATE=${DATE:-"$(date +%Y%m%d)"}
export PORTAGE_DIR=${PORTAGE_DIR:-"/var/tmp/catalyst/snapshots"}
# profiles supported are as follows
# default/linux/amd64/13.0
# default/linux/amd64/13.0/no-multilib
# hardened/linux/amd64
# hardened/linux/amd64/no-multilib
# hardened/linux/amd64/selinux (eventually)
# hardened/linux/amd64/no-multilib/selinux (eventually)
export PROFILE=${PROFILE:-"default/linux/amd64/13.0"}
if [[ "${PROFILE}" == "default/linux/amd64/13.0" ]]; then
PROFILE_SHORTNAME="amd64-default"
elif [[ "${PROFILE}" == "default/linux/amd64/13.0/no-multilib" ]]; then
PROFILE_SHORTNAME="amd64-default-nomultilib"
elif [[ "${PROFILE}" == "hardened/linux/amd64" ]]; then
PROFILE_SHORTNAME="amd64-hardened"
elif [[ "${PROFILE}" == "hardened/linux/amd64/no-multilib" ]]; then
PROFILE_SHORTNAME="amd64-hardened-nomultilib"
else
echo 'invalid profile, exiting'
exit 1
fi
export TARBALL=${TARBALL:-"/root/tmp/catalyst/gentoo/stage4-${PROFILE_SHORTNAME}-${DATE}.tar.bz2"}
export TEMP_IMAGE=${TEMP_IMAGE:-"gentoo-${PROFILE_SHORTNAME}.img"}
export TARGET_IMAGE=${TARGET_IMAGE:-"/root/openstack-${PROFILE_SHORTNAME}-${DATE}.qcow2"}

# create a raw partition and do stuff with it
fallocate -l 1G "${TEMP_DIR}/${TEMP_IMAGE}"
BLOCK_DEV=$(losetup -f --show "${TEMP_DIR}/${TEMP_IMAGE}")

# Okay, we have the disk, let's prep it
echo 'Building disk'
parted -s /dev/$TARGET_DISK mklabel msdos
parted -s --align=none /dev/$TARGET_DISK mkpart primary 2048s 100%
parted -s /dev/$TARGET_DISK set 1 boot on
mkfs.ext4 -F /dev/${TARGET_DISK}1
parted -s "${BLOCK_DEV}" mklabel gpt
parted -s --align=none "${BLOCK_DEV}" mkpart bios_boot 0 2M
parted -s --align=none "${BLOCK_DEV}" mkpart primary 2M 100%
parted -s "${BLOCK_DEV}" set 1 boot on
parted -s "${BLOCK_DEV}" set 1 bios_grub on
mkfs.ext4 -F "${BLOCK_DEV}p2"
e2label "${BLOCK_DEV}p2" cloudimg-rootfs

# Mount it
echo 'Mounting disk'
mount /dev/${TARGET_DISK}1 $MOUNT_DIR

# Let's localize commands now
cd $MOUNT_DIR
mkdir -p "${MOUNT_DIR}/${PROFILE_SHORTNAME}"
mount "${BLOCK_DEV}p2" "${MOUNT_DIR}/${PROFILE_SHORTNAME}"

# Expand the stage
echo 'Expanding tarball'
tar xjpf $TARBALL -C ./
tar --xattrs -xjpf "${TARBALL}" -C "${MOUNT_DIR}/${PROFILE_SHORTNAME}"

# Throw in a resolv.conf (because we download portage next)
cp /etc/resolv.conf etc/resolv.conf
#echo 'Adding in /usr/portage'
#tar --xattrs -xjpf "${PORTAGE_DIR}/portage-latest.tar.bz2" -C "${MOUNT_DIR}/${PROFILE_SHORTNAME}/usr"

# Catalyst doesn't give us portage, so that's cool
echo 'Downloading portage'
curl -s http://mirror.reenigne.net/gentoo/snapshots/portage-latest.tar.bz2 > portage-latest.tar.bz2
echo 'Expanding portage'
tar xjf portage-latest.tar.bz2 -C usr/
rm portage-latest.tar.bz2
# Install grub
echo 'Installing grub'
grub2-install "${BLOCK_DEV}" --root-directory "${MOUNT_DIR}/${PROFILE_SHORTNAME}/"

# Clean up
echo 'Syncing; unmounting'
sync
sleep 5; # To unmount, just in case. 5 seconds is nothing next to the dd below
cd $ORIG_DIR
umount $MOUNT_DIR

# Install grub
echo 'Installing grub'
printf "device (hd0) /dev/${TARGET_DISK}\nroot (hd0,0)\nsetup (hd0)\nquit\n" | grub --batch
umount "${MOUNT_DIR}/${PROFILE_SHORTNAME}"

# Now it's unmounted, but we need to make an image!
echo 'dding image'
dd if=/dev/$TARGET_DISK of=${TEMP_DIR}/temp.raw
# get rid of block mapping
losetup -d "${BLOCK_DEV}"

echo 'Converting dd image to qcow2'
qemu-img convert -c -f raw -O qcow2 ${TEMP_DIR}/temp.raw ${TARGET_IMAGE}.qcow2
echo 'Converting raw image to qcow2'
qemu-img convert -c -f raw -O qcow2 "${TEMP_DIR}/${TEMP_IMAGE}" "${TARGET_IMAGE}"

echo 'Cleaning up'
rm ${TEMP_DIR}/temp.raw
rm "${TEMP_DIR}/${TEMP_IMAGE}"
Loading