elixir/utils/index-repository
Théo Lebrun 9d90b07201 utils/index-repository: support calling on existing repository
Make utils/index-repository idempotent, meaning we can call it multiple
times on the same repo and same remotes without issues.

Also allow adding new remotes to an existing repo.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2025-01-31 19:27:17 +01:00

45 lines
1 KiB
Bash
Executable file

#!/bin/sh
if [ "$#" -lt 2 ]; then
echo "Usage: $0 repo_name repo_urls..."
exit 1
fi
export ELIXIR_INSTALL=$(dirname $(dirname $(readlink -f "$0")))
. $ELIXIR_INSTALL/utils/common.sh
dir=/srv/elixir-data/$1
mkdir -p $dir/data $dir/repo
git="git -C $dir/repo"
# This doesn't fail if repo already exists
$git init --bare
git config --system --add safe.directory $dir/repo
existing_remotes="$($git remote | xargs -L1 -r $git remote get-url | sort -u)"
shift
i="$($git remote | awk '
BEGIN { n=-1; }
$0 ~ /^remote[0-9]+$/ { i=substr($0, length("remote")+1);
if (i>n) n=i; }
END { print n+1; }')"
for remote
do
# Don't `git remote add` remotes that already exist, which is not an error.
if echo "$existing_remotes" | grep -qF "$remote"; then
continue;
fi
$git remote add remote$i $remote
i=$(($i+1))
done
$git fetch --all --tags -j4
export LXR_REPO_DIR=$dir/repo
export LXR_DATA_DIR=$dir/data
python3 /usr/local/elixir/update.py $ELIXIR_THREADS