ROS/start.sh

54 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
if [[ "$EUID" = 0 ]]; then
printf "Please run as user. I will invoke sudo when needed."
exit
fi
pushd "$(dirname "$0")" || exit
if [ ! -d "home" ]; then
mkdir home
fi
if [ ! -d "home/.ssh" ]; then
mkdir home/.ssh
fi
ident=$(<~/.ssh/id_rsa.pub)
grep -sqF -- "$ident" "home/.ssh/authorized_keys" || echo "$ident" >> "home/.ssh/authorized_keys"
sudo docker-compose down
echo U_ID="$(id -u)" > "$(dirname "$0")/.env"
echo G_ID="$(id -g)" >> "$(dirname "$0")/.env"
sudo U_ID="$(id -u)" G_ID="$(id -g)" docker-compose build
sudo U_ID="$(id -u)" G_ID="$(id -g)" docker-compose up -d
up_result="$(sudo docker-compose ps -q)"
hosts=()
while read -r line; do
hosts+=("$(sudo docker inspect --format='{{ .Config.Hostname }}' "$line")")
#xhost +local:`sudo docker inspect --format='{{ .Config.Hostname }}' $line`
done <<< "$up_result"
echo "Adding to xhost:"
for host in "${hosts[@]}"; do
echo " + $host"
xhost "+local:$host"
done
echo "Attaching."
sudo docker-compose up
echo "Removing from xhost:"
for host in "${hosts[@]}"; do
echo " - $host"
xhost "-local:$host"
done
popd || exit