Compare commits

..
8 Commits
Author SHA1 Message Date
wyj 96e0ccfbdd fix: clean the message file
Fixes #3
2026-02-06 16:44:42 -05:00
wyj 4b895a0591 fix: clean the home and temdir 2026-02-06 16:28:33 -05:00
wyj 94379cb720 feat: set terminal title 2026-02-06 15:46:51 -05:00
wyj 7587d72578 update: fix PATH 2026-01-19 17:31:33 -05:00
wyj cfe99f928a update: change filedir 2026-01-19 17:30:10 -05:00
wyj 2fc05ba7ea update: safe leaf_update_package_datebase 2026-01-17 16:18:42 -05:00
wyj 30fed4b734 update: add leaf query 2026-01-17 15:17:42 -05:00
wyj caf66028e6 update: add leaf_info to print 2026-01-14 00:27:18 -05:00
+79 -12
View File
@@ -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
@@ -604,8 +632,10 @@ leaf_prepare_package() {
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)
@@ -858,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
# =========================================================
@@ -998,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