Admin/lib/Tools/makedist_bundle
changeset 51064 9c425ed4a52c
parent 50961 d64bc889f7d6
child 52501 e4f668f258a1
equal deleted inserted replaced
51062:d5fd24f73555 51064:9c425ed4a52c
       
     1 #!/usr/bin/env bash
       
     2 #
       
     3 # DESCRIPTION: re-package Isabelle distribution with add-on components
       
     4 
       
     5 ## diagnostics
       
     6 
       
     7 PRG=$(basename "$0")
       
     8 
       
     9 function usage()
       
    10 {
       
    11   echo
       
    12   echo "Usage: isabelle $PRG ARCHIVE PLATFORM_FAMILY"
       
    13   echo
       
    14   echo "  Re-package Isabelle source distribution with add-on components"
       
    15   echo "  and post-hoc patches for platform family linux, macos, windows."
       
    16   echo
       
    17   echo "  Add-on components are that of the running Isabelle version!"
       
    18   echo
       
    19   exit 1
       
    20 }
       
    21 
       
    22 function fail()
       
    23 {
       
    24   echo "$1" >&2
       
    25   exit 2
       
    26 }
       
    27 
       
    28 
       
    29 ## arguments
       
    30 
       
    31 [ "$#" -ne 2 ] && usage
       
    32 
       
    33 ARCHIVE="$1"; shift
       
    34 PLATFORM_FAMILY="$1"; shift
       
    35 
       
    36 [ -f "$ARCHIVE" ] || fail "Bad source archive: $ARCHIVE"
       
    37 
       
    38 ARCHIVE_DIR="$(cd $(dirname "$ARCHIVE"); echo "$PWD")"
       
    39 ISABELLE_NAME="$(basename "$ARCHIVE" .tar.gz)"
       
    40 
       
    41 
       
    42 ## main
       
    43 
       
    44 export COPYFILE_DISABLE=true
       
    45 
       
    46 TMP="/var/tmp/isabelle-makedist$$"
       
    47 mkdir "$TMP" || fail "Cannot create directory $TMP"
       
    48 
       
    49 ISABELLE_TARGET="$TMP/$ISABELLE_NAME"
       
    50 
       
    51 tar -C "$TMP" -x -z -f "$ARCHIVE"
       
    52 
       
    53 
       
    54 # bundled components
       
    55 
       
    56 mkdir -p "$ARCHIVE_DIR/contrib"
       
    57 
       
    58 echo "#bundled components" >> "$ISABELLE_TARGET/etc/components"
       
    59 
       
    60 for CATALOG in main "$PLATFORM_FAMILY" bundled "bundled-$PLATFORM_FAMILY"
       
    61 do
       
    62   CATALOG_FILE="$ISABELLE_HOME/Admin/components/$CATALOG"
       
    63   if [ -f "$CATALOG_FILE" ]
       
    64   then
       
    65     echo "catalog ${CATALOG}"
       
    66     {
       
    67       while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
       
    68       do
       
    69         case "$REPLY" in
       
    70           \#* | "") ;;
       
    71           *)
       
    72             COMPONENT="$REPLY"
       
    73             COMPONENT_DIR="$ISABELLE_TARGET/contrib/$COMPONENT"
       
    74             case "$COMPONENT" in
       
    75               jedit_build*) ;;
       
    76               *)
       
    77                 echo "  component $COMPONENT"
       
    78                 CONTRIB="$ARCHIVE_DIR/contrib/${COMPONENT}.tar.gz"
       
    79                 if [ ! -f "$CONTRIB" ]; then
       
    80                   REMOTE="$ISABELLE_COMPONENT_REPOSITORY/${COMPONENT}.tar.gz"
       
    81                   echo "  download $REMOTE"
       
    82                   perl -MLWP::Simple -e "getprint '$REMOTE';" > "$CONTRIB"
       
    83                   perl -e "exit((stat('${CONTRIB}'))[7] == 0 ? 0 : 1);" && exit 2
       
    84                 fi
       
    85 
       
    86                 tar -C "$ISABELLE_TARGET/contrib" -x -z -f "$CONTRIB"
       
    87                 if [ -f "$COMPONENT_DIR/etc/settings" -o -f "$COMPONENT_DIR/etc/components" ]
       
    88                 then
       
    89                   echo "contrib/$COMPONENT" >> "$ISABELLE_TARGET/etc/components"
       
    90                 fi
       
    91                 ;;
       
    92             esac
       
    93             ;;
       
    94         esac
       
    95       done
       
    96     } < "$CATALOG_FILE"
       
    97   fi
       
    98 done
       
    99 
       
   100 
       
   101 # platform-specific patches
       
   102 
       
   103 case "$PLATFORM_FAMILY" in
       
   104   linux)
       
   105     OTHER_PLATFORMS='-name "x86*-darwin" -o -name "x86*-cygwin" -o -name "x86*-windows"'
       
   106     ;;
       
   107   macos)
       
   108     OTHER_PLATFORMS='-name "x86*-linux" -o -name "x86*-cygwin" -o -name "x86*-windows"'
       
   109 
       
   110     perl -pi -e "s,lookAndFeel=.*,lookAndFeel=com.apple.laf.AquaLookAndFeel,g;" \
       
   111       -e "s,delete-line.shortcut=.*,delete-line.shortcut=C+d,g;" \
       
   112       -e "s,delete.shortcut2=.*,delete.shortcut2=A+d,g;" \
       
   113       "$TMP/$ISABELLE_NAME/src/Tools/jEdit/dist/properties/jEdit.props"
       
   114     ;;
       
   115   windows)
       
   116     OTHER_PLATFORMS='-name "x86*-linux" -o -name "x86*-darwin"'
       
   117 
       
   118     perl -pi -e "s,lookAndFeel=.*,lookAndFeel=com.sun.java.swing.plaf.windows.WindowsLookAndFeel,g;" \
       
   119       "$TMP/$ISABELLE_NAME/src/Tools/jEdit/dist/properties/jEdit.props"
       
   120 
       
   121     cp "$ISABELLE_HOME/Admin/Windows/launch4j/Isabelle.exe" "$ISABELLE_TARGET/Isabelle2013.exe"
       
   122     cp "$ISABELLE_HOME/Admin/Windows/Cygwin/Cygwin-Setup.bat" \
       
   123       "$ISABELLE_HOME/Admin/Windows/Cygwin/Cygwin-Latex-Setup.bat" \
       
   124       "$ISABELLE_HOME/Admin/Windows/Cygwin/Cygwin-Terminal.bat" "$ISABELLE_TARGET"
       
   125 
       
   126     for NAME in init.bat postinstall rebaseall
       
   127     do
       
   128       cp -a "$ISABELLE_HOME/Admin/Windows/Cygwin/isabelle/$NAME" \
       
   129         "$ISABELLE_TARGET/contrib/cygwin/isabelle/."
       
   130     done
       
   131 
       
   132     perl -pi -e "s,/bin/rebaseall.*,/isabelle/rebaseall,g;" \
       
   133       "$ISABELLE_TARGET/contrib/cygwin/etc/postinstall/autorebase.bat.done"
       
   134 
       
   135     for NAME in ANNOUNCE README NEWS COPYRIGHT CONTRIBUTORS contrib/README
       
   136     do
       
   137       FILE="$ISABELLE_TARGET/$NAME"
       
   138       {
       
   139         echo '<?xml version="1.0" encoding="utf-8" ?>'
       
   140         echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
       
   141         echo '<html xmlns="http://www.w3.org/1999/xhtml">'
       
   142         echo '<head>'
       
   143         echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>'
       
   144         echo "<title>${NAME}</title>"
       
   145         echo '</head>'
       
   146         echo '<body>'
       
   147         echo '<pre>'
       
   148         perl -w -p -e "s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g; s/'/&apos;/g; s/\"/&quot;/g;" "$FILE"
       
   149         echo '</pre>'
       
   150         echo '</body>'
       
   151       } > "${FILE}.html"
       
   152     done
       
   153     ;;
       
   154   *)
       
   155     ;;
       
   156 esac
       
   157 
       
   158 
       
   159 # purge other platforms
       
   160 
       
   161 (
       
   162   cd "$ISABELLE_TARGET"
       
   163   for DIR in $(eval find contrib $OTHER_PLATFORMS | sort)
       
   164   do
       
   165     echo "removing $DIR"
       
   166     rm -rf "$DIR"
       
   167   done
       
   168 )
       
   169 
       
   170 
       
   171 # archive
       
   172 
       
   173 BUNDLE_ARCHIVE="${ARCHIVE_DIR}/${ISABELLE_NAME}_${PLATFORM_FAMILY}.tar.gz"
       
   174 
       
   175 echo "packaging $(basename "$BUNDLE_ARCHIVE")"
       
   176 tar -C "$TMP" -c -z -f "$BUNDLE_ARCHIVE" "$ISABELLE_NAME" || exit 2
       
   177 
       
   178 
       
   179 # clean up
       
   180 rm -rf "$TMP"