initramfs to also use merge-rootfs

This commit is contained in:
2026-03-24 23:58:33 +08:00
parent aad4edd194
commit ec8ceb1690
9 changed files with 167 additions and 26 deletions

View File

@@ -75,21 +75,60 @@ check_template_vars() {
[[ "$missing" -eq 0 ]]
}
preserve_exec_bit() {
local old="$1"
local new="$2"
if [[ -e "$old" && -x "$old" ]]; then
chmod +x "$new"
fi
}
get_envsubst_vars() {
local rel="$1"
case "$rel" in
bin/flash-emmc.sh.tmpl)
echo '${BUILD_TAG}'
;;
*)
echo ''
;;
esac
}
render_template() {
local src="$1"
local out="$2"
local allowed="${3:-}"
mkdir -p "$(dirname "$out")"
check_template_vars "$src"
envsubst < "$src" > "$out"
if [[ -n "$allowed" ]]; then
envsubst "$allowed" < "$src" > "$out"
else
check_template_vars "$src"
envsubst < "$src" > "$out"
fi
if [[ -x "$src" ]]; then
chmod +x "$out"
fi
}
replace_file() {
local src="$1"
local dst="$2"
local had_exec=0
[[ -e "$dst" && -x "$dst" ]] && had_exec=1
mkdir -p "$(dirname "$dst")"
cp -a "$src" "$dst"
if [[ "$had_exec" -eq 1 ]]; then
chmod +x "$dst"
fi
echo "Replaced file: $dst"
}
@@ -101,11 +140,19 @@ merge_or_copy_file() {
mkdir -p "$(dirname "$dst")"
# scripts: replace
if [[ "$rel" == opt/scripts/* ]]; then
cp -a "$src" "$dst"
echo "Replaced script: $dst"
return
fi
if [[ "$rel" == opt/scripts/* ]]; then
local had_exec=0
[[ -e "$dst" && -x "$dst" ]] && had_exec=1
cp -a "$src" "$dst"
if [[ "$had_exec" -eq 1 ]]; then
chmod +x "$dst"
fi
echo "Replaced script: $dst"
return
fi
# /etc: merge missing lines
if [[ "$rel" == etc/* ]]; then
@@ -177,12 +224,12 @@ find "$SRC_ROOT" -mindepth 1 | while IFS= read -r src_path; do
mode="override"
rel_for_target="${rel_for_target%.override}"
elif [[ "$rel_for_target" == *.tmpl ]]; then
rel_for_target="${rel_for_target%.tmpl}"
rendered="$TMP_DIR/$rel_for_target"
render_template "$src_path" "$rendered"
src_for_merge="$rendered"
fi
elif [[ "$rel_for_target" == *.tmpl ]]; then
rel_for_target="${rel_for_target%.tmpl}"
rendered="$TMP_DIR/$rel_for_target"
render_template "$src_path" "$rendered" "$(get_envsubst_vars "$rel_path")"
src_for_merge="$rendered"
fi
dst_path="$DST_ROOT/$rel_for_target"