scripts/functions
changeset 1116 46f6f7f9f37d
parent 1104 a781c47bb638
child 1120 ba7f344ed57f
     1.1 --- a/scripts/functions	Sun Dec 21 20:07:47 2008 +0000
     1.2 +++ b/scripts/functions	Sun Jan 04 14:18:20 2009 +0000
     1.3 @@ -255,7 +255,7 @@
     1.4  # Usage: CT_MktempDir foo
     1.5  CT_MktempDir() {
     1.6      # Some mktemp do not allow more than 6 Xs
     1.7 -    eval "$1"=$(mktemp -q -d "${CT_BUILD_DIR}/.XXXXXX")
     1.8 +    eval "$1"=$(mktemp -q -d "${CT_BUILD_DIR}/tmp.XXXXXX")
     1.9      CT_TestOrAbort "Could not make temporary directory" -n "${!1}" -a -d "${!1}"
    1.10      CT_DoLog DEBUG "Made temporary directory '${!1}'"
    1.11      return 0
    1.12 @@ -403,7 +403,7 @@
    1.13      # -c to continue the downloads. It's far better to simply overwrite the
    1.14      # destination file
    1.15      # Some company networks have firewalls to connect to the internet, but it's
    1.16 -    # not easy to detect them, and wget does not timeout by default  while
    1.17 +    # not easy to detect them, and wget does not timeout by default while
    1.18      # connecting, so force a global ${CT_CONNECT_TIMEOUT}-second timeout.
    1.19      wget -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary --tries=3 --passive-ftp "$1"    \
    1.20      || wget -T ${CT_CONNECT_TIMEOUT} -nc --progress=dot:binary --tries=3 "$1"               \
    1.21 @@ -433,13 +433,61 @@
    1.22      esac
    1.23  }
    1.24  
    1.25 +# This function tries to retrieve a tarball form a local directory
    1.26 +# Usage: CT_GetLocal <basename> [.extension]
    1.27 +CT_GetLocal() {
    1.28 +    local basename="$1"
    1.29 +    local first_ext="$2"
    1.30 +    local ext
    1.31 +
    1.32 +    # Do we already have it in *our* tarballs dir?
    1.33 +    ext=$(CT_GetFileExtension "${basename}" ${first_ext})
    1.34 +    if [ -n "${ext}" ]; then
    1.35 +        CT_DoLog DEBUG "Already have '${basename}'"
    1.36 +        return 0
    1.37 +    fi
    1.38 +
    1.39 +    if [ -n "${CT_LOCAL_TARBALLS_DIR}" ]; then
    1.40 +        CT_DoLog DEBUG "Trying to retrieve an already downloaded copy of '${basename}'"
    1.41 +        # We'd rather have a bzip2'ed tarball, then gzipped tarball, plain tarball,
    1.42 +        # or, as a failover, a file without extension.
    1.43 +        # Try local copy first, if it exists
    1.44 +        for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
    1.45 +            CT_DoLog DEBUG "Trying '${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}'"
    1.46 +            if [ -r "${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}" -a \
    1.47 +                 "${CT_FORCE_DOWNLOAD}" != "y" ]; then
    1.48 +                CT_DoLog DEBUG "Got '${basename}' from local storage"
    1.49 +                CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${basename}${ext}" "${CT_TARBALLS_DIR}/${basename}${ext}"
    1.50 +                return 0
    1.51 +            fi
    1.52 +        done
    1.53 +    fi
    1.54 +    return 1
    1.55 +}
    1.56 +
    1.57 +# This function saves the specified to local storage if possible,
    1.58 +# and if so, symlinks it for later usage
    1.59 +# Usage: CT_SaveLocal </full/path/file.name>
    1.60 +CT_SaveLocal() {
    1.61 +    local file="$1"
    1.62 +    local basename="${file##*/}"
    1.63 +
    1.64 +    if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
    1.65 +        CT_DoLog EXTRA "Saving '${file}' to local storage"
    1.66 +        # The file may already exist if downloads are forced: remove it first
    1.67 +        CT_DoExecLog ALL rm -f "${CT_LOCAL_TARBALLS_DIR}/${basename}"
    1.68 +        CT_DoExecLog ALL mv -f "${file}" "${CT_LOCAL_TARBALLS_DIR}"
    1.69 +        CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${basename}" "${file}"
    1.70 +    fi
    1.71 +}
    1.72 +
    1.73  # Download the file from one of the URLs passed as argument
    1.74 -# Usage: CT_GetFile <filename> [.extension] <url> [url ...]
    1.75 +# Usage: CT_GetFile <basename> [.extension] <url> [url ...]
    1.76  CT_GetFile() {
    1.77      local ext
    1.78      local url
    1.79      local file="$1"
    1.80 -    local first_ext=""
    1.81 +    local first_ext
    1.82      shift
    1.83      # If next argument starts with a dot, then this is not an URL,
    1.84      # and we can consider that it is a preferred extension.
    1.85 @@ -449,35 +497,14 @@
    1.86              ;;
    1.87      esac
    1.88  
    1.89 -    # Do we already have it?
    1.90 -    ext=$(CT_GetFileExtension "${file}" ${first_ext})
    1.91 -    if [ -n "${ext}" ]; then
    1.92 -        CT_DoLog DEBUG "Already have '${file}'"
    1.93 -        return 0
    1.94 -    fi
    1.95 +    # Does it exist localy?
    1.96 +    CT_GetLocal "${file}" ${first_ext} && return 0 || true
    1.97 +    # No, it does not...
    1.98  
    1.99      # Try to retrieve the file
   1.100      CT_DoLog EXTRA "Retrieving '${file}'"
   1.101      CT_Pushd "${CT_TARBALLS_DIR}"
   1.102  
   1.103 -    if [ -n "${CT_LOCAL_TARBALLS_DIR}" ]; then
   1.104 -        CT_DoLog DEBUG "Trying to retrieve an already downloaded copy of '${file}'"
   1.105 -        # We'd rather have a bzip2'ed tarball, then gzipped tarball, plain tarball,
   1.106 -        # or, as a failover, a file without extension.
   1.107 -        # Try local copy first, if it exists
   1.108 -        for ext in ${first_ext} .tar.bz2 .tar.gz .tgz .tar ''; do
   1.109 -            CT_DoLog DEBUG "Trying '${CT_LOCAL_TARBALLS_DIR}/${file}${ext}'"
   1.110 -            if [ -r "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" -a \
   1.111 -                 "${CT_FORCE_DOWNLOAD}" != "y" ]; then
   1.112 -                CT_DoLog DEBUG "Got '${file}' from local storage"
   1.113 -                CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}"
   1.114 -                return 0
   1.115 -            fi
   1.116 -        done
   1.117 -    fi
   1.118 -
   1.119 -    # Not found locally, try from the network
   1.120 -
   1.121      # Add URLs on the LAN mirror
   1.122      LAN_URLS=
   1.123      if [ "${CT_USE_MIRROR}" = "y" ]; then
   1.124 @@ -503,13 +530,7 @@
   1.125              CT_DoGetFile "${url}/${file}${ext}"
   1.126              if [ -f "${file}${ext}" ]; then
   1.127                  CT_DoLog DEBUG "Got '${file}' from the Internet"
   1.128 -                if [ "${CT_SAVE_TARBALLS}" = "y" ]; then
   1.129 -                    # The file may already exist if downloads are forced: remove it first
   1.130 -                    CT_DoLog EXTRA "Saving '${file}' to local storage"
   1.131 -                    CT_DoExecLog ALL rm -f "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}"
   1.132 -                    CT_DoExecLog ALL mv -f "${file}${ext}" "${CT_LOCAL_TARBALLS_DIR}"
   1.133 -                    CT_DoExecLog ALL ln -s "${CT_LOCAL_TARBALLS_DIR}/${file}${ext}" "${file}${ext}"
   1.134 -                fi
   1.135 +                CT_SaveLocal "${CT_TARBALLS_DIR}/${file}${ext}"
   1.136                  return 0
   1.137              fi
   1.138          done
   1.139 @@ -519,6 +540,41 @@
   1.140      CT_Abort "Could not retrieve '${file}'."
   1.141  }
   1.142  
   1.143 +# Checkout from CVS, and build the associated tarball
   1.144 +# The tarball will be called ${basename}.tar.bz2
   1.145 +# Prerequisite: either the server does not require password,
   1.146 +# or the user must already be logged in.
   1.147 +# 'tag' is the tag to retrieve. Must be specified, but can be empty.
   1.148 +# If dirname is specified, then module will be renamed to dirname
   1.149 +# prior to building the tarball.
   1.150 +# Usage: CT_GetCVS <basename> <url> <module> <tag> [dirname]
   1.151 +CT_GetCVS() {
   1.152 +    local basename="$1"
   1.153 +    local uri="$2"
   1.154 +    local module="$3"
   1.155 +    local tag="${4:+-r ${4}}"
   1.156 +    local dirname="$5"
   1.157 +    local tmp_dir
   1.158 +
   1.159 +    # Does it exist localy?
   1.160 +    CT_GetLocal "${basename}" && return 0 || true
   1.161 +    # No, it does not...
   1.162 +
   1.163 +    CT_DoLog EXTRA "Retrieving '${basename}'"
   1.164 +
   1.165 +    CT_MktempDir tmp_dir
   1.166 +    CT_Pushd "${tmp_dir}"
   1.167 +
   1.168 +    CT_DoSetProxy ${CT_PROXY_TYPE}
   1.169 +    CT_DoExecLog ALL cvs -z 9 -d "${uri}" co -P ${tag} "${module}"
   1.170 +    [ -n "${dirname}" ] && CT_DoExecLog ALL mv "${module}" "${dirname}"
   1.171 +    CT_DoExecLog ALL tar cjf "${CT_TARBALLS_DIR}/${basename}.tar.bz2" "${dirname:-${module}}"
   1.172 +    CT_SaveLocal "${CT_TARBALLS_DIR}/${basename}.tar.bz2"
   1.173 +
   1.174 +    CT_Popd
   1.175 +    CT_DoExecLog ALL rm -rf "${tmp_dir}"
   1.176 +}
   1.177 +
   1.178  # Extract a tarball and patch the resulting sources if necessary.
   1.179  # Some tarballs need to be extracted in specific places. Eg.: glibc addons
   1.180  # must be extracted in the glibc directory; uCLibc locales must be extracted