slapos-client-config.sh 2.47 KB
Newer Older
Jondy Zhao's avatar
Jondy Zhao committed
1 2 3 4 5 6
#! /bin/bash
#
# Configure slapos desktop,
#
# Usage:
#
7
#    ./slapos-client-config certificate_file key_file
Jondy Zhao's avatar
Jondy Zhao committed
8
#
Jondy Zhao's avatar
Jondy Zhao committed
9
export PATH=/usr/local/bin:/usr/bin:$PATH
Jondy Zhao's avatar
Jondy Zhao committed
10

11 12 13 14 15 16 17 18 19 20 21
#
# Show error message and waiting for user to press any key quit
#
function show_error_exit()
{
    msg=${1-Configure node failed.}
    echo $msg
    read -n 1 -t 15 -p "Press any key to exit..."
    exit 1
}

Jondy Zhao's avatar
Jondy Zhao committed
22 23 24 25
slapos_client_home=~/.slapos
client_configure_file=$slapos_client_home/slapos.cfg
client_certificate_file=$slapos_client_home/certificate
client_key_file=$slapos_client_home/key
26
template_configure_file=/etc/slapos/slapos-client.cfg.example
Jondy Zhao's avatar
Jondy Zhao committed
27 28 29 30

mkdir -p $slapos_client_home

#
31
# Generate desktop configure file
Jondy Zhao's avatar
Jondy Zhao committed
32
#
33
echo
Jondy Zhao's avatar
Jondy Zhao committed
34 35 36 37 38
echo Before continue to configure, make sure you have an account in the
echo slapos.org community, and have obtained X509 certificate and key
echo which are needed for the following configuration process.
echo
echo Refer to http://community.slapos.org/wiki/osoe-Lecture.SlapOS.Extended/developer-Installing.SlapOS.Client
39
echo
Jondy Zhao's avatar
Jondy Zhao committed
40 41 42 43 44 45 46

if [[ -f "$1" ]] ; then
    echo "Copy certificate from $2 to $client_certificate_file"
    cp $1 $client_certificate_file
elif [[ ! -f $client_certificate_file ]] ; then
    read -p "Where is certificate file: " certificate_file
    [[ ! -f "$certificate_file" ]] && \
47
        show_error_exit "Certificate file $certificate_file doesn't exists."
Jondy Zhao's avatar
Jondy Zhao committed
48
    echo "Copy certificate from $certificate_file to $client_certificate_file"
49
    certificate_file=$(cygpath -u $certificate_file)
50
    cp $certificate_file $client_certificate_file
Jondy Zhao's avatar
Jondy Zhao committed
51 52 53 54 55 56 57 58
fi

if [[ -f "$2" ]] ; then
    echo "Copy key from $3 to $client_key_file"
    cp $2 $client_key_file
elif [[ ! -f $client_key_file ]] ; then
    read -p "Where is key file: " key_file
    [[ ! -f "$key_file" ]] && \
59
        show_error_exit "Key file $key_file doesn't exists."
Jondy Zhao's avatar
Jondy Zhao committed
60
    echo "Copy key from $key_file to $client_key_file"
61
    key_file=$(cygpath -u $key_file)
62
    cp $key_file $client_key_file
Jondy Zhao's avatar
Jondy Zhao committed
63 64 65
fi

if [[ ! -f $client_configure_file ]] ; then
66
    [[ -f $template_configure_file ]] || \
Jondy Zhao's avatar
Jondy Zhao committed
67
        (cd /etc/slapos; wget http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos-client.cfg.example) || \
68
        show_error_exit "Download slapos-client.cfg.example failed."
69
    cp $template_configure_file $client_configure_file
Jondy Zhao's avatar
Jondy Zhao committed
70 71
fi

Jondy Zhao's avatar
Jondy Zhao committed
72 73
sed -i -e "s%^cert_file.*$%cert_file = $client_certificate_file%" \
       -e "s%^key_file.*$%key_file = $client_key_file%" \
Jondy Zhao's avatar
Jondy Zhao committed
74
       $client_configure_file
75 76

echo SlapOS Client configure successfully.
77
read -n 1 -p "Press any key to exit..."
78
exit 0