aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README7
-rwxr-xr-xdfly-update49
2 files changed, 53 insertions, 3 deletions
diff --git a/README b/README
index dcad080..d40e0ed 100644
--- a/README
+++ b/README
@@ -31,10 +31,11 @@ the following steps:
1. mount the system image file (*.img);
2. backup the current kernel and world (including "/etc");
3. install the kernel and world using cpdup (similar to the installer);
-4. identify the new/changed "/etc" files, rename the conflicting ones
+4. create new users and groups;
+5. identify the new/changed "/etc" files, rename the conflicting ones
with suffix ".__new__" and then copy over;
-5. get obsolete files from "Makefile_upgrade.inc" and remove them;
-6. umount, show the "*.__new__" files need manual merge.
+6. get obsolete files from "Makefile_upgrade.inc" and remove them;
+7. umount, show the "*.__new__" files need manual merge.
Usage
-----
diff --git a/dfly-update b/dfly-update
index 971b1a2..5f4d370 100755
--- a/dfly-update
+++ b/dfly-update
@@ -36,6 +36,7 @@ EC_TAR=18
EC_MTREE=19
EC_CPDUP=20
EC_NOFILE=21
+EC_PW=22
#
@@ -261,6 +262,53 @@ install_system() {
echo " => DONE!"
}
+# Add new users and groups
+add_users() {
+ [ $# -eq 0 ] ||
+ error ${EC_ARGS} "add_users: invalid arguments: $@"
+
+ local fpasswd="${MNT_DIR}/etc.hdd/master.passwd"
+ local fgroup="${MNT_DIR}/etc.hdd/group"
+ local _name _pw _uid _gid _gids item
+ local _class _change _expire _gecos _home _shell _members
+ echo "Adding new users and groups ..."
+
+ echo " => Adding new users ..."
+ _gids=""
+ grep -Ev '^(#.*|\s*)$' ${fpasswd} |
+ while IFS=':' read -r _name _pw _uid _gid _class \
+ _change _expire _gecos _home _shell; do
+ pw usershow ${_name} -q >/dev/null && continue
+
+ # NOTE: There is circular dependence: 'groupadd' requires the members
+ # already exist, while 'useradd' requires the group exists.
+ # So first assign new users to the 'nogroup' group, and make
+ # adjustments after group creation.
+ echo " * ${_name}, ${_uid}, ${_gid}, ${_gecos}, ${_home}, ${_shell}"
+ pw useradd ${_name} \
+ -u ${_uid} -g nogroup -d ${_home} -s ${_shell} \
+ -L "${_class}" -c "${_gecos}" || exit ${EC_PW}
+ _gids="${_gids} ${_name}:${_gid}"
+ done
+
+ echo " => Adding new groups ..."
+ grep -Ev '^(#.*|\s*)$' ${fgroup} |
+ while IFS=':' read -r _name _pw _gid _members; do
+ pw groupshow ${_name} -q >/dev/null && continue
+
+ echo " * ${_name}, ${_gid}, ${_members}"
+ pw groupadd ${_name} -g ${_gid} -M "${_members}" || exit ${EC_PW}
+ done
+
+ echo " => Adjusting the group of new users ..."
+ for item in ${_gids}; do
+ _name=${item%:*}
+ _gid=${item#*:}
+ echo " * ${_name}, ${_gid}"
+ pw usermod ${_name} -g ${_gid} || exit ${EC_PW}
+ done
+}
+
# Upgrade the system with new configuration files
upgrade_system() {
[ $# -eq 0 ] ||
@@ -434,6 +482,7 @@ cmd_upgrade() {
error ${EC_ARGS} "cmd_upgrade: invalid arguments: $@"
install_system
+ add_users
upgrade_system
}