All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
publish.sh
Go to the documentation of this file.
1 #!/usr/bin/env bash
2 #
3 # Ran without arguments, will publish the current Doxygen output.
4 #
5 #
6 # Changes
7 # --------
8 #
9 # 20220301 (petrillo@slac.stanford.edu) [v1.2]
10 # * added `--overwrite` option and reworked the internals of the update mode
11 # * added `--force` option (affects only `--overwrite` so far)
12 # * added current directory as priority source for the location of Doxyfile
13 # 20200520 (petrillo@slac.stanford.edu) [v1.1]
14 # * added script argument parsing
15 # * added `--update` option
16 # * the option to remove the existing data (`CleanOutputArea`) is not enabled
17 #
18 
19 
20 # -- BEGIN -- boilerplate settings and library loading -------------------------
21 SCRIPTNAME="$(basename "$0")"
22 SCRIPTDIR="$(dirname "$0")"
23 
24 declare LibraryToLoad
25 for LibraryToLoad in 'settings.sh' 'utilities.sh' ; do
26 
27  source "${SCRIPTDIR%/}/${LibraryToLoad}" || exit $?
28 
29 done
30 unset LibraryToLoad
31 # -- END -- boilerplate settings and library loading ---------------------------
32 
33 # ------------------------------------------------------------------------------
34 SCRIPTVERSION="1.2"
35 
36 
37 declare -r RepoDir="./"
38 
39 declare -r UpdateMode='update'
40 declare -r OverwriteMode='overwrite'
41 declare -r CleanPublishMode='newonly'
42 
43 
44 # ------------------------------------------------------------------------------
45 function printHelp() {
46 
47  cat <<EOH
48 
49 Copies the documentation into the public web page storage area.
50 
51 Usage: ${SCRIPTNAME} [options]
52 
53 Supported options:
54 --srcdocdir=SOURCEDIR [autodetect]
55  directory where the HTML documentation has been rendered
56 --experiment=EXPERIMENTNAME [autodetect]
57  the name of the experiment (e.g. 'MicroBooNE')
58 --codeversion=VERSION [from metadata]
59  the version of the code being documented
60 --update
61  if there is already documentation for the same version, update it
62  instead of refusing to proceed; the existing directory is not removed
63  before publishing
64 --overwrite
65  destination directory is fully removed before the copy proceeds
66 --force
67  in options like \`--overwrite\` it does not ask for confirmation
68 --version , -V
69  prints the script version and exits (hint: it's version ${SCRIPTVERSION}
70 --help , -h , -?
71  prints this usage message and exits
72 
73 EOH
74 
75 } # printHelp()
76 
77 
78 function printVersion() {
79  echo "${SCRIPTNAME} version ${SCRIPTVERSION}."
80 } # printVersion()
81 
82 
83 ################################################################################
84 ### Start here!
85 ################################################################################
86 #
87 # parameter parsing
88 #
89 declare -i NoMoreOptions
90 declare -i DoVersion=0 DoHelp=0
91 declare PublishMode="$CleanPublishMode"
92 declare ExitWithCode
93 declare Param
94 for (( iParam = 1 ; iParam <= $# ; ++iParam )); do
95  Param="${!iParam}"
96  if isFlagUnset NoMoreOptions && [[ "${Param:0:1}" == '-' ]]; then
97  case "$Param" in
98  ( '--experiment='* ) ExperimentName="${Param#--*=}" ;;
99  ( '--srcdocdir='* ) SourceDir="${Param#--*=}" ;;
100  ( '--codeversion='* ) Version="${Param#--*=}" ;;
101  ( '--update' ) PublishMode="$UpdateMode" ;;
102  ( '--overwrite' ) PublishMode="$OverwriteMode" ;;
103  ( '--force' ) FORCE=1 ;;
104  ( '--version' | '-V' ) DoVersion=1 ;;
105  ( '--help' | '-h' | '-?' ) DoHelp=1 ;;
106  ( '-' | '--' ) NoMoreOptions=1 ;;
107  ( * )
108  ERROR "Unknown option: '${Param}'."
109  ExitWithCode=1
110  esac
111  else
112  PositionalArguments+=( "$Param" )
113  fi
114 done
115 
116 [[ "${#PositionalArguments[@]}" -gt 0 ]] && FATAL 1 "Found ${#PositionalArguments[@]} spurious arguments on command line: ${PositionalArguments[@]}."
117 
118 : ${ExperimentName="$(FindExperiment)"}
119 LASTFATAL "Can't detect the experiment name."
120 
121 : ${ExperimentCodeName:="$(ExperimentCodeProduct "$ExperimentName")"}
122 LASTFATAL "Can't put together the experiment code repository name for '${ExperimentName}'."
123 
124 if isFlagSet DoVersion ; then
125  printVersion
126  [[ -z "$ExitWithCode" ]] && ExitWithCode=0
127 fi
128 if isFlagSet DoHelp ; then
129  printHelp
130  [[ -z "$ExitWithCode" ]] && ExitWithCode=0
131 fi
132 
133 [[ -n "$ExitWithCode" ]] && exit "$ExitWithCode"
134 
135 
136 # ------------------------------------------------------------------------------
137 #
138 # find the GIT repository (may contain doxygen file!)
139 #
140 declare GitRepoPath
141 GitRepoPath="$(FindGitRepository "$ExperimentCodeName")"
142 if [[ $? == 0 ]] && [[ -n "$GitRepoPath" ]]; then
143  echo "GIT repository: '${GitRepoPath}'"
144 else
145  echo "GIT repository not found."
146  GitRepoPath=""
147 fi
148 
149 #
150 # find the Doxygen configuration file
151 #
152 declare Doxyfile
153 Doxyfile="$(FindDoxyfile "$ExperimentName" "$(pwd)")"
154 if [[ $? == 0 ]] && [[ -n "$Doxyfile" ]]; then
155  echo "Doxygen configuration: '${Doxyfile}'"
156 else
157  echo "Doxygen configuration file not found."
158  Doxyfile=""
159 fi
160 
161 #
162 # finally find the directory of Doxygen output (hint: it's "html")
163 #
164 if [[ -z "$SourceDir" ]]; then
165  [[ -r "$Doxyfile" ]] || FATAL 1 "The source directory must be specified."
166  SourceDir="$(ExtractValueFromDoxyfile 'HTML_OUTPUT' "$Doxyfile")"
167  [[ -n "$SourceDir" ]] || FATAL 1 "Can't extract the output directory from the Doxygen configuration file."
168  echo "Doxygen output directory detected: '${SourceDir}'."
169  MetadataFile="${SourceDir%/}/${MetadataFileRelPath}"
170  if [[ -r "$MetadataFile" ]]; then
171  MetadataVersion="$(ExtractFromMetadata 'MetadataVersion' "$MetadataFile")"
172  echo " => metadata (version ${MetadataVersion}) found at: '${MetadataFile}'"
173  fi
174 fi
175 [[ -d "$SourceDir" ]] || FATAL 2 "Can't find the source directory '${SourceDir}'."
176 
177 #
178 # with metadata we know everything about generation of documentation
179 #
180 if [[ "${MetadataVersion:-0}" -ge 1 ]]; then
181  Version="$(ExtractFromMetadata 'CodeVersion' "$MetadataFile")"
182  [[ $? == 0 ]] && [[ -n "$Version" ]] && echo "Code version from metadata: ${Version}."
183 fi
184 
185 [[ -z "$Version" ]] && FATAL 1 "The version of the documentation must be specified."
186 
187 #
188 # transfer the content
189 #
190 declare TransferLogFile="${LogDir:+${LogDir%/}/}transfer-${ExperimentCodeName}-${Version}.log"
191 declare -r DestVersionsDir="${PublishBaseDir:+${PublishBaseDir%/}/}${ExperimentCodeName}"
192 mkdir -p "$DestVersionsDir"
193 declare -r DestDir="${DestVersionsDir}/${Version}"
194 if [[ -d "$DestDir" ]]; then
195  case "$PublishMode" in
196  ( "$OverwriteMode" )
197  echo "The existing content in '${DestDir}' will be removed before proceeding."
198  if isFlagUnset FORCE ; then
199  ConfirmOpt='-I'
200  echo "Please confirm the removal of its content:"
201  fi
202  rm -Rf $ConfirmOpt "$DestDir"
203  [[ -d "$DestDir" ]] && FATAL 1 "output directory won't be overwritten."
204  ;;
205  ( "$UpdateMode" )
206  echo "The existing content in '${DestDir}' will be updated."
207  # no action actually needed
208  ;;
209  ( "$CleanPublishMode" )
210  FATAL 1 "Output directory '${DestDir}' already exists: remove it first!"
211  ;;
212  ( * )
213  FATAL 1 "INTERNAL ERROR: PublishMode='${PublishMode}' not recognised."
214  ;;
215  esac
216 fi
217 declare -a Cmd=( rsync -av "${SourceDir%/}/" "${DestDir%/}/" ">&" "$TransferLogFile")
218 
219 echo "Copying the documentation content:"
220 echo "${Cmd[@]}"
221 eval "${Cmd[@]}"
222 LASTFATAL "Error while copying the content from '${SourceDir}' to '${DestDir}'."
223 
224 #
225 # update the link
226 #
227 echo "Updating latest version link:"
228 declare -r LatestLinkPath="${DestVersionsDir}/${LatestLinkName}"
229 [[ -h "$LatestLinkPath" ]] && rm "$LatestLinkPath"
230 ln -sfv "$(basename "$DestDir")" "$LatestLinkPath"
231 
process_name opflash particleana ie ie ie z
bool printHelp
then echo FATAL
function LASTFATAL()
Definition: utilities.sh:25
do source
pdgs p
Definition: selectors.fcl:22
#define the
SCRIPTNAME
Definition: publish.sh:21
process_name gaushit a
while getopts h
BEGIN_PROLOG V
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
then shift fi
then echo Work directory not specified exit fi echo Work directory
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker options
do i e
T copy(T const &v)
then echo fcl name
esac echo uname r
do Param
function isFlagUnset()
Definition: utilities.sh:12
experiment
Definition: ffttest.sh:3