summaryrefslogtreecommitdiffstats
path: root/geo-replication/src/set_geo_rep_pem_keys.sh
blob: ae23f4ff0c6ab41ea861328dc6fd5d179a4e1cda (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
#!/bin/bash

# Script to copy the pem keys from the user's home directory
# to $GLUSTERD_WORKDIR/geo-replication and then copy
# the keys to other nodes in the cluster and add them to the
# respective authorized keys. The script takes as argument the
# user name and assumes that the user will be present in all
# the nodes in the cluster. Not to be used for root user

function main()
{
    user=$1
    master_vol=$2
    slave_vol=$3
    GLUSTERD_WORKDIR=$(gluster system:: getwd)

    if [ "$user" == "" ];  then
        echo "Please enter the user's name"
        exit 1;
    fi

    if [ "$master_vol" == "" ]; then
        echo "Invalid master volume name"
        exit 1;
    fi

    if [ "$slave_vol" == "" ]; then
        echo "Invalid slave volume name"
        exit 1;
    fi

    COMMON_SECRET_PEM_PUB=${master_vol}_${slave_vol}_common_secret.pem.pub

    if [ "$user" == "root" ]; then
        echo "This script is not needed for root"
        exit 1;
    fi

    home_dir=`getent passwd $user | cut -d ':' -f 6`;

    if [ "$home_dir" == "" ]; then
        echo "No user $user found"
        exit 1;
    fi

    if [ -f $home_dir/${COMMON_SECRET_PEM_PUB} ]; then
        cp $home_dir/${COMMON_SECRET_PEM_PUB} ${GLUSTERD_WORKDIR}/geo-replication/
        gluster system:: copy file /geo-replication/${COMMON_SECRET_PEM_PUB}
        gluster system:: execute add_secret_pub $user geo-replication/${master_vol}_${slave_vol}_common_secret.pem.pub
    else
        echo "$home_dir/common_secret.pem.pub not present. Please run geo-replication command on master with push-pem option to generate the file"
        exit 1;
    fi
    exit 0;
}

main "$@";