blob: a297dd097544134cd1e9ecacb3d42d5b8fb97382 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/bin/bash
user=$1
mastervol=$2
slavevol=$3
if [ "$user" == "" ]; then
echo "Invalid User";
exit 1;
fi
if [ "$mastervol" == "" ]; then
echo "Invalid master volume";
exit 1;
fi
if [ "$slavevol" == "" ]; then
echo "Invalid slave volume";
exit 1;
fi
home_dir=`getent passwd $user | cut -d ':' -f 6`;
if [ "$home_dir" == "" ]; then
echo "Invalid home dir";
exit 1;
fi
authorized_keys_file=$(cat /etc/ssh/sshd_config | \
grep -e "^AuthorizedKeysFile" | \
awk '{print $2}' | tail -1);
# If not set, use default location
if [ "x$authorized_keys_file" == "x" ]; then
authorized_keys_file="%h/.ssh/authorized_keys"
fi
# If default location
if [ "$authorized_keys_file" == ".ssh/authorized_keys" ]; then
authorized_keys_file="%h/$authorized_keys_file"
fi
# Replace %u with user name (ex: /etc/ssh/keys/%u/authorized_keys)
authorized_keys_file="${authorized_keys_file//%u/$user}";
# Replace %h with home dir (ex: %h/.ssh/authorized_keys)
authorized_keys_file="${authorized_keys_file//%h/$home_dir}";
ssh_dir=$(dirname $authorized_keys_file);
if [ ! -d $ssh_dir ]; then
mkdir $ssh_dir;
chmod 700 $ssh_dir;
chown $user: $ssh_dir;
fi
if [ ! -d $authorized_keys_file ]; then
touch $authorized_keys_file;
chmod 600 $authorized_keys_file;
chown $user: $authorized_keys_file;
fi
pub_file=${mastervol}_${slavevol}_common_secret.pem.pub
cat "$GLUSTERD_WORKDIR"/geo-replication/$pub_file >> \
$authorized_keys_file;
|