diff options
-rw-r--r-- | scripts/utils | 46 | ||||
-rwxr-xr-x | templates/turris4x.run | 9 |
2 files changed, 39 insertions, 16 deletions
diff --git a/scripts/utils b/scripts/utils index 4f8fbec..a689c12 100644 --- a/scripts/utils +++ b/scripts/utils @@ -5,6 +5,15 @@ jobid() { basename "$0" | sed 's/\.run$//' } +# Return current template's id +# If this is not template then this returns job's id +templateid() { + basename "$(readlink -f "$0")" | sed 's/\.run$//' +} + +TWORKSPACE="~/workspace/$(templateid)" +[ "$(jobid)" != "$(templateid)" ] || TWORKSPACE="~/workspace/notemplate" + ## Simple echo wrappers ######################################################### echo_stage() { echo -e "\033[1;34m========== $@ ==========\033[0m ($(date))" >&2 @@ -38,27 +47,42 @@ _check_trap() { } ################################################################################# -# Fetch bare git repository to WORKSPACE +# Fetch bare git repository # First argument has to be a source URL -# Second argument is name of directory to which will be repository cloned to. +# Second argument is path to directory to which will be repository cloned to. git_fetch_bare() { - if [ -d "$WORKSPACE/$2" ]; then - git --git-dir="$WORKSPACE/$2" --bare remote update --prune + if [ -d "$2" ]; then + git --git-dir="$2" --bare remote update --prune else - git clone --mirror "$1" "$WORKSPACE/$2" + git clone --mirror "$1" "$2" fi } -# Calls git_fetch_bare and then creates detached work tree in run directory +# Common function for git_fetch_{w,g} +# Additional fourth argument should be base path to git mirror +_git_fetch() { + local BRANCH="$3" + [ -n "$BRANCH" ] || BRANCH=master + git_fetch_bare "$1" "$4/$2" + git --git-dir="$4/$2" --bare worktree add --detach "$2" "$BRANCH" +} + +# Fetch git repository with mirror +# _w: mirror is in WORKSPACE +# _t: mirror is in TWORKSPACE +# _g: mirror is in global workspace # First agument has to be a source URL # Second argument is name of directory to which will be directory cloned in. # Second argument is optional and should be branch name (master is used if not # provided). -git_fetch() { - git_fetch_bare "$1" "$2" - local BRANCH="$3" - [ -n "$BRANCH" ] || BRANCH=master - git --git-dir="$WORKSPACE/$2" --bare worktree add --detach "$2" "$BRANCH" +git_fetch_w() { + _git_fetch "$1" "$2" "$3" "$WORKSPACE/git-mirror" +} +git_fetch_t() { + _git_fetch "$1" "$2" "$3" "$TWORKSPACE/git-mirror" +} +git_fetch_g() { + _git_fetch "$1" "$2" "$3" "~/workspace/git-mirror" } # Clones one depth given repository with given branch/tag/hash diff --git a/templates/turris4x.run b/templates/turris4x.run index 2c9e1ec..a916dc5 100755 --- a/templates/turris4x.run +++ b/templates/turris4x.run @@ -1,7 +1,6 @@ #!/bin/sh # vim: ft=sh set -e -GWORKSPACE=~/workspace/turris4x . utils MAKE="make -j4 IS_TTY=1 BUILD_LOG=1" @@ -18,14 +17,14 @@ else echo_stage "Get turris-build" HASH="$(awk '/ \* turris-build\: /{print $3}' git-hash)" - git_clone "https://gitlab.labs.nic.cz/turris/turris-build.git" turris-build "$HASH" + git_fetch_t "https://gitlab.labs.nic.cz/turris/turris-build.git" turris-build "$HASH" echo_stage "Prepare SDK" mkdir openwrt cd openwrt - echo ../turris-build/compile_fw -t $BOARD -p $BRANCH repo_prepare - GIT_MIRROR="$GWORKSPACE/mirror" \ - CCACHE_HOST_DIR="$GWORKSPACE/ccache-host" \ + echo "Template workspace: $TWORKSPACE/openwrt-git-mirror" + GIT_MIRROR="$TWORKSPACE/openwrt-git-mirror" \ + CCACHE_HOST_DIR="$TWORKSPACE/ccache-host" \ CCACHE_TARGET_DIR="$WORKSPACE/ccache-target" \ ../turris-build/compile_fw -t $BOARD -p $BRANCH repo_prepare |