Skip to contentSkip to conversation

mkusers: make it work with mksh

PATCH New Kurt Van Dijck 2 participants 2 messages May 30, 2016 – Jul 5, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkusers: make it work with mksh

I use mksh as my /bin/sh.
I found that mkusers does not work.
This patch alters the script so that it works with mksh also.

---
 support/scripts/mkusers | 43 +++++++++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 16 deletions(-)
support/scripts/mkusers +27 -16
index e2c24c7..68fda99 100755
@@ -370,9 +370,9 @@ main() {
     fi
 
     # Read in all the file in memory, exclude empty lines and comments
-    while read line; do
-        LINES+=( "${line}" )
-    done < <( sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" )
+    #while read line; do
+    #    LINES+=( "${line}" )
+    #done < < ( sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" )
 
     # We first create groups whose gid is not -1, and then we create groups
     # whose gid is -1 (automatic), so that, if a group is defined both with
@@ -380,24 +380,30 @@ main() {
     # used, rather than a different automatic gid is computed.
 
     # First, create all the main groups which gid is *not* automatic
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
-        [ ${gid} -ge 0 ] || continue    # Automatic gid
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while 
+        read username uid group gid passwd home shell groups comment; do
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
+        [ "${gid}" -ge 0 ] || continue    # Automatic gid
         add_one_group "${group}" "${gid}"
     done
 
     # Then, create all the main groups which gid *is* automatic
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
-        [ ${gid} -eq -1 ] || continue    # Non-automatic gid
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while 
+        read username uid group gid passwd home shell groups comment; do
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
+        [ "${gid}" -eq -1 ] || continue    # Non-automatic gid
         add_one_group "${group}" "${gid}"
     done
 
     # Then, create all the additional groups
     # If any additional group is already a main group, we should use
     # the gid of that main group; otherwise, we can use any gid
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while
+        read username uid group gid passwd home shell groups comment; do
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
         if [ "${groups}" != "-" ]; then
             for g in ${groups//,/ }; do
                 add_one_group "${g}" -1
@@ -411,17 +417,22 @@ main() {
     # uid be generated.
 
     # Now, add users whose uid is *not* automatic
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while
+        read username uid group gid passwd home shell groups comment; do
+
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
         [ "${username}" != "-" ] || continue # Magic string to skip user creation
-        [ ${uid} -ge 0         ] || continue # Automatic uid
+        [ "${uid}" -ge 0       ] || continue # Automatic uid
         add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
                      "${home}" "${shell}" "${groups}" "${comment}"
     done
 
     # Finally, add users whose uid *is* automatic
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while
+        read username uid group gid passwd home shell groups comment; do
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
         [ "${username}" != "-" ] || continue # Magic string to skip user creation
         [ ${uid} -eq -1        ] || continue # Non-automatic uid
         add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
Signature · 1 line
1.8.5.rc3
#1 lore raw

PATCH 1/1 mkusers: make it work with mksh

Kurt, All,

On 2016-05-30 08:37 +0200, Kurt Van Dijck spake thusly:

Quoted 1 line

I use mksh as my /bin/sh.

mkuser does not use /bin/sh, it explicitly uses bash. See the first line of that script:

    #!/usr/bin/env bash
Quoted 28 lines

I found that mkusers does not work.
This patch alters the script so that it works with mksh also.

---
 support/scripts/mkusers | 43 +++++++++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 16 deletions(-)
support/scripts/mkusers +3 -3
index e2c24c7..68fda99 100755
@@ -370,9 +370,9 @@ main() {
     fi
 
     # Read in all the file in memory, exclude empty lines and comments
-    while read line; do
-        LINES+=( "${line}" )
-    done < <( sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" )
+    #while read line; do
+    #    LINES+=( "${line}" )
+    #done < < ( sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" )
 
     # We first create groups whose gid is not -1, and then we create groups
     # whose gid is -1 (automatic), so that, if a group is defined both with
@@ -380,24 +380,30 @@ main() {
     # used, rather than a different automatic gid is computed.
 

support/scripts/mkusers main() { · line 388

Quoted 10 lines
support/scripts/mkusers +5 -3
     # First, create all the main groups which gid is *not* automatic
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
-        [ ${gid} -ge 0 ] || continue    # Automatic gid
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while 
+        read username uid group gid passwd home shell groups comment; do
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
+        [ "${gid}" -ge 0 ] || continue    # Automatic gid
         add_one_group "${group}" "${gid}"

This does not work in case of error: the add_one_group function will call "exit 1" in case of error, causing the shell to exit, but since you are now using a pipe command, the script itself will not exit.

This is wrong.

But anyway, because the script is explcitly calling to bash, I'd like to understand why it would fail with mksh, since mksh is not used at all...

Regards,
Yann E. MORIN.

Quoted 61 lines
support/scripts/mkusers +19 -10
     done
 
     # Then, create all the main groups which gid *is* automatic
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
-        [ ${gid} -eq -1 ] || continue    # Non-automatic gid
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while 
+        read username uid group gid passwd home shell groups comment; do
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
+        [ "${gid}" -eq -1 ] || continue    # Non-automatic gid
         add_one_group "${group}" "${gid}"
     done
 
     # Then, create all the additional groups
     # If any additional group is already a main group, we should use
     # the gid of that main group; otherwise, we can use any gid
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while
+        read username uid group gid passwd home shell groups comment; do
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
         if [ "${groups}" != "-" ]; then
             for g in ${groups//,/ }; do
                 add_one_group "${g}" -1
@@ -411,17 +417,22 @@ main() {
     # uid be generated.
 
     # Now, add users whose uid is *not* automatic
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while
+        read username uid group gid passwd home shell groups comment; do
+
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
         [ "${username}" != "-" ] || continue # Magic string to skip user creation
-        [ ${uid} -ge 0         ] || continue # Automatic uid
+        [ "${uid}" -ge 0       ] || continue # Automatic uid
         add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
                      "${home}" "${shell}" "${groups}" "${comment}"
     done
 
     # Finally, add users whose uid *is* automatic
-    for line in "${LINES[@]}"; do
-        read username uid group gid passwd home shell groups comment <<<"${line}"
+    sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" | while
+        read username uid group gid passwd home shell groups comment; do
+    #for line in "${LINES[@]}"; do
+        #read username uid group gid passwd home shell groups comment <<<"${line}"
         [ "${username}" != "-" ] || continue # Magic string to skip user creation
         [ ${uid} -eq -1        ] || continue # Non-automatic uid
         add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
Signature · 6 lines
1.8.5.rc3

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'