1#!/usr/bin/env bash 2 3# Copyright 2011 The Go Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style 5# license that can be found in the LICENSE file. 6 7# This script creates a .zip file representing the $GOROOT file system 8# and computes the corresponding search index files. 9# 10# These are used in production (see app.prod.yaml) 11 12set -e -u -x 13 14ZIPFILE=godoc.zip 15INDEXFILE=godoc.index 16SPLITFILES=index.split. 17 18error() { 19 echo "error: $1" 20 exit 2 21} 22 23install() { 24 go install 25} 26 27getArgs() { 28 if [ ! -v GODOC_DOCSET ]; then 29 GODOC_DOCSET="$(go env GOROOT)" 30 echo "GODOC_DOCSET not set explicitly, using GOROOT instead" 31 fi 32 33 # safety checks 34 if [ ! -d "$GODOC_DOCSET" ]; then 35 error "$GODOC_DOCSET is not a directory" 36 fi 37 38 # reporting 39 echo "GODOC_DOCSET = $GODOC_DOCSET" 40} 41 42makeZipfile() { 43 echo "*** make $ZIPFILE" 44 rm -f $ZIPFILE goroot 45 ln -s "$GODOC_DOCSET" goroot 46 zip -q -r $ZIPFILE goroot/* # glob to ignore dotfiles (like .git) 47 rm goroot 48} 49 50makeIndexfile() { 51 echo "*** make $INDEXFILE" 52 godoc=$(go env GOPATH)/bin/godoc 53 # NOTE: run godoc without GOPATH set. Otherwise third-party packages will end up in the index. 54 GOPATH= $godoc -write_index -goroot goroot -index_files=$INDEXFILE -zip=$ZIPFILE 55} 56 57splitIndexfile() { 58 echo "*** split $INDEXFILE" 59 rm -f $SPLITFILES* 60 split -b8m $INDEXFILE $SPLITFILES 61} 62 63cd $(dirname $0) 64 65install 66getArgs "$@" 67makeZipfile 68makeIndexfile 69splitIndexfile 70rm $INDEXFILE 71 72echo "*** setup complete" 73