From 0c4026699186df47e80058c370044ac2a507f9e2 Mon Sep 17 00:00:00 2001
From: Jibec <jean-baptiste@holcroft.fr>
Date: Wed, 2 Jan 2019 10:15:28 +0200
Subject: [PATCH] fix the misuse of Here document (preventing manual imports)

---
 manifest.json   |  4 ++--
 scripts/install | 12 ++++++++----
 scripts/upgrade | 12 ++++++++----
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/manifest.json b/manifest.json
index 2314e12..7ec8807 100644
--- a/manifest.json
+++ b/manifest.json
@@ -8,7 +8,7 @@
 	"description": {
 		"en": "A modern, convivial and free music server"
 	},
-	"version": "0.17.0~ynh2",
+	"version": "0.17.0~ynh3",
 	"url": "https://funkwhale.audio",
 	"license": "BSD-3-Clause",
 	"maintainer": {
@@ -47,4 +47,4 @@
 			}
 		]
 	}
-}
+}
\ No newline at end of file
diff --git a/scripts/install b/scripts/install
index 767341f..2e03ddc 100644
--- a/scripts/install
+++ b/scripts/install
@@ -172,12 +172,16 @@ ynh_replace_string "__DBNAME__"    "$app"         "$configfile"
 ynh_replace_string "__FINALPATH__" "$final_path"  "$configfile"
 ynh_replace_string "__KEY__"       "$key"         "$configfile"
 
-cat > "$final_path/code/load_env" <<'EOL'
+loadfile="$final_path/code/load_env"
+
+cat > "$loadfile" <<'EOL'
 #!/bin/bash
-export $(cat "$final_path/code/config/.env" | grep -v ^# | xargs)
+export $(cat "__FINALPATH__/code/config/.env" | grep -v ^# | xargs)
 EOL
 
-chmod +x "$final_path/code/load_env"
+chmod +x "$loadfile"
+
+ynh_replace_string "__FINALPATH__" "$final_path"  "$loadfile"
 
 #=================================================
 # MODIFY THE CONFIG FILE
@@ -187,7 +191,7 @@ admin_mail=$(ynh_user_get_info "$admin" "mail")
 (
 	set +o nounset
 	source "${final_path}/code/virtualenv/bin/activate"
-	source "${final_path}/code/load_env"
+	source "$loadfile"
 	set -o nounset
 	cd "$final_path/code/"
 
diff --git a/scripts/upgrade b/scripts/upgrade
index 5c92527..1bd9d5b 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -175,12 +175,16 @@ ynh_replace_string "__DBNAME__"    "$app"         "$configfile"
 ynh_replace_string "__FINALPATH__" "$final_path"  "$configfile"
 ynh_replace_string "__KEY__"       "$key"         "$configfile"
 
-cat > "$final_path/code/load_env" <<'EOL'
+loadfile="$final_path/code/load_env"
+
+cat > "$loadfile" <<'EOL'
 #!/bin/bash
-export $(cat "$final_path/code/config/.env" | grep -v ^# | xargs)
+export $(cat "__FINALPATH__/code/config/.env" | grep -v ^# | xargs)
 EOL
 
-chmod +x "$final_path/code/load_env"
+chmod +x "$loadfile"
+
+ynh_replace_string "__FINALPATH__" "$final_path"  "$loadfile"
 
 #=================================================
 # MIGRATE
@@ -189,7 +193,7 @@ chmod +x "$final_path/code/load_env"
 (
 	set +o nounset
 	source "${final_path}/code/virtualenv/bin/activate"
-	source "${final_path}/code/load_env"
+	source "$loadfile"
 	set -o nounset
 	cd "$final_path/code"