From 24971c25a74f33b7986891683176d98cb07d8827 Mon Sep 17 00:00:00 2001
From: Lincoln Lee <git@lincoln.hk>
Date: Sun, 6 Dec 2015 10:57:08 +0800
Subject: [PATCH] Set home path to 3.x default when it exists

- set directory to right permission
---
 attributes/default.rb    | 7 ++++++-
 recipes/configuration.rb | 6 ++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/attributes/default.rb b/attributes/default.rb
index 124cae2..0d6b496 100644
--- a/attributes/default.rb
+++ b/attributes/default.rb
@@ -3,7 +3,12 @@
 default['stash']['version']      = '4.1.0'
 default['stash']['product']      = Chef::Version.new(node['stash']['version']) >= Chef::Version.new('4.0.0') ? 'bitbucket' : 'stash'
 
-default['stash']['home_path']    = "/var/atlassian/application-data/#{node['stash']['product']}"
+if Dir.exists?('/var/atlassian/application-data/stash')
+  default['stash']['home_path']    = '/var/atlassian/application-data/stash'
+else
+  default['stash']['home_path']    = "/var/atlassian/application-data/#{node['stash']['product']}"
+end
+
 default['stash']['install_path'] = '/opt/atlassian'
 default['stash']['install_type'] = 'standalone'
 default['stash']['service_type'] = 'init'
diff --git a/recipes/configuration.rb b/recipes/configuration.rb
index 1fe92e1..8777c41 100644
--- a/recipes/configuration.rb
+++ b/recipes/configuration.rb
@@ -22,6 +22,12 @@
     action :create
     recursive true
   end
+
+  bash 'update home path permission' do
+    code <<-EOH
+      chown -R #{node['stash']['user']}:#{node['stash']['user']} #{node['stash']['home_path']}
+    EOH
+  end
 else
   config_path = '/stash-config.properties'
 end