feat: include distfile downloading and checking in main leaf script

This commit is contained in:
Yingjie Wang 2024-06-05 19:31:33 -04:00
parent b2a10ea78d
commit cd8d4135c0
2 changed files with 31 additions and 0 deletions

View File

@ -64,6 +64,8 @@
- pkgurl 字符串, 软件主页/上游地址
- license 数组, 软件许可证
- sources 数组, 构建过程使用到的所有源码包和补丁
- urls 数组, `sources` 各项对应的地址, 当前仅限使用 `wget` 获取
- md5sums 数组, `sources` 各项对应的 md5 checksum
- options 数组, 构建选项, 详见第4小节
- srcdir 字符串, 构建路径(在leaf主程序中定义)
- pkgdir 字符串, 虚拟根目录(在leaf主程序中定义)

29
leaf
View File

@ -300,6 +300,35 @@ leaf_update_environment() {
}
leaf_prepare_package() {
local distdir url sourcefile index _md5sum
distdir="${DIST_DIR}/${pkgname}-${pkgver}"
mkdir -pv "${distdir}"
pushd "${distdir}"
for index in "${!sources[@]}"; do
sourcefile="${sources[$index]}"
url="${urls[$index]}"
if [ -f "${sourcefile}" ]; then
echo "${sourcefile} exits, checking..."
_md5sum=$(md5sum ${sourcefile} | awk '{print $1}')
if [ "${_md5sum}" == "${md5sums[$index]}" ]; then
echo "md5sum match, skip ${sourcefile}."
else
echo "md5sum does not match, redownloading..."
rm -rf "${sourcefile}"
wget "${urls[$index]}"
fi
else
echo "Downloading ${sourcefile}..."
wget "${urls[$index]}"
fi
_md5sum=$(md5sum "${sourcefile}" | awk '{print $1}')
if [ "${_md5sum}" != "${md5sums[$index]}" ]; then
leaf_error "md5sums of ${sourcefile}(${_md5sum}) does not match with ${md5sums[$index]}!"
fi
done
popd
echo "Sources ready."
src_prepare
}