diff --git a/manifest.json b/manifest.json index ae06694..a82252e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "name": "Dont-Code Services", + "name": "Dont-code Services", "id": "dont-code", "packaging_format": 1, "description": { diff --git a/scripts/_common.sh b/scripts/_common.sh index a4476c8..454c6ec 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -19,6 +19,15 @@ MONGO_DB_LIST=(dontCodeProjects dontCodeDemoProjects dontCodeData dontCodeTestPr #================================================= # PERSONAL HELPERS #================================================= +append_uri() { + local return=""; + if [[ $1 == */ ]]; then + return=$1$2; + else + return=$1/$2 + fi + echo "$return"; +} #================================================= # EXPERIMENTAL HELPERS diff --git a/scripts/change_url b/scripts/change_url index 041fb2f..8e9fd8e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -37,6 +37,7 @@ port_project=$(ynh_app_setting_get --app=$app --key=port_project) port_data=$(ynh_app_setting_get --app=$app --key=port_data) html_path=$(ynh_app_setting_get --app=$app --key=html_path) document_path=$(ynh_app_setting_get --app=$app --key=document_path) +document_url=$(ynh_app_setting_get --app=$app --key=document_url) #================================================= # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP @@ -119,13 +120,13 @@ fi #================================================= ynh_script_progression --message="Updating .env configuration..." -document_url=https://${new_domain}${new_path}/documents -old_document_url=https://${old_domain}${old_path}/documents -ynh_app_setting_set --app=$app --key=document_url --value=$document_url +new_document_url=$(append_uri "https://${new_domain}${new_path}" "docs") +ynh_app_setting_set --app=$app --key=document_url --value=$new_document_url ynh_backup_if_checksum_is_different --file="$final_path/.env" -ynh_replace_string --match_string="$old_document_url" --replace_string="$document_url" --target_file="$final_path/.env" +ynh_replace_string --match_string="$document_url" --replace_string="$new_document_url" --target_file="$final_path/.env" ynh_store_file_checksum --file="$final_path/.env" +document_url=new_document_url #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index fac3c8e..442c282 100755 --- a/scripts/install +++ b/scripts/install @@ -219,7 +219,7 @@ chmod 750 "$html_path" chmod -R o-rwx "$html_path" chown -R $app:www-data "$html_path" -document_url=https://${domain}${path_url}/docs +document_url=$(append_uri "https://${domain}${path_url}" "docs") ynh_app_setting_set --app=$app --key=document_url --value=$document_url diff --git a/scripts/upgrade b/scripts/upgrade index 8fe55e9..3862ab4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -27,6 +27,7 @@ port_data=$(ynh_app_setting_get --app=$app --key=port_data) db_user=$(ynh_app_setting_get --app=$app --key=db_user) final_path=$(ynh_app_setting_get --app=$app --key=final_path) document_path=$(ynh_app_setting_get --app=$app --key=document_path) +document_url=$(ynh_app_setting_get --app=$app --key=document_url) html_path=$(ynh_app_setting_get --app=$app --key=html_path) PORT_LIST=($port_ide $port_preview $port_project $port_data) @@ -172,18 +173,28 @@ if [ "$document_path" != "/usr/share/nginx/html/$app/docs" ]; then # Update the path in .env file ynh_backup_if_checksum_is_different --file="$final_path/.env" - ynh_replace_string --match_string="$old_old_doc_path" --replace_string="$document_document_path" --target_file="$final_path/.env" - - # Changed the document url as well - old_document_url=$document_url - document_url=https://${domain}${path_url}/docs - ynh_app_setting_set --app=$app --key=document_url --value=$document_url - - ynh_replace_string --match_string="$old_document_url" --replace_string="$document_url" --target_file="$final_path/.env" + ynh_replace_string --match_string="$old_doc_path" --replace_string="$document_path" --target_file="$final_path/.env" ynh_store_file_checksum --file="$final_path/.env" fi +# Regenerate the .env file if the document_url was incorrectly set before +correct_document_url=$(append_uri "https://${domain}${path_url}" "docs") +if [ "$correct_document_url" != "$document_url" ]; then + ynh_script_progression --message="Updading url for documents" --weight=1 + old_doc_url=$document_url + document_url=$correct_document_url + ynh_app_setting_set --app=$app --key=document_url --value=$document_url + + ynh_add_config --template=".env" --destination="$final_path/.env" + + # FIXME: this should be handled by the core in the future + # You may need to use chmod 600 instead of 400, + # for example if the app is expected to be able to modify its own config + chmod 400 "$final_path/.env" + chown $app:$app "$final_path/.env" +fi + #================================================= # UPDATE A CONFIG FILE #=================================================