From 08144baa42a39860f2f16ddbb21b8d0cf30fcc49 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Wed, 27 Dec 2023 22:49:39 +0000 Subject: [PATCH] feat: will now only update teh links if they change, or if an override is passed --- .gitlab-ci.yml | 1 + sync/.gitignore | 4 +++- sync/sync.sh | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a431299..f9d6ad4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,6 +48,7 @@ sync_repos: - chmod +x ./sync.sh - ./sync.sh rules: + - if: '$SYNC_OVERRIDE == "true"' - changes: - sync/repos.csv diff --git a/sync/.gitignore b/sync/.gitignore index 6b8afe3..a153487 100644 --- a/sync/.gitignore +++ b/sync/.gitignore @@ -1,2 +1,4 @@ /.idea -.env \ No newline at end of file +.env +repos_active.csv +repos_diff.csv \ No newline at end of file diff --git a/sync/sync.sh b/sync/sync.sh index ba42cf4..87c27e5 100644 --- a/sync/sync.sh +++ b/sync/sync.sh @@ -1,5 +1,13 @@ #!/bin/bash +Get-Existing(){ + curl -s "https://gitlab.skynet.ie/compsoc1/skynet/nixos/-/raw/main/sync/repos.csv" -o "./repos_active.csv" +} + +Get-Diff(){ + diff --changed-group-format='%<' --unchanged-group-format='' repos.csv repos_active.csv > repos_diff.csv +} + Mirror-Clear(){ # existing remotes local id=$(tr -d '\n\t\r ' <<<"${1}" ) @@ -35,11 +43,19 @@ Main() { # for local dev source .env + # if SYNC_OVERRIDE is not set then + if [ -z "${SYNC_OVERRIDE}" ]; then + Get-Existing + Get-Diff + else + cp repos.csv repos_diff.csv + fi + while IFS="," read -r id remote do Mirror-Clear $id Mirror-Create $id $remote - done < <(tail -n +2 ./repos.csv) + done < <(tail -n +2 ./repos_diff.csv) } Main \ No newline at end of file