Permalink
Browse files

Checksum refactorings.

  • Loading branch information...
1 parent 7d7f55f commit 9e993be6c8e2cd028829ebf252dfa1af5e9c7a3c @wayneeseguin wayneeseguin committed Mar 27, 2012
@@ -137,7 +137,5 @@ array()
__sm.log.fail "Unknown array command '${_command}'"
;;
esac
-
-
}
@@ -12,7 +12,7 @@ api_package_extension_setup()
echo "#!/bin/sh" > "${_path}/shell/functions"
fi
- for _template in config/defaults config/md5 shell/functions
+ for _template in config/defaults config/checksum shell/functions
do
template install ${_module}/ext/${_template} \
append to "${_path}/${_template}" \
@@ -41,7 +41,7 @@ package()
{
trace_filter package || set -o xtrace
typeset -g package_name package_version package_base_url package_file \
- package_user archive_format package_md5 package_sha256 package_sha512
+ package_user archive_format package_checksum
typeset _token _command _logfile _lines _key _log _message
typeset -a _params __package_commands
@@ -116,9 +116,9 @@ package()
archive_format="$1"
(( $# )) && shift || __sm.log.fail "a package archive_format must follow keyword 'archive_format'"
;;
- (md5)
- package_md5="$1"
- (( $# )) && shift || __sm.log.fail "a package md5 sum must follow keyword 'md5'"
+ (checksum)
+ package_checksum="$1"
+ (( $# )) && shift || __sm.log.fail "a package checksum sum must follow keyword 'checksum'. Format: '{type},{checksum}'"
;;
(sha256)
package_sha256="$1"
@@ -1,2 +0,0 @@
-# The format for this file is: ${downloaded file name}=${md5 sum}. For example,
-{{extension}}-1.0.tar.gz=...
@@ -108,10 +108,10 @@ extension_package()
for file in "${_name}-${_version}".tar.*
do
log " - ${file}"
- files write string "$( files md5 "${file}" )" to "${file}.md5"
- log " - ${file}.md5"
+ files write string "sha256,$( files sha256 "${file}" )" to "${file}.checksum"
+ log " - ${file}.checksum"
files move force to "${_path}/pkg" from "${_path}" \
- "${file}" "${file}.md5"
+ "${file}" "${file}.checksum"
done
done
log "Packaging complete! (Packages are located in '${_path}/pkg'.)"
@@ -15,11 +15,11 @@ __sm.checksum()
elif __sm.command.exists md5sum
then
read _sum < <( md5sum "${_file}" )
- _sum="${_sum/* = }"
else
__sm.log.fail "Neither md5sum nor md5 were found in PATH."
fi
+ _sum="${_sum%% *}"
;;
(sha*)
_number="${_type#sha}"
@@ -43,7 +43,7 @@ __sm.checksum()
if [[ -n "${_checksum}" ]]
then
- if "${_checksum}" == "${_sum}" ]]
+ if [[ "${_checksum}" == "${_sum}" ]]
then return 0
else return 1 ; fi
else
@@ -53,10 +53,10 @@ __sm.package.cli()
[[ -n "${archive_format}" ]] ||
__sm.log.error "an archive format (tar.gz,tar.bz2,tar.xz,zip,...) must follow keyword 'archive_format'"
;;
- (md5)
- package_md5="${_package_args[$((++index))]}"
- [[ -n "${package_md5}" ]] ||
- __sm.log.error "an md5 sum string must follow keyword 'md5'"
+ (checksum)
+ package_checksum="${_package_args[$((++index))]}"
+ [[ -n "${package_checksum}" ]] ||
+ __sm.log.error "an checksum sum string must follow keyword 'checksum'. Format: '{type},{sum}'. eg. 'sha256,abcde...'"
;;
(force)
force_flag=1
@@ -148,8 +148,8 @@ __sm.package.define()
(patches_url)
package_patches_url="${value}"
;;
- (md5_url)
- package_md5_url="${value}"
+ (checksum_url)
+ package_checksum_url="${value}"
;;
(bin_path)
bin_path="${value}"
@@ -167,7 +167,7 @@ __sm.package.define()
archive_format="${value}"
;;
# TODO: Simplify into
- #(+([[[:alnum:]]|])_path|name|version|url|md5_url)
+ #(+([[[:alnum:]]|])_path|name|version|url|checksum_url)
# eval "${key}=${value}"
# ;;
(*)
@@ -271,7 +271,7 @@ __sm.package.set.cc()
__sm.package.exports()
{
export package_name packages_path package_name package_version archive_format \
- package_file package_url package_md5_url packages_path bin_path source_path \
+ package_file package_url package_checksum_url packages_path bin_path source_path \
LDFLAGS CFLAGS package_default_version
}
@@ -482,7 +482,7 @@ __sm.package.init()
__sm.package.exports
# Ensure that package_version is set at this point
- for variable in version base_url md5_url user
+ for variable in version base_url checksum_url user
do
if variable is empty "package_${variable}"
then
@@ -570,42 +570,42 @@ __sm.package.java.install()
# TODO: fetch, extract, copy to install path, setup java launcher.
}
-__sm.package.fetch.md5()
+__sm.package.fetch.checksum()
{
trace_filter package || set -o xtrace
typeset download_url
(( $# == 0 )) || __sm.package.cli $@
- : "${package_file:="${package_name}-${package_version}.${archive_format}"}"
+ true "${package_file:="${package_name}-${package_version}.${archive_format}"}"
- if [[ -z "${package_md5_url:-}" ]]
+ if [[ -z "${package_checksum_url:-}" ]]
then
for download_url in ${=package_base_url}
do
- package_md5_url="${package_md5_url:-} ${download_url}/${package_file}.md5"
+ package_checksum_url="${package_checksum_url:-} ${download_url}/${package_file}.checksum"
done
fi
- [[ -n "${package_md5}" ]] || __sm.config.read "${package_name}" md5 "${package_file}" package_md5
- [[ -n "${package_md5}" ]] ||
- for download_url in ${=package_md5_url}
+ [[ -n "${package_checksum}" ]] || __sm.config.read "${package_name}" checksum "${package_file}" package_checksum
+ [[ -n "${package_checksum}" ]] ||
+ for download_url in ${=package_checksum_url}
do
if [[ -f "${download_url}" ]]
then
__sm.file.copy "${download_url}" "${archives_path}/${package_file}" -f
else
- ${curl} -L "${download_url}" -o "${archives_path}/${package_file}.md5" 2>/dev/null ||
- __sm.log.error "Fetching MD5 checksum from '${download_url}' failed."
+ ${curl} -L "${download_url}" -o "${archives_path}/${package_file}.checksum" 2>/dev/null ||
+ __sm.log.error "Fetching checksum from '${download_url}' failed."
fi
- package_md5=$(cat "${archives_path}/${package_file}.md5")
+ package_checksum=$(cat "${archives_path}/${package_file}.checksum")
- rm "${archives_path}/${package_file}.md5"
+ rm "${archives_path}/${package_file}.checksum"
- if (( ${#package_md5} == 32 ))
+ if (( ${#package_checksum} == 32 ))
then
return 0
else
- package_md5=""
+ package_checksum=""
fi
done
}
@@ -633,11 +633,10 @@ __sm.package.fetch()
_args+=( "scm_type" "${scm_type}" )
fi
- __sm.package.fetch.md5
- if [[ -n "${package_md5:-}" ]]
- then
- _args+=( "md5" "${package_md5}" )
- fi
+ __sm.package.fetch.checksum
+
+ if [[ -n "${package_checksum:-}" ]]
+ then _args+=( "checksum" "${package_checksum}" ) ; fi
fetch_uris "${package_url}" "${source_path}/${package_dir}" ${_args[@]} || return 1
@@ -1048,13 +1047,13 @@ __sm.package.info()
trace_filter package || set -o xtrace
(( $# == 0 )) || __sm.package.cli $@
- typeset _installed _path package_md5 _installed
+ typeset _installed _path package_checksum _installed
_path="${packages_path}/versions/${package_name}"
true "${package_dir:="${package_name}-${package_version}"}" \
"${package_url:="${package_base_url}/${package_file}"}"
- [[ -n "${package_md5}" ]] || __sm.config.read "${package_name}" md5 "${package_file}" package_md5
+ [[ -n "${package_checksum}" ]] || __sm.config.read "${package_name}" checksum "${package_file}" package_checksum
log "package_name: ${package_name}"
if paths exist "${_path}"
@@ -1075,7 +1074,7 @@ __sm.package.info()
log " base_url: ${package_base_url}"
log " download_url: ${package_url}"
log " archive_format: ${package_file}"
- log " stored archive_md5: ${package_md5:-}"
+ log " stored archive_checksum: ${package_checksum:-}"
log " source_path: ${source_path}/${package_dir}"
if [[ -n "${package_dependencies}" ]]
@@ -2,11 +2,11 @@
typeset -g \
src_path data_path package_user package_version package_base_url \
- package_file package_directory archive_format package_md5 force_flag \
+ package_file package_directory archive_format package_checksum force_flag \
static_flag shared_flag package_user configure_flags configure_command \
package_name package_dir package_url package_docs_url package_patches_url \
- package_md5_url bin_path packages_path source_path target_path archive_format \
- extension_patches_path
+ package_checksum_url bin_path packages_path source_path target_path \
+ archive_format extension_patches_path
typeset -ga \
configure_flags make_flags package_dependencies fhs_dirs
@@ -69,7 +69,7 @@ fetch_uri()
# DEBUG vcs: type: github, params: mpapis/mpapis_test /home/mpapis/tmp/test_uris.
# DEBUG vcs: github -> https://github.com/mpapis/mpapis_test/tarball/master
# DEBUG vcs: github tarball archive name /home/mpapis/.sm/archives/mpapis_mpapis_test_master.tar.gz.
-# DEBUG vcs: master does not match MD5 checksum #; removing and downloading.
+# DEBUG vcs: master does not match checksum #; removing and downloading.
#
fetch_uris()
{
@@ -106,17 +106,16 @@ fetch_uris()
#
# # VCS (SCM) Module
#
-
fetch_uri_parse_args()
{
- typeset -g fetch_error_handler branch remote revision scm_type md5
+ typeset -g fetch_error_handler branch remote revision scm_type checksum
typeset -ga _uris
typeset _token _allowed_arg
while (( $# > 0 ))
do
_token="$1" && shift
- for _allowed_arg in branch remote revision scm_type md5
+ for _allowed_arg in branch remote revision scm_type checksum
do
case "${_token}" in
(*${_allowed_arg})
@@ -7,11 +7,13 @@
# Code Walkthrough
archive_get()
{
- typeset _uri _final_target _package_md5 _archive
+ typeset _uri _final_target _package_checksum _archive _type _sum
+
_uri="${1:-}"
_final_target="${2:-}"
- _package_md5="${3:-${md5:-#}}"
+ _package_checksum="${3:-${checksum:-#}}"
_archive="${archives_path}/${_uri##*/}"
+
(( $# )) && shift || __sm.log.fail "uri must be specified as the first parameter."
(( $# )) && shift || __sm.log.fail "target path must be specified as the second parameter."
@@ -33,10 +35,11 @@ archive_get()
[[ -d "${archives_path}" ]] || mkdir -p "${archives_path}"
- # TOD: shasum default instead
- if [[ -f "${_archive}" && "$(files md5 "${_archive}")" != "${_package_md5}" ]]
+ _type="${_package_checksum%,*}" ; _sum="${_package_checksum#*,}"
+
+ if [[ -f "${_archive}" ]] && ! __sm.checksum "${_type}" "${_archive}" "${_sum}" "" ""
then
- __sm.log.debug vcs "${_uri##*/} does not match MD5 checksum ${_package_md5}; removing and downloading."
+ __sm.log.debug vcs "${_uri##*/} does not match ${type} checksum ${_sum}; removing and downloading."
rm -f "${_archive}"
fi
@@ -1,2 +1,3 @@
api/files
api/paths
+api/checksum

0 comments on commit 9e993be

Please sign in to comment.