mirror of
https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh.git
synced 2024-09-03 19:46:01 +02:00
Better handling of special chars like *
This commit is contained in:
parent
dac54950af
commit
b4fb086590
1 changed files with 7 additions and 5 deletions
|
@ -64,27 +64,29 @@ EOF
|
|||
}
|
||||
|
||||
function set__role {
|
||||
set -o noglob # Disable globbing to avoid expansions when passing * as value.
|
||||
declare values="list$role"
|
||||
newValues="${!values}" # Here we expand the dynamic variable we created in the previous line. ! Does the trick
|
||||
usersArray=(${newValues//,/ }) # Split the values using comma (,) as separator.
|
||||
|
||||
if [ -n "${!values}" ]
|
||||
if [ -n "$newValues" ]
|
||||
then
|
||||
ynh_systemd_action --service_name="$app" --action=stop
|
||||
# Get all entries between "permissions:" and "relay:" keys, remove the role part, remove commented parts, format it with newlines and clean whitespaces and double quotes.
|
||||
allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relay:/{flag=0} flag' "$final_path/config.yaml" | sed -r 's/: (admin|user|relay)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' )
|
||||
allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relay:/{flag=0} flag' "$final_path/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relay)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' )
|
||||
# Delete everything from the corresponding role to insert the new defined values. This way we also handle deletion of users.
|
||||
sed -i "/permissions:/,/relay:/{/: ${role}/d;}" "$final_path/config.yaml"
|
||||
sed -i "/permissions:/,/relay:/{/: $role/d;}" "$final_path/config.yaml"
|
||||
for user in "${usersArray[@]}"
|
||||
do
|
||||
if echo "$allDefinedEntries" | grep -q -E "^${user}$"
|
||||
if grep -q -x "${user}" <<< "$allDefinedEntries"
|
||||
then
|
||||
ynh_print_info "User $user already defined in another role."
|
||||
else
|
||||
sed -i "/permissions:/a \ \\\"${user}\": ${role}" "$final_path/config.yaml" # Whitespaces are needed so that the file can be correctly parsed
|
||||
sed -i "/permissions:/a \ \\\"$user\": $role" "$final_path/config.yaml" # Whitespaces are needed so that the file can be correctly parsed
|
||||
fi
|
||||
done
|
||||
fi
|
||||
set +o noglob
|
||||
|
||||
ynh_print_info "Users with role $role added in $final_path/config.yaml"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue