From 7f51f0e82f6f808f01f515a8db80fb28be1bac74 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 07 Jul 2020 19:52:25 -0400 Subject: install: Replace sed "arrays" with eval "arrays" Before: real 21.89 user 2.08 sys 2.54 After: real 23.93 user 1.93 sys 2.61 --- diff --git a/src/install.sh b/src/install.sh index ab2977b..6f727ea 100644 --- a/src/install.sh +++ b/src/install.sh @@ -19,9 +19,6 @@ # . _install_deps= -_install_urls= -_install_md5sums= -_install_sha256sums= _install_feed_url= _usign_fingerprint() @@ -62,9 +59,10 @@ _install_fname_cb() local pkg="${1}" local fname="${2}" shift 2 + local pkg_clean= - _install_urls="$(printf '%s\n%s %s/%s' "${_install_urls}" \ - "${pkg}" "${_install_feed_url}" "${fname}")" + pkg_clean="$(printf '%s' "${pkg}" | tr -C 'A-Za-z0-9' '_')" + eval "_install_url_${pkg_clean}=\"\${_install_feed_url}/\${fname}\"" return 0 } @@ -74,9 +72,10 @@ _install_md5sum_cb() local pkg="${1}" local md5sum="${2}" shift 2 + local pkg_clean= - _install_md5sums="$(printf '%s\n%s %s' "${_install_md5sums}" \ - "${pkg}" "${md5sum}")" + pkg_clean="$(printf '%s' "${pkg}" | tr -C 'A-Za-z0-9' '_')" + eval "_install_md5sum_${pkg_clean}=\"\${md5sum}\"" return 0 } @@ -86,9 +85,10 @@ _install_sha256sum_cb() local pkg="${1}" local sha256sum="${2}" shift 2 + local pkg_clean= - _install_sha256sums="$(printf '%s\n%s %s' \ - "${_install_sha256sums}" "${pkg}" "${sha256sum}")" + pkg_clean="$(printf '%s' "${pkg}" | tr -C 'A-Za-z0-9' '_')" + eval "_install_sha256sum_${pkg_clean}=\"\${sha256sum}\"" return 0 } @@ -120,9 +120,6 @@ install_find_pkgs() opkg_conf_fd=${FD} _install_deps= - _install_urls= - _install_md5sums= - _install_sha256sums= if ! fopen "${root}/.prokit/packages" 'w'; then return 1 @@ -197,6 +194,7 @@ install_get_pkgs() local status_fd= local errors= local pkg= + local pkg_clean= local url= local md5sum= local sha256sum= @@ -218,12 +216,12 @@ install_get_pkgs() for pkg in $(cat -- "${root}/.prokit/packages"); do info "$(get_msg 'install_downloading_pkg')" "${pkg}" - url="$(printf '%s\n' "${_install_urls}" | \ - sed -n "s/^${pkg} //p")" - md5sum="$(printf '%s\n' "${_install_md5sums}" | \ - sed -n "s/^${pkg} //p")" - sha256sum="$(printf '%s\n' "${_install_sha256sums}" | \ - sed -n "s/^${pkg} //p")" + pkg_clean="$(printf '%s' "${pkg}" | tr -C 'A-Za-z0-9' '_')" + url="$(eval "printf '%s' \"\${_install_url_${pkg_clean}}\"")" + md5sum="$(eval "printf '%s' \ + \"\${_install_md5sum_${pkg_clean}}\"")" + sha256sum="$(eval "printf '%s' \ + \"\${_install_sha256sum_${pkg_clean}}\"")" fname="var/cache/opkg/archives/${url##*/}" if ! ${WGET} -q -O "${root}/${fname}" -- "${url}"; then error "$(get_msg 'install_downloading_pkg_fail')" -- cgit v0.9.1