<commit_before>#! /bin/sh

# ----------------------------------------------------------------------------

function printUsage()
{
  cat <<EOT
Usage: $ScriptName [ACTION]
where ACTION is:
   get       -- download and unpack GDAL libraries and C# bindings
   update    -- update the local list of available GDAL packages with the
                current list in the svn repos, then do the "get" action
   clean     -- remove all unpacked files
   help      -- display this message (default)
EOT
}

# ----------------------------------------------------------------------------

function processArgs()
{
  Action=
  if [ "$1" = "" ] ; then
    Action=help
  else
    case $1 in
      get | update | clean | help ) Action=$1;;
      *) usageError "unknown action \"$1\"";;
    esac
  fi
  if [ "$3" != "" ] ; then
    usageError "extra arguments after \"$1\" action: $2 ..."
  fi
  if [ "$2" != "" ] ; then
    usageError "extra argument after \"$1\" action: $2"
  fi
}

# ----------------------------------------------------------------------------

function usageError()
{
  printf "Error: $1\n"
  printUsage
  exit 1
}

#-----------------------------------------------------------------------------

# A function for downloading a file from a URL to a local path

function downloadFile()
{
  echo Downloading $2 ...
  curl --progress-bar --fail --show-error --url $1 -o $2
  if [ $? -ne 0 ] ; then 
    curlExitCode=$?
    printf "  URL = $1\n"
    exit $curlExitCode
  fi
}

#-----------------------------------------------------------------------------

# Remove all files that are unpacked from the GDAL package

function cleanFiles()
{
  deleteFile $GdalAdmin_InstallDir/README.txt
  deleteDir  $GdalAdmin_InstallDir/managed
  deleteDir  $GdalAdmin_InstallDir/native
}

#-----------------------------------------------------------------------------

function deleteFile()
{
  if [ -f $1 ] ; then
    rm -f $1
    echo Deleted $1
  fi
}

#-----------------------------------------------------------------------------

function deleteDir()
{
  if [ -d $1 ] ; then
    rm -fR $1
    echo Deleted $1/
  fi
}

#-----------------------------------------------------------------------------

MissingVar=no
for VarName in GdalAdmin_VersionFile GdalAdmin_InstallDir ; do
  if [ "${!VarName}" = "" ] ; then
    printf "Error: The environment variable $VarName is not set.\n"
    MissingVar=yes
  fi
done
if [ "$MissingVar" = "yes" ] ; then
  exit 1
fi

ScriptName=`basename $0`
processArgs $*
case $Action in
  clean)  cleanFiles ; exit 0 ;;
  help)   printUsage ; exit 0 ;;
esac
#  $Action == get or update

#  Read GDAL version #
GdalVersion=`awk '{print $1}' $GdalAdmin_VersionFile`
echo This version of LSML uses GDAL ${GdalVersion}

#  The list of packages available for the specified GDAL version
ProjectUrl=http://landis-spatial.googlecode.com/
PackageList=gdal-${GdalVersion}-csharp.txt
GetPackageList=no
if [ ! -f $PackageList ] ; then
  GetPackageList=yes
fi
if [ "$Action" = "update" ]  ; then
  GetPackageList=yes
fi
if [ "${GetPackageList}" = "yes" ] ; then
  SvnPath=svn/trunk/external/gdal/packages/${PackageList}
  PackageListUrl=${ProjectUrl}${SvnPath}
  downloadFile $PackageListUrl $PackageList
fi

#  Determine the platform (win32 or win64)
Platform=`uname -s`
echo Platform = ${Platform}

#  Search for the platform in the package list
PackageSHA1=`fgrep $Platform $PackageList | awk '{print $2}' `
if [ "$PackageSHA1" = "" ] ; then
  cat <<-HERE
	No GDAL package for platform "$Platform" is available at the web site:

	   $ProjectUrl
<commit_msg>Restructured the GDAL-admin shell script so it has getPkgList and getPlatform functions.  This structure matches that of its Windows script counterpart, making it easier to compare them.<commit_after>#! /bin/sh

# ----------------------------------------------------------------------------

function printUsage()
{
  cat <<EOT
Usage: $ScriptName [ACTION]
where ACTION is:
   get       -- download and unpack GDAL libraries and C# bindings
   update    -- update the local list of available GDAL packages with the
                current list in the svn repos, then do the "get" action
   clean     -- remove all unpacked files
   help      -- display this message (default)
EOT
}

# ----------------------------------------------------------------------------

function processArgs()
{
  Action=
  if [ "$1" = "" ] ; then
    Action=help
  else
    case $1 in
      get | update | clean | help ) Action=$1;;
      *) usageError "unknown action \"$1\"";;
    esac
  fi
  if [ "$3" != "" ] ; then
    usageError "extra arguments after \"$1\" action: $2 ..."
  fi
  if [ "$2" != "" ] ; then
    usageError "extra argument after \"$1\" action: $2"
  fi
}

# ----------------------------------------------------------------------------

function usageError()
{
  printf "Error: $1\n"
  printUsage
  exit 1
}

#-----------------------------------------------------------------------------

# A function for downloading a file from a URL to a local path

function downloadFile()
{
  echo Downloading $2 ...
  curl --progress-bar --fail --show-error --url $1 -o $2
  if [ $? -ne 0 ] ; then 
    curlExitCode=$?
    printf "  URL = $1\n"
    exit $curlExitCode
  fi
}

#-----------------------------------------------------------------------------

function getPkgList()
{
  SvnPath=svn/trunk/external/gdal/packages/${PackageList}
  PackageListUrl=${ProjectUrl}${SvnPath}
  downloadFile $PackageListUrl $PackageList
}

#-----------------------------------------------------------------------------

function getPlatform()
{
  if [ "$GdalAdmin_Platform" != "" ] ; then
    Platform=$GdalAdmin_Platform
  else
    Platform=`uname -s`
  fi
}

#-----------------------------------------------------------------------------

# Remove all files that are unpacked from the GDAL package

function cleanFiles()
{
  deleteFile $GdalAdmin_InstallDir/README.txt
  deleteDir  $GdalAdmin_InstallDir/managed
  deleteDir  $GdalAdmin_InstallDir/native
}

#-----------------------------------------------------------------------------

function deleteFile()
{
  if [ -f $1 ] ; then
    rm -f $1
    echo Deleted $1
  fi
}

#-----------------------------------------------------------------------------

function deleteDir()
{
  if [ -d $1 ] ; then
    rm -fR $1
    echo Deleted $1/
  fi
}

#-----------------------------------------------------------------------------

MissingVar=no
for VarName in GdalAdmin_VersionFile GdalAdmin_InstallDir ; do
  if [ "${!VarName}" = "" ] ; then
    printf "Error: The environment variable $VarName is not set.\n"
    MissingVar=yes
  fi
done
if [ "$MissingVar" = "yes" ] ; then
  exit 1
fi

ScriptName=`basename $0`
processArgs $*
case $Action in
  clean)  cleanFiles ; exit 0 ;;
  help)   printUsage ; exit 0 ;;
esac
#  $Action == get or update

#  Read GDAL version #
GdalVersion=`awk '{print $1}' $GdalAdmin_VersionFile`
echo This version of LSML uses GDAL ${GdalVersion}

#  The list of packages available for the specified GDAL version
ProjectUrl=http://landis-spatial.googlecode.com/
PackageList=gdal-${GdalVersion}-csharp.txt
GetPackageList=no
if [ ! -f $PackageList ] ; then
  GetPackageList=yes
fi
if [ "$Action" = "update" ]  ; then
  GetPackageList=yes
fi
if [ "${GetPackageList}" = "yes" ] ; then
  getPkgList
fi

#  Determine the platform
getPlatform
echo Platform = ${Platform}

#  Search for the platform in the package list
PackageSHA1=`fgrep $Platform $PackageList | awk '{print $2}' `
if [ "$PackageSHA1" = "" ] ; then
  cat <<-HERE
	No GDAL package for platform "$Platform" is available at the web site:

	   $ProjectUrl

{'fraction_non_alphanumeric': 0.28023637557452397, 'fraction_numerical': 0.008667104399212082, 'mean_word_length': 1.6289264756644806, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3260609', 'n_tokens_mistral': 2178, 'n_tokens_neox': 2124, 'n_words': 691}