a15c972220c566b381b35e6095e7a9ee055fe8ae
[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 cp /etc/passwd /etc/group /etc/shadow /tmp
24 cd /
25 tar xzf /sysupgrade.tgz
26 missing_lines /tmp/passwd /etc/passwd >> /etc/passwd
27 missing_lines /tmp/group /etc/group >> /etc/group
28 missing_lines /tmp/shadow /etc/shadow >> /etc/shadow
29 rm /tmp/passwd /tmp/group /tmp/shadow
30 # Prevent configuration corruption on a power loss
31 sync
32 }
33 }
34
35 [ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root