80_mount_root 920 B

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