Compare commits
10
Commits
4ff79cfdd6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96e0ccfbdd | ||
|
|
4b895a0591 | ||
|
|
94379cb720 | ||
|
|
7587d72578 | ||
|
|
cfe99f928a | ||
|
|
2fc05ba7ea | ||
|
|
30fed4b734 | ||
|
|
caf66028e6 | ||
|
|
d5188a3385 | ||
|
|
618ad9222a |
@@ -65,6 +65,9 @@
|
||||
- license 数组, 软件许可证
|
||||
- sources 数组, 构建过程使用到的所有源码包和补丁,可以是 `https://...` 也可以是文件相对路径
|
||||
- urls 数组, `sources` 各项对应的地址, 当前仅限使用 `wget` 获取或复制文件
|
||||
- 以下三个数组有一个即可
|
||||
- sha512sums 数组, `sources` 各项对应的 sha512 checksum
|
||||
- sha256sums 数组, `sources` 各项对应的 sha256 checksum
|
||||
- md5sums 数组, `sources` 各项对应的 md5 checksum
|
||||
- options 数组, 构建选项, 详见第4小节
|
||||
- srcdir 字符串, 构建路径(在leaf主程序中定义)
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
set -e
|
||||
shopt -s inherit_errexit 2>/dev/null || true
|
||||
|
||||
RED_COLOR="\e[1;31m"
|
||||
PURPLE_COLOR="\e[1;35m"
|
||||
GREEN_COLOR="\e[1;32m"
|
||||
CLEAR_COLOR="\e[0m"
|
||||
RED_COLOR=$"\e[1;31m"
|
||||
PURPLE_COLOR=$"\e[1;35m"
|
||||
GREEN_COLOR=$'\e[1;32m'
|
||||
CLEAR_COLOR=$'\e[0m'
|
||||
|
||||
_DEF_PARALLEL_JOBS=4
|
||||
_ENV_PARALLEL_JOBS="${PARALLEL_JOBS}"
|
||||
source /etc/leaf.conf
|
||||
export PATH="/usr/bin:/usr/sbin"
|
||||
if [ -n "${_ENV_PARALLEL_JOBS}" ]; then
|
||||
export PARALLEL_JOBS="${_ENV_PARALLEL_JOBS}"
|
||||
elif [ -z "${PARALLEL_JOBS}" ]; then
|
||||
@@ -23,6 +24,7 @@ export TESTSUITEFLAGS="-j${PARALLEL_JOBS}"
|
||||
export LANG=C
|
||||
export LC_CTYPE=C.UTF-8
|
||||
export leaf_flags="CFLAGS CXXFLAGS FCFLAGS FFLAGS RUSTFLAGS"
|
||||
export LEAF_MESSAGE_DIR="${TEMP_DIR:-/tmp}/leaf-messages"
|
||||
for flag in ${leaf_flags}; do
|
||||
export $flag
|
||||
done
|
||||
@@ -33,7 +35,12 @@ BUILD_OPTIONS=([strip]="0" [libtool]="0" [zipman]="0")
|
||||
# global message file list
|
||||
declare -a LEAF_MESSAGE_FILES=()
|
||||
|
||||
leaf_set_title() {
|
||||
printf '\e]2;%s\a' "$*"
|
||||
}
|
||||
|
||||
main() {
|
||||
leaf_set_title "leaf"
|
||||
leaf_check_directories
|
||||
if [ $# -le 1 ]; then
|
||||
case $1 in
|
||||
@@ -102,6 +109,11 @@ main() {
|
||||
leaf_unpack_package "${_item}"
|
||||
done
|
||||
;;
|
||||
query)
|
||||
shift
|
||||
[[ $# -eq 1 ]] || leaf_error "usage: leaf query <atom-or-name>"
|
||||
leaf_query "$1"
|
||||
;;
|
||||
*)
|
||||
leaf_print_usage
|
||||
;;
|
||||
@@ -114,6 +126,10 @@ main() {
|
||||
# Help functions that give PKGBUILD to use
|
||||
###########################################################
|
||||
|
||||
leaf_info() {
|
||||
echo -e "${GREEN_COLOR} * $1${CLEAR_COLOR}"
|
||||
}
|
||||
|
||||
leaf_clear_flags() {
|
||||
for flag in $leaf_flags; do
|
||||
unset $flag
|
||||
@@ -242,6 +258,7 @@ leaf_invoke_hooks() {
|
||||
|
||||
leaf_merge_package() {
|
||||
pushd $1 > /dev/null 2>&1
|
||||
leaf_set_title "leaf: ${PKG_PREFIX}/${PKG_NAME} (Merging)"
|
||||
local _trace_dir="${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}"
|
||||
local _item _item_conflict _mode _owner _group
|
||||
local _time="$(date +%Y%m%d%H%M%S)"
|
||||
@@ -289,6 +306,8 @@ leaf_merge_package() {
|
||||
done
|
||||
leaf_invoke_hooks install
|
||||
popd > /dev/null 2>&1
|
||||
rm -rf "${LEAFHOME}"
|
||||
rm -rf "${LEAFTMPDIR}"
|
||||
}
|
||||
|
||||
leaf_parse_options() {
|
||||
@@ -337,7 +356,7 @@ EOF
|
||||
|
||||
leaf_message_init() {
|
||||
# one log per package invocation
|
||||
local d="${TEMP_DIR}/leaf-messages/${PKG_PREFIX}/${PKG_NAME}"
|
||||
local d="${LEAF_MESSAGE_DIR}/${PKG_PREFIX}/${PKG_NAME}"
|
||||
install -dm755 -- "$d"
|
||||
LEAF_MESSAGE_FILE="${d}/messages.$$.$(date +%Y%m%d%H%M%S).log"
|
||||
: > "${LEAF_MESSAGE_FILE}"
|
||||
@@ -374,9 +393,10 @@ leaf_print_message() {
|
||||
|
||||
echo -e "\n${PURPLE_COLOR}* Message from ${prefix}/${name}${CLEAR_COLOR}\n"
|
||||
cat -- "$f"
|
||||
rm -f -- "$f"
|
||||
done
|
||||
|
||||
rm -rf -- "${LEAF_MESSAGE_DIR}"/*
|
||||
|
||||
LEAF_MESSAGE_FILES=()
|
||||
unset LEAF_MESSAGE_FILE
|
||||
}
|
||||
@@ -539,18 +559,25 @@ leaf_conffile_is_unmodified() {
|
||||
}
|
||||
|
||||
leaf_update_package_database() {
|
||||
local _item="$(echo "$2" | awk 'BEGIN{FS="/";OFS="\\/"}{print $1,$2}')"
|
||||
case $1 in
|
||||
local action=$1 atom=$2 db="${INSTALLED_PACKAGES}"
|
||||
local tmp="${db}.tmp.$$"
|
||||
|
||||
case "$action" in
|
||||
add)
|
||||
sed -i "/${_item}/d" "${INSTALLED_PACKAGES}"
|
||||
echo "$2" >> ${INSTALLED_PACKAGES}
|
||||
{ [ -f "$db" ] && grep -Fvx -- "$atom" "$db" || :; printf '%s\n' "$atom"; } >"$tmp" &&
|
||||
mv -f -- "$tmp" "$db"
|
||||
;;
|
||||
delete)
|
||||
sed -i "/${_item}/d" "${INSTALLED_PACKAGES}"
|
||||
grep -Fvx -- "$atom" "$db" >"$tmp" &&
|
||||
mv -f -- "$tmp" "$db"
|
||||
;;
|
||||
*)
|
||||
leaf_error "unknown operation leaf_update_package_database ${action}."
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
leaf_update_environment() {
|
||||
ldconfig
|
||||
[ ! -r /etc/profile ] || source /etc/profile
|
||||
@@ -572,6 +599,7 @@ leaf_run_phase() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
leaf_set_title "leaf: ${PKG_PREFIX}/${PKG_NAME} (${phase})"
|
||||
echo -e "${GREEN_COLOR}>>> ${PKG_PREFIX}/${PKG_NAME}: ${phase}${CLEAR_COLOR}"
|
||||
|
||||
set +e
|
||||
@@ -600,12 +628,42 @@ leaf_phase_try() {
|
||||
|
||||
|
||||
leaf_prepare_package() {
|
||||
local url sourcefile index _md5sum local_src
|
||||
local url sourcefile index _sum local_src
|
||||
local checksum_algo checksum_arr_name
|
||||
local decl
|
||||
|
||||
leaf_set_title "leaf: ${PKG_PREFIX}/${PKG_NAME} (Fetching)"
|
||||
|
||||
distdir="${DIST_DIR}"
|
||||
filedir="${PKGBUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}"
|
||||
filedir="${PKGBUILD_DIR}/${PKG_PREFIX}/${pkgname}"
|
||||
mkdir -pv -- "${distdir}"
|
||||
|
||||
# choose checksum type (sha512 -> sha256 -> md5)
|
||||
if declare -p sha512sums &>/dev/null; then
|
||||
decl="$(declare -p sha512sums 2>/dev/null)"
|
||||
[[ "${decl}" == "declare -a "* || "${decl}" == "declare -a"* ]] \
|
||||
|| leaf_error "sha512sums is defined but is not an array"
|
||||
checksum_algo="sha512"
|
||||
checksum_arr_name="sha512sums"
|
||||
elif declare -p sha256sums &>/dev/null; then
|
||||
decl="$(declare -p sha256sums 2>/dev/null)"
|
||||
[[ "${decl}" == "declare -a "* || "${decl}" == "declare -a"* ]] \
|
||||
|| leaf_error "sha256sums is defined but is not an array"
|
||||
checksum_algo="sha256"
|
||||
checksum_arr_name="sha256sums"
|
||||
elif declare -p md5sums &>/dev/null; then
|
||||
decl="$(declare -p md5sums 2>/dev/null)"
|
||||
[[ "${decl}" == "declare -a "* || "${decl}" == "declare -a"* ]] \
|
||||
|| leaf_error "md5sums is defined but is not an array"
|
||||
checksum_algo="md5"
|
||||
checksum_arr_name="md5sums"
|
||||
else
|
||||
leaf_error "no checksum list defined: need one of sha512sums/sha256sums/md5sums"
|
||||
fi
|
||||
|
||||
local -n checksums_ref="${checksum_arr_name}"
|
||||
|
||||
# enter ${distdir}
|
||||
pushd "${distdir}" >/dev/null || leaf_error "cannot enter distdir: ${distdir}"
|
||||
|
||||
for index in "${!sources[@]}"; do
|
||||
@@ -618,12 +676,17 @@ leaf_prepare_package() {
|
||||
|
||||
if [ -f "${sourcefile}" ]; then
|
||||
echo "${sourcefile} exists, checking..."
|
||||
_md5sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')"
|
||||
if [ "${_md5sum}" = "${md5sums[$index]}" ]; then
|
||||
echo "md5sum match, skip ${sourcefile}."
|
||||
case "${checksum_algo}" in
|
||||
sha512) _sum="$(sha512sum -- "${sourcefile}" | awk '{print $1}')" ;;
|
||||
sha256) _sum="$(sha256sum -- "${sourcefile}" | awk '{print $1}')" ;;
|
||||
md5) _sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')" ;;
|
||||
*) leaf_error "internal error: unknown checksum algo: ${checksum_algo}" ;;
|
||||
esac
|
||||
if [ "${_sum}" = "${checksums_ref[$index]}" ]; then
|
||||
echo "${checksum_algo}sum match, skip ${sourcefile}."
|
||||
continue
|
||||
fi
|
||||
echo "md5sum does not match, refetching..."
|
||||
echo "${checksum_algo}sum does not match, refetching..."
|
||||
rm -f -- "${sourcefile}"
|
||||
fi
|
||||
|
||||
@@ -640,9 +703,14 @@ leaf_prepare_package() {
|
||||
;;
|
||||
esac
|
||||
|
||||
_md5sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')"
|
||||
if [ "${_md5sum}" != "${md5sums[$index]}" ]; then
|
||||
leaf_error "md5sums of ${sourcefile}(${_md5sum}) does not match with ${md5sums[$index]}!"
|
||||
case "${checksum_algo}" in
|
||||
sha512) _sum="$(sha512sum -- "${sourcefile}" | awk '{print $1}')" ;;
|
||||
sha256) _sum="$(sha256sum -- "${sourcefile}" | awk '{print $1}')" ;;
|
||||
md5) _sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')" ;;
|
||||
*) leaf_error "internal error: unknown checksum algo: ${checksum_algo}" ;;
|
||||
esac
|
||||
if [ "${_sum}" != "${checksums_ref[$index]}" ]; then
|
||||
leaf_error "${checksum_algo}sum of ${sourcefile}(${_sum}) does not match with ${checksums_ref[$index]}!"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -820,6 +888,9 @@ leaf_upgrade_package() {
|
||||
new_trace_dir="${TRACE_DIR}/${new_prefix}/${new_name}"
|
||||
[ -d "${new_trace_dir}" ] || leaf_error "upgrade: new trace dir missing: ${new_trace_dir}"
|
||||
|
||||
rm -rf "${LEAFHOME}"
|
||||
rm -rf "${LEAFTMPDIR}"
|
||||
|
||||
# =========================================================
|
||||
# 3) REMOVE OLD, but SKIP paths owned by NEW
|
||||
# =========================================================
|
||||
@@ -960,6 +1031,40 @@ leaf_show_package() {
|
||||
echo -e "License: ${license[@]}\n"
|
||||
}
|
||||
|
||||
leaf_query() {
|
||||
local q="$1"
|
||||
local trace_root="${TRACE_DIR:-/var/lib/leaf/trace}"
|
||||
|
||||
if ! leaf_find_remove_pkgbuild "$q"; then
|
||||
leaf_error "${q} cannot found in the leaf installed database."
|
||||
fi
|
||||
|
||||
local pkgbuild_path="${trace_root}/${PKG_PREFIX}/${PKG_NAME}/PKGBUILD"
|
||||
[[ -f "$pkgbuild_path" ]] || leaf_error "query: missing PKGBUILD: $pkgbuild_path"
|
||||
[[ -r "$pkgbuild_path" ]] || leaf_error "query: PKGBUILD not readable: $pkgbuild_path"
|
||||
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
unset pkgname pkgver
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "$pkgbuild_path"
|
||||
|
||||
local full="${PKG_PREFIX}/${PKG_NAME}"
|
||||
|
||||
if [[ -t 1 && -z "${NO_COLOR-}" ]]; then
|
||||
local BOLD=$'\e[1m'
|
||||
printf '%s%s%s %s %s%s%s\n' \
|
||||
"${BOLD}" "${full}" "${CLEAR_COLOR}" \
|
||||
"${pkgname}" \
|
||||
"${GREEN_COLOR}" "${pkgver}" "${CLEAR_COLOR}"
|
||||
else
|
||||
printf '%s %s %s\n' "${full}" "${pkgname}" "${pkgver}"
|
||||
fi
|
||||
)
|
||||
}
|
||||
|
||||
leaf_pack_package() {
|
||||
leaf_build_package
|
||||
pushd "${srcdir}" > /dev/null 2>&1
|
||||
|
||||
Reference in New Issue
Block a user