From 89fb789a0e5455ca33d449bf04ca327ac3c9db13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Mennetrier?= Date: Mon, 25 Oct 2021 23:03:08 +0200 Subject: [PATCH] Use yii commands during install yii commands are now used to migrate database, configure ldap connection, set admin user and so on --- conf/ldap.sql | 28 ------------------------- scripts/install | 55 ++++++++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 51 deletions(-) delete mode 100644 conf/ldap.sql diff --git a/conf/ldap.sql b/conf/ldap.sql deleted file mode 100644 index 53ff5e7..0000000 --- a/conf/ldap.sql +++ /dev/null @@ -1,28 +0,0 @@ -BEGIN; - -DELETE FROM setting WHERE -(`name` = 'auth.anonymousRegistration') OR -(`name` = 'auth.allowGuestAccess') OR -(`name` = 'auth.internalUsersCanInvite'); - -INSERT INTO setting (`name`, `value`, `module_id`) VALUES -('enabled', '1', 'ldap'), -('hostname', 'localhost', 'ldap'), -('port', '389', 'ldap'), -('encryption', '', 'ldap'), -('username', '', 'ldap'), -('password', '', 'ldap'), -('baseDn', 'ou=users,dc=yunohost,dc=org', 'ldap'), -('loginFilter', '(uid=%s)', 'ldap'), -('userFilter', 'objectClass=mailAccount', 'ldap'), -('emailAttribute', 'mail', 'ldap'), -('usernameAttribute', 'uid', 'ldap'), -('idAttribute', 'uid', 'ldap'), -('refreshUsers', '1', 'ldap'), -('auth.anonymousRegistration', '0', 'user'), -('auth.allowGuestAccess', '0', 'user'), -('auth.internalUsersCanInvite', '0', 'user'); - -UPDATE `user` SET `auth_mode` = 'ldap' WHERE `user`.`username` = '__ADMIN__'; - -COMMIT; diff --git a/scripts/install b/scripts/install index a46fa97..a57b1fc 100644 --- a/scripts/install +++ b/scripts/install @@ -136,35 +136,44 @@ ynh_systemd_action --service_name=nginx --action=reload # Installation with curl ynh_script_progression --message="Finalizing installation..." --weight=2 -admin_temp_pass=$(ynh_string_random 6) -admin_email=$(ynh_user_get_info "$admin" mail) -admin_firstname=$(ynh_user_get_info "$admin" firstname) -admin_lastname=$(ynh_user_get_info "$admin" lastname) +pushd $final_path/protected + php${YNH_PHP_VERSION} yii migrate/up --includeModuleMigrations=1 --interactive=0 -ynh_local_curl "/index.php?r=installer/index/go" + php${YNH_PHP_VERSION} yii settings/set ldap enabled '1' + php${YNH_PHP_VERSION} yii settings/set ldap hostname 'localhost' + php${YNH_PHP_VERSION} yii settings/set ldap port 389 + php${YNH_PHP_VERSION} yii settings/set ldap encryption '' + php${YNH_PHP_VERSION} yii settings/set ldap username '' + php${YNH_PHP_VERSION} yii settings/set ldap password '' + php${YNH_PHP_VERSION} yii settings/set ldap baseDn 'ou=users,dc=yunohost,dc=org' + php${YNH_PHP_VERSION} yii settings/set ldap loginFilter '(uid=%s)' + php${YNH_PHP_VERSION} yii settings/set ldap userFilter 'objectClass=mailAccount' + php${YNH_PHP_VERSION} yii settings/set ldap emailAttribute 'mail' + php${YNH_PHP_VERSION} yii settings/set ldap usernameAttribute 'uid' + php${YNH_PHP_VERSION} yii settings/set ldap idAttribute 'uid' + php${YNH_PHP_VERSION} yii settings/set ldap refreshUsers '1' + php${YNH_PHP_VERSION} yii settings/set ldap refreshUsers '1' -local_curl_csrf "/index.php?r=installer/config/basic" \ - "ConfigBasicForm[name]=YunoHost" + php${YNH_PHP_VERSION} yii ldap/sync + php${YNH_PHP_VERSION} yii user/make-admin ${admin} -local_curl_csrf "/index.php?r=installer/config/use-case" \ - "UseCaseForm[useCase]=" \ - "UseCaseForm[useCase]=other" + ynh_local_curl "/index.php?r=installer/index/go" -local_curl_csrf "/index.php?r=installer/config/admin" \ - `myynh_urlencode "User[username]=$admin"` \ - `myynh_urlencode "User[email]=$admin_email"` \ - `myynh_urlencode "Password[newPassword]=$admin_temp_pass"` \ - `myynh_urlencode "Password[newPasswordConfirm]=$admin_temp_pass"` \ - `myynh_urlencode "Profile[firstname]=${admin_firstname}"` \ - `myynh_urlencode "Profile[lastname]=${admin_lastname}"` \ - "save" + local_curl_csrf "/index.php?r=installer/config/basic" \ + "ConfigBasicForm[name]=YunoHost" -local_curl_csrf "/index.php?r=installer/config/sample-data" \ - "SampleDataForm[sampleData]=0" + local_curl_csrf "/index.php?r=installer/config/use-case" \ + "UseCaseForm[useCase]=" \ + "UseCaseForm[useCase]=other" -# Populate the LDAP parameters -ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="../conf/ldap.sql" -mysql -u $db_user -p${db_pwd} $db_name < ../conf/ldap.sql + local_curl_csrf "/index.php?r=installer/config/sample-data" \ + "SampleDataForm[sampleData]=0" + + php${YNH_PHP_VERSION} yii settings/set user auth.anonymousRegistration '0' + php${YNH_PHP_VERSION} yii settings/set user auth.allowGuestAccess '0' + php${YNH_PHP_VERSION} yii settings/set user auth.internalUsersCanInvite '0' + +popd # Remove the public access ynh_permission_update --permission="main" --remove="visitors"