scripts/functions
changeset 85 ac2845835b13
parent 82 a1c93f975268
child 88 f67b52e42fd1
     1.1 --- a/scripts/functions	Wed May 09 13:11:04 2007 +0000
     1.2 +++ b/scripts/functions	Thu May 10 21:33:35 2007 +0000
     1.3 @@ -229,6 +229,28 @@
     1.4      yes "$1" || true
     1.5  }
     1.6  
     1.7 +# Get the file name extension of a component
     1.8 +# Usage: CT_GetFileExtension <component_name-component_version>
     1.9 +# If found, echoes the extension to stdout
    1.10 +# If not found, echoes nothing on stdout.
    1.11 +CT_GetFileExtension() {
    1.12 +    local ext
    1.13 +    local file="$1"
    1.14 +    local got_it=1
    1.15 +
    1.16 +    CT_Pushd "${CT_TARBALLS_DIR}"
    1.17 +    for ext in .tar.gz .tar.bz2 .tgz .tar; do
    1.18 +        if [ -f "${file}${ext}" ]; then
    1.19 +            echo "${ext}"
    1.20 +            got_it=0
    1.21 +            break
    1.22 +        fi
    1.23 +    done
    1.24 +    CT_Popd
    1.25 +
    1.26 +    return 0
    1.27 +}
    1.28 +
    1.29  # Download an URL using wget
    1.30  # Usage: CT_DoGetFileWget <URL>
    1.31  CT_DoGetFileWget() {
    1.32 @@ -276,58 +298,39 @@
    1.33      # Do we already have it?
    1.34      ext=`CT_GetFileExtension "${file}"`
    1.35      if [ -n "${ext}" ]; then
    1.36 -        if [ "${CT_FORCE_DOWNLOAD}" = "y" ]; then
    1.37 -            CT_DoLog DEBUG "Removing already present \"${file}\""
    1.38 -            rm -f "${CT_TARBALLS_DIR}/${file}${ext}"
    1.39 -        else
    1.40 -            CT_DoLog DEBUG "Already have \"${file}\""
    1.41 -            return 0
    1.42 -        fi
    1.43 +        CT_DoLog DEBUG "Already have \"${file}\""
    1.44 +        return 0
    1.45      fi
    1.46  
    1.47      CT_DoLog EXTRA "Retrieving \"${file}\""
    1.48      CT_Pushd "${CT_TARBALLS_DIR}"
    1.49      # File not yet downloaded, try to get it
    1.50      got_it=0
    1.51 -    if [ "${got_it}" != "y" ]; then
    1.52 -        # We'd rather have a bzip2'ed tarball, then gzipped, and finally plain tar.
    1.53 -        for ext in .tar.bz2 .tar.gz .tgz .tar; do
    1.54 -            # Try all urls in turn
    1.55 -            for url in "$@"; do
    1.56 -                case "${url}" in
    1.57 -                    *)  CT_DoLog DEBUG "Trying \"${url}/${file}${ext}\""
    1.58 -                        CT_DoGetFile "${url}/${file}${ext}"
    1.59 -                        ;;
    1.60 -                esac
    1.61 -                [ -f "${file}${ext}" ] && got_it=1 && break 2 || true
    1.62 -            done
    1.63 -        done
    1.64 -    fi
    1.65 -    CT_Popd
    1.66 -
    1.67 -    CT_TestAndAbort "Could not download \"${file}\", and not present in \"${CT_TARBALLS_DIR}\"" ${got_it} -eq 0
    1.68 -}
    1.69 -
    1.70 -# Get the file name extension of a component
    1.71 -# Usage: CT_GetFileExtension <component_name-component_version>
    1.72 -# If found, echoes the extension to stdout
    1.73 -# If not found, echoes nothing on stdout.
    1.74 -CT_GetFileExtension() {
    1.75 -    local ext
    1.76 -    local file="$1"
    1.77 -    local got_it=1
    1.78 -
    1.79 -    CT_Pushd "${CT_TARBALLS_DIR}"
    1.80 -    for ext in .tar.gz .tar.bz2 .tgz .tar; do
    1.81 -        if [ -f "${file}${ext}" ]; then
    1.82 -            echo "${ext}"
    1.83 -            got_it=0
    1.84 -            break
    1.85 +    # We'd rather have a bzip2'ed tarball, then gzipped, and finally plain tar.
    1.86 +    for ext in .tar.bz2 .tar.gz .tgz .tar; do
    1.87 +        if [ ${got_it} -ne 1 ]; then
    1.88 +            # Try local copy first, if it exists
    1.89 +            if [ -r "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" -a \
    1.90 +                 "${CT_FORCE_DOWNLOAD}" != "y" ]; then
    1.91 +                cp -v "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}" |CT_DoLog DEBUG
    1.92 +                got_it=1
    1.93 +                break 1
    1.94 +            else
    1.95 +                # Try all urls in turn
    1.96 +                for url in "$@"; do
    1.97 +                    case "${url}" in
    1.98 +                        *)  CT_DoLog DEBUG "Trying \"${url}/${file}${ext}\""
    1.99 +                            CT_DoGetFile "${url}/${file}${ext}"
   1.100 +                            ;;
   1.101 +                    esac
   1.102 +                    [ -f "${file}${ext}" ] && got_it=1 && break 2 || true
   1.103 +                done
   1.104 +            fi
   1.105          fi
   1.106      done
   1.107      CT_Popd
   1.108  
   1.109 -    return 0
   1.110 +    CT_TestAndAbort "Could not download \"${file}\", and not present in \"${CT_LOCAL_TARBALLS_DIR}\"" ${got_it} -eq 0
   1.111  }
   1.112  
   1.113  # Extract a tarball and patch the resulting sources if necessary.