Isabelle/DOF is a novel Document Ontology Framework on top of Isabelle. Isabelle/DOF allows for both conventional typesetting as well as formal development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

302 lines
11 KiB

  1. #!/usr/bin/env bash
  2. # Copyright (c) 2018-2019 The University of Sheffield.
  3. # 2019-2020 The University of Exeter.
  4. # 2018-2020 The University of Paris-Saclay.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in
  13. # the documentation and/or other materials provided with the
  14. # distribution.
  15. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  18. # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  19. # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  21. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  25. # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. # POSSIBILITY OF SUCH DAMAGE.
  27. #
  28. # SPDX-License-Identifier: BSD-2-Clause
  29. #set -e
  30. shopt -s nocasematch
  31. # get global configuration
  32. if [ -d .git ]; then
  33. export `git show -s --format="COMMIT=%H DATE=%cd" --date=short | sed -e 's|-|/|g'`
  34. fi
  35. source .config
  36. print_help()
  37. {
  38. echo "Usage: install [OPTION] "
  39. echo ""
  40. echo "Run ..."
  41. echo ""
  42. echo " --help, -h display this help message"
  43. echo " --isabelle, -i isabelle isabelle command used for installation"
  44. echo " (default: $ISABELLE)"
  45. echo " --skip-patch-and-afp, -s skip installation of Isabelle/DOF patch for"
  46. echo " Isabelle and required AFP entries. "
  47. echo " USE AT YOUR OWN RISK (default: $SKIP)"
  48. }
  49. exit_error() {
  50. echo ""
  51. echo " *** Isabelle/DOF installation FAILED, please check the README.md for help ***"
  52. echo ""
  53. exit 1
  54. }
  55. check_isabelle_version() {
  56. echo "* Checking Isabelle version:"
  57. if [ "$ISABELLE_VERSION" != "$ACTUAL_ISABELLE_VERSION" ]; then
  58. echo " WARNING:"
  59. echo " The version of Isabelle (i.e., $ACTUAL_ISABELLE_VERSION) you are using"
  60. echo " IS NOT SUPPORTED"
  61. echo " by the current version of Isabelle/DOF. Please install a supported"
  62. echo " version of Isabelle and rerun the install script, providing the"
  63. echo " the \"isabelle\" command as argument."
  64. echo " Isabelle ($ISABELLE_VERSION) can be obtained from:"
  65. echo " $ISABELLE_URL"
  66. echo
  67. read -p " Still continue (y/N)? " -n 1 -r
  68. echo
  69. if [[ $REPLY =~ ^[Yy]$ ]];
  70. then
  71. echo " Continuing installation on your OWN risk."
  72. else
  73. exit_error
  74. fi
  75. else
  76. echo " Success: found supported Isabelle version ($ISABELLE_VERSION)"
  77. fi
  78. }
  79. check_pdftex() {
  80. echo "* Checking (La)TeX installation:"
  81. OLDDIR=`pwd`
  82. DIR=`mktemp -d`
  83. cd $DIR;
  84. pdftex -interaction=nonstopmode \\expanded{Success}\\end > /dev/null
  85. if [ $? -eq 0 ]; then
  86. echo " Success: pdftex supports \\expanded{} primitive."
  87. else
  88. cd $OLDDIR
  89. echo " WARNING:"
  90. echo " The version of pdf(La)TeX you are using is outdated (and does"
  91. echo " not support the \\expanded primitive). It is not supported by the"
  92. echo " current version of Isabelle/DOF. Please install a supported TeX"
  93. echo " distribution (e.g., TeXLive 2019 or later)."
  94. echo
  95. read -p " Still continue (y/N)? " -n 1 -r
  96. echo
  97. if [[ $REPLY =~ ^[Yy]$ ]];
  98. then
  99. echo " Continuing installation on your OWN risk."
  100. else
  101. exit_error
  102. fi
  103. fi
  104. cd $OLDDIR
  105. }
  106. check_afp_entries() {
  107. echo "* Checking availability of AFP entries:"
  108. missing=""
  109. required="Regular-Sets Functional-Automata"
  110. for afp in $required; do
  111. res=`$ISABELLE build -n $afp 2>/dev/null || true`
  112. if [ "$res" != "" ]; then
  113. echo " Success: found APF entry $afp."
  114. else
  115. echo " Warning: could not find AFP entry $afp."
  116. missing="$missing $afp"
  117. fi
  118. done
  119. if [ "$missing" != "" ]; then
  120. echo " Trying to install AFP (this might take a few *minutes*) ...."
  121. extract=""
  122. for e in $missing; do
  123. extract="$extract $AFP_DATE/thys/$e"
  124. done
  125. mkdir -p .afp
  126. if curl -s -L $AFP_URL | tar zxf - -C .afp $extract; then
  127. for e in $missing; do
  128. echo " Registering $e in $ISABELLE_HOME_USER/ROOTS"
  129. touch $ISABELLE_HOME_USER/ROOTS
  130. grep -q $PWD/.afp/$AFP_DATE/thys/$e $ISABELLE_HOME_USER/ROOTS || echo "$PWD/.afp/$AFP_DATE/thys/$e" >> $ISABELLE_HOME_USER/ROOTS
  131. done
  132. echo " AFP installation successful."
  133. else
  134. echo " FAILURE: could not find AFP entries: $missing."
  135. echo " Please obtain the AFP from"
  136. echo " $AFP_URL"
  137. echo " and follow the following instructions:"
  138. echo " https://www.isa-afp.org/using.html"
  139. exit_error
  140. fi
  141. fi
  142. }
  143. check_isa_dof_patch() {
  144. echo "* Check availability of Isabelle/DOF patch:"
  145. src="src/patches/thy_output.ML"
  146. dst="$ISABELLE_HOME/src/Pure/Thy/thy_output.ML"
  147. if command -v cmp > /dev/null 2>&1 && cmp -s "$src" "$dst" ; then
  148. echo " Success: latest Isabelle/DOF patch already applied"
  149. if isabelle process -e 'Thy_Output.set_meta_args_parser' &> /dev/null ; then
  150. true
  151. else
  152. echo " Warning: Isabelle/HOL needs to be rebuild to activate patch."
  153. fi
  154. else
  155. command -v cmp >/dev/null 2>&1 || echo " Warning: cmp not available, cannot check if patch is already applied."
  156. echo " Warning: Isabelle/DOF patch is not available or outdated."
  157. echo " Trying to patch system ...."
  158. if [ ! -f "$dst.backup-by-isadof-installer" ]; then
  159. cp -f "$dst" "$dst.backup-by-isadof-installer" || true;
  160. fi
  161. if (cp -f $src $dst) &> /dev/null; then
  162. echo " Applied patch successfully, Isabelle/HOL will be rebuilt during"
  163. echo " the next start of Isabelle."
  164. else
  165. echo " FAILURE: Could not apply Isabelle/DOF patch."
  166. echo " Please copy $src to $dst, e.g.:"
  167. echo " cp -f $src $dst"
  168. echo " and rebuild Isabelle/HOL."
  169. exit_error
  170. fi
  171. fi
  172. }
  173. check_old_installation(){
  174. echo "* Searching for existing installation:"
  175. if [[ -d "$ISABELLE_HOME_USER/DOF" ]]; then
  176. echo " Found old installation, moving it to $ISABELLE_HOME_USER/DOF.bak."
  177. rm -rf "$ISABELLE_HOME_USER/DOF.bak"
  178. mv "$ISABELLE_HOME_USER/DOF" "$ISABELLE_HOME_USER/DOF.bak"
  179. else
  180. echo " No old installation found."
  181. fi
  182. }
  183. install_and_register(){
  184. echo "* Installing Isabelle/DOF"
  185. DIR="$ISABELLE_HOME_USER/DOF/Tools"
  186. echo " - Installing Tools in $DIR"
  187. mkdir -p "$DIR"
  188. cp $GEN_DIR/Tools/* "$DIR"
  189. chmod 755 "$DIR"/*
  190. DIR="$ISABELLE_HOME_USER/DOF/document-template"
  191. echo " - Installing document templates in $DIR"
  192. mkdir -p "$DIR"
  193. cp $GEN_DIR/scripts/* "$DIR"
  194. cp $GEN_DIR/document-templates/* "$DIR"
  195. cp $GEN_DIR/DOF/*/*.sty "$DIR"
  196. ISABELLE_SHORT_VERSION=`echo $ISABELLE_VERSION | sed -e 's/:.*$//'`
  197. sed -i -e "s|%%% CONFIG %%%| \
  198. \\\\renewcommand{\\\\dof@isabelleversion}{$ISABELLE_SHORT_VERSION} \
  199. \\\\renewcommand{\\\\isabellelatestversion}{$DOF_LATEST_ISABELLE} \
  200. \\\\renewcommand{\\\\isabellefullversion}{$ISABELLE_VERSION\\\\xspace} \
  201. \\\\renewcommand{\\\\dof@version}{$DOF_VERSION} \
  202. \\\\renewcommand{\\\\doflatestversion}{$DOF_LATEST_VERSION} \
  203. \\\\renewcommand{\\\\isadoflatestdoi}{$DOF_LATEST_DOI} \
  204. \\\\renewcommand{\\\\isadofgenericdoi}{$DOF_GENERIC_DOI} \
  205. \\\\renewcommand{\\\\isabelleurl}{$ISABELLE_URL} \
  206. \\\\renewcommand{\\\\dofurl}{$DOF_URL} \
  207. \\\\renewcommand{\\\\dof@artifacturl}{https://$DOF_ARTIFACT_HOST/$DOF_ARTIFACT_DIR}|" \
  208. "$DIR/DOF-core.sty"
  209. DIR="$ISABELLE_HOME_USER/DOF/latex"
  210. echo " - Installing LaTeX styles in $DIR"
  211. mkdir -p "$DIR"
  212. cp $GEN_DIR/ontologies/*/*.sty "$DIR"
  213. DIR="$ISABELLE_HOME_USER/etc"
  214. echo " - Registering Isabelle/DOF"
  215. mkdir -p "$DIR"
  216. if [[ $ISABELLE_TOOLS = *DOF* ]]; then
  217. echo " * Tools already registered in $DIR/settings"
  218. else
  219. echo " * Registering tools in $DIR/settings"
  220. echo 'ISABELLE_TOOLS=$ISABELLE_TOOLS:$ISABELLE_HOME_USER/DOF/Tools' \
  221. >> "$DIR/settings"
  222. fi
  223. if [[ $ISABELLE_DOCS = *DOF* ]]; then
  224. echo " * Docs already registered in $DIR/settings"
  225. else
  226. echo " * Registering docs in $DIR/settings"
  227. echo "ISABELLE_DOCS=$PWD/doc"':$ISABELLE_DOCS' \
  228. >> "$DIR/settings"
  229. fi
  230. sed -i -e "s|<isadofurl>|$DOF_URL|" $ISABELLE_HOME_USER/DOF/*/*
  231. LTX_VERSION="$DATE $DOF_VERSION/$ISABELLE_SHORT_VERSION"
  232. sed -i -e "s|<isadofltxversion>|$LTX_VERSION|" $ISABELLE_HOME_USER/DOF/*/*
  233. touch $ISABELLE_HOME_USER/ROOTS
  234. grep -q $PWD'$' $ISABELLE_HOME_USER/ROOTS || echo "$PWD" >> $ISABELLE_HOME_USER/ROOTS
  235. }
  236. ISABELLE=`which isabelle`
  237. SKIP="false"
  238. while [ $# -gt 0 ]
  239. do
  240. case "$1" in
  241. --isabelle|-i)
  242. ISABELLE="$2";
  243. shift;;
  244. --skip-patch-and-afp|-s)
  245. SKIP="true";;
  246. --help|-h)
  247. print_help
  248. exit 0;;
  249. *) print_help
  250. exit 1;;
  251. esac
  252. shift
  253. done
  254. ACTUAL_ISABELLE_VERSION=`$ISABELLE version`
  255. GEN_DIR=src
  256. PROG=`echo $0 | sed 's|.*/||'`;
  257. VARS=`$ISABELLE getenv ISABELLE_HOME_USER ISABELLE_HOME ISABELLE_TOOLS ISABELLE_DOCS`
  258. for i in $VARS; do
  259. export "$i"
  260. done
  261. echo ""
  262. echo "Isabelle/DOF Installer"
  263. echo "======================"
  264. check_isabelle_version
  265. check_pdftex
  266. if [ "$SKIP" = "true" ]; then
  267. echo "* Warning: skipping installation of Isabelle patch and AFP entries."
  268. else
  269. check_isa_dof_patch
  270. check_afp_entries
  271. fi
  272. check_old_installation
  273. install_and_register
  274. echo "* Installation successful. Enjoy Isabelle/DOF, you can build the session"
  275. echo " Isabelle/DOF and all example documents by executing:"
  276. echo " $ISABELLE build -D ."
  277. exit 0