mirror of
https://github.com/home-assistant/operating-system.git
synced 2026-05-23 17:08:54 +01:00
bb176184b2
Since enter.sh starts Docker with `--interactive --tty` flags, it fails to run if started from another script which doesn't allocate TTY. Detect if the parent shell is a terminal and if not, do not attempt to run in interactive mode.
37 lines
844 B
Bash
Executable File
37 lines
844 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
BUILDER_UID="$(id -u)"
|
|
BUILDER_GID="$(id -g)"
|
|
CACHE_DIR="${CACHE_DIR:-$HOME/hassos-cache}"
|
|
|
|
if [ "$BUILDER_UID" -eq "0" ] || [ "$BUILDER_GID" == "0" ]; then
|
|
echo "ERROR: Please run this script as a regular (non-root) user with sudo privileges."
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "${CACHE_DIR}"
|
|
docker build -t hassos:local .
|
|
|
|
if [ ! -f buildroot/Makefile ]; then
|
|
# Initialize git submodule
|
|
git submodule update --init
|
|
fi
|
|
|
|
if command -v losetup >/dev/null && [ ! -e /dev/loop0 ]; then
|
|
# Make sure loop devices are present before starting the container
|
|
sudo losetup -f > /dev/null
|
|
fi
|
|
|
|
TTY_OPTS=""
|
|
|
|
if [ -t 0 ]; then
|
|
TTY_OPTS="-it"
|
|
fi
|
|
|
|
docker run --rm --privileged \
|
|
${TTY_OPTS} \
|
|
-v "$(pwd):/build" -v "${CACHE_DIR}:/cache" \
|
|
-e BUILDER_UID="${BUILDER_UID}" -e BUILDER_GID="${BUILDER_GID}" \
|
|
hassos:local "${@:-bash}"
|