Files
tegra-demo-distro/scripts-setup/setup-env-internal
Matt Madison 56f5fa84dd setup-env-internal: improve distro name checking
so substrings of distro names in the list don't
count as valid.

Signed-off-by: Matt Madison <matt@madison.systems>
2022-05-15 04:11:18 -07:00

163 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
SETUP_SCRIPT="$1"
shift
PROGNAME=$(basename "$SETUP_SCRIPT")
SETUP_SCRIPTDIR=$(dirname "$SETUP_SCRIPT")
TD_TOP="${TD_TOP:-$(readlink -f $SETUP_SCRIPTDIR)}"
DISTRO_DEFAULT="tegrademo"
BUILDDIR_DEFAULT="build"
distro_list() {
local paths
paths=$(find -L $TD_TOP/layers/ -path '*meta-*/conf/distro/*' -name '*.conf')
find $paths -maxdepth 1 -name '*.conf' | xargs basename -s .conf | sort -u | awk '{print "\t" $0}'
}
distro_path() {
local dconf=$(find -L "$TD_TOP"/layers -path "*/conf/distro/*" -name "${1}.conf" | head -n 1)
[ -n "$dconf" ] || exit 1
echo "$dconf" | sed -E -e's,.*/layers/([^/]+)/conf/.*,\1,'
}
machine_list() {
find -L "$TD_TOP"/layers/meta*/conf/machine -maxdepth 1 -name '*.conf' | xargs basename -s .conf | sort -u | awk '{print "\t" $0}'
}
usage()
{
cat >&2 <<EOF
Usage: . $PROGNAME --machine <MACHINE> [<options>] [<BUILDDIR>]
Usage: . $PROGNAME [<BUILDDIR>]
Options:
-h, --help Print this usage message
-m, --machine Set the MACHINE name in the build configuratino
-d, --distro Set the DISTRO name in the build configuration (default '${DISTRO_DEFAULT}')
-c, --color Colorize the output; can be 'never', 'always',
or 'auto' (default 'auto')
Arguments:
BUILDDIR Location of BUILDDIR (default '${BUILDDIR_DEFAULT}')
The first usage is for creating a new build directory. In this case, the
script creates the build directory <BUILDDIR>, configures it for the
specified <MACHINE> and <DISTRO>, and prepares the calling shell for
running bitbake on the build directory.
The second usage is for using an existing build directory. In this case,
the script prepares the calling shell for running bitbake on the build
directory <BUILDDIR>. The build directory configuration is unchanged.
Available distros:
$(distro_list)
Available machines:
$(machine_list)
Examples:
- To create a new Yocto build directory:
$ . $PROGNAME --machine jetson-tx2 --distro testdistro build-testdistro
- To use an existing Yocto build directory:
$ . $PROGNAME build-testdistro
EOF
}
COLOR=auto
DISTRO="${DISTRO:-$DISTRO_DEFAULT}"
# get command line options
SHORTOPTS="hm:d:b:c:"
LONGOPTS="help,machine:,distro:,color:"
ARGS=$(getopt --options $SHORTOPTS --longoptions $LONGOPTS --name $PROGNAME -- "$@" )
# Print the usage menu if invalid options are specified
if [ $? != 0 ]; then
usage
echo "TD_RC=1"
exit 1
fi
eval set -- "$ARGS"
while true;
do
case $1 in
-h | --help) usage; echo "TD_RC=1"; exit 0 ;;
-m | --machine) MACHINE="$2"; shift 2;;
-d | --distro) DISTRO="$2"; shift 2;;
-c | --color) COLOR="$2"; shift 2;;
-- ) shift; break ;;
* ) break ;;
esac
done
BUILDDIR="${1:-$BUILDDIR_DEFAULT}"
if [ ! -e $BUILDDIR/conf/local.conf ]; then
if [ -z "$MACHINE" ]; then
usage
echo "ERROR: You must set MACHINE when creating a new build directory." >&2
echo "TD_RC=1"
exit 1
fi
if ! machine_list | grep -qx "[[:space:]]*$MACHINE"; then
echo "ERROR: machine \"$MACHINE\" not found" >&2
echo "Available MACHINEs:" >&2
machine_list >&2
echo "TD_RC=1"
exit 1
fi
if [ -z "$DISTRO" ]; then
DISTRO=$DISTRO_DEFAULT
fi
if ! distro_list | egrep -qx "[[:space:]]*$DISTRO"; then
echo "ERROR: distro \"$DISTRO\" not found" >&2
echo "Available DISTROs:" >&2
distro_list >&2
echo "TD_RC=1"
exit 1
fi
LAYERPATH=$(distro_path $DISTRO)
NEEDSETUP=yes
fi
if [ $COLOR = "auto" ]; then
if [ -t 1 ]; then
COLOR=always
else
COLOR=never
fi
else
COLOR=never
fi
[ "$NVIDIA_DEVNET_MIRROR" != "" ] || NVIDIA_DEVNET_MIRROR="$HOME/Downloads/nvidia/sdkm_downloads"
if echo "$NVIDIA_DEVNET_MIRROR" | egrep -q "^[^:]+://"; then
TD_DEVNET_MIRROR="$NVIDIA_DEVNET_MIRROR"
if [ "${NVIDIA_DEVNET_MIRROR:0:7}" = "file://" ]; then
if [ ! -d "${NVIDIA_DEVNET_MIRROR:7}" ]; then
TD_DEVNET_MIRROR=
fi
fi
else
TD_DEVNET_MIRROR="file://$NVIDIA_DEVNET_MIRROR"
if [ ! -d "$NVIDIA_DEVNET_MIRROR" ]; then
TD_DEVNET_MIRROR=
fi
fi
cat <<EOF
BDIR="$BUILDDIR"
TD_COLOR="$COLOR"
TD_NEEDSETUP=$NEEDSETUP
TD_DISTRO=$DISTRO
TD_MACHINE=$MACHINE
TD_LAYERPATH=$LAYERPATH
TD_DEVNET_MIRROR="$TD_DEVNET_MIRROR"
TD_RC=0
TD_VARS="\$TD_VARS TD_COLOR TD_NEEDSETUP TD_DISTRO TD_MACHINE TD_LAYERPATH TD_DEVNET_MIRROR"
EOF
exit 0