@@ -131,15 +131,10 @@ do_zephyrrc()
131
131
echo " export ZEPHYR_SDK_INSTALL_DIR=$target_sdk_dir"
132
132
echo
133
133
if [ -z "$rc_confirm" ]; then
134
- echo "Update/Create $HOME/.zephyrrc with environment variables setup for you (y/n)? "
135
- while read rc_confirm; do
136
- [ "$rc_confirm" = "Y" -o "$rc_confirm" = "y" \
137
- -o "$rc_confirm" = "n" \
138
- -o "$rc_confirm" = "N" ] && break
139
- echo "Invalid input \"$rc_confirm\", please input 'y' or 'n': "
140
- done
134
+ prompt "creating/updating $HOME/.zephyrrc with environment variables setup for you "
135
+ rc_confirm=$answer
141
136
fi
142
- if [ "$rc_confirm" = "y" -o "$rc_confirm" = "Y" ]; then
137
+ if [ "$rc_confirm" = "y" ]; then
143
138
if [ -f $HOME/.zephyrrc ]; then
144
139
sed -i "s#ZEPHYR_SDK_INSTALL_DIR=.*#ZEPHYR_SDK_INSTALL_DIR=${target_sdk_dir}#" $HOME/.zephyrrc
145
140
sed -i "s#ZEPHYR_TOOLCHAIN_VARIANT=.*#ZEPHYR_TOOLCHAIN_VARIANT=zephyr#" $HOME/.zephyrrc
@@ -163,8 +158,8 @@ do_cmake_package()
163
158
return
164
159
fi
165
160
166
- read_confirm "registering Zephyr-sdk CMake module with path $target_sdk_dir "
167
- if [ "$confirm " = "y" -o "$confirm" = "Y " ]; then
161
+ query "registering Zephyr-sdk CMake module with path $target_sdk_dir "
162
+ if [ "$answer " = "y" ]; then
168
163
if [ ! -d $ZEPHYR_SDK_REGISTRY_DIR ]; then
169
164
mkdir -p $ZEPHYR_SDK_REGISTRY_DIR
170
165
fi
@@ -176,17 +171,28 @@ do_cmake_package()
176
171
177
172
# Read the input "y"
178
173
# $1 is optional, but allows the caller to provide additional text.
179
- read_confirm () {
180
- if [ "$confirm" != "y" ]; then
181
- echo "Do you want to continue $1(y/n)? "
182
- while read confirm; do
183
- [ "$confirm" = "Y" -o "$confirm" = "y" -o "$confirm" = "n" \
184
- -o "$confirm" = "N" ] && break
185
- echo "Invalid input \"$confirm\", please input 'y' or 'n': "
186
- done
187
- else
188
- echo
189
- fi
174
+ prompt () {
175
+ echo "Do you want to continue $1(y/n)? "
176
+ while read answer; do
177
+ if [ "$answer" = "Y" -o "$answer" = "y" ]; then
178
+ answer="y"
179
+ break
180
+ elif [ "$answer" = "N" -o "$answer" = "n" ]; then
181
+ answer="n"
182
+ break
183
+ else
184
+ echo "Invalid input \"$answer\", please input 'y' or 'n': "
185
+ fi
186
+ done
187
+ }
188
+ # Like prompt, but only if prompts were not pre-answered by -y argument
189
+ query () {
190
+ if [ "$confirm" != "y" ]; then
191
+ prompt "$1"
192
+ else
193
+ answer="y"
194
+ echo
195
+ fi
190
196
}
191
197
192
198
verify_os
@@ -261,8 +267,8 @@ if [ "$sdk_dirname" != "/opt" \
261
267
echo Note: The version number \'-$SDK_VERSION\' can be omitted.
262
268
echo
263
269
264
- read_confirm "installing to ${target_sdk_dir} "
265
- if [ "$confirm " = "n" -o "$confirm" = "N " ]; then
270
+ query "installing to ${target_sdk_dir} "
271
+ if [ "$answer " = "n" ]; then
266
272
# Abort the installation
267
273
echo "SDK installation aborted!"
268
274
exit 1
@@ -282,8 +288,8 @@ if [ -d $target_sdk_dir ]; then
282
288
# wipe the directory first
283
289
if [ -d $target_sdk_dir/sysroots ]; then
284
290
echo "The directory $target_sdk_dir/sysroots will be removed! "
285
- read_confirm
286
- if [ "$confirm " = "y" -o "$confirm" = "Y " ]; then
291
+ query
292
+ if [ "$answer " = "y" ]; then
287
293
rm -rf $target_sdk_dir/sysroots/
288
294
rm -rf $target_sdk_dir/info-zephyr-sdk*/
289
295
rm -fr $target_sdk_dir/sdk_version
0 commit comments