#!/usr/bin/sh

# This simple script lists out the current pkgs git repos to a file.
# This speeds up cgit as it doesn't have to recurse into all dirs
# Looking for git repos.

destination=/var/lib/copr-dist-git/cgit_pkg_list

if [ -n "$1" ]
then
  destination=$1
fi

newfile=`mktemp`

# TODO: we should read the 'SetEnv GIT_PROJECT_ROOT /var/lib/dist-git/git'
# instead of hardcoding it here
cd /var/lib/dist-git/git

# We expect <user>/<copr>/<package>.git directories.
find -maxdepth 3 -mindepth 3 -type d -printf '%P\n' > "$newfile"
cp -fZ "$newfile" "$destination"
rm "$newfile"
chmod 644 "$destination"
