+# returns true if "$1" is ftp, http or https protocol url
+is_url()
+{
+ case "$1" in
+ ftp://*|http://*|https://*)
+ return 0
+ ;;
+ esac
+ return 1
+}
+
+update_md5()
+{
+ if [ $# -eq 0 ]; then
+ return
+ fi
+
+ update_shell_title "update md5"
+ if [ -n "$DEBUG" ]; then
+ set -x
+ set -v
+ fi
+
+ cd "$SOURCE_DIR"
+
+ # pass 1: check files to be fetched
+ local todo
+ local need_files
+ for i in "$@"; do
+ local fp=$(nourl "$i")
+ local srcno=$(src_no "$i")
+ if [ -n "$ADD5" ]; then
+ [ "$fp" = "$i" ] && continue # FIXME what is this check doing?
+ grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE && continue
+ else
+ grep -qiE '^#[ ]*Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE || continue
+ fi
+ if [ ! -f "$fp" ] || [ $ALWAYS_CVSUP = "yes" ]; then
+ need_files="$need_files $i"
+ fi
+ done
+
+ # pass 1a: get needed files
+ if [ "$need_files" ]; then
+ get_files $need_files
+ fi
+
+ # pass 2: proceed with md5 adding or updating
+ for i in "$@"; do
+ local fp=$(nourl "$i")
+ local srcno=$(src_no "$i")
+ local md5=$(grep -iE '^#[ ]*(No)?Source'$srcno'-md5[ ]*:' $SPECS_DIR/$SPECFILE )
+ if [ -n "$ADD5" ] && is_url $i || [ -n "$md5" ]; then
+ local tag="Source$srcno-md5"
+ if [[ "$md5" == *NoSource* ]]; then
+ tag="NoSource$srcno-md5"
+ fi
+ md5=$(md5sum "$fp" | cut -f1 -d' ')
+ echo "Updating $tag ($md5: $fp)."
+ perl -i -ne '
+ print unless /^\s*#\s*(No)?Source'$srcno'-md5\s*:/i;
+ print "# '$tag':\t'$md5'\n" if /^Source'$srcno'\s*:\s+/;
+ ' \
+ $SPECS_DIR/$SPECFILE
+ fi
+ done
+}
+
+check_md5()
+{
+ update_shell_title "check md5"
+
+ for i in "$@"; do
+ if good_md5 "$i" && good_size "$i"; then
+ continue
+ fi
+
+ echo "MD5 sum mismatch or 0 size. Use -U to refetch sources,"
+ echo "or -5 to update md5 sums, if you're sure files are correct."
+ Exit_error err_no_source_in_repo $i
+ done
+}
+