base-files: merge /etc/passwd et al at sysupgrade config restore
[openwrt/openwrt.git] / package / base-files / files / lib / preinit / 80_mount_root
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3 # Copyright (C) 2010 Vertical Communications
4
5 missing_lines() {
6 local file1 file2 line
7 file1="$1"
8 file2="$2"
9 oIFS="$IFS"
10 IFS=":"
11 while read line; do
12 set -- $line
13 grep -q "^$1:" "$file2" || echo "$*"
14 done < "$file1"
15 IFS="$oIFS"
16 }
17
18 do_mount_root() {
19 mount_root
20 boot_run_hook preinit_mount_root
21 [ -f /sysupgrade.tgz ] && {
22 echo "- config restore -"
23 cd /
24 tar xzf /sysupgrade.tgz
25 missing_lines /rom/etc/passwd /etc/passwd >> /etc/passwd
26 missing_lines /rom/etc/group /etc/group >> /etc/group
27 missing_lines /rom/etc/shadow /etc/shadow >> /etc/shadow
28 # Prevent configuration corruption on a power loss
29 sync
30 }
31 }
32
33 [ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root