109 lines
3.5 KiB
Diff
109 lines
3.5 KiB
Diff
From 03933375277558f939a12990cae3ee372511d87e Mon Sep 17 00:00:00 2001
|
|
From: Alexei Colin <ac@alexeicolin.com>
|
|
Date: Sat, 18 Jul 2020 12:14:07 -0400
|
|
Subject: [PATCH 3/4] scripts/template_dir: re-use common prompting code
|
|
|
|
---
|
|
scripts/template_dir | 56 ++++++++++++++++++++++++--------------------
|
|
1 file changed, 31 insertions(+), 25 deletions(-)
|
|
|
|
diff --git a/scripts/template_dir b/scripts/template_dir
|
|
index b03d4b5..0a0d69e 100644
|
|
--- a/scripts/template_dir
|
|
+++ b/scripts/template_dir
|
|
@@ -131,15 +131,10 @@ do_zephyrrc()
|
|
echo " export ZEPHYR_SDK_INSTALL_DIR=$target_sdk_dir"
|
|
echo
|
|
if [ -z "$rc_confirm" ]; then
|
|
- echo "Update/Create $HOME/.zephyrrc with environment variables setup for you (y/n)? "
|
|
- while read rc_confirm; do
|
|
- [ "$rc_confirm" = "Y" -o "$rc_confirm" = "y" \
|
|
- -o "$rc_confirm" = "n" \
|
|
- -o "$rc_confirm" = "N" ] && break
|
|
- echo "Invalid input \"$rc_confirm\", please input 'y' or 'n': "
|
|
- done
|
|
+ prompt "creating/updating $HOME/.zephyrrc with environment variables setup for you "
|
|
+ rc_confirm=$answer
|
|
fi
|
|
- if [ "$rc_confirm" = "y" -o "$rc_confirm" = "Y" ]; then
|
|
+ if [ "$rc_confirm" = "y" ]; then
|
|
if [ -f $HOME/.zephyrrc ]; then
|
|
sed -i "s#ZEPHYR_SDK_INSTALL_DIR=.*#ZEPHYR_SDK_INSTALL_DIR=${target_sdk_dir}#" $HOME/.zephyrrc
|
|
sed -i "s#ZEPHYR_TOOLCHAIN_VARIANT=.*#ZEPHYR_TOOLCHAIN_VARIANT=zephyr#" $HOME/.zephyrrc
|
|
@@ -163,8 +158,8 @@ do_cmake_package()
|
|
return
|
|
fi
|
|
|
|
- read_confirm "registering Zephyr-sdk CMake module with path $target_sdk_dir "
|
|
- if [ "$confirm" = "y" -o "$confirm" = "Y" ]; then
|
|
+ query "registering Zephyr-sdk CMake module with path $target_sdk_dir "
|
|
+ if [ "$answer" = "y" ]; then
|
|
if [ ! -d $ZEPHYR_SDK_REGISTRY_DIR ]; then
|
|
mkdir -p $ZEPHYR_SDK_REGISTRY_DIR
|
|
fi
|
|
@@ -176,17 +171,28 @@ do_cmake_package()
|
|
|
|
# Read the input "y"
|
|
# $1 is optional, but allows the caller to provide additional text.
|
|
-read_confirm () {
|
|
- if [ "$confirm" != "y" ]; then
|
|
- echo "Do you want to continue $1(y/n)? "
|
|
- while read confirm; do
|
|
- [ "$confirm" = "Y" -o "$confirm" = "y" -o "$confirm" = "n" \
|
|
- -o "$confirm" = "N" ] && break
|
|
- echo "Invalid input \"$confirm\", please input 'y' or 'n': "
|
|
- done
|
|
- else
|
|
- echo
|
|
- fi
|
|
+prompt () {
|
|
+ echo "Do you want to continue $1(y/n)? "
|
|
+ while read answer; do
|
|
+ if [ "$answer" = "Y" -o "$answer" = "y" ]; then
|
|
+ answer="y"
|
|
+ break
|
|
+ elif [ "$answer" = "N" -o "$answer" = "n" ]; then
|
|
+ answer="n"
|
|
+ break
|
|
+ else
|
|
+ echo "Invalid input \"$answer\", please input 'y' or 'n': "
|
|
+ fi
|
|
+ done
|
|
+}
|
|
+# Like prompt, but only if prompts were not pre-answered by -y argument
|
|
+query () {
|
|
+ if [ "$confirm" != "y" ]; then
|
|
+ prompt "$1"
|
|
+ else
|
|
+ answer="y"
|
|
+ echo
|
|
+ fi
|
|
}
|
|
|
|
verify_os
|
|
@@ -261,8 +267,8 @@ if [ "$sdk_dirname" != "/opt" \
|
|
echo Note: The version number \'-$SDK_VERSION\' can be omitted.
|
|
echo
|
|
|
|
- read_confirm "installing to ${target_sdk_dir} "
|
|
- if [ "$confirm" = "n" -o "$confirm" = "N" ]; then
|
|
+ query "installing to ${target_sdk_dir} "
|
|
+ if [ "$answer" = "n" ]; then
|
|
# Abort the installation
|
|
echo "SDK installation aborted!"
|
|
exit 1
|
|
@@ -282,8 +288,8 @@ if [ -d $target_sdk_dir ]; then
|
|
# wipe the directory first
|
|
if [ -d $target_sdk_dir/sysroots ]; then
|
|
echo "The directory $target_sdk_dir/sysroots will be removed! "
|
|
- read_confirm
|
|
- if [ "$confirm" = "y" -o "$confirm" = "Y" ]; then
|
|
+ query
|
|
+ if [ "$answer" = "y" ]; then
|
|
rm -rf $target_sdk_dir/sysroots/
|
|
rm -rf $target_sdk_dir/info-zephyr-sdk*/
|
|
rm -fr $target_sdk_dir/sdk_version
|
|
--
|
|
2.27.0
|
|
|