Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion scripts/repack_rom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ REPACK_PARTITION() {
sed -i '/^[a-zA-Z0-9\/]/ { /capabilities=/! s/$/ capabilities=0x0/ }' "$fs_config"
sed -i 's/ */ /g' "$fs_config"

# Validate and fix file_contexts entries that may be missing SELinux contexts
# Each line must have format: <path> <selinux_context>
# Determine default context based on partition type
local default_context="u:object_r:system_file:s0"
case "$partition_name" in
vendor*|odm*)
default_context="u:object_r:vendor_file:s0"
;;
esac

# Fix incomplete file_contexts entries (lines with only path, no context)
awk -v default_ctx="$default_context" '{
# Skip empty lines and comments
if (NF == 0 || $0 ~ /^[[:space:]]*#/) next
# If line has only one field (path only), add default context
if (NF == 1) {
print $0 " " default_ctx
} else {
# Line has 2+ fields (path and context), keep as is
# Extra fields after context are preserved for compatibility
print $0
}
}' "$file_contexts" > "$file_contexts.tmp" && mv "$file_contexts.tmp" "$file_contexts"


# https://source.android.com/docs/core/architecture/android-kernel-file-system-support
case "$target_fs" in
Expand All @@ -85,7 +109,10 @@ REPACK_PARTITION() {
grep -q "^/lost\+found " "$file_contexts" || echo "/lost\+found u:object_r:rootfs:s0" >> "$file_contexts"
grep -q "^lost\+found " "$fs_config" || echo "lost+found 0 0 700 capabilities=0x0" >> "$fs_config"
else
grep -q "^/$partition_name/lost\+found " "$file_contexts" || echo "/$partition_name/lost\+found $(head -n 1 "$file_contexts" | awk '{print $2}')" >> "$file_contexts"
# Get context from first valid line (with 2+ fields), with fallback to default_context
local lost_found_ctx=$(awk '$0 !~ /^[[:space:]]*#/ && NF>=2 {print $2; exit}' "$file_contexts")
[[ -z "$lost_found_ctx" ]] && lost_found_ctx="$default_context"
grep -q "^/$partition_name/lost\+found " "$file_contexts" || echo "/$partition_name/lost\+found $lost_found_ctx" >> "$file_contexts"
grep -q "^$partition_name/lost\+found " "$fs_config" || echo "$partition_name/lost+found 0 0 700 capabilities=0x0" >> "$fs_config"
fi

Expand Down