aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2020-12-27 21:41:57 +0800
committerAaron LI <aly@aaronly.me>2020-12-27 21:41:57 +0800
commit4f2318ef5c45287feb5ec4248954107f599c8109 (patch)
tree79acf9a9e9048fb685013d1bb97d085c26e662b4
parent3142ec6809343dc63488add4e1c92d0e73cccd2b (diff)
downloaddfly-update-4f2318ef5c45287feb5ec4248954107f599c8109.tar.bz2
Fix add_users() issue about '_gids' variable
A pipe creates a subshell, so updates to the '_gids' variable would just get lost after the while loop. Use IO redirection instead of pipe to fix this issue.
-rwxr-xr-xdfly-update26
1 files changed, 15 insertions, 11 deletions
diff --git a/dfly-update b/dfly-update
index e8d6db7..f4ab6ed 100755
--- a/dfly-update
+++ b/dfly-update
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# Copyright (c) 2017-2019 Aaron LI <aly@aaronly.me>
+# Copyright (c) 2017-2020 Aaron LI <aly@aaronly.me>
# MIT License
#
# Tool to update a DragonFly BSD system using binary releases or
@@ -265,36 +265,40 @@ add_users() {
echo " => Adding new users ..."
_gids=""
- grep -Ev '^(#.*|\s*)$' ${fpasswd} |
- while IFS=':' read -r _name _pw _uid _gid _class \
- _change _expire _gecos _home _shell; do
+ while IFS=':' read -r _name _pw _uid _gid _class \
+ _change _expire _gecos _home _shell; do
+ case ${_name} in
+ '' | \#*) continue ;;
+ esac
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}"
+ 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
+ done < ${fpasswd}
echo " => Adding new groups ..."
- grep -Ev '^(#.*|\s*)$' ${fgroup} |
- while IFS=':' read -r _name _pw _gid _members; do
+ while IFS=':' read -r _name _pw _gid _members; do
+ case ${_name} in
+ '' | \#*) continue ;;
+ esac
pw groupshow ${_name} -q >/dev/null && continue
- echo " * ${_name}, ${_gid}, ${_members}"
+ echo " * ${_name}: ${_gid}, ${_members}"
pw groupadd ${_name} -g ${_gid} -M "${_members}" || exit ${EC_PW}
- done
+ done < ${fgroup}
echo " => Adjusting the group of new users ..."
for item in ${_gids}; do
_name=${item%:*}
_gid=${item#*:}
- echo " * ${_name}, ${_gid}"
+ echo " * ${_name}: ${_gid}"
pw usermod ${_name} -g ${_gid} || exit ${EC_PW}
done
}