Compare commits

...
2 Commits
Author SHA1 Message Date
wyj 5d42d56441 update: add list of leaf func avaliable in PKGBUILD 2025-12-25 05:13:13 -05:00
wyj e8309233e7 new: add leaf_add_shell and leaf_remove_shell 2025-12-25 05:12:25 -05:00
2 changed files with 51 additions and 0 deletions
+11
View File
@@ -88,6 +88,17 @@
另外, 某些软件包需要生成缓存或更改文件属性才能正常使用(见`HOOKS.md`), 需要定义特定操作的钩子文件, 模板见`template.HOOK`, 语法必须符合`BASH`。在 `PKGBUILD` 文件内请使用 `leaf_install_hook <foo>.HOOK` 来安全地安装 `<foo>.HOOK` 文件,该函数将检查 `.HOOK` 文件的有效性,并正确安装到 `${pkgdir}${HOOK_DIR}`。 另外, 某些软件包需要生成缓存或更改文件属性才能正常使用(见`HOOKS.md`), 需要定义特定操作的钩子文件, 模板见`template.HOOK`, 语法必须符合`BASH`。在 `PKGBUILD` 文件内请使用 `leaf_install_hook <foo>.HOOK` 来安全地安装 `<foo>.HOOK` 文件,该函数将检查 `.HOOK` 文件的有效性,并正确安装到 `${pkgdir}${HOOK_DIR}`。
`PKGBUILD` 文件内可用的函数:
```
- leaf_error
- leaf_record_message
- leaf_clear_flags
- leaf_install_hook
- leaf_add_shell
- leaf_remove_shell
````
4. 构建选项 4. 构建选项
在PKGBUILD中定义的options可以是以下字段: 在PKGBUILD中定义的options可以是以下字段:
+40
View File
@@ -607,4 +607,44 @@ leaf_unpack_package() {
echo -e "${GREEN_COLOR}* Package ${PKG_PREFIX}/${PKG_NAME} has been installed${CLEAR_COLOR}\n" echo -e "${GREEN_COLOR}* Package ${PKG_PREFIX}/${PKG_NAME} has been installed${CLEAR_COLOR}\n"
} }
leaf_add_shell() {
# usage: leaf_add_shell <abs_shell_path>
local shell="$1" f="/etc/shells" tmp
# ensure file exists
if [ ! -f "$f" ]; then
install -m 0644 -o root -g root /dev/null "$f" || return 1
fi
# already present? (exact whole-line match)
grep -Fxq -- "$shell" "$f" && return 0
tmp="$(mktemp "${f}.leaf.XXXXXX")" || return 1
cat "$f" > "$tmp" || { rm -f "$tmp"; return 1; }
# append with newline
printf '%s\n' "$shell" >> "$tmp" || { rm -f "$tmp"; return 1; }
# atomic replace
install -m 0644 -o root -g root "$tmp" "$f" || { rm -f "$tmp"; return 1; }
rm -f "$tmp"
}
leaf_remove_shell() {
# usage: leaf_remove_shell <abs_shell_path>
local shell="$1" f="/etc/shells" tmp
[ -f "$f" ] || return 0
# if not present, nothing to do
grep -Fxq -- "$shell" "$f" || return 0
tmp="$(mktemp "${f}.leaf.XXXXXX")" || return 1
# delete exact matching lines only
grep -Fvx -- "$shell" "$f" > "$tmp" || true
install -m 0644 -o root -g root "$tmp" "$f" || { rm -f "$tmp"; return 1; }
rm -f "$tmp"
}
main $@ main $@