support/scripts/mkusers: fix shellcheck errors
the user tables do not use trailing backslash \ to continue lines,
so we don't want them to be interpreted thusly, so we use 'read -r'
(SC2162).
Integer variables need not be quoted (SC2086). In any case, should
there be an actual issue and they be set empty, that would cause a
runtime issue, wether they be quoted or not.
The binary -o and -a ar perfectly defined in bash's test (SC2166).
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
(cherry picked from commit 01b3053cec
)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
This commit is contained in:
parent
9698702615
commit
1f46f56346
@ -1466,7 +1466,6 @@ support/scripts/expunge-gconv-modules Shellcheck
|
|||||||
support/scripts/fix-configure-powerpc64.sh EmptyLastLine
|
support/scripts/fix-configure-powerpc64.sh EmptyLastLine
|
||||||
support/scripts/generate-gitlab-ci-yml Shellcheck
|
support/scripts/generate-gitlab-ci-yml Shellcheck
|
||||||
support/scripts/mkmakefile ConsecutiveEmptyLines Shellcheck
|
support/scripts/mkmakefile ConsecutiveEmptyLines Shellcheck
|
||||||
support/scripts/mkusers Shellcheck
|
|
||||||
support/scripts/setlocalversion Shellcheck
|
support/scripts/setlocalversion Shellcheck
|
||||||
support/testing/tests/core/post-build.sh Shellcheck
|
support/testing/tests/core/post-build.sh Shellcheck
|
||||||
support/testing/tests/package/test_opkg/post-build.sh Shellcheck
|
support/testing/tests/package/test_opkg/post-build.sh Shellcheck
|
||||||
|
@ -26,6 +26,7 @@ error() {
|
|||||||
shift
|
shift
|
||||||
|
|
||||||
printf "%s: " "${myname}" >&2
|
printf "%s: " "${myname}" >&2
|
||||||
|
# shellcheck disable=SC2059 # fmt is the format passed to error()
|
||||||
printf "${fmt}" "${@}" >&2
|
printf "${fmt}" "${@}" >&2
|
||||||
}
|
}
|
||||||
fail() {
|
fail() {
|
||||||
@ -145,6 +146,8 @@ check_user_validity() {
|
|||||||
fail "invalid username '%s\n'" "${username}"
|
fail "invalid username '%s\n'" "${username}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086 # gid is a non-empty int
|
||||||
|
# shellcheck disable=SC2166 # [ .. -o .. ] works well in this case
|
||||||
if [ ${gid} -lt -2 -o ${gid} -eq 0 ]; then
|
if [ ${gid} -lt -2 -o ${gid} -eq 0 ]; then
|
||||||
fail "invalid gid '%d' for '%s'\n" ${gid} "${username}"
|
fail "invalid gid '%d' for '%s'\n" ${gid} "${username}"
|
||||||
elif [ ${gid} -ge 0 ]; then
|
elif [ ${gid} -ge 0 ]; then
|
||||||
@ -171,6 +174,8 @@ check_user_validity() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086 # uid is a non-empty int
|
||||||
|
# shellcheck disable=SC2166 # [ .. -o .. ] works well in this case
|
||||||
if [ ${uid} -lt -2 -o ${uid} -eq 0 ]; then
|
if [ ${uid} -lt -2 -o ${uid} -eq 0 ]; then
|
||||||
fail "invalid uid '%d' for '%s'\n" ${uid} "${username}"
|
fail "invalid uid '%d' for '%s'\n" ${uid} "${username}"
|
||||||
elif [ ${uid} -ge 0 ]; then
|
elif [ ${uid} -ge 0 ]; then
|
||||||
@ -190,6 +195,7 @@ check_user_validity() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# check the user does not already exist in another group
|
# check the user does not already exist in another group
|
||||||
|
# shellcheck disable=SC2166 # [ .. -a .. ] works well in this case
|
||||||
if [ -n "${_ugroup}" -a "${_ugroup}" != "${group}" ]; then
|
if [ -n "${_ugroup}" -a "${_ugroup}" != "${group}" ]; then
|
||||||
fail "user '%s' already exists with group '%s' (wants '%s')\n" \
|
fail "user '%s' already exists with group '%s' (wants '%s')\n" \
|
||||||
"${username}" "${_ugroup}" "${group}"
|
"${username}" "${_ugroup}" "${group}"
|
||||||
@ -218,6 +224,7 @@ generate_gid() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
# shellcheck disable=SC2086 # gid and maxgid are non-empty ints
|
||||||
if [ ${gid} -gt ${maxgid} ]; then
|
if [ ${gid} -gt ${maxgid} ]; then
|
||||||
fail "can not allocate a GID for group '%s'\n" "${group}"
|
fail "can not allocate a GID for group '%s'\n" "${group}"
|
||||||
fi
|
fi
|
||||||
@ -233,6 +240,7 @@ add_one_group() {
|
|||||||
local members
|
local members
|
||||||
|
|
||||||
# Generate a new GID if needed
|
# Generate a new GID if needed
|
||||||
|
# shellcheck disable=SC2086 # gid is a non-empty int
|
||||||
if [ ${gid} -eq ${AUTO_USER_ID} ]; then
|
if [ ${gid} -eq ${AUTO_USER_ID} ]; then
|
||||||
gid="$( generate_gid "${group}" $FIRST_USER_GID $LAST_USER_GID )"
|
gid="$( generate_gid "${group}" $FIRST_USER_GID $LAST_USER_GID )"
|
||||||
elif [ ${gid} -eq ${AUTO_SYSTEM_ID} ]; then
|
elif [ ${gid} -eq ${AUTO_SYSTEM_ID} ]; then
|
||||||
@ -272,6 +280,7 @@ generate_uid() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
# shellcheck disable=SC2086 # uid is a non-empty int
|
||||||
if [ ${uid} -gt ${maxuid} ]; then
|
if [ ${uid} -gt ${maxuid} ]; then
|
||||||
fail "can not allocate a UID for user '%s'\n" "${username}"
|
fail "can not allocate a UID for user '%s'\n" "${username}"
|
||||||
fi
|
fi
|
||||||
@ -323,6 +332,7 @@ add_one_user() {
|
|||||||
check_user_validity "${username}" "${uid}" "${group}" "${gid}"
|
check_user_validity "${username}" "${uid}" "${group}" "${gid}"
|
||||||
|
|
||||||
# Generate a new UID if needed
|
# Generate a new UID if needed
|
||||||
|
# shellcheck disable=SC2086 # uid is a non-empty int
|
||||||
if [ ${uid} -eq ${AUTO_USER_ID} ]; then
|
if [ ${uid} -eq ${AUTO_USER_ID} ]; then
|
||||||
uid="$( generate_uid "${username}" $FIRST_USER_UID $LAST_USER_UID )"
|
uid="$( generate_uid "${username}" $FIRST_USER_UID $LAST_USER_UID )"
|
||||||
elif [ ${uid} -eq ${AUTO_SYSTEM_ID} ]; then
|
elif [ ${uid} -eq ${AUTO_SYSTEM_ID} ]; then
|
||||||
@ -399,7 +409,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Read in all the file in memory, exclude empty lines and comments
|
# Read in all the file in memory, exclude empty lines and comments
|
||||||
while read line; do
|
while read -r line; do
|
||||||
ENTRIES+=( "${line}" )
|
ENTRIES+=( "${line}" )
|
||||||
done < <( sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" )
|
done < <( sed -r -e 's/#.*//; /^[[:space:]]*$/d;' "${USERS_TABLE}" )
|
||||||
|
|
||||||
@ -410,14 +420,16 @@ main() {
|
|||||||
|
|
||||||
# First, create all the main groups which gid is *not* automatic
|
# First, create all the main groups which gid is *not* automatic
|
||||||
for line in "${ENTRIES[@]}"; do
|
for line in "${ENTRIES[@]}"; do
|
||||||
read username uid group gid passwd home shell groups comment <<<"${line}"
|
read -r username uid group gid passwd home shell groups comment <<<"${line}"
|
||||||
|
# shellcheck disable=SC2086 # gid is a non-empty int
|
||||||
[ ${gid} -ge 0 ] || continue # Automatic gid
|
[ ${gid} -ge 0 ] || continue # Automatic gid
|
||||||
add_one_group "${group}" "${gid}"
|
add_one_group "${group}" "${gid}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Then, create all the main groups which gid *is* automatic
|
# Then, create all the main groups which gid *is* automatic
|
||||||
for line in "${ENTRIES[@]}"; do
|
for line in "${ENTRIES[@]}"; do
|
||||||
read username uid group gid passwd home shell groups comment <<<"${line}"
|
read -r username uid group gid passwd home shell groups comment <<<"${line}"
|
||||||
|
# shellcheck disable=SC2086 # gid is a non-empty int
|
||||||
[ ${gid} -lt 0 ] || continue # Non-automatic gid
|
[ ${gid} -lt 0 ] || continue # Non-automatic gid
|
||||||
add_one_group "${group}" "${gid}"
|
add_one_group "${group}" "${gid}"
|
||||||
done
|
done
|
||||||
@ -428,8 +440,9 @@ main() {
|
|||||||
# system gid if the uid is a system user (<= LAST_SYSTEM_UID),
|
# system gid if the uid is a system user (<= LAST_SYSTEM_UID),
|
||||||
# otherwise a user gid.
|
# otherwise a user gid.
|
||||||
for line in "${ENTRIES[@]}"; do
|
for line in "${ENTRIES[@]}"; do
|
||||||
read username uid group gid passwd home shell groups comment <<<"${line}"
|
read -r username uid group gid passwd home shell groups comment <<<"${line}"
|
||||||
if [ "${groups}" != "-" ]; then
|
if [ "${groups}" != "-" ]; then
|
||||||
|
# shellcheck disable=SC2086 # uid is a non-empty int
|
||||||
if [ ${uid} -le 0 ]; then
|
if [ ${uid} -le 0 ]; then
|
||||||
auto_id=${uid}
|
auto_id=${uid}
|
||||||
elif [ ${uid} -le ${LAST_SYSTEM_UID} ]; then
|
elif [ ${uid} -le ${LAST_SYSTEM_UID} ]; then
|
||||||
@ -450,8 +463,9 @@ main() {
|
|||||||
|
|
||||||
# Now, add users whose uid is *not* automatic
|
# Now, add users whose uid is *not* automatic
|
||||||
for line in "${ENTRIES[@]}"; do
|
for line in "${ENTRIES[@]}"; do
|
||||||
read username uid group gid passwd home shell groups comment <<<"${line}"
|
read -r username uid group gid passwd home shell groups comment <<<"${line}"
|
||||||
[ "${username}" != "-" ] || continue # Magic string to skip user creation
|
[ "${username}" != "-" ] || continue # Magic string to skip user creation
|
||||||
|
# shellcheck disable=SC2086 # uid is a non-empty int
|
||||||
[ ${uid} -ge 0 ] || continue # Automatic uid
|
[ ${uid} -ge 0 ] || continue # Automatic uid
|
||||||
add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
|
add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
|
||||||
"${home}" "${shell}" "${groups}" "${comment}"
|
"${home}" "${shell}" "${groups}" "${comment}"
|
||||||
@ -459,8 +473,9 @@ main() {
|
|||||||
|
|
||||||
# Finally, add users whose uid *is* automatic
|
# Finally, add users whose uid *is* automatic
|
||||||
for line in "${ENTRIES[@]}"; do
|
for line in "${ENTRIES[@]}"; do
|
||||||
read username uid group gid passwd home shell groups comment <<<"${line}"
|
read -r username uid group gid passwd home shell groups comment <<<"${line}"
|
||||||
[ "${username}" != "-" ] || continue # Magic string to skip user creation
|
[ "${username}" != "-" ] || continue # Magic string to skip user creation
|
||||||
|
# shellcheck disable=SC2086 # uid is a non-empty int
|
||||||
[ ${uid} -lt 0 ] || continue # Non-automatic uid
|
[ ${uid} -lt 0 ] || continue # Non-automatic uid
|
||||||
add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
|
add_one_user "${username}" "${uid}" "${group}" "${gid}" "${passwd}" \
|
||||||
"${home}" "${shell}" "${groups}" "${comment}"
|
"${home}" "${shell}" "${groups}" "${comment}"
|
||||||
|
Loading…
Reference in New Issue
Block a user