mirror of
https://github.com/YunoHost-Apps/kimai2_ynh.git
synced 2024-09-03 19:26:26 +02:00
enhancement:New user registration and choose database
This commit is contained in:
parent
d705a35246
commit
c0246fb0a3
9 changed files with 158 additions and 48 deletions
|
@ -7,6 +7,8 @@
|
|||
; Manifest
|
||||
domain="domain.tld" (DOMAIN)
|
||||
admin="john" (USER)
|
||||
database="mysql"
|
||||
registration=1
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
|
|
29
conf/.env.sqlite
Normal file
29
conf/.env.sqlite
Normal file
|
@ -0,0 +1,29 @@
|
|||
# This file is a "template" of which env vars need to be defined for your application
|
||||
# Copy this file to .env file for development, create environment variables when deploying to production
|
||||
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
|
||||
|
||||
# KIMAI DEFAULT ENV VARS
|
||||
DATABASE_PREFIX=kimai2_
|
||||
MAILER_FROM=admin@__DOMAIN__
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
APP_ENV=prod
|
||||
APP_SECRET=__RANDOM_KEY__
|
||||
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
|
||||
#TRUSTED_HOSTS=localhost,example.com
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
###> doctrine/doctrine-bundle ###
|
||||
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
|
||||
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data/kimai.sqlite"
|
||||
# Configure your db driver and server_version in config/packages/doctrine.yaml
|
||||
# DATABASE_URL=mysql://__DB_USER__:__DB_PASSWORD__@127.0.0.1:3306/__DB_NAME__
|
||||
DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/kimai.sqlite
|
||||
###< doctrine/doctrine-bundle ###
|
||||
|
||||
###> symfony/swiftmailer-bundle ###
|
||||
# For Gmail as a transport, use: "gmail://username:password@localhost"
|
||||
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
|
||||
# Delivery is disabled by default via "null://localhost"
|
||||
MAILER_URL=smtp://localhost:25?encryption=&auth_mode=
|
||||
###< symfony/swiftmailer-bundle ###
|
3
conf/local.yaml
Normal file
3
conf/local.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
kimai:
|
||||
user:
|
||||
registration: __REGISTRATION__
|
|
@ -46,6 +46,22 @@
|
|||
},
|
||||
"example": "johndoe"
|
||||
},
|
||||
{
|
||||
"name": "database",
|
||||
"ask": {
|
||||
"en": "Choose the database to use (If you are not sure choose mysql)"
|
||||
},
|
||||
"choices": ["mysql","sqlite"],
|
||||
"default": "mysql"
|
||||
},
|
||||
{
|
||||
"name": "registration",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Are new users allowed to register ?"
|
||||
},
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
|
|
|
@ -29,7 +29,7 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
database=$(ynh_app_setting_get $app database)
|
||||
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
|
@ -51,9 +51,12 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|||
|
||||
ynh_backup "/etc/php/7.2/fpm/pool.d/$app.conf"
|
||||
|
||||
if [ "$database" == "mysql" ]; then
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
ynh_mysql_dump_db "$db_name" > db.sql
|
||||
ynh_mysql_dump_db "$db_name" > db.sql
|
||||
|
||||
fi
|
||||
|
|
|
@ -26,8 +26,8 @@ admin=$YNH_APP_ARG_ADMIN
|
|||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
admin_pass=$(ynh_string_random 24)
|
||||
random_key=$(ynh_string_random 32)
|
||||
registration="true"
|
||||
|
||||
registration=$(YNH_APP_ARG_REGISTRATION)
|
||||
database=$(YNH_APP_ARG_DATABASE)
|
||||
|
||||
# This is a multi-instance app, meaning it can be installed several times independently
|
||||
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
||||
|
@ -66,6 +66,8 @@ ynh_app_setting_set $app admin $admin
|
|||
ynh_app_setting_set $app is_public $is_public
|
||||
ynh_app_setting_set $app random_key $random_key
|
||||
ynh_app_setting_set $app registration $registration
|
||||
ynh_app_setting_set $app database $database
|
||||
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
|
@ -75,23 +77,6 @@ ynh_app_setting_set $app registration $registration
|
|||
|
||||
ynh_install_php7
|
||||
|
||||
#=================================================
|
||||
# CREATE A MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
### Use these lines if you need a database for the application.
|
||||
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
|
||||
### The password will be stored as 'mysqlpwd' into the app settings,
|
||||
### and will be available as $db_pwd
|
||||
### If you're not using these lines:
|
||||
### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script
|
||||
### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script
|
||||
### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script
|
||||
|
||||
db_name=$(ynh_sanitize_dbid $app)
|
||||
ynh_app_setting_set $app db_name $db_name
|
||||
ynh_mysql_setup_db $db_name $db_name
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
@ -130,23 +115,64 @@ ynh_add_fpm7.2_config
|
|||
# SPECIFIC SETUP
|
||||
#=================================================
|
||||
|
||||
# create a user
|
||||
# GET THE ADMIN EMAIL
|
||||
email=$(ynh_user_get_info $admin 'mail')
|
||||
|
||||
# setup application config
|
||||
sudo cp ../conf/.env $final_path/.env
|
||||
# COPY LOCAL.YAML
|
||||
sudo cp ../conf/local.yaml $final_path/config/packages/local.yaml
|
||||
|
||||
if [ "$registration" = "1" ]; then
|
||||
|
||||
# MODIFY LOCAL.YAML
|
||||
ynh_replace_string "__REGISTRATION__" "true" "$final_path/config/packages/local.yaml"
|
||||
|
||||
elif [ "$registration" = "0" ]; then
|
||||
# MODIFY LOCAL.YAML
|
||||
ynh_replace_string "__REGISTRATION__" "false" "$final_path/config/packages/local.yaml"
|
||||
fi
|
||||
|
||||
# CHECK WHICH DATABASE TO USE
|
||||
if [ "$database" == "mysql" ]; then
|
||||
# setup application config
|
||||
sudo cp ../conf/.env $final_path/.env
|
||||
#=================================================
|
||||
# CREATE A MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
### Use these lines if you need a database for the application.
|
||||
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
|
||||
### The password will be stored as 'mysqlpwd' into the app settings,
|
||||
### and will be available as $db_pwd
|
||||
### If you're not using these lines:
|
||||
### - Remove the section "BACKUP THE MYSQL DATABASE" in the backup script
|
||||
### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script
|
||||
### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script
|
||||
|
||||
db_name=$(ynh_sanitize_dbid $app)
|
||||
ynh_app_setting_set $app db_name $db_name
|
||||
ynh_mysql_setup_db $db_name $db_name
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_replace_string "__RANDOM_KEY__" "$random_key" "$final_path/.env"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env"
|
||||
ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/.env"
|
||||
ynh_replace_string "__DB_USER__" "$db_name" "$final_path/.env"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/.env"
|
||||
ynh_replace_string "__RANDOM_KEY__" "$random_key" "$final_path/.env"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env"
|
||||
ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/.env"
|
||||
ynh_replace_string "__DB_USER__" "$db_name" "$final_path/.env"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/.env"
|
||||
else
|
||||
# setup application config
|
||||
sudo cp ../conf/.env.sqlite $final_path/.env
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_replace_string "__RANDOM_KEY__" "$random_key" "$final_path/.env"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env"
|
||||
|
||||
fi
|
||||
|
||||
# COMPOSR AND SPECIFIC INSTALL FOR THE APP
|
||||
init_composer $final_path
|
||||
cd $final_path && sudo /usr/bin/php7.2 bin/console doctrine:schema:create
|
||||
cd $final_path && sudo /usr/bin/php7.2 bin/console cache:warmup --env=prod
|
||||
|
@ -200,9 +226,12 @@ fi
|
|||
#=================================================
|
||||
|
||||
message=" $app was successfully installed :)
|
||||
|
||||
Please open https://$domain$path_url
|
||||
|
||||
The admin username is: $email
|
||||
Here is the admin password: $admin_pass
|
||||
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/kimai2_ynh"
|
||||
|
||||
If you facing any issue or want to improve the app, please open a new issue on the project page: https://github.com/YunoHost-Apps/kimai2_ynh"
|
||||
|
||||
ynh_send_readme_to_admin "$message"
|
||||
|
|
|
@ -17,8 +17,8 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_user=$db_name
|
||||
database=$(ynh_app_setting_get $app database)
|
||||
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
|
@ -39,12 +39,16 @@ ynh_secure_remove "$final_path"
|
|||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
if [ "$database" == "mysql" ]; then
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_user=$db_name
|
||||
#=================================================
|
||||
# REMOVE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
# Remove a database if it exists, along with the associated user
|
||||
ynh_mysql_remove_db $db_user $db_name
|
||||
ynh_mysql_remove_db $db_user $db_name
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# REMOVE PHP-FPM CONFIGURATION
|
||||
|
|
|
@ -30,7 +30,7 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
domain=$(ynh_app_setting_get $app domain)
|
||||
path_url=$(ynh_app_setting_get $app path)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
database=$(ynh_app_setting_get $app database)
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
|
@ -62,13 +62,16 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|||
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
if [ "$database" == "mysql" ]; then
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
ynh_mysql_setup_db $db_name $db_name $db_pwd
|
||||
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
ynh_mysql_setup_db $db_name $db_name $db_pwd
|
||||
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||
if
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
|
|
|
@ -21,8 +21,6 @@ admin=$(ynh_app_setting_get $app admin)
|
|||
is_public=$(ynh_app_setting_get $app is_public)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
random_key=$(ynh_app_setting_get $app random_key)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
|
||||
|
||||
#=================================================
|
||||
|
@ -92,12 +90,16 @@ fi
|
|||
if [ -d $final_path/var/invoices ]; then
|
||||
cp -af "$final_path/var/invoices" "$tmpdir/."
|
||||
fi
|
||||
cp -a "$final_path/var/data/kimai.sqlite" "$tmpdir/."
|
||||
if [ -f $final_path/var/data/kimai.sqlite ]; then
|
||||
cp -a "$final_path/var/data/kimai.sqlite" "$tmpdir/."
|
||||
ynh_app_setting_set $app database "sqlite"
|
||||
fi
|
||||
|
||||
|
||||
ynh_setup_source "$final_path"
|
||||
|
||||
# If the version is 0.3, symfony update is required
|
||||
if [ "$version" = "0.3" ]
|
||||
if [ "$version" == "0.3" ]
|
||||
then
|
||||
ynh_secure_remove "$final_path"
|
||||
ynh_setup_source "$final_path"
|
||||
|
@ -111,21 +113,40 @@ fi
|
|||
if [ -d $tmpdir/invoices ]; then
|
||||
cp -af "$tmpdir/invoices" "$final_path/var/."
|
||||
fi
|
||||
if [ -f $tmpdir/kimai.sqlite ]; then
|
||||
sudo cp -af "$tmpdir/kimai.sqlite" "$final_path/var/data/."
|
||||
sudo rm -Rf "$tmpdir"
|
||||
fi
|
||||
|
||||
sudo rm -Rf "$tmpdir"
|
||||
database=$(ynh_app_setting_get $app database)
|
||||
if [ "$database" == "mysql" ]; then
|
||||
# setup application config
|
||||
sudo cp ../conf/.env $final_path/.env
|
||||
sudo cp ../conf/.env $final_path/.env
|
||||
|
||||
# GET DATABASE SETTINGS
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_replace_string "__RANDOM_KEY__" "$random_key" "$final_path/.env"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env"
|
||||
ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/.env"
|
||||
ynh_replace_string "__DB_USER__" "$db_name" "$final_path/.env"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/.env"
|
||||
else
|
||||
# setup application config
|
||||
sudo cp ../conf/.env.sqlite $final_path/.env
|
||||
|
||||
#=================================================
|
||||
# MODIFY A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_replace_string "__RANDOM_KEY__" "$random_key" "$final_path/.env"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env"
|
||||
ynh_replace_string "__DB_PASSWORD__" "$db_pwd" "$final_path/.env"
|
||||
ynh_replace_string "__DB_USER__" "$db_name" "$final_path/.env"
|
||||
ynh_replace_string "__DB_NAME__" "$db_name" "$final_path/.env"
|
||||
ynh_replace_string "__RANDOM_KEY__" "$random_key" "$final_path/.env"
|
||||
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env"
|
||||
|
||||
fi
|
||||
|
||||
# COMPOSR AND SPECIFIC INSTALL FOR THE APP
|
||||
init_composer $final_path
|
||||
(
|
||||
cd $final_path && sudo /usr/bin/php7.2 bin/console cache:clear --env=prod
|
||||
|
|
Loading…
Add table
Reference in a new issue