Simplification of list_account_by_UID in ftpadmin

Setting / unsetting IFS variables can be removed by setting it only
in the loop context.

The for cat can be replaced by a simpler while read loop.

Proper variable quoting was added.

Changed the way modif was optionally passed, this removes the
extraneous ':' at the end.

echo(1) the lines as we go instead of building an array, this removes
the possibility of sub-shell screwups.
This commit is contained in:
Patrick Marchand 2018-11-09 17:33:44 -05:00
parent e3a50177c8
commit e97ddd8be0

View file

@ -60,36 +60,24 @@ get_user_login_by_UID() {
list_accounts_by_UID() { list_accounts_by_UID() {
uid=$1 uid=$1
account_list='' while IFS=$'\n' read -r line;
oldIFS=IFS
IFS=$'\n'
for line in `cat $VPASSWD_PATH`
do do
line_uid=`echo $line | cut -d":" -f3` line_uid="$(echo "$line" | cut -d":" -f3)"
if [ ! "$uid" ] || [ "$line_uid" == "$uid" ]; then if [[ ! "$uid" ]] || [[ "$line_uid" == "$uid" ]]; then
username=`get_user_login_by_UID $line_uid` username="$(get_user_login_by_UID "$line_uid")"
account=`echo $line | cut -d":" -f1` account="$(echo "$line" | cut -d":" -f1)"
path=`echo $line | cut -d":" -f6` path="$(echo "$line" | cut -d":" -f6)"
if [ -r $path/.size ]; then size="$(du -s "$path" | cut -f 1)"
size=`cat $path/.size` #modif="$(cat $path/.lastmodified)"
else
size=0
fi
#modif=`cat $path/.lastmodified`
# Passage en minuscule ? # Passage en minuscule ?
#account=`echo $account | tr '[A-Z]' '[a-z]'` #account="$(echo $account | tr '[A-Z]' '[a-z]')"
#path=`echo $path | tr '[A-Z]' '[a-z]'` #path="$(echo $path | tr '[A-Z]' '[a-z]')"
account_list="${account_list}$username:$account:$path:$size:$modif\n" echo "$username:$account:$path:$size${modif:+:$modif}"
fi fi
done done < "$VPASSWD_PATH"
echo "$account_list"
IFS=$oldIFS
} }
add_account() { add_account() {