| #!/bin/ash |
| |
| # Copyright (C) 2024 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http:#www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| usage() { |
| me=`basename "$0"` |
| echo >&2 "Usage: $me [--help] [--output OUTPUT]" |
| exit 1 |
| } |
| |
| while test $# -gt 0 ; do |
| case "$1" in |
| --help) |
| usage |
| ;; |
| |
| --output) |
| shift |
| OUTPUT=$1 |
| shift |
| ;; |
| |
| *) |
| break |
| esac |
| done |
| |
| INDEX_TYPE="LUCENE" |
| INDEX_MODULE="$(git config --file /var/gerrit/etc/gerrit.config gerrit.installIndexModule | tr '[:upper:]' '[:lower:]')" |
| if [ "$INDEX_MODULE" = "elasticsearch" ]; then |
| INDEX_TYPE="ELASTICSEARCH" |
| elif [ "$INDEX_MODULE" = "opensearch" ]; then |
| INDEX_TYPE="OPENSEARCH" |
| fi |
| |
| JAVA_OPTIONS=$(git config --file /var/gerrit/etc/gerrit.config --get-all container.javaOptions) |
| java ${JAVA_OPTIONS} -jar /var/gerrit/bin/gerrit.war reindex \ |
| -d /var/gerrit \ |
| --read-only-disk-caches |
| |
| if [ "$INDEX_TYPE" = "LUCENE" ] && test -n "$OUTPUT"; then |
| INDEXES=$(java -jar /var/gerrit/bin/gerrit.war reindex -d /var/gerrit --list) |
| for INDEX in $INDEXES; do |
| LATEST_INDEX=$( |
| cd /var/gerrit/index && \ |
| find . -type d -name "${INDEX}_*" | \ |
| sort | \ |
| tail -n1 |
| ) |
| LATEST_INDEX=${LATEST_INDEX#"./"} |
| SHARED_INDEX_TARGET=$OUTPUT/$LATEST_INDEX |
| echo "Pruning $SHARED_INDEX_TARGET" |
| rm -rf $SHARED_INDEX_TARGET |
| echo "Copying $LATEST_INDEX to $SHARED_INDEX_TARGET" |
| cp -R /var/gerrit/index/$LATEST_INDEX $SHARED_INDEX_TARGET |
| done |
| fi |