forked from ONEST-Network/protocol-server-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_bpp_config.sh
executable file
·197 lines (176 loc) · 7.27 KB
/
update_bpp_config.sh
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
source registry_entry.sh
source generate_keys.sh
source variables.sh
source package_manager.sh
display_help() {
# Define color codes
echo "${YELLOW}usage: $0 [options]${NC}"
echo "${GREEN}options:${NC}"
echo " --help${NC} display this help message"
echo " ${RED}--bpp_subscriber_id <value>${NC} set bpp_subscriber_id ${RED}(required)${NC}"
echo " ${RED}--bpp_subscriber_uri <value>${NC} set bpp_subscriber_uri ${RED}(required)${NC}"
echo " --registry_url <value> set registry_url without lookup"
echo " For example if your registry lookup URL is ${GREEN}$registry_url/lookup${NC}"
echo " then enter only ${GREEN}$registry_url${NC}"
echo " (default: ${GREEN}$registry_url${NC})"
echo " --mongouser <value> set mongodb username (default: ${GREEN}$mongo_initdb_root_username${NC})"
echo " --mongopassword <value> set mongodb password (default: ${GREEN}$mongo_initdb_root_password${NC})"
echo " --mongodatabase <value> set mongodb database (default: ${GREEN}$mongo_initdb_database${NC})"
echo " --rabbitmquser <value> set rabbitmq username (default: ${GREEN}$rabbitmq_default_user${NC})"
echo " --rabbitmqpassword <value> set rabbitmq password (default: ${GREEN}$rabbitmq_default_pass${NC})"
exit 1
}
# File names
clientFile=$bppClientFile
networkFile=$bppNetworkFile
client_port=$bpp_client_port
network_port=$bpp_network_port
# Display current values
echo "Current BPP_CLIENT_PORT value is set to 6001."
# Prompt user for BPP_CLIENT_PORT value
read -p "Do you want to change the BPP_CLIENT_PORT value? (y/n): " changeClientPort
if [[ "${changeClientPort,,}" == "yes" || "${changeClientPort,,}" == "y" ]]; then
read -p "Enter new BPP_CLIENT_PORT value: " newClientPort\
client_port=$newClientPort
# sed -i "s/BPP_CLIENT_PORT/$newClientPort/" $clientFile
# echo "BPP_CLIENT_PORT value updated to $newClientPort."
else
echo "Keeping the default BPP_CLIENT_PORT value."
fi
# Display current values
echo "Current BPP_NETWORK_PORT value is set to 6002."
# Prompt user for BPP_NETWORK_PORT value
read -p "Do you want to change the BPP_NETWORK_PORT value? (y/n): " changeNetworkPort
if [[ "${changeNetworkPort,,}" == "yes" || "${changeNetworkPort,,}" == "y" ]]; then
read -p "Enter new BPP_NETWORK_PORT value: " newNetworkPort
network_port=$newNetworkPort
# sed -i "s/BPP_CLIENT_PORT/$newNetworkPort/" $clientFile
# echo "BPP_NETWORK_PORT value updated to $newNetworkPort."
else
echo "Keeping the default BPP_NETWORK_PORT value."
fi
sed -i "s/BPP_CLIENT_PORT/$client_port/g; s/BPP_NETWORK_PORT/$network_port/g" "$clientFile" "$HOME/deploy-bpp.sh" "$networkFile"
# Ask user about Redis and RabbitMQ configurations
read -p "Is Redis running on the same instance? (y/n): " redisSameInstance
if [[ "${redisSameInstance,,}" == "no" || "${redisSameInstance,,}" == "n" ]]; then
read -p "Enter the private IP or URL for Redis: " redisUrl
else
redisUrl="0.0.0.0"
fi
read -p "Is RabbitMQ running on the same instance? (y/n): " rabbitmqSameInstance
if [[ "${rabbitmqSameInstance,,}" == "no" || "${rabbitmqSameInstance,,}" == "n" ]]; then
read -p "${YELLOW}Enter the private IP or URL for RabbitMQ: ${NC}" rabbitmqUrl
read -p "${YELLOW}Enter the RabbitMQ Username (default: $rabbitmq_default_user): ${NC}" rabbitmq_default_user
read -p "${YELLOW}Enter the RabbitMQ Password (default: $rabbitmq_default_pass): ${NC}" rabbitmq_default_pass
else
rabbitmqUrl="0.0.0.0"
fi
read -p "Is MonogDB running on the same instance? (y/n): " mongoSameInstance
if [[ "${mongoSameInstance,,}" == "no" || "${mongoSameInstance,,}" == "n" ]]; then
read -p "${YELLOW}Enter the private IP or URL for MonogDB: ${NC}" mongoUrl
read -p "${YELLOW}Enter the MonogDB Root Username (default: $mongo_initdb_root_username): ${NC}" mongo_initdb_root_username
read -p "${YELLOW}Enter the MonogDB Root Password (default: $mongo_initdb_root_password): ${NC}" mongo_initdb_root_password
read -p "${YELLOW}Enter the MonogDB Database Name (default: $mongo_initdb_database):: ${NC}" mongo_initdb_database
else
mongoUrl="0.0.0.0"
fi
install_package nodejs && install_package npm
npm install
get_keys
echo "Your Private Key: $private_key"
echo "Your Public Key: $public_key"
remove_package nodejs && remove_package npm
valid_from=$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")
valid_until=$(date -u -d "+1 year" +"%Y-%m-%dT%H:%M:%S.%3NZ")
type=BPP
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--mongo_initdb_root_username)
mongo_initdb_root_username="$2"
shift 2
;;
--mongo_initdb_root_password)
mongo_initdb_root_password="$2"
shift 2
;;
--mongo_initdb_database)
mongo_initdb_database="$2"
shift 2
;;
--rabbitmq_default_user)
rabbitmq_default_user="$2"
shift 2
;;
--rabbitmq_default_pass)
rabbitmq_default_pass="$2"
shift 2
;;
--rabbitmqUrl)
rabbitmqUrl="$2"
shift 2
;;
--bpp_subscriber_id)
if [ -n "$2" ]; then
bpp_subscriber_id="$2"
bpp_subscriber_id_key="$2-key"
shift 2
else
echo "error: --bpp_subscriber_id requires a non-empty option argument."
exit 1
fi
;;
--registry_url)
if [ -n "$2" ]; then
registry_url="$2"
shift 2
else
echo "error: --registry_url requires a non-empty option argument."
exit 1
fi
;;
--bpp_subscriber_url)
if [ -n "$2" ]; then
bpp_subscriber_url="$2"
shift 2
else
echo "error: --bpp_subscriber_url requires a non-empty option argument."
exit 1
fi
;;
*)
echo "error: Unknown option $1"
exit 1
;;
esac
done
# Define an associative array for replacements
declare -A replacements=(
["REDIS_URL"]=$redisUrl
["REGISTRY_URL"]=$registry_url
["MONGO_USERNAME"]=$mongo_initdb_root_username
["MONGO_PASSWORD"]=$mongo_initdb_root_password
["MONGO_DB_NAME"]=$mongo_initdb_database
["MONOG_URL"]=$mongoUrl
["RABBITMQ_USERNAME"]=$rabbitmq_default_user
["RABBITMQ_PASSWORD"]=$rabbitmq_default_pass
["RABBITMQ_URL"]=$rabbitmqUrl
["PRIVATE_KEY"]=$private_key
["PUBLIC_KEY"]=$public_key
["BPP_SUBSCRIBER_ID"]=$bpp_subscriber_id
["SUBSCRIBER_URL"]=$$bpp_subscriber_url
["BPP_SUBSCRIBER_ID_KEY"]=$bpp_subscriber_id_key
)
# Apply replacements in both files
for file in "$clientFile" "$networkFile"; do
for key in "${!replacements[@]}"; do
sed -i "s|$key|${replacements[$key]}|" "$file"
done
done
if [ -z "$bpp_subscriber_id" ] || [ -z "$bpp_subscriber_url" ]; then
echo "error: Both --bpp_subscriber_id and --bpp_subscriber_url must be provided."
exit 1
fi
create_network_participant "$registry_url" "application/json" "$bpp_subscriber_id" "$bpp_subscriber_id_key" "$bpp_subscriber_url" "$public_key" "$public_key" "$valid_from" "$valid_until" "$type"
$HOME/./deploy-bpp.sh