-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathripple
executable file
·125 lines (115 loc) · 5.04 KB
/
ripple
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# Copyright 2023 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
function print_help() {
echo "Instructions to use Rip Utility"
echo "_______________________________"
echo ""
echo "Init"
echo "Initialize rip utility and manifest files"
echo "./ripple init"
echo ""
echo "Run"
echo "To Run Ripple alongside a device connected to the same network use the below command"
echo "ripple run <ip address of the device>"
echo "Example"
echo "ripple run 10.0.0.1"
}
function get_default_extension() {
case "$(uname -s)" in
Darwin)
echo "dylib"
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
echo "dll"
;;
Linux)
echo "so"
;;
esac
}
function backup_dot_ripple() {
echo "Would you like to back it up? (Y/n)"
read -r confirm
if [ "$confirm" == "Y" ]; then
backup_name=".ripple-$(date +"%F-%H-%M")"
local backup_name
echo "Copying existing ~/.ripple directory to ~/$backup_name"
mv ~/.ripple ~/"$backup_name"
elif [ "$confirm" == "n" ]; then
return
else
echo "Please choose Y or n"
backup_dot_ripple
fi;
}
case ${1} in
"init")
workspace_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [[ $workspace_dir == *".cargo/bin" ]]; then
echo "ripple init can only be run from the script in the Ripple project root"
exit 1;
fi
echo "Adding ripple command to .cargo/bin"
cp -f ./ripple ~/.cargo/bin
if [ -e ~/.ripple ]; then
echo "Previous ripple config folder found."
backup_dot_ripple
fi
echo "Setup Ripple manifests"
mkdir -p ~/.ripple
cp ./examples/manifest/app-library-example.json ~/.ripple/firebolt-app-library.json
cp ./examples/manifest/device-manifest-example.json ~/.ripple/firebolt-device-manifest.json
cp ./examples/manifest/extn-manifest-example.json ~/.ripple/firebolt-extn-manifest.json
## Update firebolt-extn-manifest.json
sed -i "" "s@\"default_path\": \"/usr/lib/rust/\"@\"default_path\": \"$workspace_dir/target/debug/\"@" ~/.ripple/firebolt-extn-manifest.json
default_extension=$(get_default_extension)
sed -i "" "s@\"default_extension\": \"so\"@\"default_extension\": \"$default_extension\"@" ~/.ripple/firebolt-extn-manifest.json
## Update firebolt-device-manifest.json
sed -i "" "s@\"library\": \"/etc/firebolt-app-library.json\"@\"library\": \"$HOME/.ripple/firebolt-app-library.json\"@" ~/.ripple/firebolt-device-manifest.json
echo "All Done!"
;;
"run")
cargo build --features local_dev
DEVICE_HOST=${2} cargo run --features local_dev core/main
;;
"run-mock")
workspace_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
mkdir -p target/manifests
rm -rf target/manifests/*
cp examples/manifest/mock/mock-device-manifest.json target/manifests/firebolt-device-manifest.json
cp examples/manifest/mock/mock-app-library.json target/manifests/firebolt-app-library.json
cp examples/manifest/mock/mock-extn-manifest.json target/manifests/firebolt-extn-manifest.json
cp examples/manifest/mock/mock-thunder-device.json target/manifests/mock-thunder-device.json
sed -i "" "s@\"default_path\": \"/usr/lib/rust/\"@\"default_path\": \"$workspace_dir/target/debug/\"@" target/manifests/firebolt-extn-manifest.json
default_extension=$(get_default_extension)
sed -i "" "s@\"default_extension\": \"so\"@\"default_extension\": \"$default_extension\"@" target/manifests/firebolt-extn-manifest.json
## Update firebolt-device-manifest.json
sed -i "" "s@\"library\": \"/etc/firebolt-app-library.json\"@\"library\": \"$workspace_dir/target/manifests/firebolt-app-library.json\"@" target/manifests/firebolt-device-manifest.json
sed -i "" "s@\"mock_data_file\": \"mock-device.json\"@\"mock_data_file\": \"$workspace_dir/target/manifests/mock-thunder-device.json\"@" target/manifests/firebolt-extn-manifest.json
export EXTN_MANIFEST=${workspace_dir}/target/manifests/firebolt-extn-manifest.json
export DEVICE_MANIFEST=${workspace_dir}/target/manifests/firebolt-device-manifest.json
cargo build --features local_dev
cargo run --features local_dev core/main
;;
"-h")
print_help
;;
*)
print_help
;;
esac