<commit_before>#!/bin/bash

PATH=$PATH:/bin:/usr/bin:/usr/local/bin

SCP=${COPASI_SCP:-scp}

if [ x"$COPASI_UPLOAD" != x ]; then
  function UPLOAD () {
    SRC=""
    while [ x"$2" != x ]; do
      SRC="$SRC $1"
      shift
    done
    echo ${SCP} ${SRC} ${COPASI_UPLOAD}/$1
    ${SCP} ${SRC} ${COPASI_UPLOAD}/$1
  }
else
  function UPLOAD () {
    echo "Skipping upload (environment variable COPASI_UPLOAD not set)."
  }
fi

pushd ../..

AdvancedInstallerPath="/cygdrive/c/Program Files/Caphyon/Advanced Installer"
VisualStudioPath="/cygdrive/c/Program Files/Microsoft Visual Studio 8"

if [ x"$#" = x1 ]; then
  major=`gawk -- '$2 ~ "VERSION_MAJOR" {print $3}' copasi/copasiversion.h`
  minor=`gawk -- '$2 ~ "VERSION_MINOR" {print $3}' copasi/copasiversion.h`
  build=`gawk -- '$2 ~ "VERSION_BUILD" {print $3}' copasi/copasiversion.h`

  license=`gawk -- ' BEGIN {license = "US"} $0 ~ "USE_LICENSE=DE" {license = "DE"} $0 ~ "USE_LICENSE=COM" {license = "COM"} END {print license} ' copasi/Makefile`

  rm Copasi-$build-$1*.*

  case x"$1" in 
  xWIN32)
    productcode=${build}${minor}${major}32DDC6BEE41C
    productcode=${productcode:0:12}

    productversion=${major}.${minor}.${build}

    [ -e setup ] && rm -rf setup
    mkdir setup
    cd setup

    mkdir copasi
    mkdir copasi/bin
    mkdir copasi/share
    mkdir copasi/share/copasi
    mkdir copasi/share/copasi/doc
    mkdir copasi/share/copasi/doc/html
    mkdir copasi/share/copasi/doc/html/figures
    mkdir copasi/share/copasi/examples
    mkdir copasi/share/copasi/icons
    mkdir copasi/share/copasi/config
    chmod -R 755 copasi

    cp ../README.$1 copasi/README.txt
    chmod 644 copasi/README.txt

    cp ../COPASI_License_${license}.txt copasi/LICENSE.txt
    chmod 644 copasi/LICENSE.txt

    cp ../copasi/CopasiUI/release/CopasiUI.exe*  copasi/bin
    "$VisualStudioPath/VC/bin/mt.exe" -nologo -hashupdate -makecdfs \
      -manifest copasi\\bin\\CopasiUI.exe.manifest \
      -outputresource:copasi\\bin\\CopasiUI.exe\;1

    cp ../copasi/CopasiSE/release/CopasiSE.exe  copasi/bin
    # "$VisualStudioPath/VC/bin/mt.exe" -nologo -hashupdate -makecdfs \
    #   -manifest copasi\\bin\\CopasiSE.exe.manifest \
    #   -outputresource:copasi\\bin\\CopasiSE.exe\;1

    cp ~/environment/distribution/* copasi/bin

    if [ x"$license" = xUS ]; then
      UPLOAD copasi/bin/CopasiSE.exe \
        $license/Copasi-AllSE/$1/CopasiSE-$build.exe

      # This is a hack to circumvent a time out in ssh
      sleep 10
    fi
    
    cp ../copasi/MIRIAM/MIRIAMResources.xml copasi/share/copasi/config
    chmod 444 copasi/share/copasi/config/*

    cp ../TestSuite/distribution/* copasi/share/copasi/examples
    chmod 444 copasi/share/copasi/examples/*

    cp ../copasi/CopasiUI/icons/Copasi.ico copasi/share/copasi/icons
    cp ../copasi/CopasiUI/icons/CopasiDoc.ico copasi/share/copasi/icons
    chmod 644 copasi/share/copasi/icons/*

    cp ../copasi/wizard/help_html/*.html copasi/share/copasi/doc/html
    chmod 644 copasi/share/copasi/doc/html/*.html

    cp ../copasi/wizard/help_html/figures/*.png \
       copasi/share/copasi/doc/html/figures
    chmod 644 copasi/share/copasi/doc/html/figures/*.png

    cd ../admin

#   replace defaults with COPASI bitmaps
    mv -- \
      "$AdvancedInstallerPath/resources/default-banner.bmp" \
      "$AdvancedInstallerPath/resources/default-dialog.bmp" .
    cp -- \
       ../copasi/CopasiUI/icons/install_banner.bmp \
       "$AdvancedInstallerPath/resources/default-banner.bmp"
    cp -- \
       ../copasi/CopasiUI/icons/install_dialog.bmp \
       "$AdvancedInstallerPath/resources/default-dialog.bmp"

#   modify product code, product version, and package name
    sed -e '/ProductCode/s/[0-9A-F]*}/'$productcode'}/' \
        -e '/ProductVersion/s/Value=".*"/Value="'$productversion'"/' \
        -e '/PackageName/s/Copasi-.*-WIN32/Copasi-'$build'-'$1'/' \
        -e '/ProductName/s/COPASI/COPASI '$productversion'/' \
        copasi.aip > tmp.aip

#   run Advanced Installer to create msi package
    "$AdvancedInstallerPath/AdvancedInstaller" /build tmp.aip
    rm tmp.aip

#   restore defaults
    mv -- \
      default-banner.bmp default-dialog.bmp \
      "$AdvancedInstallerPath/resources"

#   assure proper access rights
    chmod 644 ../Copasi-$build-$1.msi

    cd ..
    ;;

  xDarwin)
    if otool -L ./copasi/CopasiUI/CopasiUI.app/Contents/MacOS/CopasiUI \
      | grep libqt 2>&1 > /dev/null ;then
        echo ""
        echo "CopasiUI is dynamicall linked against Qt."
        echo "Please link the binary statically before making an image."
        echo ""
        exit 1
    fi
    
    SETFILE=/Developer/Tools/SetFile

# Create temporary package image drive
    hdiutil create Copasi-tmp.dmg -megabytes 400 -volname Copasi-$build-$1 \
      -fs HFS+ -layout NONE

# Mount temporary package image drive
    drive=`hdid Copasi-tmp.dmg | gawk -- '{print $1}'`
    TMPDIR=`df -l | gawk -- '$1 ~ "'$drive'" {print $6}'`
    echo $drive '->' $TMPDIR

    echo "Copying application bundle."
    mkdir ${TMPDIR}/copasi
    cp -r copasi/CopasiUI/CopasiUI.app ${TMPDIR}/copasi/

    strip ${TMPDIR}/copasi/CopasiUI.app/Contents/MacOS/CopasiUI

# copy the commandline version if it exists
    if [ -e copasi/CopasiSE/CopasiSE.app/Contents/MacOS/CopasiSE ] ; then    
      cp copasi/CopasiSE/CopasiSE.app/Contents/MacOS/CopasiSE ${TMPDIR}/copasi/
      strip ${TMPDIR}/copasi/CopasiSE
      
      if [ x"$license" = xUS ]; then
        UPLOAD ${TMPDIR}/copasi/CopasiSE \
          $license/Copasi-AllSE/$1/CopasiSE-$build
       fi
    fi  
    
# copy the icon into the Resources directory
    echo "Creating Resources directory."<commit_msg>Added option to specify gawk executable.<commit_after>#!/bin/bash

PATH=$PATH:/bin:/usr/bin:/usr/local/bin

SCP=${COPASI_SCP:-scp}
AWK=${COPASI_AWK:-gawk}

if [ x"$COPASI_UPLOAD" != x ]; then
  function UPLOAD () {
    SRC=""
    while [ x"$2" != x ]; do
      SRC="$SRC $1"
      shift
    done
    echo ${SCP} ${SRC} ${COPASI_UPLOAD}/$1
    ${SCP} ${SRC} ${COPASI_UPLOAD}/$1
  }
else
  function UPLOAD () {
    echo "Skipping upload (environment variable COPASI_UPLOAD not set)."
  }
fi

pushd ../..

AdvancedInstallerPath="/cygdrive/c/Program Files/Caphyon/Advanced Installer"
VisualStudioPath="/cygdrive/c/Program Files/Microsoft Visual Studio 8"

if [ x"$#" = x1 ]; then
  major=`${AWK} -- '$2 ~ "VERSION_MAJOR" {print $3}' copasi/copasiversion.h`
  minor=`${AWK} -- '$2 ~ "VERSION_MINOR" {print $3}' copasi/copasiversion.h`
  build=`${AWK} -- '$2 ~ "VERSION_BUILD" {print $3}' copasi/copasiversion.h`

  license=`${AWK} -- ' BEGIN {license = "US"} $0 ~ "USE_LICENSE=DE" {license = "DE"} $0 ~ "USE_LICENSE=COM" {license = "COM"} END {print license} ' copasi/Makefile`

  rm Copasi-$build-$1*.*

  case x"$1" in 
  xWIN32)
    productcode=${build}${minor}${major}32DDC6BEE41C
    productcode=${productcode:0:12}

    productversion=${major}.${minor}.${build}

    [ -e setup ] && rm -rf setup
    mkdir setup
    cd setup

    mkdir copasi
    mkdir copasi/bin
    mkdir copasi/share
    mkdir copasi/share/copasi
    mkdir copasi/share/copasi/doc
    mkdir copasi/share/copasi/doc/html
    mkdir copasi/share/copasi/doc/html/figures
    mkdir copasi/share/copasi/examples
    mkdir copasi/share/copasi/icons
    mkdir copasi/share/copasi/config
    chmod -R 755 copasi

    cp ../README.$1 copasi/README.txt
    chmod 644 copasi/README.txt

    cp ../COPASI_License_${license}.txt copasi/LICENSE.txt
    chmod 644 copasi/LICENSE.txt

    cp ../copasi/CopasiUI/release/CopasiUI.exe*  copasi/bin
    "$VisualStudioPath/VC/bin/mt.exe" -nologo -hashupdate -makecdfs \
      -manifest copasi\\bin\\CopasiUI.exe.manifest \
      -outputresource:copasi\\bin\\CopasiUI.exe\;1

    cp ../copasi/CopasiSE/release/CopasiSE.exe  copasi/bin
    # "$VisualStudioPath/VC/bin/mt.exe" -nologo -hashupdate -makecdfs \
    #   -manifest copasi\\bin\\CopasiSE.exe.manifest \
    #   -outputresource:copasi\\bin\\CopasiSE.exe\;1

    cp ~/environment/distribution/* copasi/bin

    if [ x"$license" = xUS ]; then
      UPLOAD copasi/bin/CopasiSE.exe \
        $license/Copasi-AllSE/$1/CopasiSE-$build.exe

      # This is a hack to circumvent a time out in ssh
      sleep 10
    fi
    
    cp ../copasi/MIRIAM/MIRIAMResources.xml copasi/share/copasi/config
    chmod 444 copasi/share/copasi/config/*

    cp ../TestSuite/distribution/* copasi/share/copasi/examples
    chmod 444 copasi/share/copasi/examples/*

    cp ../copasi/CopasiUI/icons/Copasi.ico copasi/share/copasi/icons
    cp ../copasi/CopasiUI/icons/CopasiDoc.ico copasi/share/copasi/icons
    chmod 644 copasi/share/copasi/icons/*

    cp ../copasi/wizard/help_html/*.html copasi/share/copasi/doc/html
    chmod 644 copasi/share/copasi/doc/html/*.html

    cp ../copasi/wizard/help_html/figures/*.png \
       copasi/share/copasi/doc/html/figures
    chmod 644 copasi/share/copasi/doc/html/figures/*.png

    cd ../admin

#   replace defaults with COPASI bitmaps
    mv -- \
      "$AdvancedInstallerPath/resources/default-banner.bmp" \
      "$AdvancedInstallerPath/resources/default-dialog.bmp" .
    cp -- \
       ../copasi/CopasiUI/icons/install_banner.bmp \
       "$AdvancedInstallerPath/resources/default-banner.bmp"
    cp -- \
       ../copasi/CopasiUI/icons/install_dialog.bmp \
       "$AdvancedInstallerPath/resources/default-dialog.bmp"

#   modify product code, product version, and package name
    sed -e '/ProductCode/s/[0-9A-F]*}/'$productcode'}/' \
        -e '/ProductVersion/s/Value=".*"/Value="'$productversion'"/' \
        -e '/PackageName/s/Copasi-.*-WIN32/Copasi-'$build'-'$1'/' \
        -e '/ProductName/s/COPASI/COPASI '$productversion'/' \
        copasi.aip > tmp.aip

#   run Advanced Installer to create msi package
    "$AdvancedInstallerPath/AdvancedInstaller" /build tmp.aip
    rm tmp.aip

#   restore defaults
    mv -- \
      default-banner.bmp default-dialog.bmp \
      "$AdvancedInstallerPath/resources"

#   assure proper access rights
    chmod 644 ../Copasi-$build-$1.msi

    cd ..
    ;;

  xDarwin)
    if otool -L ./copasi/CopasiUI/CopasiUI.app/Contents/MacOS/CopasiUI \
      | grep libqt 2>&1 > /dev/null ;then
        echo ""
        echo "CopasiUI is dynamicall linked against Qt."
        echo "Please link the binary statically before making an image."
        echo ""
        exit 1
    fi
    
    SETFILE=/Developer/Tools/SetFile

# Create temporary package image drive
    hdiutil create Copasi-tmp.dmg -megabytes 400 -volname Copasi-$build-$1 \
      -fs HFS+ -layout NONE

# Mount temporary package image drive
    drive=`hdid Copasi-tmp.dmg | ${AWK} -- '{print $1}'`
    TMPDIR=`df -l | ${AWK} -- '$1 ~ "'$drive'" {print $6}'`
    echo $drive '->' $TMPDIR

    echo "Copying application bundle."
    mkdir ${TMPDIR}/copasi
    cp -r copasi/CopasiUI/CopasiUI.app ${TMPDIR}/copasi/

    strip ${TMPDIR}/copasi/CopasiUI.app/Contents/MacOS/CopasiUI

# copy the commandline version if it exists
    if [ -e copasi/CopasiSE/CopasiSE.app/Contents/MacOS/CopasiSE ] ; then    
      cp copasi/CopasiSE/CopasiSE.app/Contents/MacOS/CopasiSE ${TMPDIR}/copasi/
      strip ${TMPDIR}/copasi/CopasiSE
      
      if [ x"$license" = xUS ]; then
        UPLOAD ${TMPDIR}/copasi/CopasiSE \
          $license/Copasi-AllSE/$1/CopasiSE-$build
       fi
    fi  
    
# copy the icon into the Resources directory
    echo "Creating Resources directory."
{'fraction_non_alphanumeric': 0.14480706973488494, 'fraction_numerical': 0.013299501268702423, 'mean_word_length': 2.681159420289855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3550129', 'n_tokens_mistral': 4343, 'n_tokens_neox': 4082, 'n_words': 793}