From c4fb0035eab63411a724d73fcf1c6713f2e84ec7 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Thu, 24 Dec 2020 12:11:42 +0100 Subject: [PATCH 1/2] Fix --- check_process.default => check_process | 10 ++--- conf/nginx.conf | 52 +++++++---------------- conf/systemd.service | 2 +- manifest.json | 25 ++++++++--- scripts/backup | 24 +++++------ scripts/change_url | 1 + scripts/install | 25 ++++++----- scripts/remove | 2 +- scripts/restore | 10 +++-- scripts/upgrade | 59 ++++++++++++++------------ 10 files changed, 105 insertions(+), 105 deletions(-) rename check_process.default => check_process (82%) diff --git a/check_process.default b/check_process similarity index 82% rename from check_process.default rename to check_process index 00325ad..9248fe3 100644 --- a/check_process.default +++ b/check_process @@ -7,11 +7,7 @@ ; Manifest domain="domain.tld" (DOMAIN) path="/path" (PATH) - admin="john" (USER) - language="en" is_public=1 (PUBLIC|public=1|private=0) - password="pass" - port="666" (PORT) ; Checks pkg_linter=1 setup_sub_dir=1 @@ -31,10 +27,10 @@ # If the level 5 (Package linter) is forced to 1. Please add justifications here. Level 5=auto ;;; Options -Email= -Notification=none +Email=wilkens.fabian+github@gmail.com +Notification=all ;;; Upgrade options ; commit=CommitHash name=Name and date of the commit. - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666& + manifest_arg=domain=DOMAIN&path=PATH&is_public=1 diff --git a/conf/nginx.conf b/conf/nginx.conf index 39f75e9..b41e01e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,38 +1,18 @@ -root __FINALPATH__/live/public; +location __PATH__/ { + alias __FINALPATH__/live/public ; -location / { - if ($scheme = http) { - rewrite ^ https://$server_name$request_uri? permanent; - } - proxy_set_header Accept-Encoding ""; - try_files $uri @proxy; - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + + proxy_pass http://127.0.0.1:__PORT__/; + proxy_http_version 1.1; + proxy_set_header Host $http_host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_buffering off; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } - -location @proxy { - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - proxy_set_header Proxy ""; - proxy_pass_header Server; - - proxy_pass http://127.0.0.1:__PORT__; - proxy_buffering on; - proxy_redirect off; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - - #proxy_cache CACHE; - proxy_cache_valid 200 7d; - proxy_cache_valid 410 24h; - proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; - add_header X-Cached $upstream_cache_status; - add_header Strict-Transport-Security "max-age=31536000"; - tcp_nodelay on; -} - -error_page 500 501 502 503 504 /500.html; diff --git a/conf/systemd.service b/conf/systemd.service index 6009597..4c22962 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -8,7 +8,7 @@ User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/live Environment=RAILS_ENV=production -Environment="PORT=__PORT_WEB__" +Environment="PORT=__PORT__" ExecStart=/opt/rbenv/versions/__RUBY_VERSION__/bin/bundle exec rails server ExecReload=/bin/kill -SIGUSR1 $MAINPID StandardOutput=file:/var/log/__APP__/__APP__.log diff --git a/manifest.json b/manifest.json index f747b60..16bdcf4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "name": "Standard Notes - Syncing Server", + "name": "Standard Notes - Server", "id": "snserver", "packaging_format": 1, "description": { @@ -18,7 +18,7 @@ }, "multi_instance": true, "services": [ - "nginx", + "nginx", "mysql" ], "arguments": { @@ -28,18 +28,31 @@ "type": "domain", "ask": { "en": "Choose a domain name for snserver", - "fr": "Choisissez un domaine pour Mastodon", - "de": "Wähle einen Domain Namen für snserver" + "fr": "Choisissez un domaine pour Mastodon", + "de": "Wähle einen Domain Namen für snserver" }, "example": "example.com" }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for ynhexample", + "fr": "Choisissez un chemin pour ynhexample" + }, + "example": "/example", + "default": "/example" + }, { "name": "is_public", "type": "boolean", + "help": { + "en": "The Standard Notes - Syncing Server should be public accessable if you want to connect with a desktop or mobile app." + }, "ask": { "en": "Is it a public application?", - "fr": "Est-ce une application publique ?", - "de": "Ist die Application Öffendlich?" + "fr": "Est-ce une application publique ?", + "de": "Ist die Application Öffendlich?" }, "default": true } diff --git a/scripts/backup b/scripts/backup index e8b33b9..b4bcaf3 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,7 +24,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 +ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -37,35 +37,35 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +#ynh_print_info "Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +#ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --weight=1 +ynh_print_info "Backing up the main app directory..." ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --weight=2 +ynh_print_info "Backing up nginx web server configuration..." ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Backing up the MySQL database..." --weight=1 +ynh_print_info "Backing up the MySQL database..." ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= -#ynh_script_progression --message="Backing up fail2ban configuration..." --weight=1 +#ynh_print_info "Backing up fail2ban configuration..." #ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" #ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" @@ -75,26 +75,26 @@ ynh_mysql_dump_db --database="$db_name" > db.sql #================================================= # BACKUP LOGROTATE #================================================= -ynh_script_progression --message="Backing up logrotate configuration..." --weight=1 +ynh_print_info "Backing up logrotate configuration..." ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_script_progression --message="Backing up systemd configuration..." --weight=1 +ynh_print_info "Backing up systemd configuration..." ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +#ynh_print_info "Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +#ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 171cc7f..701ed2f 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -127,6 +127,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload +sleep 10 #================================================= # STORE SETTINGS diff --git a/scripts/install b/scripts/install index 2135737..e0df728 100755 --- a/scripts/install +++ b/scripts/install @@ -25,8 +25,7 @@ ynh_abort_if_errors #================================================= domain=$YNH_APP_ARG_DOMAIN -#path_url=$YNH_APP_ARG_PATH -path_url="/" +path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME @@ -56,9 +55,9 @@ ynh_app_setting_set --app=$app --key=is_public --value=$is_public ynh_script_progression --message="Configuring firewall..." --weight=1 # Find an available port -port_web=$(ynh_find_port --port=3000) +port=$(ynh_find_port --port=3000) # Open the port -ynh_app_setting_set --app=$app --key=port_web --value=$port_web +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= @@ -86,7 +85,7 @@ ynh_script_progression --message="Setting up source files..." --weight=2 ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -mkdir $final_path +mkdir -p $final_path ynh_setup_source --dest_dir="$final_path/live" #================================================= @@ -95,7 +94,7 @@ ynh_setup_source --dest_dir="$final_path/live" ynh_script_progression --message="Configuring nginx web server..." --weight=3 # Create a dedicated nginx config -ynh_replace_string --match_string="proxy_pass http://127.0.0.1:__PORT__;" --replace_string="proxy_pass http://127.0.0.1:$port_web;" --target_file="../conf/nginx.conf" +ynh_replace_string --match_string="proxy_pass http://127.0.0.1:__PORT__;" --replace_string="proxy_pass http://127.0.0.1:$port;" --target_file="../conf/nginx.conf" ynh_add_nginx_config #================================================= @@ -109,9 +108,9 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # SPECIFIC SETUP #================================================= -# INSTALLING RUBY AND BUNDLER +# INSTALLING RUBY #================================================= -ynh_script_progression --message="Installing Ruby..." --weight=331 +ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 ynh_install_ruby --ruby_version=$RUBY_VERSION /opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document @@ -126,7 +125,7 @@ ynh_script_progression --message="Modifying a config file..." --weight=2 config_file="$final_path/live/.env" cp -f ../conf/env.sample $config_file -ynh_replace_string --match_string="EXPOSED_PORT=3000" --replace_string="EXPOSED_PORT=$port_web" --target_file="$config_file" +ynh_replace_string --match_string="EXPOSED_PORT=3000" --replace_string="EXPOSED_PORT=$port" --target_file="$config_file" secret_key=$(ynh_string_random --length=48 | base64) ynh_replace_string --match_string="SECRET_KEY_BASE=changeme123" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file" pseudo_key=$(ynh_string_random --length=48 | base64) @@ -156,13 +155,14 @@ popd ynh_script_progression --message="Configuring a systemd service..." --weight=4 # Create a dedicated systemd config -ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/systemd.service" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/systemd.service" ynh_replace_string --match_string="__RUBY_VERSION__" --replace_string="$RUBY_VERSION" --target_file="../conf/systemd.service" ynh_add_systemd_config --service="$app" --template="systemd.service" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= +ynh_script_progression --message="Storing the config file checksum..." --weight=1 # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config_file" @@ -174,6 +174,7 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_script_progression --message="Securing files and directories..." --weight=1 # Set permissions to app files chown -R root: $final_path @@ -200,7 +201,7 @@ ynh_use_logrotate --logfile="/var/log/$app/$app.log" #================================================= ynh_script_progression --message="Integrate $app service in Yunohost..." --weight=1 -yunohost service add $app --description "Standard Notes - Syncing Server" +yunohost service add $app --description "Standard Notes - Syncing Server" --log "/var/log/$app/$app.log" #================================================= # SETUP FAIL2BAN @@ -228,6 +229,8 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +# Wait 10 secends tor server to start +sleep 10 #================================================= # RELOAD NGINX diff --git a/scripts/remove b/scripts/remove index 20c8447..fc7c394 100755 --- a/scripts/remove +++ b/scripts/remove @@ -18,7 +18,7 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -port_web=$(ynh_app_setting_get --app=$app --key=port_web) +port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) diff --git a/scripts/restore b/scripts/restore index 22c3f79..05f07b6 100755 --- a/scripts/restore +++ b/scripts/restore @@ -97,7 +97,7 @@ chown -R $app: /var/log/$app #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=254 +ynh_script_progression --message="Reinstalling dependencies..." --weight=17 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies @@ -106,7 +106,7 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # INSTALLING RUBY #================================================= -ynh_script_progression --message="Installing Ruby..." --weight=331 +ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 ynh_install_ruby --ruby_version=$RUBY_VERSION /opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document @@ -125,11 +125,12 @@ ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./ ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service +systemctl enable $app.service --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrate $app service in Yunohost..." --weight=1 yunohost service add $app --description "Standard Notes - Syncing Server" --log "/var/log/$app/$app.log" @@ -139,10 +140,13 @@ yunohost service add $app --description "Standard Notes - Syncing Server" --log ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +# Wait 10 secends tor server to start +sleep 10 #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=1 ynh_restore_file --origin_path="/etc/logrotate.d/$app" diff --git a/scripts/upgrade b/scripts/upgrade index e1aa878..f0ca15a 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -22,6 +22,9 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION @@ -38,7 +41,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then @@ -64,7 +67,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -75,19 +78,12 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# CHECK THE PATH -#================================================= - -# Normalize the URL path syntax -path_url=$(ynh_normalize_url_path --path_url=$path_url) - #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" @@ -97,7 +93,7 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --time --weight=1 + ynh_script_progression --message="Upgrading source files..." --weight=1 # Backup files to keep tmpdir=$(mktemp -d) @@ -117,24 +113,23 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 # Create a dedicated nginx config -ynh_replace_string --match_string="proxy_pass http://127.0.0.1:__PORT__;" --replace_string="proxy_pass http://127.0.0.1:$port_web;" --target_file="../conf/nginx.conf" -ynh_add_nginx_config +ynh_add_nginx_config "port" #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 +ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_install_app_dependencies $pkg_dependencies #================================================= # INSTALL RUBY #================================================= -ynh_script_progression --message="Installing Ruby..." +ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 ynh_install_ruby --ruby_version=$RUBY_VERSION /opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document @@ -142,7 +137,7 @@ ynh_install_ruby --ruby_version=$RUBY_VERSION #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir=$final_path @@ -153,13 +148,13 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # MODIFY A CONFIG FILE #================================================= +config_file="$final_path/live/.env" if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Modifying a config file..." --weight=2 - config_file="$final_path/live/.env" cp -f ../conf/env.sample $config_file - ynh_replace_string --match_string="EXPOSED_PORT=3000" --replace_string="EXPOSED_PORT=$port_web" --target_file="$config_file" + ynh_replace_string --match_string="EXPOSED_PORT=3000" --replace_string="EXPOSED_PORT=$port" --target_file="$config_file" secret_key=$(ynh_string_random --length=48 | base64) ynh_replace_string --match_string="SECRET_KEY_BASE=changeme123" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file" pseudo_key=$(ynh_string_random --length=48 | base64) @@ -189,10 +184,10 @@ fi #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config -ynh_replace_string --match_string="__PORT_WEB__" --replace_string="$port_web" --target_file="../conf/systemd.service" +ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/systemd.service" ynh_replace_string --match_string="__RUBY_VERSION__" --replace_string="$RUBY_VERSION" --target_file="../conf/systemd.service" ynh_add_systemd_config --service="$app" --template="systemd.service" @@ -225,16 +220,22 @@ chown -R $app: /var/log/$app #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 # Use logrotate to manage application logfile(s) ynh_use_logrotate --logfile="$final_path/live/log/production.log" ynh_use_logrotate --logfile="/var/log/$app/$app.log" +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= + +yunohost service add $app --description "Standard Notes - Syncing Server" --log "/var/log/$app/$app.log" + #================================================= # SETUP FAIL2BAN #================================================= -#ynh_script_progression --message="Reconfiguring fail2ban..." --time --weight=1 +#ynh_script_progression --message="Reconfiguring fail2ban..." --weight=1 # Create a dedicated fail2ban config #ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" @@ -242,7 +243,7 @@ ynh_use_logrotate --logfile="/var/log/$app/$app.log" #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 # Make app public if necessary or protect it if [ $is_public -eq 1 ] then @@ -255,15 +256,17 @@ fi #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +# Wait 10 secends tor server to start +sleep 10 #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -271,4 +274,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --time --last +ynh_script_progression --message="Upgrade of $app completed" --last From c8d423c4e44dda91545ae9b16a79d3272baadcc5 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Sun, 27 Dec 2020 23:18:55 +0100 Subject: [PATCH 2/2] Fix, Cleanup --- README.md | 2 +- README_fr.md | 77 -------------- check_process | 48 ++++----- conf/env.sample | 3 + conf/nginx.conf | 3 +- conf/systemd.service | 5 - manifest.json | 2 +- pull_request_template.md | 2 +- scripts/_common.sh | 34 +++--- scripts/backup | 20 +--- scripts/change_url | 51 ++++----- scripts/install | 42 ++++---- scripts/remove | 8 +- scripts/restore | 23 ++-- scripts/upgrade | 121 +++++++++++----------- sources/patches/app-00-add-path-url.patch | 12 +++ 16 files changed, 183 insertions(+), 270 deletions(-) delete mode 100644 README_fr.md create mode 100644 sources/patches/app-00-add-path-url.patch diff --git a/README.md b/README.md index 0bbaf54..2339283 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ How to configure this app: #### Multi-users support -* Are LDAP and HTTP auth supported? No +* Are LDAP and HTTP auth supported? LDAP=No HTTP=Yes * Can the app be used by multiple users? Yes #### Supported architectures diff --git a/README_fr.md b/README_fr.md deleted file mode 100644 index c37d358..0000000 --- a/README_fr.md +++ /dev/null @@ -1,77 +0,0 @@ -# App exemple pour YunoHost - -[![Niveau d'intégration](https://dash.yunohost.org/integration/REPLACEBYYOURAPP.svg)](https://dash.yunohost.org/appci/app/REPLACEBYYOURAPP) -[![Installer REPLACEBYYOURAPP avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=REPLACEBYYOURAPP) - -*[Read this readme in english.](./README.md)* - -> *Ce package vous permet d'installer REPLACEBYYOURAPP rapidement et simplement sur un serveur Yunohost. -Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* - -## Vue d'ensemble -Description rapide de cette application. - -**Version incluse:** 1.0 - -## Captures d'écran - -![](Lien vers une capture d'écran pour cette application) - -## Démo - -* [Démo officielle](Lien vers un site de démonstration pour cette application) - -## Configuration - -Comment configurer cette application: via le panneau d'administration, un fichier brut en SSH ou tout autre moyen. - -## Documentation - - * Documentation officielle: Lien vers la documentation officielle de cette application - * Documentation YunoHost: Si une documentation spécifique est nécessaire, n'hésitez pas à contribuer. - -## Caractéristiques spécifiques YunoHost - -#### Support multi-utilisateurs - -L'authentification LDAP et HTTP est-elle prise en charge? -L'application peut-elle être utilisée par plusieurs utilisateurs? - -#### Architectures supportées - -* x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/REPLACEBYYOURAPP%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/REPLACEBYYOURAPP/) -* ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/REPLACEBYYOURAPP%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/REPLACEBYYOURAPP/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/REPLACEBYYOURAPP%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/REPLACEBYYOURAPP/) - -## Limitations - -* Limitations connues. - -## Informations additionnelles - -* Autres informations à ajouter sur cette application - -**Plus d'informations sur la page de documentation:** -https://yunohost.org/packaging_apps - -## Liens - - * Signaler un bug: https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/issues - * Site de l'application: Lien vers le site officiel de cette application - * Dépôt de l'application principale: Lien vers le dépôt officiel de l'application principale - * Site web YunoHost: https://yunohost.org/ - ---- - -Informations pour les développeurs ----------------- - -**Seulement si vous voulez utiliser une branche de test pour le codage, au lieu de fusionner directement dans la banche principale.** -Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing). - -Pour essayer la branche testing, procédez comme suit. -``` -sudo yunohost app install https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing --debug -ou -sudo yunohost app upgrade REPLACEBYYOURAPP -u https://github.com/YunoHost-Apps/REPLACEBYYOURAPP_ynh/tree/testing --debug -``` diff --git a/check_process b/check_process index 9248fe3..d5c773f 100644 --- a/check_process +++ b/check_process @@ -4,33 +4,33 @@ # Move this file from check_process.default to check_process when you have filled it. ;; Test complet - ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) - is_public=1 (PUBLIC|public=1|private=0) - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - upgrade=1 from_commit=CommitHash - backup_restore=1 - multi_instance=1 - # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. - # incorrect_path=1 - port_already_use=0 - change_url=1 + ; Manifest + domain="domain.tld" (DOMAIN) + path="/path" (PATH) + is_public=1 (PUBLIC|public=1|private=0) + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=1 + upgrade=1 + upgrade=0 from_commit= + backup_restore=1 + multi_instance=1 + # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. + # incorrect_path=1 + port_already_use=0 + change_url=1 ;;; Levels - # If the level 5 (Package linter) is forced to 1. Please add justifications here. - Level 5=auto + # If the level 5 (Package linter) is forced to 1. Please add justifications here. + Level 5=auto ;;; Options Email=wilkens.fabian+github@gmail.com Notification=all ;;; Upgrade options - ; commit=CommitHash - name=Name and date of the commit. - manifest_arg=domain=DOMAIN&path=PATH&is_public=1 + ; commit= + name= + manifest_arg=domain=DOMAIN&path=PATH&is_public=1 diff --git a/conf/env.sample b/conf/env.sample index e007ec1..f443916 100644 --- a/conf/env.sample +++ b/conf/env.sample @@ -58,3 +58,6 @@ EMAIL_ATTACHMENT_MAX_SIZE=10485760 # Revisions persistency REVISIONS_FREQUENCY=300 + +# Sub-URI +RAILS_RELATIVE_URL_ROOT=/ diff --git a/conf/nginx.conf b/conf/nginx.conf index b41e01e..7f58986 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -5,7 +5,7 @@ location __PATH__/ { rewrite ^ https://$server_name$request_uri? permanent; } - proxy_pass http://127.0.0.1:__PORT__/; + proxy_pass http://127.0.0.1:__PORT____PATH__/; proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header Upgrade $http_upgrade; @@ -15,4 +15,5 @@ location __PATH__/ { # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; + more_clear_input_headers 'Accept-Encoding'; } diff --git a/conf/systemd.service b/conf/systemd.service index 4c22962..53ea030 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -19,8 +19,3 @@ RestartSec=15 [Install] WantedBy=multi-user.target - - - - - diff --git a/manifest.json b/manifest.json index 16bdcf4..9e1da2b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "name": "Standard Notes - Server", + "name": "Standard Notes Server", "id": "snserver", "packaging_format": 1, "description": { diff --git a/pull_request_template.md b/pull_request_template.md index 0287f9f..ec23d9f 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -15,4 +15,4 @@ --- *If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results* -[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/REPLACEBYYOURAPP_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/REPLACEBYYOURAPP_ynh%20PR-NUM-%20(USERNAME)/) +[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/snserver_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/snserver_ynh%20PR-NUM-%20(USERNAME)/) diff --git a/scripts/_common.sh b/scripts/_common.sh index 02fa355..02ec33c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,12 +7,12 @@ RUBY_VERSION="2.7.2" # dependencies used by the app pkg_dependencies="\ - zlib1g-dev \ - libsqlite3-dev \ - default-libmysqlclient-dev \ - libssl-dev \ - libreadline-dev \ - libjemalloc-dev" + zlib1g-dev \ + libsqlite3-dev \ + default-libmysqlclient-dev \ + libssl-dev \ + libreadline-dev \ + libjemalloc-dev" #================================================= # PERSONAL HELPERS @@ -22,21 +22,21 @@ pkg_dependencies="\ # (hence in user home dir, with prior loading of .profile, etc.) # usage: exec_login_as USER COMMAND [ARG ...] exec_login_as() { - local user=$1 - shift 1 - exec_as $user --login "$@" + local user=$1 + shift 1 + exec_as $user --login "$@" } # Execute a command as another user # usage: exec_as USER COMMAND [ARG ...] exec_as() { - local user=$1 - shift 1 - - if [[ $user = $(whoami) ]]; then - eval "$@" - else - sudo -u "$user" "$@" - fi + local user=$1 + shift 1 + + if [[ $user = $(whoami) ]]; then + eval "$@" + else + sudo -u "$user" "$@" + fi } #================================================ diff --git a/scripts/backup b/scripts/backup index b4bcaf3..2ba18bf 100755 --- a/scripts/backup +++ b/scripts/backup @@ -15,8 +15,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true + ### Remove this function if there's nothing to clean before calling the remove script. + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -32,15 +32,6 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#================================================= -# STANDARD BACKUP STEPS -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -#ynh_print_info "Stopping a systemd service..." - -#ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" - #================================================= # BACKUP THE APP MAIN DIR #================================================= @@ -86,13 +77,6 @@ ynh_print_info "Backing up systemd configuration..." ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# START SYSTEMD SERVICE -#================================================= -#ynh_print_info "Starting a systemd service..." - -#ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index 701ed2f..f04724e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -43,11 +43,11 @@ ynh_script_progression --message="Backing up the app before changing its url (ma # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - # restore it if the upgrade fails - ynh_restore_upgradebackup + # restore it if the upgrade fails + ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -59,13 +59,13 @@ ynh_abort_if_errors change_domain=0 if [ "$old_domain" != "$new_domain" ] then - change_domain=1 + change_domain=1 fi change_path=0 if [ "$old_path" != "$new_path" ] then - change_path=1 + change_path=1 fi #================================================= @@ -87,29 +87,32 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf # Change the path in the nginx config file if [ $change_path -eq 1 ] then - # Make a backup of the original nginx config file if modified - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for nginx helper - domain="$old_domain" - path_url="$new_path" - # Create a dedicated nginx config - ynh_add_nginx_config "port" + # Make a backup of the original nginx config file if modified + ynh_backup_if_checksum_is_different --file="$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated nginx config + ynh_add_nginx_config "port" fi # Change the domain for nginx if [ $change_domain -eq 1 ] then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + # Delete file checksum for the old conf file location + ynh_delete_file_checksum --file="$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= # SPECIFIC MODIFICATIONS #================================================= -# ... +ynh_script_progression --message="Modifying a config file..." --weight=1 + +config_file="$final_path/live/.env" +ynh_replace_string --match_string="RAILS_RELATIVE_URL_ROOT=$old_path" --replace_string="RAILS_RELATIVE_URL_ROOT=$new_path" --target_file="$config_file" #================================================= #================================================= @@ -120,6 +123,7 @@ fi ynh_script_progression --message="Starting a systemd service..." --weight=2 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +sleep 10 #================================================= # RELOAD NGINX @@ -127,15 +131,6 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap ynh_script_progression --message="Reloading nginx web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload -sleep 10 - -#================================================= -# STORE SETTINGS -#================================================= -ynh_script_progression --message="Storing settings..." --weight=2 - -ynh_app_setting_set --app=$app --key=domain --value=$new_domain -ynh_app_setting_set --app=$app --key=path --value=$new_path #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index e0df728..bfd6a8b 100755 --- a/scripts/install +++ b/scripts/install @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -94,8 +94,7 @@ ynh_setup_source --dest_dir="$final_path/live" ynh_script_progression --message="Configuring nginx web server..." --weight=3 # Create a dedicated nginx config -ynh_replace_string --match_string="proxy_pass http://127.0.0.1:__PORT__;" --replace_string="proxy_pass http://127.0.0.1:$port;" --target_file="../conf/nginx.conf" -ynh_add_nginx_config +ynh_add_nginx_config "port" #================================================= # CREATE DEDICATED USER @@ -110,7 +109,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # INSTALLING RUBY #================================================= -ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 +ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 ynh_install_ruby --ruby_version=$RUBY_VERSION /opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document @@ -134,19 +133,20 @@ ynh_replace_string --match_string="RAILS_ENV=development" --replace_string="RAIL ynh_replace_string --match_string="DB_DATABASE=standard_notes_db" --replace_string="DB_DATABASE=$db_name" --target_file="$config_file" ynh_replace_string --match_string="DB_USERNAME=std_notes_user" --replace_string="DB_USERNAME=$db_user" --target_file="$config_file" ynh_replace_string --match_string="DB_PASSWORD=changeme123" --replace_string="DB_PASSWORD=$db_pwd" --target_file="$config_file" +ynh_replace_string --match_string="RAILS_RELATIVE_URL_ROOT=/" --replace_string="RAILS_RELATIVE_URL_ROOT=$path_url" --target_file="$config_file" #================================================= -# INSTALLING Standard Notes - Synicing Server +# INSTALLING Standard Notes - Synicing Server #================================================= ynh_script_progression --message="Installing Standard Notes - Synicing Server..." --weight=93 chown -R "$app": "$final_path" pushd "$final_path/live" - exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set path 'vendor/bundle' - exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set with 'development' - exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle install - exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:create db:migrate + exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set path 'vendor/bundle' + exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set with 'development' + exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle install + exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:create db:migrate --quiet popd #================================================= @@ -155,9 +155,10 @@ popd ynh_script_progression --message="Configuring a systemd service..." --weight=4 # Create a dedicated systemd config -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/systemd.service" -ynh_replace_string --match_string="__RUBY_VERSION__" --replace_string="$RUBY_VERSION" --target_file="../conf/systemd.service" -ynh_add_systemd_config --service="$app" --template="systemd.service" +ynh_add_systemd_config --others_var="\ + port \ + RUBY_VERSION \ +" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -179,13 +180,13 @@ ynh_script_progression --message="Securing files and directories..." --weight=1 # Set permissions to app files chown -R root: $final_path chown $app: $final_path -mkdir -p $final_path/live/log -chown -R $app: $final_path/live/log/ -mkdir -p $final_path/live/tmp -chown -R $app: $final_path/live/tmp/ +mkdir -p "$final_path/live/log" +chown -R $app: "$final_path/live/log/" +mkdir -p "$final_path/live/tmp" +chown -R $app: "$final_path/live/tmp/" -mkdir -p /var/log/$app -chown -R $app: /var/log/$app +mkdir -p "/var/log/$app" +chown -R $app: "/var/log/$app" #================================================= # SETUP LOGROTATE @@ -218,8 +219,8 @@ ynh_script_progression --message="Configuring SSOwat..." --weight=3 # Make app public if necessary or protect it if [ $is_public -eq 1 ] then - # Create the visitors permission if needed - ynh_permission_update --permission "main" --add "visitors" --remove "all_users" + # Create the visitors permission if needed + ynh_permission_update --permission "main" --add "visitors" --remove "all_users" fi #================================================= @@ -229,7 +230,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -# Wait 10 secends tor server to start sleep 10 #================================================= diff --git a/scripts/remove b/scripts/remove index fc7c394..3bd0d9c 100755 --- a/scripts/remove +++ b/scripts/remove @@ -32,8 +32,8 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Remove the service from the list of services known by Yunohost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --weight=1 - yunohost service remove $app + ynh_script_progression --message="Removing $app service..." --weight=1 + yunohost service remove $app fi #================================================= @@ -92,8 +92,8 @@ ynh_secure_remove --file="/var/log/$app" if yunohost firewall list | grep -q "\- $port$" then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port + ynh_script_progression --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP $port fi #================================================= diff --git a/scripts/restore b/scripts/restore index 05f07b6..73106e4 100755 --- a/scripts/restore +++ b/scripts/restore @@ -16,8 +16,8 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true + #### Remove this function if there's nothing to clean before calling the remove script. + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -42,9 +42,9 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) ynh_script_progression --message="Validating restoration parameters..." --weight=2 ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" + || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -76,12 +76,12 @@ ynh_system_user_create --username=$app --home_dir=$final_path # Restore permissions on app files chown -R root: $final_path chown $app: $final_path -mkdir -p $final_path/live/log -chown -R $app: $final_path/live/log/ -mkdir -p $final_path/live/tmp -chown -R $app: $final_path/live/tmp/ -mkdir -p /var/log/$app -chown -R $app: /var/log/$app +mkdir -p "$final_path/live/log" +chown -R $app: "$final_path/live/log/" +mkdir -p "$final_path/live/tmp" +chown -R $app: "$final_path/live/tmp/" +mkdir -p "/var/log/$app" +chown -R $app: "/var/log/$app" #================================================= # RESTORE FAIL2BAN CONFIGURATION @@ -106,7 +106,7 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # INSTALLING RUBY #================================================= -ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 +ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 ynh_install_ruby --ruby_version=$RUBY_VERSION /opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document @@ -140,7 +140,6 @@ yunohost service add $app --description "Standard Notes - Syncing Server" --log ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -# Wait 10 secends tor server to start sleep 10 #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f0ca15a..5fd9337 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -45,23 +45,23 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=1 - is_public=1 + ynh_app_setting_set --app=$app --key=is_public --value=1 + is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app=$app --key=is_public --value=0 - is_public=0 + ynh_app_setting_set --app=$app --key=is_public --value=0 + is_public=0 fi # If db_name doesn't exist, create it if [ -z "$db_name" ]; then - db_name=$(ynh_sanitize_dbid --db_name=$app) - ynh_app_setting_set --app=$app --key=db_name --value=$db_name + db_name=$(ynh_sanitize_dbid --db_name=$app) + ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then - final_path=/opt/yunohost/$app - ynh_app_setting_set --app=$app --key=final_path --value=$final_path + final_path=/opt/yunohost/$app + ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi #================================================= @@ -72,8 +72,8 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails - ynh_restore_upgradebackup + # restore it if the upgrade fails + ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -93,21 +93,21 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --weight=1 + ynh_script_progression --message="Upgrading source files..." --weight=1 - # Backup files to keep - tmpdir=$(mktemp -d) - if [ -d $final_path/live/log ] ; then - cp -Rp $final_path/live/log $tmpdir - fi - # Remove destination directory - ynh_secure_remove --file=$final_path - # Download, check integrity, uncompress and patch the source from app.src - mkdir -p $final_path - ynh_setup_source --dest_dir="$final_path/live" - if [ -d $tmpdir/log ] ; then - cp -Rp $tmpdir/log $final_path/live - fi + # Backup files to keep + tmpdir=$(mktemp -d) + if [ -d $final_path/live/log ] ; then + cp -Rp $final_path/live/log $tmpdir + fi + # Remove destination directory + ynh_secure_remove --file=$final_path + # Download, check integrity, uncompress and patch the source from app.src + mkdir -p $final_path + ynh_setup_source --dest_dir="$final_path/live" + if [ -d $tmpdir/log ] ; then + cp -Rp $tmpdir/log $final_path/live + fi fi #================================================= @@ -129,7 +129,7 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # INSTALL RUBY #================================================= -ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 +ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331 ynh_install_ruby --ruby_version=$RUBY_VERSION /opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document @@ -151,34 +151,35 @@ ynh_system_user_create --username=$app --home_dir=$final_path config_file="$final_path/live/.env" if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Modifying a config file..." --weight=2 + ynh_script_progression --message="Modifying a config file..." --weight=2 - cp -f ../conf/env.sample $config_file - ynh_replace_string --match_string="EXPOSED_PORT=3000" --replace_string="EXPOSED_PORT=$port" --target_file="$config_file" - secret_key=$(ynh_string_random --length=48 | base64) - ynh_replace_string --match_string="SECRET_KEY_BASE=changeme123" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file" - pseudo_key=$(ynh_string_random --length=48 | base64) - ynh_replace_string --match_string="PSEUDO_KEY_PARAMS_KEY=changeme456" --replace_string="PSEUDO_KEY_PARAMS_KEY=$pseudo_key" --target_file="$config_file" - ynh_replace_string --match_string="RAILS_ENV=development" --replace_string="RAILS_ENV=production" --target_file="$config_file" - ynh_replace_string --match_string="DB_DATABASE=standard_notes_db" --replace_string="DB_DATABASE=$db_name" --target_file="$config_file" - ynh_replace_string --match_string="DB_USERNAME=std_notes_user" --replace_string="DB_USERNAME=$db_user" --target_file="$config_file" - ynh_replace_string --match_string="DB_PASSWORD=changeme123" --replace_string="DB_PASSWORD=$db_pwd" --target_file="$config_file" + cp -f ../conf/env.sample $config_file + ynh_replace_string --match_string="EXPOSED_PORT=3000" --replace_string="EXPOSED_PORT=$port" --target_file="$config_file" + secret_key=$(ynh_string_random --length=48 | base64) + ynh_replace_string --match_string="SECRET_KEY_BASE=changeme123" --replace_string="SECRET_KEY_BASE=$secret_key" --target_file="$config_file" + pseudo_key=$(ynh_string_random --length=48 | base64) + ynh_replace_string --match_string="PSEUDO_KEY_PARAMS_KEY=changeme456" --replace_string="PSEUDO_KEY_PARAMS_KEY=$pseudo_key" --target_file="$config_file" + ynh_replace_string --match_string="RAILS_ENV=development" --replace_string="RAILS_ENV=production" --target_file="$config_file" + ynh_replace_string --match_string="DB_DATABASE=standard_notes_db" --replace_string="DB_DATABASE=$db_name" --target_file="$config_file" + ynh_replace_string --match_string="DB_USERNAME=std_notes_user" --replace_string="DB_USERNAME=$db_user" --target_file="$config_file" + ynh_replace_string --match_string="DB_PASSWORD=changeme123" --replace_string="DB_PASSWORD=$db_pwd" --target_file="$config_file" + ynh_replace_string --match_string="RAILS_RELATIVE_URL_ROOT=/" --replace_string="RAILS_RELATIVE_URL_ROOT=$path_url" --target_file="$config_file" fi #================================================= # INSTALLING Standard Notes - Synicing Server #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Installing Standard Notes - Synicing Server..." --weight=93 - - chown -R "$app": "$final_path" - - pushd "$final_path/live" - exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set path 'vendor/bundle' - exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set with 'development' - exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle install - exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:create db:migrate - popd + ynh_script_progression --message="Installing Standard Notes - Synicing Server..." --weight=93 + + chown -R "$app": "$final_path" + + pushd "$final_path/live" + exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set path 'vendor/bundle' + exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set with 'development' + exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle install + exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:create db:migrate --quiet + popd fi #================================================= @@ -187,9 +188,10 @@ fi ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/systemd.service" -ynh_replace_string --match_string="__RUBY_VERSION__" --replace_string="$RUBY_VERSION" --target_file="../conf/systemd.service" -ynh_add_systemd_config --service="$app" --template="systemd.service" +ynh_add_systemd_config --others_var="\ + port \ + RUBY_VERSION \ +" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -209,13 +211,13 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" # Set permissions to app files chown -R root: $final_path chown $app: $final_path -mkdir -p $final_path/live/log -chown -R $app: $final_path/live/log/ -mkdir -p $final_path/live/tmp -chown -R $app: $final_path/live/tmp/ +mkdir -p "$final_path/live/log" +chown -R $app: "$final_path/live/log/" +mkdir -p "$final_path/live/tmp" +chown -R $app: "$final_path/live/tmp/" -mkdir -p /var/log/$app -chown -R $app: /var/log/$app +mkdir -p "/var/log/$app" +chown -R $app: "/var/log/$app" #================================================= # SETUP LOGROTATE @@ -247,10 +249,10 @@ ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 # Make app public if necessary or protect it if [ $is_public -eq 1 ] then - # Create the visitors permission if needed - if ! ynh_permission_exists --permission "main"; then - ynh_permission_create --permission "main" --allowed "visitors" - fi + # Create the visitors permission if needed + if ! ynh_permission_exists --permission "main"; then + ynh_permission_create --permission "main" --allowed "visitors" + fi fi #================================================= @@ -260,7 +262,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -# Wait 10 secends tor server to start sleep 10 #================================================= diff --git a/sources/patches/app-00-add-path-url.patch b/sources/patches/app-00-add-path-url.patch new file mode 100644 index 0000000..73f971a --- /dev/null +++ b/sources/patches/app-00-add-path-url.patch @@ -0,0 +1,12 @@ +diff --git a/config.ru b/config.ru +index bd83b25..6b1bb50 100644 +--- a/config.ru ++++ b/config.ru +@@ -1,4 +1,6 @@ + # This file is used by Rack-based servers to start the application. + + require ::File.expand_path('../config/environment', __FILE__) +-run Rails.application ++map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do ++ run Rails.application ++end