Skip to content

Commit ea0e096

Browse files
stephanosionashif
authored andcommitted
scripts: Add POSIX setup script template
This commit adds a setup script template for the POSIX-compliant host operating systems (i.e. Linux and macOS) to be distributed as a part of the Zephyr SDK distribution bundle archive. This setup script can be executed by the user to configure the Zephyr SDK on their local system. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent f29d271 commit ea0e096

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

scripts/template_setup_posix

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env bash
2+
3+
# Automated setup script for Zephyr SDK distribution bundle archive
4+
# for POSIX-compliant host operating systems (Linux and macOS)
5+
6+
# Utility functions
7+
pushd()
8+
{
9+
command pushd "$@" > /dev/null
10+
}
11+
12+
popd()
13+
{
14+
command popd "$@" > /dev/null
15+
}
16+
17+
# Display script usage
18+
usage()
19+
{
20+
echo "Usage: $(basename $0) [-c] [-t]"
21+
echo
22+
echo " -c Register Zephyr SDK CMake package"
23+
echo " -t Install host tools"
24+
echo
25+
echo "If no arguments are specified, the setup script runs in the interactive"
26+
echo "mode asking for user inputs."
27+
exit 1
28+
}
29+
30+
# Ask for user inputs (interactive mode)
31+
user_prompt()
32+
{
33+
echo "** NOTE **"
34+
echo "You only need to run this script once after extracting the Zephyr SDK"
35+
echo "distribution bundle archive."
36+
echo
37+
38+
read -n 1 -r -p "Register Zephyr SDK CMake package [y/n]? " yn && echo
39+
[ "${yn}" = "y" ] && do_cmake_pkg="y"
40+
41+
read -n 1 -r -p "Install host tools [y/n]? " yn && echo
42+
[ "${yn}" = "y" ] && do_hosttools="y"
43+
44+
echo
45+
}
46+
47+
# Entry point
48+
pushd "$(dirname "${BASH_SOURCE[0]}")"
49+
50+
# Parse arguments
51+
if [ $# == "0" ]; then
52+
interactive="y"
53+
else
54+
while [ "$1" != "" ]; do
55+
case $1 in
56+
-c)
57+
do_cmake_pkg="y"
58+
;;
59+
-t)
60+
do_hosttools="y"
61+
;;
62+
*)
63+
echo "Invalid argument '$1'"
64+
usage
65+
exit 1
66+
;;
67+
esac
68+
shift
69+
done
70+
fi
71+
72+
# Read bundle version from file
73+
version=$(<sdk_version)
74+
75+
# Print banner
76+
echo "Zephyr SDK ${version} Setup"
77+
echo
78+
79+
# Check dependencies
80+
which cmake &> /dev/null
81+
if [ $? != 0 ]; then
82+
echo "Zephyr SDK setup requires CMake to be installed and available in the PATH."
83+
echo "Please install CMake and run this script again."
84+
exit 90
85+
fi
86+
87+
# Ask for user inputs if no argument is specified
88+
if [ "${interactive}" = "y" ]; then
89+
interactive="y"
90+
user_prompt
91+
fi
92+
93+
# Register Zephyr SDK CMake package
94+
if [ "${do_cmake_pkg}" = "y" ]; then
95+
echo "Registering Zephyr SDK CMake package ..."
96+
cmake -P cmake/zephyr_sdk_export.cmake
97+
echo
98+
fi
99+
100+
# Install host tools
101+
if [ "${do_hosttools}" = "y" ]; then
102+
echo "Installing host tools ..."
103+
case ${OSTYPE} in
104+
linux-gnu*)
105+
./zephyr-sdk-x86_64-hosttools-standalone-0.9.sh -y -d .
106+
;;
107+
darwin*)
108+
echo "SKIPPED: macOS host tools are not available yet."
109+
;;
110+
*)
111+
echo "SKIPPED: Unsupported host operating system"
112+
exit 2
113+
;;
114+
esac
115+
echo
116+
fi
117+
118+
echo "All done."
119+
if [ "${interactive}" = "y" ]; then
120+
read -n 1 -s -r -p "Press any key to exit ..."
121+
echo
122+
fi
123+
124+
popd

0 commit comments

Comments
 (0)