diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2010-10-08 17:53:42 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2011-05-04 12:41:28 +0200 |
commit | e4b48676a7bde19b4c898cda17a05f8b1c4b09ed (patch) | |
tree | 560e8ecf6cc88f7743a65915a439a56a5cdc88e5 /scripts | |
parent | 500f8887a86dc3be81b5e43227e84001276e5919 (diff) | |
download | ptxdist-e4b48676a7bde19b4c898cda17a05f8b1c4b09ed.tar.gz ptxdist-e4b48676a7bde19b4c898cda17a05f8b1c4b09ed.tar.xz |
[get] add md5sum checking for downloaded archives
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/ptxd_lib_dgen.awk | 1 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_check_src.sh | 53 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_world_check_src.sh | 104 |
3 files changed, 158 insertions, 0 deletions
diff --git a/scripts/lib/ptxd_lib_dgen.awk b/scripts/lib/ptxd_lib_dgen.awk index 8e976cc72..27b6ce265 100644 --- a/scripts/lib/ptxd_lib_dgen.awk +++ b/scripts/lib/ptxd_lib_dgen.awk @@ -270,6 +270,7 @@ function import_PKG(this_PKG, this_pkg) { # define default ${PKG}, ${PKG}_SOURCE, ${PKG}_DIR if (target_PKG in PKG_to_pkg) { print this_PKG " = $(" target_PKG ")" > DGEN_DEPS_PRE; + print this_PKG "_MD5 = $(" target_PKG "_MD5)" > DGEN_DEPS_PRE; print this_PKG "_SOURCE = $(" \ target_PKG "_SOURCE)" > DGEN_DEPS_PRE; print this_PKG "_DIR = $(addprefix $(" this_PKG_type \ diff --git a/scripts/lib/ptxd_make_check_src.sh b/scripts/lib/ptxd_make_check_src.sh new file mode 100644 index 000000000..3c377a37d --- /dev/null +++ b/scripts/lib/ptxd_make_check_src.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Copyright (C) 2010 by Michael Olbrich <m.olbrich@pengutronix.de> +# +# See CREDITS for details about who has contributed to this project. +# +# For further information about the PTXdist project and license conditions +# see the README file. +# + +# +# $1: filename of the source archive to check +# $2: md5sum of the source archive to check +# +ptxd_make_check_src_impl() { + local src="${1}" + local md5="${2}" + + if [ -z "${src}" ]; then + ptxd_bailout "ptxd_make_check_src called without source file." + fi + case "${PTXCONF_SETUP_CHECK}" in + never) + return + ;; + notempty) + [ -z "${md5}" ] && return + ;; + esac + # for some packages setting the md5sum in the makefile is not possible + # e.g. for the kernel with its variable version number. Use "none" to + # disable the check. + if [ "${md5}" = "none" ]; then + return + fi + + echo "${md5} ${src}" | md5sum --check --quiet > /dev/null 2>&1 +} +export -f ptxd_make_check_src_impl + +# +# verify the md5sum of the source file of the current package +# +ptxd_make_check_src() { + ptxd_make_check_src_impl "$@" && return + + if [ -z "${2}" ]; then + ptxd_bailout "md5sum for '${1}' missing." + else + ptxd_bailout "Wrong md5sum for '${1}'" + fi +} +export -f ptxd_make_check_src diff --git a/scripts/lib/ptxd_make_world_check_src.sh b/scripts/lib/ptxd_make_world_check_src.sh new file mode 100644 index 000000000..2dc118000 --- /dev/null +++ b/scripts/lib/ptxd_make_world_check_src.sh @@ -0,0 +1,104 @@ +#!/bin/bash +# +# Copyright (C) 2010 by Michael Olbrich <m.olbrich@pengutronix.de> +# +# See CREDITS for details about who has contributed to this project. +# +# For further information about the PTXdist project and license conditions +# see the README file. +# + +# +# check if a file is the makefile for a specific package +# +# $1: package name +# $2: file name +# +ptxd_is_pkg_makefile() { + local pkg="$1" + local file="$2" + + grep -q -e "^[A-Z_]*PACKAGES\(-\$(PTXCONF_[^)]*)\)* += ${pkg}$" "${file}" +} +export -f ptxd_is_pkg_makefile + + +# +# find the makefile for the current package +# +# $1: package name +# +ptxd_find_pkg_makefile() { + local pkg="$1" + local rulesfiles="${ptx_state_dir}/ptx_dgen_rulesfiles.make" + local ignore + + if ptxd_get_path "${ptx_path_rules//://${pkg_label}.make }"; then + if ptxd_is_pkg_makefile "${pkg}" "${ptxd_reply}"; then + return + fi + fi + while read ignore ptxd_reply; do + if ptxd_is_pkg_makefile "${pkg}" "${ptxd_reply}"; then + return + fi + done < "${rulesfiles}" + return 1 +} +export -f ptxd_find_pkg_makefile + +# +# try to update the md5sum of the current package +# this only works if the makefile contains a "<PKG>_MD5 := ..." line. +# +ptxd_make_world_update_md5() { + local PKG="$(ptxd_name_to_NAME "${pkg_label}")" + set -- $(md5sum "${pkg_src}") + local md5="${1}" + + local PKG_MD5="PTXCONF_${PKG}_MD5" + for conf in "${PTXDIST_PLATFORMCONFIG}" "${PTXDIST_PTXCONFIG}"; do + if [ $(grep "^${PKG_MD5}=\"" "${conf}" 2> /dev/null | wc -l) = 1 ]; then + sed -i "s/^${PKG_MD5}=\".*$/${PKG_MD5}=\"${md5}\"/" "${conf}" + ptxd_warning "New checksum for ${pkg_label}: ${md5} in $(ptxd_print_path "${conf}")" + return + fi + done + local makefile + if ! ptxd_find_pkg_makefile "${pkg_label}"; then + ptxd_bailout "Could not update md5sum for '${pkg_label}': makefile not found" + else + makefile="${ptxd_reply}" + fi + local count=$(grep "\<${PKG}_MD5[ ]*:=" "${makefile}" 2> /dev/null | wc -l) + if [ "${count}" -gt 1 ]; then + ptxd_bailout "Could not update md5sum for '${pkg_label}': ${PKG}_MD5 found ${count} times in '$(ptxd_print_path ${makefile})'." + fi + sed -i "s/^\(\<${PKG}_MD5[ ]*:=\) *[a-f0-9]*\$/\1 ${md5}/" "${makefile}" + if ! grep -q "${md5}\$" "${makefile}"; then + ptxd_bailout "Could not update md5sum for '${pkg_label}': ${PKG}_MD5 not found" + fi + ptxd_warning "New checksum for ${pkg_label}: ${md5} in $(ptxd_print_path "${makefile}")" +} +export -f ptxd_make_world_update_md5 + +# +# verify the md5sum of the source file of the current package +# +ptxd_make_world_check_src() { + ptxd_make_world_init && + + if [ -z "${pkg_src}" ]; then + return + fi + ptxd_make_check_src_impl "${pkg_src}" "${pkg_md5}" && return + + if [ "${PTXCONF_SETUP_CHECK}" = "update" ]; then + ptxd_make_world_update_md5 + elif [ -z "${pkg_md5}" ]; then + ptxd_bailout "md5sum for '${pkg_label}' (${pkg_src}) missing." + else + ptxd_bailout "Wrong md5sum for '${pkg_label}' (${pkg_src})" + fi +} +export -f ptxd_make_world_check_src |