Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explicitly connect /dev/tty. Allows running via sh #5500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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