From 3ddd4d4690c2d41f3a73ce1de903d3a7da55fdae Mon Sep 17 00:00:00 2001
From: Liu Long <long.liu@linux.intel.com>
Date: Wed, 24 Aug 2022 22:57:24 +0800
Subject: [PATCH] SampleApplicaton: Change schroot data mapping to desktop

1.Use desktop profie to repalce the default profile.
2.Change the flask images path as a absolute path.
3.Add the ssh config function to enable the ssh.

Tracked-On: #7820
Signed-off-by: Liu Long long.liu@linux.intel.com
---
 misc/sample_application/image_builder/create_image.sh |  3 ++-
 misc/sample_application/image_builder/setup_hmi_vm.sh | 10 +++++++++-
 misc/sample_application/uservm/histapp.py             |  4 ++--
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/misc/sample_application/image_builder/create_image.sh b/misc/sample_application/image_builder/create_image.sh
index 772e37f39..83d7b9acc 100755
--- a/misc/sample_application/image_builder/create_image.sh
+++ b/misc/sample_application/image_builder/create_image.sh
@@ -146,7 +146,8 @@ profile=desktop
 personality=linux
 preserve-environment=true
 EOF
-    sudo sed -i -e '3,9 s/^/#/' /etc/schroot/default/nssdatabases
+    sudo sed -ie "/passwd/d;/shadow/d;/group/d;/gshadow/d" \
+        /etc/schroot/desktop/nssdatabases && \
     sudo mv ${temp_file} /etc/schroot/chroot.d/acrn-guest && \
         sudo chown root:root /etc/schroot/chroot.d/acrn-guest
 }
diff --git a/misc/sample_application/image_builder/setup_hmi_vm.sh b/misc/sample_application/image_builder/setup_hmi_vm.sh
index 4d78fd091..c0c8defff 100644
--- a/misc/sample_application/image_builder/setup_hmi_vm.sh
+++ b/misc/sample_application/image_builder/setup_hmi_vm.sh
@@ -41,7 +41,6 @@ function add_normal_user() {
 
 function enable_services() {
     services=(ssh.service isc-dhcp-server)
-    sudo ssh-keygen -A
     for service in ${services[*]}
     do
         systemctl enable ${service}
@@ -49,6 +48,14 @@ function enable_services() {
     done
 }
 
+function config_ssh() {
+
+    sudo sed -ie 's/PasswordAuthentication no/PasswordAuthentication yes/g' \
+	    /etc/ssh/sshd_config
+    sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
+    sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
+}
+
 # Change current working directory to the root to avoid "target is busy" errors
 # on unmounting.
 cd /
@@ -60,3 +67,4 @@ try_step "Installing GNOME desktop" install_desktop
 try_step "Changing the password of the root user" change_root_password
 try_step "Enable root user login" enable_root_login
 try_step "Adding the normal user acrn" add_normal_user
+try_step "Configure the ssh service" config_ssh
diff --git a/misc/sample_application/uservm/histapp.py b/misc/sample_application/uservm/histapp.py
index 61f853d0e..06d434084 100644
--- a/misc/sample_application/uservm/histapp.py
+++ b/misc/sample_application/uservm/histapp.py
@@ -26,7 +26,7 @@ def histapp():
 	create_hist()
 
 	#Send the histogram as a webpage to the user
-	return send_file("hist.png", mimetype='image/png')
+	return send_file("/root/hist.png", mimetype='image/png')
 
 #Creates the user histogram and saves to hist.png
 def create_hist():
@@ -52,7 +52,7 @@ def create_hist():
 	plt.title("ACRN Sample Application cyclictest display (unoptimized)")
 	plt.xlabel("Latency Value (microseconds)")
 	plt.ylabel("Count Percentage      " + f"{count:,}")
-	plt.savefig("hist.png")
+	plt.savefig("/root/hist.png")
 
 	return figure