#!/bin/bash

# This script helps to create a tarball which contains 2 directories
# with ports: core from upstream CRUX and core-arm overlay
# Both dirs have the version number for each port that will be taken
# as the starting point

GIT_REPO_UPSTREAM="git://crux.nu/ports/core.git"
GIT_REPO_OVERLAY="git://crux-arm.nu/crux-arm/ports/core-arm.git"

# we used the tag created for CRUX and the first commit hash in CRUX-ARM
# CRUX-3.1 8ac5de3d6d32e963b8d90a130222052662cb6ef2 
# CRUX-ARM 3.1 574c4008c8d63ac004b5196615da9fd29ef0c1d3
GIT_BRANCH="3.2"
GIT_COMMIT_HASH_UPSTREAM="8ac5de3d6d32e963b8d90a130222052662cb6ef2"
GIT_COMMIT_HASH_OVERLAY="c3fae79db1ed58ddea2e72d291e90617a55f2e89"

PWD_DIR=$(pwd)
TMP_DIR=$(mktemp -d)

cd $TMP_DIR && \
  git clone $GIT_REPO_UPSTREAM && \
  cd core && \
  git checkout $GIT_BRANCH && \
  git fetch && \
  git reset --hard $GIT_COMMIT_HASH_UPSTREAM && \
  rm -rvf .git README && \
  cd .. && \
  git clone $GIT_REPO_OVERLAY && \
  cd core-arm && \
  git branch $GIT_BRANCH origin/$GIT_BRANCH && \
  git checkout $GIT_BRANCH && \
  git fetch && \
  git reset --hard $GIT_COMMIT_HASH_OVERLAY && \
  rm -rvf .git README && \
  cd .. && \
  tar cvJf $PWD_DIR/crossrootfs-extras-$GIT_BRANCH.tar.xz core core-arm

rm -fr $TMP_DIR