I have seen this (and I upvoted it), but it falls a bit short from my needs because:
- I have to I need to give on-terminal feedback (that is easy, just
| tee /dev/tty
) - I have to get input from users in several ways:
read -p 'prompt: ' var
select yn in "Yes" "No"; do ...
git clone
from private repository asking user/pass
How can I do this (especially the select
stuff)?
My current test setup (cut down to size) is:
#/bin/bash
set -e
set -x
{
if lxc list | grep container
then
:
else
lxc launch images:ubuntu/20.04 container
echo 'waiting for networking to be up-and-running...' | tee /dev/tty
sleep 5
echo 'installing base system...' | tee /dev/tty
lxc exec container -- apt update
lxc exec container -- apt install -y git
echo "install documentation processor? " | tee /dev/tty
select yn in "Yes" "No"
do
if [ $yn == "Yes" ]
then
echo 'installing documentation processor...' | tee /dev/tty
lxc exec container -- apt install -y wget
lxc exec container -- wget https://github.com/plantuml/plantuml/releases/download/v1.2022.12/plantuml-1.2022.12.jar -O /usr/local/bin/plantuml.jar
fi
break
done
read -p 'enter your EMAIL address: ' email | tee /dev/tty
lxc exec container --user 1000 --group 1000 --cwd /home/ubuntu --env HOME=/home/ubuntu -- git config --global user.email "$email"
read -p 'enter your FULL NAME: ' name | tee /dev/tty
lxc exec container --user 1000 --group 1000 --cwd /home/ubuntu --env HOME=/home/ubuntu -- git config --global user.name "$name"
lxc exec container --user 1000 --group 1000 --cwd /home/ubuntu --env HOME=/home/ubuntu -- git config --global credential.helper store
echo 'cloning repository...' | tee /dev/tty
lxc exec container --user 1000 --group 1000 --cwd /home/ubuntu --env HOME=/home/ubuntu -- git clone git@github.com:gabime/spdlog.git
echo "enable audio in container? " | tee /dev/tty
select yn in "Yes" "No"
do
if [ $yn == "Yes" ]
then
for dev in $(find /dev/snd -type c)
do
lxc config device add container snd_$(basename $dev) unix-char source=$dev path=$dev gid=1000
lxc exec container -- apt install -y alsa-utils
done
fi
break
done
fi
} >lxd_build.log 2>&1
This has all said defects:
read -p
prompts are not seen on terminal (but are in log file)select yn in "Yes" "No"
prompts are not seen on terminal (but are in log file); this is unsurprising asselect
doesn't accept redirection.git clone
prompt for user/pass are not seen on terminal.
How can I fix this?