mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-07 21:16:57 +02:00
117 lines
4.4 KiB
Bash
Executable File
117 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
#
|
|
# This uses Gentoo's catalyst for very thoroughly building images from
|
|
# scratch. Using images based on this will eliminate some of the hackery
|
|
# in make_chroot.sh for building up the sdk from a stock stage3 tarball.
|
|
#
|
|
# For reference the procedure it performs is this:
|
|
#
|
|
# 1. snapshot: Grab a snapshot of portage-stable. Note that overalys are
|
|
# not snapshotted.
|
|
# 2. stage1: Using a "seed" tarball as a build environment, build a
|
|
# minimal root file system into a clean directory using ROOT=...
|
|
# and USE=-* The restricted USE flags are key be small and avoid
|
|
# circular dependencies.
|
|
# 3. stage2: Run portage-stable/scripts/bootstrap.sh
|
|
# This rebuilds the toolchain. Probably not strictly necessary most of
|
|
# the time but does super-duper-promise that the toolchain isn't linked
|
|
# to or otherwise influenced by whatever was in the "seed" tarball.
|
|
# 4. stage3: Run emerge -e system to rebuild everything using the fresh
|
|
# toolchain using the normal USE flags provided by the profile. This
|
|
# will also pull in assorted base system packages that weren't included
|
|
# in the minimal environment stage1 created.
|
|
# 5. stage4: Install any extra packages or other desired tweaks. For the
|
|
# sdk we just install all the packages normally make_chroot.sh does.
|
|
#
|
|
# Usage: bootstrap_sdk [stage1 stage2 etc]
|
|
# By default all four stages will be built using the latest stage4 as a seed.
|
|
|
|
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
|
|
. "${SCRIPT_ROOT}/common.sh" || exit 1
|
|
|
|
TYPE="coreos-sdk"
|
|
ARCH=$(portageq envvar ARCH)
|
|
DEFAULT_PROFILE="coreos:default/linux/${ARCH}/10.0"
|
|
UPLOAD_ROOT="gs://storage.core-os.net/coreos/sdk/${ARCH}"
|
|
|
|
. "${SCRIPT_ROOT}/lib/catalyst.sh" || exit 1
|
|
|
|
DEFINE_boolean parallel ${FLAGS_TRUE} "Enable parallelism in gsutil."
|
|
DEFINE_boolean upload ${FLAGS_FALSE} \
|
|
"Upload final tarball and all packages via gsutil."
|
|
|
|
## Define the stage4 config template
|
|
catalyst_stage4() {
|
|
cat <<EOF
|
|
target: stage4
|
|
pkgcache_path: $BINPKGS
|
|
stage4/packages: dev-python/setuptools dev-vcs/git app-arch/pbzip2 net-misc/curl app-admin/sudo app-shells/bash-completion sys-devel/crossdev coreos-base/hard-host-depends
|
|
stage4/fsscript: ${SCRIPT_ROOT}/lib/catalyst_stage4.sh
|
|
EOF
|
|
catalyst_stage_default
|
|
}
|
|
|
|
catalyst_init "$@"
|
|
|
|
# Search for .boto, this runs under sudo so ~/.boto may not be right
|
|
if [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]]; then
|
|
for boto in "$HOME/.boto" "/home/$SUDO_USER/.boto" /etc/boto.cfg; do
|
|
if [[ -f "$boto" ]]; then
|
|
info "Using boto config $boto"
|
|
export BOTO_CONFIG="$boto"
|
|
break
|
|
fi
|
|
done
|
|
if [[ ! -f "$BOTO_CONFIG" ]]; then
|
|
die_notrace "Please run gsutil config to create ~/.boto"
|
|
fi
|
|
fi
|
|
|
|
catalyst_build
|
|
|
|
info "Build complete! Changing output name to something more sensible."
|
|
build_name="stage4-${ARCH}-${FLAGS_version}.tar.bz2"
|
|
release_name="${TYPE}-${ARCH}-${FLAGS_version}.tar.bz2"
|
|
ln -f "$BUILDS/${build_name}" "$BUILDS/${release_name}"
|
|
ln -f "$BUILDS/${build_name}.CONTENTS" "$BUILDS/${release_name}.CONTENTS"
|
|
sed -e "s/${build_name}/${release_name}/" \
|
|
"$BUILDS/${build_name}.DIGESTS" > "$BUILDS/${release_name}.DIGESTS"
|
|
|
|
# Validate we didn't break the DIGESTS with sed
|
|
for hash_type in md5 sha1 sha512; do
|
|
info "Validating ${hash_type} DIGESTS"
|
|
# shash is what's used to generate these multi-hash digests but it
|
|
# doesn't exit with non-zero on failure. I mean seriously...
|
|
#shash -c "$BUILDS/${release_name}.DIGESTS" -a "${hash_type}"
|
|
# So we do it the hard way...
|
|
grep -qi "^# ${hash_type} HASH$" "$BUILDS/${release_name}.DIGESTS"
|
|
(cd "$BUILDS" && grep -A1 -i "^# ${hash_type} HASH$" \
|
|
"${release_name}.DIGESTS" | grep -v '^--$' | \
|
|
${hash_type}sum -c - --strict)
|
|
done
|
|
|
|
info "SDK ready: $BUILDS/${release_name}"
|
|
|
|
GSUTIL_OPTS=
|
|
if [[ ${FLAGS_parallel} -eq ${FLAGS_TRUE} ]]; then
|
|
GSUTIL_OPTS="-m"
|
|
fi
|
|
|
|
if [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]]; then
|
|
info "Uploading tarball"
|
|
gsutil ${GSUTIL_OPTS} cp \
|
|
"$BUILDS/${release_name}" \
|
|
"$BUILDS/${release_name}.CONTENTS" \
|
|
"$BUILDS/${release_name}.DIGESTS" \
|
|
"${UPLOAD_ROOT}/${FLAGS_version}/"
|
|
info "Uploading packages"
|
|
gsutil ${GSUTIL_OPTS} cp -R "${BINPKGS}"/* \
|
|
"${UPLOAD_ROOT}/${FLAGS_version}/pkgs/"
|
|
fi
|
|
|
|
info "Done!"
|