From 14a433fea892b3d771e9cfcaed6919939e4f39a8 Mon Sep 17 00:00:00 2001 From: Esteban Carnevale Date: Mon, 2 Sep 2013 20:03:36 -0300 Subject: Modify Makefile to deploy all profile branches using script "expand". --- Makefile | 12 +++-- expand | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 5 deletions(-) create mode 100755 expand diff --git a/Makefile b/Makefile index cb5f9e4..397ec3c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -V=6 +V=2013.08.12 INSTALL_SRC_DIR=parabolaiso/initcpio/install HOOKS_SRC_DIR=parabolaiso/initcpio/hooks @@ -15,7 +15,7 @@ all: install dist install: install-program install-initcpio install-examples install-doc install-program: - install -D -m 755 parabolaiso/mkparabolaiso "$(DESTDIR)/usr/sbin/mkparabolaiso" + install -D -m 755 parabolaiso/mkparabolaiso "$(DESTDIR)/usr/bin/mkparabolaiso" install-initcpio: install -d "$(SCRIPT_DIR)" "$(HOOKS_DIR)" "$(INSTALL_DIR)" @@ -49,7 +49,9 @@ uninstall-doc: rm -rf "$(DOC_DIR)" dist: - git archive --format=tar --prefix=parabolaiso-$(V)/ v$(V) | gzip -9 > parabolaiso-$(V).tar.gz - gpg --detach-sign --use-agent parabolaiso-$(V).tar.gz + ./expand $(V) dist -.PHONY: install install-program install-initcpio install-examples install-doc dist uninstall uninstall-program uninstall-initcpio uninstall-examples uninstall-doc +dist-branches: + ./expand $(V) dist-branches + +.PHONY: install install-program install-initcpio install-examples install-doc dist dist-branches uninstall uninstall-program uninstall-initcpio uninstall-examples uninstall-doc diff --git a/expand b/expand new file mode 100755 index 0000000..5234379 --- /dev/null +++ b/expand @@ -0,0 +1,181 @@ +#!/bin/bash + +set -e + +version="$1" + +type="$2" + +### CONFIGURATION OPTIONS + +# Profiles to package in addition to the profile releng for the make target "dist-branches" +branches_dist_branches=(baseline gnome toolkit) + +# Profiles to package in addition to the profile releng for the make target "dist" +branches_dist=(baseline) + +### END OF CONFIGURATION OPTIONS + +error() { + echo "${@}. Stop." >&2 + exit 1 +} + +dist_branches() { + branches="${branches_dist_branches}" + # Refs to package (the branches) + refs="${branches[@]}" + # Ref of the releng profile to package + releng="master" + # Release branch. This branch only has commits to prepare the package. + release_branch="release-branches" + # Release ref. It is a branch for dist_branches. The package is created from this ref. + release="${release_branch}" + # Refs that should exist for the make target dist-branches. This branches will be packaged. + allrefs=( ${releng} ${branches[@]} ) +} + +dist() { + branches="${branches_dist}" + # Refs to package (branch names appending the date, like "baseline/2013.08.12") + refs="${branches_dist[@]/%//${version}}" + # Ref of the releng profile to package + releng="master/${version}" + # Release branch. This branch only has commits to prepare the package. + release_branch="release" + # Release ref. Tag of commit in release_branch. The package is created from this ref. + release="release/${version}" + # These refs should exist to package for the make target dist. + allrefs=( ${releng} ${refs[@]} ) +} + +expand() { + ref="$1" + dir="$2" + + GIT_INDEX_FILE="${index}" git read-tree --empty + GIT_INDEX_FILE="${index}".release git read-tree --empty + + # Find the current head of ${ref} + head="$(git show-ref --hash "refs/${ref_type}/${ref}")" + # Find the current head of the release branch. + head_release="$(git show-ref --hash refs/heads/"${release_branch}")" + if [[ $dir == releng ]] ; then + # Read the tree of "$ref" with profile path rename into an index file. + git ls-tree -z -r "${head}" | sed -z "s|configs/profile|configs/${dir}|" | GIT_INDEX_FILE="${index}" git update-index -z --index-info + # Remove the master branch from the release index, that is, leave everything from configs/ excluding configs/releng + git ls-tree -z -r "${head_release}" | grep -zZP 'configs/(?!releng)' | GIT_INDEX_FILE="${index}".release git update-index -z --index-info + # This combines the two indexes (obtained in the last two commands). + GIT_INDEX_FILE="${index}".release git ls-files -z -s | GIT_INDEX_FILE="${index}" git update-index -z --add --index-info + else + # Read only paths configs/profile of "$ref" with profile path rename into an index file. + git ls-tree -z -r "${head}" -- configs/profile | sed -z "s|configs/profile|configs/${dir}|" | GIT_INDEX_FILE="${index}" git update-index -z --index-info + # Remove configs/${dir} from the release index. + git ls-tree -z -r "${head_release}" | grep -zZv configs/"${dir}" | GIT_INDEX_FILE="${index}".release git update-index -z --index-info + # This combines the two indexes (obtained in the last two commands). + GIT_INDEX_FILE="${index}".release git ls-files -z -s | GIT_INDEX_FILE="${index}" git update-index -z --add --index-info + fi + # Write the index file into the repo as a tree. + tree="$(GIT_INDEX_FILE="${index}" git write-tree)" + # Write a commit to the repo. + commit="$(echo "Update profile ${dir}" | git commit-tree "$tree" -p "${head_release}")" + # Update the head of the repository to be the new commit. + git update-ref refs/heads/"${release_branch}" "$commit" "${head_release}" +} + +expand_empty() { + ref="${releng}" + dir="releng" + + GIT_INDEX_FILE="${index}" git read-tree --empty + + # Find the current head of ${ref} + head="$(git show-ref --hash "refs/${ref_type}/${ref}")" + # Read the tree of "$ref" with profile path rename into an index file. + git ls-tree -z -r "${head}" | sed -z "s|configs/profile|configs/${dir}|" | GIT_INDEX_FILE="${index}" git update-index -z --index-info + # Write the index file into the repo as a tree. + tree="$(GIT_INDEX_FILE="${index}" git write-tree)" + # Write a commit to the repo. + commit="$(echo "Update profile ${dir}" | git commit-tree "$tree")" + # Update the head of the repository to be the new commit. + git update-ref refs/heads/"${release_branch}" "$commit" 0000000000000000000000000000000000000000 +} + +ref_test() { + es=0 + git show-ref --quiet "$1" || es=$? + + if [[ $es == 1 ]] ; then + error "$2" + elif [[ $es > 1 ]] ; then + error "$3" + fi +} + +ref_test_negative() { + es=0 + git show-ref --quiet "$1" || es=$? + + if [[ $es == 0 ]] ; then + error "$2" + elif [[ $es > 1 ]] ; then + error "$3" + fi +} + +release_prepare() { + ref_test_negative "refs/tags/${release}" "Release tag ${release} can not be created because it already exists" "Error testing the release tag" +} + +show_ref() { + for ref in ${allrefs[@]} ; do + ref_test "refs/${ref_type}/${ref}" "Git reference refs/${ref_type}/${ref} should exist" "Error testing git reference refs/${ref_type}/${ref}" + done +} + +archive_ref() { + git archive --format=tar.gz --prefix=parabolaiso-"${version}"/ "refs/${ref_type}/${release}" > parabolaiso-"${version}".tar.gz +} + +archive() { + git tag -s -m "tag ${release}" "${release}" "${release_branch}" + archive_ref + gpg --detach-sign --use-agent parabolaiso-"${version}".tar.gz +} + +dist_expand() { + index="$(mktemp)" + + es=0 + git show-ref --quiet "refs/heads/${release_branch}" || es=$? + + if [[ $es == 0 ]] ; then + expand "${releng}" releng + elif [[ $es == 1 ]] ; then + expand_empty + echo "Release branch created." + elif [[$es > 1 ]] ; then + error "Error testing the release branch" + fi + + for i in ${!branches[@]} ; do + expand ${refs[$i]} ${branches[$i]} + done +} + +if [[ ${type} == dist ]] ; then + ref_type="tags" + dist + release_prepare + show_ref + dist_expand + archive +elif [[ ${type} == dist-branches ]] ; then + ref_type="heads" + dist_branches + show_ref + dist_expand + archive_ref +else + error "Second argument is not correct" +fi -- cgit v1.2.2