mirror of
https://github.com/YunoHost-Apps/aeneria_ynh.git
synced 2024-09-03 18:06:15 +02:00
Use permissions hooks to create/enable/disable users
This commit is contained in:
parent
6f53361068
commit
7934b9a5e9
6 changed files with 75 additions and 82 deletions
37
hooks/post_app_addaccess
Normal file
37
hooks/post_app_addaccess
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
app=$1
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
source /etc/yunohost/apps/$app/scripts/_common.sh
|
||||
|
||||
# Retrieve arguments
|
||||
usernames=$2
|
||||
permission=$3
|
||||
groups=$4
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
phpversion=$(ynh_app_setting_get "$app" phpversion)
|
||||
|
||||
IFS=',' read -r -a user_list <<< "$usernames"
|
||||
IFS=',' read -r -a group_list <<< "$groups"
|
||||
|
||||
for group in "${group_list[@]}"
|
||||
do
|
||||
group_array=$(yunohost user group list --output-as json --quiet | jq -r --arg group "$group" ".groups.$group.members | .[]")
|
||||
user_list+=("${group_array[@]}")
|
||||
done
|
||||
|
||||
pushd $final_path
|
||||
for user in "${user_list[@]}"
|
||||
do
|
||||
mail=$(ynh_user_get_info --username="$user" --key=mail)
|
||||
user_exists=$(ynh_exec_as $app php$phpversion bin/console aeneria:user:exist "$mail")
|
||||
if [ $user_exists -eq 0 ]
|
||||
then
|
||||
user_pass=$(ynh_string_random)
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:user:add "$mail" "$user_pass" -n
|
||||
else
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:user:activate "$mail"
|
||||
fi
|
||||
done
|
||||
popd
|
28
hooks/post_app_removeaccess
Normal file
28
hooks/post_app_removeaccess
Normal file
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
app=$1
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
source /etc/yunohost/apps/$app/scripts/_common.sh
|
||||
|
||||
# Retrieve arguments
|
||||
usernames=$2
|
||||
permission=$3
|
||||
groups=$4
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
phpversion=$(ynh_app_setting_get "$app" phpversion)
|
||||
|
||||
IFS=',' read -r -a user_list <<< "$usernames"
|
||||
IFS=',' read -r -a group_list <<< "$groups"
|
||||
|
||||
for group in "${group_list[@]}"
|
||||
do
|
||||
group_array=$(yunohost user group list --output-as json --quiet | jq -r --arg group "$group" ".groups.$group.members | .[]")
|
||||
user_list+=("${group_array[@]}")
|
||||
done
|
||||
|
||||
for user in "${user_list[@]}"
|
||||
do
|
||||
mail=$(ynh_user_get_info --username="$user" --key=mail)
|
||||
cd "$final_path" && ynh_exec_as $app php$phpversion bin/console aeneria:user:deactivate "$mail" -n
|
||||
done
|
|
@ -1,25 +0,0 @@
|
|||
#!/bin/bash
|
||||
app=APPNAMETOCHANGE
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
source /etc/yunohost/apps/$app/scripts/_common.sh
|
||||
|
||||
# Retrieve arguments
|
||||
username=$1
|
||||
mail=$2
|
||||
password=$3 # Clear password
|
||||
firstname=$4
|
||||
lastname=$5
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
|
||||
pushd $final_path
|
||||
user_exists=$(ynh_exec_as $app php7.3 bin/console aeneria:user:exist "$mail")
|
||||
if [ $user_exists -eq 0 ]
|
||||
then
|
||||
user_pass=$(ynh_string_random)
|
||||
ynh_exec_as $app php7.3 bin/console aeneria:user:add "$mail" "$user_pass" -n
|
||||
else
|
||||
ynh_exec_as $app php7.3 bin/console aeneria:user:activate "$mail"
|
||||
fi
|
||||
popd
|
|
@ -1,17 +0,0 @@
|
|||
#!/bin/bash
|
||||
app=APPNAMETOCHANGE
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
source /etc/yunohost/apps/$app/scripts/_common.sh
|
||||
|
||||
# Retrieve arguments
|
||||
username=$1
|
||||
mail=$2
|
||||
password=$3 # Clear password
|
||||
firstname=$4
|
||||
lastname=$5
|
||||
final_path=$(ynh_app_setting_get "$app" final_path)
|
||||
|
||||
# Deactivate the user in aeneria
|
||||
cd "$final_path" && ynh_exec_as $app php7.3 bin/console aeneria:user:deactivate "$mail" -n
|
|
@ -131,16 +131,9 @@ ynh_script_progression --message="Installing aeneria..." --weight=1
|
|||
pushd $final_path
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:install "$app" -n
|
||||
|
||||
# Create aeneria's user
|
||||
for username in $(ynh_user_list)
|
||||
do
|
||||
mail=$(ynh_user_get_info --username=$username --key='mail')
|
||||
user_pass=$(ynh_string_random)
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:user:add "$mail" "$user_pass"
|
||||
done
|
||||
|
||||
# Set admin user
|
||||
mail=$(ynh_user_get_info --username=$admin --key='mail')
|
||||
# Create admin user
|
||||
mail=$(ynh_user_get_info --username="$admin" --key='mail')
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:user:add "$mail" "$(ynh_string_random)" -n
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:user:grant "$mail"
|
||||
popd
|
||||
|
||||
|
@ -156,14 +149,6 @@ ynh_add_config --template="../conf/aeneria.cron" --destination="/etc/cron.d/$app
|
|||
chown root: "/etc/cron.d/$app"
|
||||
chmod 644 "/etc/cron.d/$app"
|
||||
|
||||
#=================================================
|
||||
# ADAPT HOOK FOR AENERIA INSTANCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Adapting hooks..." --weight=1
|
||||
|
||||
ynh_replace_string --match_string="APPNAMETOCHANGE" --replace_string="$app" --target_file="../hooks/post_user_create"
|
||||
ynh_replace_string --match_string="APPNAMETOCHANGE" --replace_string="$app" --target_file="../hooks/post_user_delete"
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
|
|
@ -166,21 +166,14 @@ pushd $final_path
|
|||
ynh_exec_as $app php$phpversion bin/console cache:clear -n
|
||||
ynh_exec_as $app php$phpversion bin/console doctrine:migrations:migrate -n
|
||||
|
||||
# Create aeneria's user
|
||||
for username in $(ynh_user_list)
|
||||
do
|
||||
mail=$(ynh_user_get_info --username=$username --key='mail')
|
||||
user_exists=$(ynh_exec_as $app php$phpversion bin/console aeneria:user:exist "$mail")
|
||||
if [ $user_exists -eq 0 ]
|
||||
then
|
||||
user_pass=$(ynh_string_random)
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:user:add "$mail" "$user_pass" -n
|
||||
fi
|
||||
done
|
||||
|
||||
# Set admin user
|
||||
mail=$(ynh_user_get_info --username=$admin --key='mail')
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:user:grant "$mail" -n
|
||||
mail=$(ynh_user_get_info --username="$admin" --key='mail')
|
||||
user_exists=$(ynh_exec_as $app php$phpversion bin/console aeneria:user:exist "$mail")
|
||||
if [ $user_exists -eq 0 ]
|
||||
then
|
||||
user_pass=$(ynh_string_random)
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:user:add "$mail" "$user_pass" -n
|
||||
fi
|
||||
|
||||
# Regenerate RSA keys
|
||||
ynh_exec_as $app php$phpversion bin/console aeneria:generate-key --force -n
|
||||
|
@ -195,14 +188,6 @@ ynh_add_config --template="../conf/aeneria.cron" --destination="/etc/cron.d/$app
|
|||
chown root: "/etc/cron.d/$app"
|
||||
chmod 644 "/etc/cron.d/$app"
|
||||
|
||||
#=================================================
|
||||
# ADAPT HOOK FOR AENERIA INSTANCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Adapting hooks..." --weight=1
|
||||
|
||||
ynh_replace_string --match_string="APPNAMETOCHANGE" --replace_string=$app --target_file="../hooks/post_user_create"
|
||||
ynh_replace_string --match_string="APPNAMETOCHANGE" --replace_string=$app --target_file="../hooks/post_user_delete"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
|
Loading…
Add table
Reference in a new issue