init: support checking out git branches
@@ -5,19 +5,21 @@ dn=$(dirname "$0")
# shellcheck source=src/cmdlib.sh
. "${dn}"/cmdlib.sh
-# Initialize FORCE to 0 and INSTALLER_DIR to null
+# Initialize FORCE to 0 and BRANCH/INSTALLER_DIR to an empty string
FORCE=0
INSTALLER_DIR=""
+BRANCH=""
print_help() {
cat 1>&2 <<'EOF'
Usage: coreos-assembler init --help
- coreos-assembler init [--force] [--installerdir INSTALLER_DIR] GITCONFIG [SUBDIR]
+ coreos-assembler init [--force] [--branch BRANCH] [--installerdir INSTALLER_DIR] GITCONFIG [SUBDIR]
For example, you can use https://github.com/coreos/fedora-coreos-config
as GITCONFIG, or fork it. Another option useful for local development
(if you're running a shell inside this container) is to pass a file path
starting with `/` - a symlink to it will be created and then used directly.
+ You can specify a branch of a git repo with the `--branch` flag.
If specified, SUBDIR is a subdirectory of the git repository that should
contain manifest.yaml and image.ks.
@@ -29,7 +31,7 @@ EOF
# Call getopt to validate the provided input.
rc=0
-options=$(getopt --options hfi: --longoptions help,force,installerdir: -- "$@") || rc=$?
+options=$(getopt --options hfb:i: --longoptions help,force,branch:,installerdir: -- "$@") || rc=$?
[ $rc -eq 0 ] || {
print_help
exit 1
@@ -44,6 +46,15 @@ while true; do
-f | --force)
FORCE=1
;;
+ -b | --branch)
+ case "$2" in
+ "")
+ shift ;;
+ *)
+ BRANCH="$2"
+ shift ;;
+ esac
+ ;;
-i | --installerdir)
case "$2" in
"")
@@ -112,6 +123,7 @@ repository_dir=${repository_dirs[$arch]}
INSTALLER=https://download.fedoraproject.org/pub/$repository_dir/releases/$release/Everything/$arch/iso/Fedora-Everything-netinst-$arch-$release-1.1.iso
INSTALLER_CHECKSUM=https://download.fedoraproject.org/pub/$repository_dir/releases/$release/Everything/$arch/iso/Fedora-Everything-$release-1.1-$arch-CHECKSUM
+set -x
# Initialize sources (git)
mkdir -p src
(cd src
@@ -119,6 +131,9 @@ mkdir -p src
case "${source}" in
/*) ln -sr "${source}/${subdir}" config;;
*) git clone "${source}" config
+ if [ -n "${BRANCH}" ]; then
+ git -C config checkout "${BRANCH}"
+ fi
if [ -n "${subdir}" ]; then
mv config config-git
ln -sr config-git/"${subdir}" config
