mirror of
https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh.git
synced 2024-09-03 19:46:01 +02:00
try
This commit is contained in:
parent
25b0f50e51
commit
b99c05e5e7
2 changed files with 59 additions and 47 deletions
|
@ -4,30 +4,16 @@ ynh_abort_if_errors
|
||||||
|
|
||||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
function get__botname {
|
#=================================================
|
||||||
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
get__botname() {
|
||||||
botname=$(ynh_app_setting_get --app $app --key botname)
|
botname=$(ynh_app_setting_get --app $app --key botname)
|
||||||
echo "${botname}"
|
echo "${botname}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function set__botname {
|
get__listuser() {
|
||||||
old_botname=$(ynh_app_setting_get --app $app --key botname)
|
|
||||||
if [ "$botname" -eq "$old_botname" ] # Check to avoid updating botname when it's not needed.
|
|
||||||
then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
ynh_app_setting_set --app=$app --key=botname --value="$botname"
|
|
||||||
synapse_instance=$(ynh_app_setting_get --app $app --key synapse_instance)
|
|
||||||
|
|
||||||
sed -i "s/username:.*/username: $botname/" "$final_path/config.yaml"
|
|
||||||
"$final_path/mautrix-whatsapp" -g -c "$final_path/config.yaml" -r "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
|
||||||
"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" || ynh_die --message="Synapse can't restart with the appservice configuration"
|
|
||||||
chown -R "$app:$app" "$final_path"
|
|
||||||
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
|
||||||
ynh_store_file_checksum --file="$final_path/config.yaml"
|
|
||||||
}
|
|
||||||
|
|
||||||
function get__listuser {
|
|
||||||
existingUsers=$(grep -- "\".*: user" "$final_path/config.yaml" | sed -r 's/: user//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
existingUsers=$(grep -- "\".*: user" "$final_path/config.yaml" | sed -r 's/: user//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
@ -35,7 +21,7 @@ function get__listuser {
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
function get__listrelay {
|
get__listrelay() {
|
||||||
existingRelayUsers=$(grep -- "\".*: relay" "$final_path/config.yaml" | sed -r 's/: relay//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
existingRelayUsers=$(grep -- "\".*: relay" "$final_path/config.yaml" | sed -r 's/: relay//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
@ -43,7 +29,7 @@ function get__listrelay {
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
function get__listadmin {
|
get__listadmin() {
|
||||||
existingAdmins=$(grep -- "\".*: admin" "$final_path/config.yaml" | sed -r 's/: admin//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
existingAdmins=$(grep -- "\".*: admin" "$final_path/config.yaml" | sed -r 's/: admin//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
@ -51,22 +37,15 @@ function get__listadmin {
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
function set__listuser {
|
#=================================================
|
||||||
role="user"
|
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
||||||
set_permissions
|
#=================================================
|
||||||
}
|
|
||||||
|
|
||||||
function set__listrelay {
|
#=================================================
|
||||||
role="relay"
|
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
||||||
set_permissions
|
#=================================================
|
||||||
}
|
|
||||||
|
|
||||||
function set__listadmin {
|
apply_permissions() {
|
||||||
role="admin"
|
|
||||||
set_permissions
|
|
||||||
}
|
|
||||||
|
|
||||||
set_permissions() {
|
|
||||||
set -o noglob # Disable globbing to avoid expansions when passing * as value.
|
set -o noglob # Disable globbing to avoid expansions when passing * as value.
|
||||||
declare values="list$role"
|
declare values="list$role"
|
||||||
newValues="${!values}" # Here we expand the dynamic variable we created in the previous line. ! Does the trick
|
newValues="${!values}" # Here we expand the dynamic variable we created in the previous line. ! Does the trick
|
||||||
|
@ -95,4 +74,37 @@ set_permissions() {
|
||||||
ynh_print_info "Users with role $role added in $final_path/config.yaml"
|
ynh_print_info "Users with role $role added in $final_path/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set__botname() {
|
||||||
|
old_botname=$(ynh_app_setting_get --app $app --key botname)
|
||||||
|
if [ "$botname" -eq "$old_botname" ] # Check to avoid updating botname when it's not needed.
|
||||||
|
then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
ynh_app_setting_set --app=$app --key=botname --value="$botname"
|
||||||
|
synapse_instance=$(ynh_app_setting_get --app $app --key synapse_instance)
|
||||||
|
|
||||||
|
sed -i "s/username:.*/username: $botname/" "$final_path/config.yaml"
|
||||||
|
"$final_path/mautrix-whatsapp" -g -c "$final_path/config.yaml" -r "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||||
|
"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" || ynh_die --message="Synapse can't restart with the appservice configuration"
|
||||||
|
chown -R "$app:$app" "$final_path"
|
||||||
|
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||||
|
ynh_store_file_checksum --file="$final_path/config.yaml"
|
||||||
|
}
|
||||||
|
|
||||||
|
set__listuser() {
|
||||||
|
role="user"
|
||||||
|
apply_permissions
|
||||||
|
}
|
||||||
|
|
||||||
|
set__listrelay() {
|
||||||
|
role="relay"
|
||||||
|
apply_permissions
|
||||||
|
}
|
||||||
|
|
||||||
|
set__listadmin() {
|
||||||
|
role="admin"
|
||||||
|
apply_permissions
|
||||||
|
}
|
||||||
|
|
||||||
ynh_app_config_run $1
|
ynh_app_config_run $1
|
||||||
|
|
|
@ -253,6 +253,17 @@ ynh_script_progression --message="Updating a configuration file..." --weight=2
|
||||||
|
|
||||||
ynh_add_config --template="../conf/config.yaml" --destination="$final_path/config.yaml"
|
ynh_add_config --template="../conf/config.yaml" --destination="$final_path/config.yaml"
|
||||||
|
|
||||||
|
# Re-apply permissions to avoid wrong syntax "domain.tld,domain2.tld: admin"
|
||||||
|
# x="$(yunohost app config get mautrix_whatsapp main.permissions.listuser)"
|
||||||
|
# yunohost app config set mautrix_whatsapp main.permissions.listuser -v ""
|
||||||
|
# yunohost app config set mautrix_whatsapp main.permissions.listuser -v "$x"
|
||||||
|
# x="$(yunohost app config get mautrix_whatsapp main.permissions.listrelay)"
|
||||||
|
# yunohost app config set mautrix_whatsapp main.permissions.listrelay -v ""
|
||||||
|
# yunohost app config set mautrix_whatsapp main.permissions.listrelay -v "$x"
|
||||||
|
# x="$(yunohost app config get mautrix_whatsapp main.permissions.listadmin)"
|
||||||
|
# yunohost app config set mautrix_whatsapp main.permissions.listadmin -v ""
|
||||||
|
# yunohost app config set mautrix_whatsapp main.permissions.listadmin -v "$x"
|
||||||
|
|
||||||
chmod 400 "$final_path/config.yaml"
|
chmod 400 "$final_path/config.yaml"
|
||||||
chown $app:$app "$final_path/config.yaml"
|
chown $app:$app "$final_path/config.yaml"
|
||||||
|
|
||||||
|
@ -305,17 +316,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||||
# Start a systemd service
|
# Start a systemd service
|
||||||
ynh_systemd_action --service_name=$app --action="start"
|
ynh_systemd_action --service_name=$app --action="start"
|
||||||
|
|
||||||
# Re-apply permissions to avoid wrong syntax "domain.tld,domain2.tld: admin"
|
|
||||||
x="$(yunohost app config get mautrix_whatsapp main.permissions.listuser)"
|
|
||||||
yunohost app config set mautrix_whatsapp main.permissions.listuser -v ""
|
|
||||||
yunohost app config set mautrix_whatsapp main.permissions.listuser -v "$x"
|
|
||||||
x="$(yunohost app config get mautrix_whatsapp main.permissions.listrelay)"
|
|
||||||
yunohost app config set mautrix_whatsapp main.permissions.listrelay -v ""
|
|
||||||
yunohost app config set mautrix_whatsapp main.permissions.listrelay -v "$x"
|
|
||||||
x="$(yunohost app config get mautrix_whatsapp main.permissions.listadmin)"
|
|
||||||
yunohost app config set mautrix_whatsapp main.permissions.listadmin -v ""
|
|
||||||
yunohost app config set mautrix_whatsapp main.permissions.listadmin -v "$x"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue