Blob Blame History Raw
#
# . ./build.vars and set -o errexit -o noglob are assumed.
# See warning at the top of build.vars.
#

cpu_get_fnames() {
	if test_cmd pkg_${cu_name}_check_updates; then
		pkg_${cu_name}_check_updates get_fnames;
	fi;
	if [ -z "${cu_fnames}" ]; then
		if [ "${cu_url#*://github.com/*}" != "${cu_url}" ]; then
			_cpugf_uname="${cu_url#*/github.com/}";
			_cpugf_uname="${_cpugf_uname%%/*}";
			_cpugf_pname="${cu_url#*/github.com/${_cpugf_uname}/}";
			_cpugf_pname="${_cpugf_pname%%/*}";
			cu_url_index="https://github.com/${_cpugf_uname%%/*}/${_cpugf_pname%%/*}/releases/";
			unset _cpu_uname _cpu_pname;
			cu_fnames="$(wget ${WGET_ARGS} -qO- ${cu_url_index}	|\
				sed -n '/<span class="tag-name">/s/^.*<span class="tag-name">\([a-zA-Z]\+-\|v\|\)\(.\+\)<\/span>.*$/\2/p')";
			cu_fname_base="${cu_name}";
			cu_fname_ext="${cu_fname#v${cu_version}.}";
		else
			cu_url_index="${cu_url%/*}/";
			cu_fnames="$(wget ${WGET_ARGS} -qO- "${cu_url_index}"	|\
				sed -n '/[hH][rR][eE][fF]="[^"]\+"/s/^.*[hH][rR][eE][fF]="\([^"]\+\)".*$/\1/p')";
		fi;
	fi;
	: ${cu_fname:="${cu_url##*/}"};
	: ${cu_fname_base:="${cu_fname%%-*}"};
	: ${cu_fname_ext:="${cu_fname#${cu_fname_base}-${cu_version}.}"};
};

cpu_get_version() {
	unset cu_fname_version;
	if test_cmd pkg_${cu_name}_check_updates; then
		pkg_${cu_name}_check_updates get_version;
	fi;
	if [ -z "${cu_fname_version}" ]; then
		if [ "${cu_url#*://github.com/*}" != "${cu_url}" ]; then
			if [ "${cu_fname#${cu_fname_base}-}" = "${cu_fname}" ]\
			&& [ "${cu_fname%.${cu_fname_ext}}" = "${cu_fname}" ]; then
				cu_fname_version="${cu_fname}";
			fi;
		elif [ "${cu_fname#${cu_fname_base}-}" != "${cu_fname}" ]\
		&& [ "${cu_fname%.${cu_fname_ext}}" != "${cu_fname}" ]; then
			cu_fname_version="${cu_fname#${cu_fname_base}-}";
			cu_fname_version="${cu_fname_version%.${cu_fname_ext}}";
		fi;
	fi;
};

check_pkg_updates() {
	cu_name="${1}"; cu_version="${2}"; cu_url="${3}"; cu_url_type="${4}";
	. vars/check_updates.vars;
	if match_list "${CHECK_UPDATES_SKIP}" " " "${cu_name}"; then
		log_msg vnfo "Skipping \`${cu_name}' (set in \${CHECK_UPDATES_SKIP}.)";
		return 0;
	elif [ "${cu_url_type}" = "git" ]; then
		log_msg vnfo "Skipping \`${cu_name}' (URL_TYPE is Git.)";
		return 0;
	elif [ -z "${cu_version}" -o -z "${cu_url}" ]; then
		log_msg fail "Zero-length \${cu_version} and/or \${cu_url} for \`${cu_name}' (ignored.)";
		return 0;
	else
		log_msg vnfo "Checking ${cu_name} v${cu_version} for updates.";
		cpu_get_fnames; _cpu_versions="";
	fi;
	for cu_fname in ${cu_fnames}; do
		cu_fname="${cu_fname##*/}"; cpu_get_version;
		if [ -z "${cu_fname_version}" ]					\
		|| ! echo "${cu_fname_version}" | grep -Eq '^[-_.0-9a-zA-Z]+$'	\
		||   echo "${cu_fname_version}" | grep -Eq '^[_.a-zA-Z]+'; then
			log_msg varn "Skipping \`${cu_fname_version}' (empty/invalid version.)";
		else
			_cpu_versions="${_cpu_versions:+${_cpu_versions} }${cu_fname_version}";
		fi;
	done;
	if [ -z "${_cpu_versions}" ]; then
		log_msg warn "No versions available for \`${cu_name}' (Filename URL: ${cu_url}, index URL: ${cu_url_index}).";
	else
		_cpu_versions="$(echo "${_cpu_versions}"	|\
			sed 's/ /\n/g' | sort -rV | uniq	|\
			head -n${CHECK_UPDATES_SHOW_NEW:-6}	|\
			paste -d" " -s)";
		if test_cmd pkg_${cu_name}_check_updates; then
			pkg_${cu_name}_check_updates version_fixup;
		fi;
		if [ "${_cpu_versions%% *}" != "${cu_version}" ]; then
			log_msg info "New release(s) available for ${cu_name} v${cu_version}: ${_cpu_versions}.";
		else
			log_msg vnfo "${cu_name} v${cu_version} is up to date.";
		fi;
	fi;
	unset	cu_fname cu_fname_base cu_fname_ext cu_fnames cu_fname_version	\
		cu_name cu_url cu_url_fname cu_url_fname_base cu_url_fname_ext	\
		cu_url_index cu_url_type cu_version _cpu_versions;
};

# vim:filetype=sh