Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / ceph-post-file.in
1 #!/bin/bash -e
2
3 # If these files exist, assume we are a source install.
4 if [[ -f ../share/known_hosts_drop.ceph.com && -f ../share/id_rsa_drop.ceph.com ]]
5     then # running from source install
6        known_hosts=../share/known_hosts_drop.ceph.com
7        ssh_key=../share/id_rsa_drop.ceph.com
8     else # running from a pkg install
9        known_hosts=@datadir@/known_hosts_drop.ceph.com
10        ssh_key=@datadir@/id_rsa_drop.ceph.com
11 fi
12
13 function usage() {
14     echo "Usage: $0 [options] file1 [dir2 ...]
15
16 Easily upload files or directories to ceph.com for analysis by Ceph
17 developers.
18
19 Each invocation uploads files or directories to a separate directory
20 with a unique tag.  That tag can be passed to a developer or
21 referenced in a bug report (http://tracker.ceph.com/).  Once the
22 upload completes, the directory is marked non-readable and
23 non-writeable to prevent access or modification by other users.
24
25 WARNING:
26   Basic measures are taken to make posted data be visible only to
27   developers with access to ceph.com infrastructure. However, users
28   should think twice and/or take appropriate precautions before
29   posting potentially sensitive data (for example, logs or data
30   directories that contain Ceph secrets).
31
32 Options:
33   -d|--description <desc>    Description for this post
34                                [Default: none]
35   -u|--user <user>           User identifier
36                                [Default: \`whoami\`@\`hostname -f\`]
37   -r|--remote <user@host>    Remote to upload to
38                                [Default: postfile@drop.ceph.com]
39   -k|--known_hosts <path>    known_hosts file
40                                [Default: /usr/share/ceph/known_hosts_drop.ceph.com]
41   -i <path>         Ssh identity file
42                       [Default: /usr/share/ceph/id_rsa_drop.ceph.com]
43   -h|--help         Show this usage information
44 "
45 }
46
47 if [ -z "$*" ]; then
48     usage
49     exit 1
50 fi
51
52 description=""
53 user="`whoami`@`hostname -f`"
54 remote="postfile@drop.ceph.com"
55
56 if [ `uname` = FreeBSD ]; then
57   GETOPT=/usr/local/bin/getopt
58 else
59   GETOPT=getopt
60 fi
61
62 ARGS=$(${GETOPT} -n "ceph-post-file" -o 'd:u:hk:i:r:' -l "description:,user:,help,known-hosts:,remote:" -- "$@")
63 eval set -- $ARGS
64
65 while true; do
66         echo "args: $@"
67         case $1 in
68             -d | --description)
69                 description="$2"
70                 shift
71                 shift
72                 ;;
73             -u | --user)
74                 user="$2"
75                 shift
76                 shift
77                 ;;
78             -h | --help)
79                 usage
80                 exit 0
81                 ;;
82             -k | --known-hosts)
83                 known_hosts="$2"
84                 shift
85                 shift
86                 ;;
87             -i)
88                 ssh_key="$2"
89                 shift
90                 shift
91                 ;;
92             -r | --remote)
93                 remote="$2"
94                 shift
95                 shift
96                 ;;
97             --)
98                 shift
99                 break
100                 ;;
101         esac
102 done
103
104 # this id should be shared
105 id=`uuidgen`
106 echo "$0: upload tag $id"
107
108 # this is secret goop we add to the directory so that $id is not
109 # enough to find the data using the shared user; only ceph developers
110 # who have access to the server and can read the post directory can
111 # find the uploaded data.
112 nonce=`uuidgen`
113
114 # stick the user info in the dir too
115 dir="${id}_${user}_${nonce}"
116
117 t1=$(mktemp) || exit
118 t2=$(mktemp) || exit
119 t3=$(mktemp) || exit
120 t4=$(mktemp) || exit
121 trap "rm -f -- '$t1' '$t2' '$t3' '$t4'" EXIT
122 cat > $t1 <<EOF
123 mkdir post/$dir
124 cd post/$dir
125 EOF
126
127 echo "$0: user: $user"
128 cat > $t3 <<EOF
129 $user
130 EOF
131 echo put $t3 user >> $t1
132
133 if [ -n "$description" ]; then
134     echo "$0: description: $description"
135     cat > $t2 <<EOF
136 $description
137 EOF
138     echo put $t2 description >> $t1
139 fi
140
141 while [ -n "$*" ]; do
142     if [ -d "$1" ]; then
143         echo $0: will upload directory $1
144         bn=`basename "$1"`
145         cat >> $t1 <<EOF
146 mkdir $bn
147 put -r $1
148 EOF
149     else
150         echo $0: will upload file $1
151         cat >> $t1 <<EOF
152 put $1
153 EOF
154     fi
155     shift
156 done
157
158 # no UserKnownHostsFile so that we don't try to record the IP hash key
159 # GlobalKnownHostsFile so that we are verifying that this is the real drop.ceph.com
160 # IdentitiesOnly=yes forces sftp to ignore any keys offered by ssh-agent
161
162 cp "$ssh_key" "$t4"
163 cp "${ssh_key}.pub" "$t4.pub"
164
165 sftp -o "IdentityFile=$t4" \
166     -C \
167     -oCheckHostIP=no \
168     -oGlobalKnownHostsFile=$known_hosts \
169     -oBatchMode=no \
170     -oIdentitiesOnly=yes \
171     -b $t1 -- $remote
172
173 echo "$0: copy the upload id below to share with a dev:
174
175 ceph-post-file: $id
176 "