52 lines
1.1 KiB
Bash
Executable file
52 lines
1.1 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
if [ "$#" -lt 2 ]; then
|
|
echo "Usage: $0 repo_name repo_urls..."
|
|
exit 1
|
|
fi
|
|
|
|
# $1 is the project path (inside will be created data/ and repo/).
|
|
# It supports being called on an existing project.
|
|
project_init() {
|
|
mkdir -p $1/data $1/repo
|
|
|
|
# This doesn't fail if repo already exists
|
|
git -C $1/repo init --bare
|
|
|
|
git config --system --add safe.directory $1/repo
|
|
}
|
|
|
|
dir=/srv/elixir-data/$1
|
|
|
|
project_init "$dir"
|
|
|
|
git="git -C $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
|
|
|
|
if test -z "$ELIXIR_THREADS"; then
|
|
ELIXIR_THREADS="$(nproc)"
|
|
fi
|
|
|
|
export LXR_REPO_DIR=$dir/repo
|
|
export LXR_DATA_DIR=$dir/data
|
|
python3 /usr/local/elixir/update.py $ELIXIR_THREADS
|