| #!/usr/bin/env bash |
| |
| |
| |
| |
| |
| |
|
|
| |
| [ -e .env ] && . .env |
| ONLINE_MODE=false |
| UD_VER=${UD_VER:-"2.15"} |
| UD_REV="r${UD_VER}" |
| UDS_SUBDIR="UD_repos"; mkdir -p ${UDS_SUBDIR} |
| GIT_API_OUTPUT=".UniversalDependencies.repos" |
| GIT_SUBMODULES_ADD=".UD_submodules_add.commands" |
|
|
| |
|
|
| |
| |
| |
| |
| |
| usage() { OUTPUT=${1:-"verbose"} |
| echo "Usage: $0 [-o] [-r REV]" >&2 |
| [ $OUTPUT = "short" ] && exit 0 |
| >&2 cat << EOF |
| |
| Identify all relevant UD repositories from GitHub: |
| * https://github.com/UniversalDependencies/ |
| and generate a list of submodules to add to a (newly created) repository in the |
| subdirectory ${UDS_SUBDIR}/. |
| |
| "${GIT_API_OUTPUT}" contains the (saved) list of GitHub repositories; the |
| file can be updated by running this script with the '-o|--online' option. |
| "${GIT_SUBMODULES_ADD}" contains the list of submodules to add to the main |
| repository. |
| |
| Options: |
| -h Print this help message |
| -o|--online Enable online mode: (re-fetch UD repos from GitHub instead |
| of using ${GIT_API_OUTPUT}) |
| -r|--rev VER The UD GitHub tagged version to checkout (default: ${UD_VER}) |
| EOF |
| } |
| |
| |
| |
| |
|
|
| VALID_ARGS=$(getopt -o hor: --long help,online,rev: -- "$@") |
| if [[ $? -ne 0 ]]; then |
| usage "short" |
| exit 1; |
| fi |
|
|
| eval set -- "$VALID_ARGS" |
| while [ : ] |
| do |
| case "$1" in |
| -o | --online) ONLINE_MODE=true; shift ;; |
| -r | --rev) UD_VER="$2"; shift 2 ;; |
| -h | --help) usage; shift ; exit 0;; |
| --) shift ; break ;; |
| *) >&2 echo Unsupported option: $1; usage; exit 1;; |
| esac |
| done |
|
|
| set -uo pipefail |
|
|
| |
| get_github_api_content() { |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| (for pg in 1 2 3; do wget "https://api.github.com/orgs/UniversalDependencies/repos?page=$pg&per_page=100" -O - ; done ) \ |
| | grep clone_url \ |
| | grep -Po 'https://.*?(?=")' \ |
| > ${UDS_SUBDIR}/${GIT_API_OUTPUT} |
| } |
|
|
| |
| if [[ $ONLINE_MODE == true ]] || [[ ! -e ${UDS_SUBDIR}/${GIT_API_OUTPUT} ]]; then |
| |
| get_github_api_content |
| fi |
|
|
|
|
| MSG="" |
| echo "" > ${UDS_SUBDIR}/${GIT_SUBMODULES_ADD} |
| for r in $(cat ${UDS_SUBDIR}/${GIT_API_OUTPUT} | sort) |
| do |
| l=$(echo $r | perl -pe 's/.*\///' | cut -f 1 -d.) |
|
|
| |
| if [[ $l == UD_* ]] && [[ $l != UD_v2 ]] |
| then |
| |
| echo "git submodule add --depth 1 -- $r $l" \ |
| >> ${UDS_SUBDIR}/${GIT_SUBMODULES_ADD} |
|
|
| |
| if [[ ! -e ${UDS_SUBDIR}/$l ]] |
| then |
| |
| |
| |
|
|
| MSG="$MSG\n${UDS_SUBDIR}/$l" |
| fi |
| fi |
| done |
|
|
| |
| |
| echo "git submodule --quiet foreach 'export name; bash -c \"( REF=\$(git ls-remote --exit-code origin refs/tags/${UD_REV} | cut -f1) && [ ! -z \\\$REF ] && git fetch --depth=1 origin \\\$REF && echo \\\$REF > .tag-${UD_REV}) || ( echo No rev:${UD_REV} \\\$name )\" ' " >> ${UDS_SUBDIR}/${GIT_SUBMODULES_ADD} |
|
|
|
|
| echo "Missing repos:" |
| echo -e "$MSG" |
|
|
| if [[ ! -e ${UDS_SUBDIR}/.git ]] |
| then |
| echo "${UDS_SUBDIR}: "'missing .git: run `git init` in subdirectory!' |
| fi |
|
|