Skip to content

Commit

Permalink
base-files: merge /etc/passwd et al at sysupgrade config restore
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Golle <[email protected]>
  • Loading branch information
dangowrt committed Oct 22, 2020
1 parent 2812ea3 commit de7ca7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package/base-files/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
include $(INCLUDE_DIR)/feeds.mk

PKG_NAME:=base-files
PKG_RELEASE:=232
PKG_RELEASE:=233
PKG_FLAGS:=nonshared

PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
Expand Down
16 changes: 16 additions & 0 deletions package/base-files/files/lib/preinit/80_mount_root
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2010 Vertical Communications

missing_lines() {
local file1 file2 line
file1="$1"
file2="$2"
oIFS="$IFS"
IFS=":"
while read line; do
set -- $line
grep -q "^$1:" "$file2" || echo "$*"
done < "$file1"
IFS="$oIFS"
}

do_mount_root() {
mount_root
boot_run_hook preinit_mount_root
[ -f /sysupgrade.tgz ] && {
echo "- config restore -"
cd /
tar xzf /sysupgrade.tgz
missing_lines /rom/etc/passwd /etc/passwd >> /etc/passwd
missing_lines /rom/etc/group /etc/group >> /etc/group
missing_lines /rom/etc/shadow /etc/shadow >> /etc/shadow
# Prevent configuration corruption on a power loss
sync
}
Expand Down

0 comments on commit de7ca7d

Please sign in to comment.