#!/bin/sh # # Copyright (C) 2021 Denis 'GNUtoo' Carikli # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . set -e usage() { echo "$0 [-j N]" echo " -j N use at most N download jobs to run in parallel;" echo " the default is 4;" exit 1 } jobs=4 get_option() { option="$1" value="$2" if [ "${option}" = "-j" ] ; then jobs="${value}" else usage fi } if [ $# -ne 2 -a $# -ne 4 ] ; then usage elif [ $# -eq 4 ] ; then get_option "$3" "$4" fi tag="$1" outdir="$2" replicant_dir="${outdir}/${tag}" repo_branch="refs/tags/${tag}" version="$(echo ${tag} | sed 's/replicant-//')" major_version="$(echo ${version} | sed 's/-.*//')" minor_version="$(echo ${version} | sed 's/.*-//')" mkdir -p "${replicant_dir}" cd "${replicant_dir}" if [ ! -d .repo ] ; then yes | repo init \ -u https://git.replicant.us/replicant/manifest.git \ -b "${repo_branch}" \ --depth=1 || rm -rf .repo/ fi # We have an issue with all the Replicant releases before Replicant 6.0-0001: # All the manifests use git://, however over the time we moved several git # repositories and wrote some apache redirect rules to handle that. # Due to that, only http:// and https:// work fine. # This should be fixed in all the replicant--dev branches, however # we cannot use that here as we are making tarballs of former releases. if [ $(echo ${major_version} | sed 's/\..*//') -lt 6 ] ; then sed 's#git://#https://#g' -i \ .repo/manifests/default.xml fi repo sync -j "${jobs}" # We want the exact same source code used to build the images, so we need to # remove all the modifications we did to enable fetching the source code if [ $(echo $major_version | sed 's/\..*//') -lt 6 ] ; then git -C .repo/manifests reset --hard fi cd .. tarball="${tag}.tar" if [ ! -f "${tarball}" ] && [ ! -f "${tarball}.lz" ] ; then tar cf "${tarball}" "${tag}" || rm -f "${tarball}" fi # TODO: Make the tarball reproducible by removing metadata lzip -vv -9 "${tarball}"