blob: dd79b27fa6b305c4645dd1c5c67edc9bd88280e5 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001# Copyright (C) 2006 OpenWrt.org
2# Copyright (C) 2010 Vertical Communications
3
4missing_lines() {
5 local file1 file2 line
6 file1="$1"
7 file2="$2"
8 oIFS="$IFS"
9 IFS=":"
10 while read line; do
11 set -- $line
12 grep -q "^$1:" "$file2" || echo "$line"
13 done < "$file1"
14 IFS="$oIFS"
15}
16
17# Rootfs mount options can be passed by declaring in the kernel
18# cmdline as much options as needed prefixed with "rootfs_mount_options."
19#
20# Example:
21# rootfs_mount_options.compress_algorithm=zstd rootfs_mount_options.noinline_data
22#
23compose_rootfs_mount_options() {
24 local mount_options
25 local cmdlinevar
26
27 for cmdlinevar in $(cat /proc/cmdline); do
28 if [ "$cmdlinevar" != "${cmdlinevar#rootfs_mount_options\.}" ]; then
29 append mount_options "${cmdlinevar#rootfs_mount_options\.}"
30 fi
31 done
32
33 echo $mount_options
34}
35
36do_mount_root() {
37 #mount_root start "$(compose_rootfs_mount_options)"
38 boot_run_hook preinit_mount_root
39 [ -f /sysupgrade.tgz -o -f /tmp/sysupgrade.tar ] && {
40 echo "- config restore -"
41 cp /etc/passwd /etc/group /etc/shadow /tmp
42 cd /
43 [ -f /sysupgrade.tgz ] && tar xzf /sysupgrade.tgz
44 [ -f /tmp/sysupgrade.tar ] && tar xf /tmp/sysupgrade.tar
45 missing_lines /tmp/passwd /etc/passwd >> /etc/passwd
46 missing_lines /tmp/group /etc/group >> /etc/group
47 missing_lines /tmp/shadow /etc/shadow >> /etc/shadow
48 rm /tmp/passwd /tmp/group /tmp/shadow
49 # Prevent configuration corruption on a power loss
50 sync
51 }
52}
53
54[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root