Skip to content

Commit

Permalink
Merge pull request #5500 from sabine/connect_stdin_explicitly
Browse files Browse the repository at this point in the history
explicitly connect /dev/tty. Allows running via sh
  • Loading branch information
kit-ty-kate authored Jan 23, 2025
2 parents f80c027 + 756fcbc commit c872562
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions shell/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,25 @@ usage() {
echo " --restore VERSION Restore a backed up opam binary and root"
echo " --version VERSION Install this specific version instead of $VERSION"
echo " --download-only Download binary in current directory and check its sha512"
echo " --tty Allow interactive questions to be asked even if the script is being piped to (e.g. curl https://../install.sh | sh)"
echo
echo "The default is to backup if the current version of opam is 1.*, or when"
echo "using '--fresh' or '--dev'"
}

read_tty() {
if [ "$TTY" = 1 ]; then
read -r "$1" < /dev/tty
else
read -r "$1"
fi
}

RESTORE=
NOBACKUP=
FRESH=
DOWNLOAD_ONLY=
TTY=

while [ $# -gt 0 ]; do
case "$1" in
Expand All @@ -398,6 +408,8 @@ while [ $# -gt 0 ]; do
FRESH=1;;
--download-only)
DOWNLOAD_ONLY=1;;
--tty)
TTY=1;;
--help|-h)
usage; exit 0;;
*)
Expand Down Expand Up @@ -552,7 +564,7 @@ if [ -n "$RESTORE" ]; then
fi
if [ "$NOBACKUP" = 1 ]; then
printf "## This will clear %s and %s. Continue ? [Y/n] " "$OPAM" "$OPAMROOT"
read -r R
read_tty R
case "$R" in
""|"y"|"Y"|"yes")
xsudo rm -f "$OPAM"
Expand Down Expand Up @@ -584,15 +596,15 @@ fi

while true; do
printf "## Where should it be installed ? [%s] " "$DEFAULT_BINDIR"
read -r BINDIR
read_tty BINDIR
if [ -z "$BINDIR" ]; then BINDIR="$DEFAULT_BINDIR"; fi

if [ -d "$BINDIR" ]; then break
else
if [ "${BINDIR#\~/}" != "$BINDIR" ] ; then
RES_BINDIR="$HOME/${BINDIR#\~/}"
printf "## '%s' resolves to '%s', do you confirm [Y/n] " "$BINDIR" "$RES_BINDIR"
read -r R
read_tty R
case "$R" in
""|"y"|"Y"|"yes")
BINDIR="$RES_BINDIR"
Expand All @@ -603,7 +615,7 @@ while true; do
esac
fi
printf "## %s does not exist. Create ? [Y/n] " "$BINDIR"
read -r R
read_tty R
case "$R" in
""|"y"|"Y"|"yes")
xsudo mkdir -p "$BINDIR"
Expand All @@ -625,7 +637,7 @@ if [ -d "$OPAMROOT" ]; then
if [ "$FRESH" = 1 ]; then
if [ "$NOBACKUP" = 1 ]; then
printf "## This will clear %s. Continue ? [Y/n] " "$OPAMROOT"
read -r R
read_tty R
case "$R" in
""|"y"|"Y"|"yes")
rm -rf "$OPAMROOT";;
Expand Down

0 comments on commit c872562

Please sign in to comment.