summaryrefslogtreecommitdiff
path: root/scripts/rvi_devrun
blob: 901b002ef20ca69c30a6f7ac48f211b138790446 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
#
# Copyright (C) 2014, Jaguar Land Rover
#
# This program is licensed under the terms and conditions of the
# Mozilla Public License, version 2.0.  The full text of the 
# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
#

#
# Launch an RVI node using the build directories
# For now this is a simple wrapper around the installer

SELF_DIR=$(dirname $(readlink -f "$0"))
PRIV_DIR=$(dirname ${SELF_DIR})/priv
TARGET_DIR=""
ROOT_CERT="${PRIV_DIR}/certificates/insecure_root_cert.crt"
DEVICE_CERT="${PRIV_DIR}/certificates/insecure_device_cert.crt"
DEVICE_KEY="${PRIV_DIR}/keys/insecure_device_key.pem"
DEVICE_CRED="${PRIV_DIR}/credentials/insecure_credential.jwt"

usage() {
    cat <<EOF
Usage:
$0 [-r root_cert] [-d device_cert] [-c credentials] config_file
 
Run a developer version of RVI
 
-r root_cert    - The certificate to validate received X509 device
                  certificates and credentials.
                  Default ${ROOT_CERT}
 
-k device_key   - The PEM file containing the device key pair used
                  to sign traff
                  Default ${DEVICE_KEY}

-d device_cert  - Certificate to use when authenticating self toward 
                  remote nodes.
                  Default ${DEVICE_CERT}

-c credentials  - Credentials to present to remote nodes. Can be specified
                  multiple times
                  Default ${DEVICE_CRED}
                         
EOF
    exit 1
}

while getopts "r:d:c:k:" o; do
    case "${o}" in
	r)
	    ROOT_CERT=${OPTARG}
	    ;;

	d)
	    DEVICE_CERT=${OPTARG}
	    ;;

	c)
	    DEVICE_CRED=${OPTARG}
	    ;;

	k)
	    DEVICE_KEY=${OPTARG}
	    ;;
        *)
            usage
            ;;
    esac
done

shift $((${OPTIND}-1))

# Check that we have a target dir

if [ "${#}" != "1" ]
then
    echo "ERROR: Wrong number of arguments. Only specify config file"
    usage
fi

CONFIG_FILE=${1}

./scripts/rvi_install \
    -k ${DEVICE_KEY} \
    -r ${ROOT_CERT} \
    -d ${DEVICE_CERT} \
    -c ${DEVICE_CRED} \
    /tmp/rvi_dev/rvi_core > /tmp/dev_install.log

if [ "${?}" != "0" ]
then
    echo "ERROR: Devevelop install failed:"
    cat /tmp/dev_install.log
    exit 255
fi

/tmp/rvi_dev/rvi_core/rvi_ctl -c ${CONFIG_FILE} console