Skip to content

Instantly share code, notes, and snippets.

@anestisb
Last active June 25, 2019 14:56
Show Gist options
  • Save anestisb/dd211d3c2c15d1350edb to your computer and use it in GitHub Desktop.
Save anestisb/dd211d3c2c15d1350edb to your computer and use it in GitHub Desktop.
OpenGrok conf
#!/bin/bash
readonly HTML_OUT="/var/lib/tomcat8/webapps/ROOT/index.html"
readonly DATA_ROOT="/var/opengrok"
readonly GROK_ROOT="/opt/opengrok/opengrok-1.2.6"
declare -ar IGNORE_PATTERNS=(
"-i *.3gp"
"-i *.a"
"-i *.app"
"-i *.bc"
"-i *.bin"
"-i *.bmp"
"-i *.bz2"
"-i *.class"
"-i *.coff-i386"
"-i *.crl"
"-i *.crt"
"-i *.dat"
"-i *.der"
"-i *.dex"
"-i *.dll"
"-i *.doc"
"-i *.docx"
"-i *.dylib"
"-i *.elf"
"-i *.elf-i386"
"-i *.elf-mipsel"
"-i *.elf-x86-64"
"-i *.emz"
"-i *.exe"
"-i *.flac"
"-i *.gcda"
"-i *.gcno"
"-i *.gif"
"-i *.gmo"
"-i *.gz"
"-i *.gz-dtb"
"-i *.i386"
"-i *.ico"
"-i *.jar"
"-i *.jpeg"
"-i *.jpg"
"-i *.keyblock"
"-i *.m2v"
"-i *.m4a"
"-i *.macho-x86_64"
"-i *.mips64"
"-i *.mp3"
"-i *.mp4"
"-i *.nib"
"-i *.o"
"-i *.odt"
"-i *.ogg"
"-i *.ogv"
"-i *.p12"
"-i *.pcap"
"-i *.pcm"
"-i *.pdb"
"-i *.pdf"
"-i *.pkb"
"-i *.pkm"
"-i *.png"
"-i *.ppm"
"-i *.ppt"
"-i *.pptx"
"-i *.pyc"
"-i *.raw"
"-i *.rtp"
"-i *.ser"
"-i *.so"
"-i *.swf"
"-i *.tar"
"-i *.tbz2"
"-i *.tgz"
"-i *.tiff"
"-i *.ttf"
"-i *.v1"
"-i *.vblock"
"-i *.vbprivk"
"-i *.vbpubk"
"-i *.vco"
"-i *.vec"
"-i *.wav"
"-i *.wbm"
"-i *.wbmp"
"-i *.webm"
"-i *.webp"
"-i *.woff"
"-i *.xcf"
"-i *.xls"
"-i *.xlsx"
"-i *.yuv"
"-i *.zip"
"-i *Image.gz-dtb"
"-i *zImage-dtb"
"-i d:external/llvm/test"
"-i d:prebuilts"
"-i *.mbn"
"-i *.mdt"
"-i *.b00"
"-i *.b01"
"-i *.b02"
"-i *.b03"
"-i *.b04"
"-i *.b05"
"-i *.b06"
"-i *.b07"
"-i *.b08"
"-i *.b09"
"-i *.b10"
"-i *.b11"
"-i *.b12"
"-i *.b13"
"-i *.b14"
"-i *.b15"
"-i *.b16"
"-i *.b17"
"-i *.b18"
"-i *.b19"
"-i *.b20"
)
index_no_history() {
local label="$1"
opengrok-indexer -J=-Djava.util.logging.config.file=${DATA_ROOT}/${label}/logging.properties \
-J=-Xmx32g -J=-d64 -a ${GROK_ROOT}/lib/opengrok.jar -- \
-c /usr/local/src/ctags/ctags \
-s ${DATA_ROOT}/${label}/src -d ${DATA_ROOT}/${label}/data -P -S --progress -r off -t 4 -m 256 --verbose \
"${IGNORE_PATTERNS[*]}" -W ${DATA_ROOT}/${label}/etc/configuration.xml -U http://localhost:8080/${label}
}
index_with_history() {
local label="$1"
opengrok-indexer -J=-Djava.util.logging.config.file=${DATA_ROOT}/${label}/logging.properties \
-K=-Xmx32g -J=-d64 -a ${GROK_ROOT}/lib/opengrok.jar -- \
-c /usr/local/src/ctags/ctags \
-s ${DATA_ROOT}/${label}/src -d ${DATA_ROOT}/${label}/data -H -P -S -G --progress -t 4 -m 256 --verbose \
"${IGNORE_PATTERNS[*]}" -W ${DATA_ROOT}/${label}/etc/configuration.xml -U http://localhost:8080/${label}
}
guess_tag() {
local srcDir="${DATA_ROOT}/$1/src"
local outHtml="$2"
local tag
if [ -f "$srcDir/.repo/manifest.xml" ]; then
tag=$(grep -o "<default revision=\".*\"" "$srcDir/.repo/manifest.xml" | cut -d '=' -f2 | cut -d '"' -f2 | cut -d '/' -f3)
elif [ -d "$srcDir/.git" ]; then
tag="$(git -C "$srcDir" describe --tags)"
else
tag=""
fi
echo "$tag"
}
index_head() {
local outHtml="$1"
cat > "$outHtml" <<- EOM
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Source Code Index Server</title>
</head>
<body>
<ul>
EOM
}
index_entry() {
local repo="$1"
local tag="$2"
local outHtml="$3"
if [[ "$tag" != "" ]]; then
echo " <li><a href=\"/$repo/xref\">$repo ($tag)</a></li>" >> "$outHtml"
else
echo " <li><a href=\"/$repo/xref\">$repo</a></li>" >> "$outHtml"
fi
}
index_tail() {
local outHtml="$1"
cat >> "$outHtml" <<- EOM
</ul>
</body>
</html>
EOM
}
# Main
declare -a repos=(
"aosp_8.1"
"aosp_9.0"
"aosp_master"
"aosp_kernels"
"brave"
"chromium"
"misc"
"trusty"
"linux-kernel"
"msm-codeaurora"
"leaks"
)
/etc/init.d/tomcat8 restart
index_head "$HTML_OUT"
for repo in "${repos[@]}"
do
echo "[*] Indexing $repo"
index_no_history "$repo"
tag=$(guess_tag "$repo")
index_entry "$repo" "$tag" "$HTML_OUT"
done
index_tail "$HTML_OUT"
/etc/init.d/tomcat8 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment