Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / qa_scripts / openstack / copy_func.sh
1 #/bin/bash -fv
2 #
3 # copy_file(<filename>, <node>, <directory>, [<permissions>], [<owner>]
4
5 # copy a file -- this is needed because passwordless ssh does not
6 #                work when sudo'ing.
7 #    <file> -- name of local file to be copied
8 #    <node> -- node where we want the file
9 #    <directory> -- location where we want the file on <node>
10 #    <permissions> -- (optional) permissions on the copied file
11 #    <owner> -- (optional) owner of the copied file
12 #
13 function copy_file() {
14     fname=`basename ${1}`
15     scp ${1} ${2}:/tmp/${fname}
16     ssh ${2} sudo cp /tmp/${fname} ${3}
17     if [ $# -gt 3 ]; then
18        ssh ${2} sudo chmod ${4} ${3}/${fname}
19     fi
20     if [ $# -gt 4 ]; then
21        ssh ${2} sudo chown ${5} ${3}/${fname}
22     fi
23 }