diff --git a/build-docker.sh b/build-docker.sh index b6a9ea3d81..22c7174a33 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -30,6 +30,8 @@ do esac done +PI_GEN_REPO=${PI_GEN_REPO:-https://github.com/RPi-Distro/pi-gen} + # Ensure that the configuration file is an absolute path if test -x /usr/bin/realpath; then CONFIG_FILE=$(realpath -s "$CONFIG_FILE" || realpath "$CONFIG_FILE") @@ -55,7 +57,11 @@ exit 1 fi # Ensure the Git Hash is recorded before entering the docker container -GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"} +if [ -d "${DIR}"/.git ]; then + GIT_HASH=${GIT_HASH:-$(git rev-parse HEAD)} +else + GIT_HASH=$(git ls-remote --tags "${PI_GEN_REPO}" | grep $(basename "${DIR}" | cut -d'-' -f3-) | awk '{print $1}') +fi CONTAINER_EXISTS=$(${DOCKER} ps -a --filter name="${CONTAINER_NAME}" -q) CONTAINER_RUNNING=$(${DOCKER} ps --filter name="${CONTAINER_NAME}" -q) diff --git a/build.sh b/build.sh index a8247ab040..3394e8c934 100755 --- a/build.sh +++ b/build.sh @@ -179,7 +179,13 @@ export KEYBOARD_LAYOUT="${KEYBOARD_LAYOUT:-English (UK)}" export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}" -export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"} +if [ -z "${GIT_HASH}" ]; then + if [ -d "${BASE_DIR}"/.git ]; then + export GIT_HASH=${GIT_HASH:-$(git rev-parse HEAD)} + else + export GIT_HASH=$(git ls-remote --tags "${PI_GEN_REPO}" | grep $(basename "${BASE_DIR}" | cut -d'-' -f3-) | awk '{print $1}') + fi +fi export CLEAN export IMG_NAME