Skip to content

Commit 2c1c744

Browse files
author
Damian Rouson
committed
Non-interactive install options: -y/--yes-to-all
``` ./install.sh -y ``` or equivalently ``` ./install.sh --yes-to-all) ``` will now causes a non-interactive build by assuming affirmative responses to all user queries. Exception: if the user passes an installation prefix (via -i or --install-prefix), the user will be prompted for a password prior to the "make install" step. To avoid this, execute as `sudo ./install.sh...` with the consequence that all steps will execute with sudo privileges.
1 parent 706ea5a commit 2c1c744

File tree

5 files changed

+100
-88
lines changed

5 files changed

+100
-88
lines changed

install.sh-usage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
-U --print-url [arg] Print download location for specified package.
2020
-v --version Print OpenCoarrays version number.
2121
-V --print-version [arg] Print version number for specified package.
22+
-y --yes-to-all Build non-interactively by assuming affirmative user responses.

prerequisites/build-functions/download_if_necessary.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ download_if_necessary()
1212
if [[ -f "${download_path}/${url_tail}" || -d "${download_path}/${url_tail}" ]] ; then
1313
info "Found '${url_tail}' in ${download_path}."
1414
info "If it resulted from an incomplete download, building ${package_name} could fail."
15-
info "Would you like to proceed anyway? (Y/n)"
16-
read -r proceed
17-
if [[ "${proceed}" == "n" || "${proceed}" == "N" || "${proceed}" == "no" ]]; then
18-
info "n"
19-
info "Please remove $url_tail and restart the installation to to ensure a fresh download." 1>&2
20-
emergency "Aborting. [exit 80]"
15+
if [[ "${arg_y}" == "${__flag_present}" ]]; then
16+
info "-y or --yes-to-all flag present. Proceeding with non-interactive build."
2117
else
22-
info "y"
18+
info "Would you like to proceed anyway? (Y/n)"
19+
read -r proceed
20+
if [[ "${proceed}" == "n" || "${proceed}" == "N" || "${proceed}" == "no" ]]; then
21+
info "n"
22+
info "Please remove $url_tail and restart the installation to to ensure a fresh download." 1>&2
23+
emergency "Aborting. [exit 80]"
24+
else
25+
info "y"
26+
fi
2327
fi
2428
elif ! type "${fetch}" &> /dev/null; then
2529
# The download mechanism is missing

prerequisites/build.sh-usage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
-U --print-url [arg] Print URL for package specified in argument.
2222
-v --version Print OpenCoarrays version number.
2323
-V --print-version [arg] Print installation version for package specified in argument.
24+
-y --yes-to-all Build non-interactively by assuming affirmative user responses.

prerequisites/install-functions/find_or_install.sh

Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -526,89 +526,93 @@ find_or_install()
526526
echo "$this_script: Ready to install $package executable $executable in $package_install_path"
527527
fi
528528

529-
echo -e "$this_script: Ok to download (if necessary), build, and install $package from source? (Y/n) "
530-
read -r proceed_with_build
531-
532-
if [[ "$proceed_with_build" == "n" || "$proceed_with_build" == "no" ]]; then
533-
printf "n\n"
534-
echo -e "$this_script: OpenCoarrays installation requires $package. Aborting. [exit 70]\n"
535-
exit 70
536-
537-
else # permission granted to build
538-
printf "Y\n"
539-
540-
# On OS X, CMake must be built with Apple LLVM gcc, which XCode command-line tools puts in /usr/bin
541-
if [[ $(uname) == "Darwin" && $package == "cmake" ]]; then
542-
if [[ -x "/usr/bin/gcc" ]]; then
543-
CC=/usr/bin/gcc
544-
else
545-
echo -e "$this_script: OS X detected. Please install XCode command-line tools and \n"
546-
echo -e "$this_script: ensure that /usr/bin/gcc exists and is executable. Aborting. [exit 75]\n"
547-
exit 75
548-
fi
549-
# Otherwise, if no CC has been defined yet, use the gcc in the user's PATH
550-
elif [[ -z "${CC:-}" ]]; then
551-
CC=gcc
529+
if [[ "${arg_y}" == "${__flag_present}" ]]; then
530+
info "-y or --yes-to-all flag present. Proceeding with non-interactive build."
531+
else
532+
echo -e "$this_script: Ok to download (if necessary), build, and install $package from source? (Y/n) "
533+
read -r proceed_with_build
534+
535+
if [[ "$proceed_with_build" == "n" || "$proceed_with_build" == "no" ]]; then
536+
printf "n\n"
537+
echo -e "$this_script: OpenCoarrays installation requires $package. Aborting. [exit 70]\n"
538+
exit 70
539+
else # permission granted to build
540+
printf "Y\n"
552541
fi
542+
fi
553543

554-
# On OS X, CMake must be built with Apple LLVM g++, which XCode command-line tools puts in /usr/bin
555-
if [[ $(uname) == "Darwin" && $package == "cmake" ]]; then
556-
if [[ -x "/usr/bin/g++" ]]; then
557-
CXX=/usr/bin/g++
558-
else
559-
echo -e "$this_script: OS X detected. Please install XCode command-line tools \n"
560-
echo -e "$this_script: and ensure that /usr/bin/g++ exists and is executable. Aborting. [exit 76]\n"
561-
exit 76
562-
fi
563-
# Otherwise, if no CXX has been defined yet, use the g++ in the user's PATH
564-
elif [[ -z "${CXX:-}" ]]; then
565-
CXX=g++
544+
# On OS X, CMake must be built with Apple LLVM gcc, which XCode command-line tools puts in /usr/bin
545+
if [[ $(uname) == "Darwin" && $package == "cmake" ]]; then
546+
if [[ -x "/usr/bin/gcc" ]]; then
547+
CC=/usr/bin/gcc
548+
else
549+
echo -e "$this_script: OS X detected. Please install XCode command-line tools and \n"
550+
echo -e "$this_script: ensure that /usr/bin/gcc exists and is executable. Aborting. [exit 75]\n"
551+
exit 75
566552
fi
553+
# Otherwise, if no CC has been defined yet, use the gcc in the user's PATH
554+
elif [[ -z "${CC:-}" ]]; then
555+
CC=gcc
556+
fi
567557

568-
# If no FC has been defined yet, use the gfortran in the user's PATH
569-
if [[ -z "${FC:-}" ]]; then
570-
FC=gfortran
558+
# On OS X, CMake must be built with Apple LLVM g++, which XCode command-line tools puts in /usr/bin
559+
if [[ $(uname) == "Darwin" && $package == "cmake" ]]; then
560+
if [[ -x "/usr/bin/g++" ]]; then
561+
CXX=/usr/bin/g++
562+
else
563+
echo -e "$this_script: OS X detected. Please install XCode command-line tools \n"
564+
echo -e "$this_script: and ensure that /usr/bin/g++ exists and is executable. Aborting. [exit 76]\n"
565+
exit 76
571566
fi
567+
# Otherwise, if no CXX has been defined yet, use the g++ in the user's PATH
568+
elif [[ -z "${CXX:-}" ]]; then
569+
CXX=g++
570+
fi
572571

572+
# If no FC has been defined yet, use the gfortran in the user's PATH
573+
if [[ -z "${FC:-}" ]]; then
574+
FC=gfortran
575+
fi
573576

574-
# Strip trailing package name and version number, if present, from installation path
575-
default_package_version=$(./build.sh -V ${package})
576-
package_install_prefix="${package_install_path%${package}/${arg_I:-${default_package_version}}*}"
577577

578-
echo -e "$this_script: Downloading, building, and installing $package \n"
579-
echo "$this_script: Build command: FC=$FC CC=$CC CXX=$CXX ./build.sh -p $package -i $package_install_prefix -j $num_threads"
580-
FC="$FC" CC="$CC" CXX="$CXX" ./build.sh -p "$package" -i "$package_install_prefix" -j "$num_threads"
578+
# Strip trailing package name and version number, if present, from installation path
579+
default_package_version=$(./build.sh -V ${package})
580+
package_install_prefix="${package_install_path%${package}/${arg_I:-${default_package_version}}*}"
581581

582-
if [[ -x "$package_install_path/bin/$executable" ]]; then
583-
echo -e "$this_script: Installation successful.\n"
584-
if [[ "$package" == "$executable" ]]; then
585-
echo -e "$this_script: $executable is in $package_install_path/bin \n"
586-
else
587-
echo -e "$this_script: $package executable $executable is in $package_install_path/bin \n"
588-
fi
589-
# TODO Merge all applicable branches under one 'if [[ $package == $executable ]]; then'
590-
if [[ $package == "cmake" ]]; then
591-
echo "$this_script: export CMAKE=$package_install_path/bin/$executable"
592-
export CMAKE="$package_install_path/bin/$executable"
593-
elif [[ $package == "bison" ]]; then
594-
echo "$this_script: export YACC=$package_install_path/bin/$executable"
595-
export YACC="$package_install_path/bin/$executable"
596-
elif [[ $package == "flex" ]]; then
597-
echo "$this_script: export FLEX=$package_install_path/bin/$executable"
598-
export FLEX="$package_install_path/bin/$executable"
599-
elif [[ $package == "m4" ]]; then
600-
echo "$this_script: export M4=$package_install_path/bin/$executable"
601-
export M4="$package_install_path/bin/$executable"
602-
elif [[ $package == "gcc" ]]; then
603-
echo "$this_script: export FC=$package_install_path/bin/gfortran"
604-
export FC="$package_install_path/bin/gfortran"
605-
echo "$this_script: export CC=$package_install_path/bin/gcc"
606-
export CC="$package_install_path/bin/gcc"
607-
echo "$this_script: export CXX=$package_install_path/bin/g++"
608-
export CXX="$package_install_path/bin/g++"
609-
gfortran_lib_paths="$package_install_path/lib64/:$package_install_path/lib"
610-
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
611-
export LD_LIBRARY_PATH="$gfortran_lib_paths"
582+
echo -e "$this_script: Downloading, building, and installing $package \n"
583+
echo "$this_script: Build command: FC=$FC CC=$CC CXX=$CXX ./build.sh -p $package -i $package_install_prefix -j $num_threads"
584+
FC="$FC" CC="$CC" CXX="$CXX" ./build.sh -p "$package" -i "$package_install_prefix" -j "$num_threads"
585+
586+
if [[ -x "$package_install_path/bin/$executable" ]]; then
587+
echo -e "$this_script: Installation successful.\n"
588+
if [[ "$package" == "$executable" ]]; then
589+
echo -e "$this_script: $executable is in $package_install_path/bin \n"
590+
else
591+
echo -e "$this_script: $package executable $executable is in $package_install_path/bin \n"
592+
fi
593+
# TODO Merge all applicable branches under one 'if [[ $package == $executable ]]; then'
594+
if [[ $package == "cmake" ]]; then
595+
echo "$this_script: export CMAKE=$package_install_path/bin/$executable"
596+
export CMAKE="$package_install_path/bin/$executable"
597+
elif [[ $package == "bison" ]]; then
598+
echo "$this_script: export YACC=$package_install_path/bin/$executable"
599+
export YACC="$package_install_path/bin/$executable"
600+
elif [[ $package == "flex" ]]; then
601+
echo "$this_script: export FLEX=$package_install_path/bin/$executable"
602+
export FLEX="$package_install_path/bin/$executable"
603+
elif [[ $package == "m4" ]]; then
604+
echo "$this_script: export M4=$package_install_path/bin/$executable"
605+
export M4="$package_install_path/bin/$executable"
606+
elif [[ $package == "gcc" ]]; then
607+
echo "$this_script: export FC=$package_install_path/bin/gfortran"
608+
export FC="$package_install_path/bin/gfortran"
609+
echo "$this_script: export CC=$package_install_path/bin/gcc"
610+
export CC="$package_install_path/bin/gcc"
611+
echo "$this_script: export CXX=$package_install_path/bin/g++"
612+
export CXX="$package_install_path/bin/g++"
613+
gfortran_lib_paths="$package_install_path/lib64/:$package_install_path/lib"
614+
if [[ -z "${LD_LIBRARY_PATH:-}" ]]; then
615+
export LD_LIBRARY_PATH="$gfortran_lib_paths"
612616
else
613617
export LD_LIBRARY_PATH="$gfortran_lib_paths:$LD_LIBRARY_PATH"
614618
fi
@@ -638,7 +642,5 @@ find_or_install()
638642
exit 80
639643
fi # End 'if [[ -x "$package_install_path/bin/$executable" ]]'
640644

641-
fi # End 'if [[ "$proceed_with_build" == "y" ]]; then'
642-
643645
fi # End 'if [[ "$package" != "none" ]]; then'
644646
}

prerequisites/install-functions/print_header.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ print_header()
2525
echo ""
2626
printf "${arg_p} will be installed in ${install_path}\n"
2727
echo ""
28-
printf "Ready to rock and roll? (Y/n)"
29-
read -r install_now
30-
echo -e " $install_now\n"
31-
if [[ "$install_now" == "n" || "$install_now" == "no" ]]; then
32-
emergency "$this_script: Aborting. [exit 85]\n"
28+
if [[ "${arg_y}" == "${__flag_present}" ]]; then
29+
info "-y or --yes-to-all flag present. Proceeding with non-interactive build."
30+
else
31+
printf "Ready to rock and roll? (Y/n)"
32+
read -r install_now
33+
echo -e " $install_now\n"
34+
if [[ "$install_now" == "n" || "$install_now" == "no" ]]; then
35+
emergency "$this_script: Aborting. [exit 85]\n"
36+
fi
3337
fi
3438
}

0 commit comments

Comments
 (0)