From 9a8b44f6908915146273757cff0ef1cb0a1f4678 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Tue, 5 Mar 2019 22:43:49 +0100 Subject: [PATCH] use more helpers --- README.md | 4 ++-- conf/emailpoubelle.cron | 1 + conf/nginx.conf | 45 +++++++++++++++++++++++++---------------- conf/nginx.conf.new | 35 -------------------------------- scripts/_common.sh | 3 +-- scripts/install | 39 ++++++++++++++--------------------- scripts/remove | 3 +-- scripts/upgrade | 27 +++++++------------------ 8 files changed, 55 insertions(+), 102 deletions(-) create mode 100644 conf/emailpoubelle.cron delete mode 100644 conf/nginx.conf.new diff --git a/README.md b/README.md index fef9c66..eeef46a 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,12 @@ sudo yunohost app upgrade emailpoubelle -u https://github.com/Yunohost-Apps/emai ## TODO : -- [ ] check nginx conf +- [X] check nginx conf - [ ] insert cron in conf - [ ] insert symlink for langages in /lang - [ ] remove new locale on remove - [ ] Test it ! (and check if that doesn't interfer with postfix and its aliases) -- [ ] cron job to remove redirections (`0 */2 * * * /usr/bin/wget -q -t 1 -T 7200 -O /dev/null 'https://domain/poubelle/index.php?act=cron' >/dev/null 2>&1) +- [X] cron job to remove redirections (`0 */2 * * * /usr/bin/wget -q -t 1 -T 7200 -O /dev/null 'https://domain/poubelle/index.php?act=cron' >/dev/null 2>&1) - [ ] conflict with SSOWAT + non-public app - [ ] package_check integration - [ ] Multiinstance diff --git a/conf/emailpoubelle.cron b/conf/emailpoubelle.cron new file mode 100644 index 0000000..45235b0 --- /dev/null +++ b/conf/emailpoubelle.cron @@ -0,0 +1 @@ +0 */2 * * * www-data cd $final_path/www/; /usr/bin/php index.php > /dev/null 2>&1 \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index 1333f44..6853de3 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,18 +1,29 @@ -location YNH_EXAMPLE_PATH { - # Path to source - alias YNH_EXAMPLE_ALIAS ; - # Example PHP configuration - index www/index.php; - try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm.sock; - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param REMOTE_USER $remote_user; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME $request_filename; - } - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; +location __PATH__/ { + + # Path to source + alias __FINALPATH__/ ; + + # Force usage of https + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + +### PHP configuration + index www/index.php; + + try_files $uri $uri/ index.php; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; + + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; + } +### End of PHP configuration part + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/conf/nginx.conf.new b/conf/nginx.conf.new deleted file mode 100644 index 2067dab..0000000 --- a/conf/nginx.conf.new +++ /dev/null @@ -1,35 +0,0 @@ - -#New nginx.conf - a implémenter -#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; -location __PATH__/ { - - # Path to source - alias __FINALPATH__/ ; - - # Force usage of https - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } - -### Example PHP configuration (remove it if not used) - index index.php; - - # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file - #client_max_body_size 50M; - - try_files $uri $uri/ index.php; - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock; - - fastcgi_index index.php; - include fastcgi_params; - fastcgi_param REMOTE_USER $remote_user; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param SCRIPT_FILENAME $request_filename; - } -### End of PHP configuration part - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; -} diff --git a/scripts/_common.sh b/scripts/_common.sh index f705c56..f1cb75a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,7 +1,6 @@ #================================================= # COMMON VARIABLES #================================================= -pkg_dependencies="php-geoip" +pkg_dependencies="php-geoip php7.0-cli" app="emailpoubelle" lang="fr_FR.UTF-8 en_US.UTF-8 it_IT.UTF-8" -postfix=/etc/postfix/main.cf diff --git a/scripts/install b/scripts/install index 87bad26..136819c 100644 --- a/scripts/install +++ b/scripts/install @@ -15,16 +15,17 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN +ynh_print_OFF password=$YNH_APP_ARG_PASSWORD +ynh_print_ON is_public=$5 final_path=/var/www/$app db_user=emailPoubelle -cronline="0 */2 * * * www-data cd $final_path/www/; /usr/bin/php index.php > /dev/null 2>&1" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= - +ynh_print_info "Check settings for installation" final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" @@ -53,7 +54,7 @@ ynh_app_setting_set $app final_path $final_path #================================================= #INSTALL DEPENDENCIES #================================================= - +ynh_print_info "Installing dependencies" ynh_install_app_dependencies $pkg_dependencies #install locale (nginx will restart at the end of the install) @@ -82,10 +83,13 @@ ln -s $final_path/www/template-exemple $final_path/template-exemple #=============================================== #SETTINGS & DATABASE #=============================================== +ynh_print_info "Setting database & settings" #generating random password for database +ynh_print_OFF db_pwd=$(ynh_string_random) ynh_app_setting_set $app mysqlpwd $db_pwd +ynh_print_ON #configuring with given settings sudo cp $final_path/conf-dist.php $final_path/conf.php @@ -99,13 +103,16 @@ ynh_replace_string "// define('DBUSER'," " define('DBUSER'," $f ynh_replace_string "// define('DBPASS'," " define('DBPASS'," $final_path/conf.php ynh_replace_string "baseMysql" "$db_user" $final_path/conf.php ynh_replace_string "utilisateurMysql" "$db_user" $final_path/conf.php +ynh_print_OFF ynh_replace_string "motdepassedefou" "$db_pwd" $final_path/conf.php ynh_replace_string "define('ADMIN_PASSWORD', 'admin');" "define('ADMIN_PASSWORD', '$password');" $final_path/conf.php +ynh_print_ON #setting conf file not world-readable (dude, there is a plain-text password !) sudo chmod o-r $final_path/conf.php - #initialize database (databasename = db_user) +ynh_print_OFF ynh_mysql_create_db $db_user $db_user $db_pwd +ynh_print_ON #setting postfix to use virtual aliases file # Add postfix configuration hook and regen postfix conf @@ -122,19 +129,12 @@ sudo cp /etc/aliases /etc/aliases.emailpoubelle.bak #backup it sudo echo "devnull:/dev/null" | sudo tee -a /etc/aliases sudo newaliases -# Modify Nginx configuration file and copy it to Nginx conf directory -sudo sed -i "s@YNH_EXAMPLE_PATH@$path_url@g" ../conf/nginx.conf -sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path/@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +#adding cronjob for removing expired email addresses +sudo cp -a ../conf/$app.cron /etc/cron.d/$app +sudo chmod 644 /etc/cron.d/$app -# Handle root path, avoid double slash. -# Temporary fix, in waiting for an upgrade of the helper. (#361) -#path_url_slash_less=${path_url%/} -#ynh_replace_string "__PATH__/" "$path_url_slash_less/" "../conf/nginx.conf" -#ynh_replace_string "__FINALPATH__/" "$final_path/www" "../conf/nginx.conf" # Create a dedicated nginx config -#ynh_add_nginx_config - +ynh_add_nginx_config #================================================= # SETUP SSOWAT @@ -147,15 +147,6 @@ then ynh_app_setting_set $app unprotected_uris "/" fi - -#A verifier? A integrer dans dépendances? -#adding php-cli for cron -sudo apt-get update -qq -sudo apt-get install -yqq php5-cli -#adding cronjob for removing expired email addresses -sudo echo "$cronline" | sudo tee -a /etc/cron.d/emailpoubelle -sudo chmod 644 /etc/cron.d/emailpoubelle - # Restart services systemctl reload nginx systemctl reload postfix diff --git a/scripts/remove b/scripts/remove index b61f02c..222a355 100644 --- a/scripts/remove +++ b/scripts/remove @@ -8,7 +8,6 @@ domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get $app db_name) db_user==$db_name root_pwd=$(sudo cat /etc/yunohost/mysql) -postfix=/etc/postfix/main.cf #remove php-geoip ynh_remove_app_dependencies @@ -26,6 +25,6 @@ ynh_secure_remove "/usr/share/yunohost/hooks/conf_regen/98-postfix_emailpoubelle #remove cronjob sudo rm -f /etc/cron.d/emailpoubelle -sudo service postfix reload +yunohost service regen-conf postfix sudo service nginx reload sudo yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index a25f670..b92f2b2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -38,13 +38,12 @@ ynh_abort_if_errors #================================================= # CHECK THE PATH #================================================= - # Normalize the URL path syntax path_url=$(ynh_normalize_url_path $path_url) #================================================= -#check for matlink's version +#check for matlink's version - deprecated - uninstall & reinstall #================================================= #deprecated - not maintained for more than a year... #cat /etc/yunohost/apps/$app/status.json | grep "matlink" @@ -66,7 +65,6 @@ path_url=$(ynh_normalize_url_path $path_url) # mkdir -p $final_path/lang #add new index.php # cp ../conf/index_source.php $final_path/www/index.php - #switch from previous (modified) conf.php to new one (emailpoubelle original) # cp ../src/conf-dist.php $final_path/conf-dist.new.php #insert domain in line 24, DB in line 31, DBUSER in line 32, etc. @@ -85,21 +83,13 @@ path_url=$(ynh_normalize_url_path $path_url) # ynh_replace_string "define('ALIASLIMITBYMAIL" "//define('ALIASLIMITBYMAIL" $final_path/conf.php # #setting conf file not world-readable (dude, there is a plain-text password !) # sudo chmod o-r $final_path/conf.php - #fi - #================================================= -# NGINX CONFIGURATION +#INSTALL DEPENDENCIES #================================================= - -#change nginx.conf as per https://forum.yunohost.org/t/need-help-on-nginx-conf-cannot-access-resources/6342 -ynh_replace_string "alias $finalpath/www/ ;" "alias $finalpath/ ;" /etc/yunohost/$domain.d/$app.conf -ynh_replace_string "index index.php;" "index www/ndex.php;" /etc/yunohost/$domain.d/$app.conf - -#correct template name in index.php -ynh_replace_string "Template-exemple" "$domain" $final_path/www/index.php - +ynh_print_info "Installing dependencies" +ynh_install_app_dependencies $pkg_dependencies #mysqlpwd setting was implemented in ynh2 - check if saved and if not implement db_pass=$(ynh_app_setting_get $app mysqlpwd) @@ -110,6 +100,9 @@ if [ -z $db_pass]; then ynh_app_setting_set $app mysqlpwd $db_pass fi +#================================================= +#INSTALL SOURCES +#=============================================== # Copy source files ynh_print_info "Downloading sources to $final_path" # Download, check integrity, uncompress and patch the source from app.src @@ -126,12 +119,6 @@ ln -s $final_path/lang/it $final_path/lang/it_IT chown -R www-data:www-data $final_path -#adding php-cli for cron -#sudo apt-get update -qq -#sudo apt-get install -yqq php5-cli -#adding cronjob for removing expired email addresses -#sudo echo "$cronline" | sudo tee -a /etc/cron.d/emailpoubelle -#sudo chmod 644 /etc/cron.d/emailpoubelle #================================================= # RELOAD SERVICES