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

Run opam init for a fresh install #5501

Open
wants to merge 5 commits 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
41 changes: 31 additions & 10 deletions shell/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ usage() {
echo "using '--fresh' or '--dev'"
}

# Conditionally connect /dev/tty when
# the environment variable TTY is set to 1
TTY="${TTY-0}"
R=
prompt() {
# expects to be called as prompt "Do you want to do this? [Y/n] "
printf "$1"
if [ "$TTY" = 1 ]; then
read R </dev/tty
else
read R
fi
}

INIT="${INIT-0}"

RESTORE=
NOBACKUP=
FRESH=
Expand Down Expand Up @@ -358,8 +374,7 @@ if [ -n "$RESTORE" ]; then
exit 1
fi
if [ "$NOBACKUP" = 1 ]; then
printf "## This will clear $OPAM and $OPAMROOT. Continue ? [Y/n] "
read R
prompt "## This will clear $OPAM and $OPAMROOT. Continue ? [Y/n] "
case "$R" in
""|"y"|"Y"|"yes")
xsudo rm -f "$OPAM"
Expand Down Expand Up @@ -390,16 +405,15 @@ if [ -n "$EXISTING_OPAM" ]; then
fi

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

if [ -d "$BINDIR" ]; then break
else
if [ "${BINDIR#\~/}" != "$BINDIR" ] ; then
RES_BINDIR="$HOME/${BINDIR#\~/}"
printf "## '$BINDIR' resolves to '$RES_BINDIR', do you confirm [Y/n] "
read R
prompt "## '$BINDIR' resolves to '$RES_BINDIR', do you confirm [Y/n] "
case "$R" in
""|"y"|"Y"|"yes")
BINDIR="$RES_BINDIR"
Expand All @@ -409,8 +423,7 @@ while true; do
;;
esac
fi
printf "## $BINDIR does not exist. Create ? [Y/n] "
read R
prompt "## $BINDIR does not exist. Create ? [Y/n] "
case "$R" in
""|"y"|"Y"|"yes")
xsudo mkdir -p $BINDIR
Expand All @@ -431,8 +444,7 @@ fi
if [ -d "$OPAMROOT" ]; then
if [ "$FRESH" = 1 ]; then
if [ "$NOBACKUP" = 1 ]; then
printf "## This will clear $OPAMROOT. Continue ? [Y/n] "
read R
prompt "## This will clear $OPAMROOT. Continue ? [Y/n] "
case "$R" in
""|"y"|"Y"|"yes")
rm -rf "$OPAMROOT";;
Expand Down Expand Up @@ -468,6 +480,15 @@ echo "## opam $VERSION installed to $BINDIR"
if [ ! "$FRESH" = 1 ]; then
echo "## Converting the opam root format & updating"
"$BINDIR/opam" init --reinit -ni
else
if [ "$INIT" = 1 ]; then
echo "## Running opam init for this fresh install"
if [ "$TTY" = 1 ]; then
"$BINDIR/opam" init </dev/tty
else
"$BINDIR/opam" init
fi
fi
fi

WHICH=$(command -v opam || echo notfound)
Expand Down