diff --git a/README.md b/README.md index 8597754..8330d8c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Integration level](https://dash.yunohost.org/integration/kimai2.svg)](https://ci-apps.yunohost.org/jenkins/job/kimai2%20%28Community%29/lastBuild/consoleFull) [![Install kimai2 with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=kimai2)
-Shipped Version: **0.4 (pre-release)** +Shipped Version: **0.5 (pre-release)** **Please note that this app will install PHP 7.2** diff --git a/check_process b/check_process index 9d2dd76..cb0e356 100644 --- a/check_process +++ b/check_process @@ -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 diff --git a/conf/.env b/conf/.env index 552faa8..c28ff3a 100644 --- a/conf/.env +++ b/conf/.env @@ -17,8 +17,8 @@ APP_SECRET=__RANDOM_KEY__ # 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 +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 ### diff --git a/conf/.env.sqlite b/conf/.env.sqlite new file mode 100644 index 0000000..6ca9be9 --- /dev/null +++ b/conf/.env.sqlite @@ -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 ### diff --git a/conf/local.yaml b/conf/local.yaml new file mode 100644 index 0000000..42dc5a7 --- /dev/null +++ b/conf/local.yaml @@ -0,0 +1,3 @@ +kimai: + user: + registration: __REGISTRATION__ diff --git a/manifest.json b/manifest.json index 3a707f2..c38bb39 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,7 @@ "fr": "Kimai2 de package d’application pour YunoHost.", "de": "Kimai 2 Paket für YunoHost." }, - "version": "0.4", + "version": "0.5", "url": "https://v2.kimai.org", "license": "free", "maintainer": { @@ -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", diff --git a/scripts/backup b/scripts/backup index 508a672..da00816 100755 --- a/scripts/backup +++ b/scripts/backup @@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get $app domain) +database=$(ynh_app_setting_get $app database) #================================================= # STANDARD BACKUP STEPS @@ -50,3 +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 + +fi diff --git a/scripts/install b/scripts/install index 65335a6..d18a9a6 100755 --- a/scripts/install +++ b/scripts/install @@ -26,7 +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=$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 @@ -64,6 +65,9 @@ ynh_app_setting_set $app path $path_url 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 @@ -73,7 +77,6 @@ ynh_app_setting_set $app random_key $random_key ynh_install_php7 - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -112,19 +115,67 @@ 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 -eq 1 ] +then + +# MODIFY LOCAL.YAML + ynh_replace_string "__REGISTRATION__" "true" "$final_path/config/packages/local.yaml" +fi + +if [ $registration -eq 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 "__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 @@ -167,7 +218,7 @@ fi systemctl reload php7.2-fpm systemctl reload nginx # Set default php to php5 or php7.0 -if [ "$(lsb_release --codename --short)" == "jessie" ]; then +if [ "$(lsb_release --codename --short)" = "jessie" ]; then update-alternatives --set php /usr/bin/php5 else update-alternatives --set php /usr/bin/php7.0 @@ -178,9 +229,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" diff --git a/scripts/remove b/scripts/remove index 8c3f5a7..42f5d76 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,6 +17,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) final_path=$(ynh_app_setting_get $app final_path) +database=$(ynh_app_setting_get $app database) + #================================================= # STANDARD REMOVE @@ -37,6 +39,17 @@ 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 +fi + #================================================= # REMOVE PHP-FPM CONFIGURATION #================================================= diff --git a/scripts/restore b/scripts/restore index 67a6fb3..712e76b 100755 --- a/scripts/restore +++ b/scripts/restore @@ -30,6 +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) +database=$(ynh_app_setting_get $app database) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -61,6 +62,17 @@ 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) + 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 #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 0781dee..3fd173f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,6 +22,7 @@ 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) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -89,7 +90,11 @@ 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" @@ -108,18 +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 "__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