Skip to content

Commit ea28a6b

Browse files
rousonzbeekman
authored andcommitted
Eliminated need for sudo install.sh or sudo build
1 parent a2e341a commit ea28a6b

File tree

3 files changed

+96
-45
lines changed

3 files changed

+96
-45
lines changed

install.sh

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,9 @@ print_header()
668668
fi
669669
}
670670

671+
. install_prerequisites/set_SUDO.sh
672+
set_SUDO_if_necessary
673+
671674
build_opencoarrays()
672675
{
673676
print_header
@@ -681,7 +684,10 @@ build_opencoarrays()
681684
else
682685
CC=$MPICC FC=$MPIFC $CMAKE .. -DCMAKE_INSTALL_PREFIX=$install_path &&
683686
make -j$num_threads &&
684-
make install
687+
if [[ ! -z $SUDO ]]; then
688+
printf "\nThe chosen installation path requires sudo privileges. Please enter password if prompted.\n"
689+
fi &&
690+
$SUDO make install
685691
fi
686692
}
687693

@@ -698,70 +704,74 @@ report_results()
698704
echo ""
699705
echo "$install_path/bin."
700706
echo ""
701-
if [[ -f $install_path/setup.sh ]]; then
702-
rm $install_path/setup.sh
707+
if [[ -f setup.sh ]]; then
708+
$SUDO rm setup.sh
703709
fi
704710
# Prepend the OpenCoarrays license to the setup.sh script:
705711
while IFS='' read -r line || [[ -n "$line" ]]; do
706-
echo "# $line" >> $install_path/setup.sh
712+
echo "# $line" >> setup.sh
707713
done < "$opencoarrays_src_dir/COPYRIGHT-BSD3"
708-
echo "# " >> $install_path/setup.sh
709-
echo "# Execute this script via the following commands: " >> $install_path/setup.sh
710-
echo "# cd $install_path " >> $install_path/setup.sh
711-
echo "# source setup.sh " >> $install_path/setup.sh
712-
echo " " >> $install_path/setup.sh
713-
echo "if [[ -z \"\$PATH\" ]]; then " >> $install_path/setup.sh
714-
echo " export PATH=\"$install_path/bin\" " >> $install_path/setup.sh
715-
echo "else " >> $install_path/setup.sh
716-
echo " export PATH=\"$install_path/bin\":\$PATH " >> $install_path/setup.sh
717-
echo "fi " >> $install_path/setup.sh
718-
echo " " >> $install_path/setup.sh
714+
echo "# " >> setup.sh
715+
echo "# Execute this script via the following commands: " >> setup.sh
716+
echo "# cd $install_path " >> setup.sh
717+
echo "# source setup.sh " >> setup.sh
718+
echo " " >> setup.sh
719+
echo "if [[ -z \"\$PATH\" ]]; then " >> setup.sh
720+
echo " export PATH=\"bin\" " >> setup.sh
721+
echo "else " >> setup.sh
722+
echo " export PATH=\"bin\":\$PATH " >> setup.sh
723+
echo "fi " >> setup.sh
724+
echo " " >> setup.sh
719725
gcc_install_path=`./build gcc --default --query-path`
720726
if [[ -d "$gcc_install_path/lib" ]]; then
721-
echo "if [[ -z \"\$LD_LIBRARY_PATH\" ]]; then " >> $install_path/setup.sh
722-
echo " export LD_LIBRARY_PATH=\"$gcc_install_path/lib\" " >> $install_path/setup.sh
723-
echo "else " >> $install_path/setup.sh
724-
echo " export LD_LIBRARY_PATH=\"$gcc_install_path/lib\":\$LD_LIBRARY_PATH " >> $install_path/setup.sh
725-
echo "fi " >> $install_path/setup.sh
727+
echo "if [[ -z \"\$LD_LIBRARY_PATH\" ]]; then " >> setup.sh
728+
echo " export LD_LIBRARY_PATH=\"$gcc_install_path/lib\" " >> setup.sh
729+
echo "else " >> setup.sh
730+
echo " export LD_LIBRARY_PATH=\"$gcc_install_path/lib\":\$LD_LIBRARY_PATH " >> setup.sh
731+
echo "fi " >> setup.sh
726732
fi
727-
echo " " >> $install_path/setup.sh
733+
echo " " >> setup.sh
728734
mpich_install_path=`./build mpich --default --query-path`
729735
if [[ -x "$mpich_install_path/bin/mpif90" ]]; then
730-
echo "if [[ -z \"\$PATH\" ]]; then " >> $install_path/setup.sh
731-
echo " export PATH=\"$mpich_install_path/bin\" " >> $install_path/setup.sh
732-
echo "else " >> $install_path/setup.sh
733-
echo " export PATH=\"$mpich_install_path/bin\":\$PATH " >> $install_path/setup.sh
734-
echo "fi " >> $install_path/setup.sh
736+
echo "if [[ -z \"\$PATH\" ]]; then " >> setup.sh
737+
echo " export PATH=\"$mpich_install_path/bin\" " >> setup.sh
738+
echo "else " >> setup.sh
739+
echo " export PATH=\"$mpich_install_path/bin\":\$PATH " >> setup.sh
740+
echo "fi " >> setup.sh
735741
fi
736742
cmake_install_path=`./build cmake --default --query-path`
737743
if [[ -x "$cmake_install_path/bin/cmake" ]]; then
738-
echo "if [[ -z \"\$PATH\" ]]; then " >> $install_path/setup.sh
739-
echo " export PATH=\"$cmake_install_path/bin\" " >> $install_path/setup.sh
740-
echo "else " >> $install_path/setup.sh
741-
echo " export PATH=\"$cmake_install_path/bin\":\$PATH " >> $install_path/setup.sh
742-
echo "fi " >> $install_path/setup.sh
744+
echo "if [[ -z \"\$PATH\" ]]; then " >> setup.sh
745+
echo " export PATH=\"$cmake_install_path/bin\" " >> setup.sh
746+
echo "else " >> setup.sh
747+
echo " export PATH=\"$cmake_install_path/bin\":\$PATH " >> setup.sh
748+
echo "fi " >> setup.sh
743749
fi
744750
flex_install_path=`./build flex --default --query-path`
745751
if [[ -x "$flex_install_path/bin/flex" ]]; then
746-
echo "if [[ -z \"\$PATH\" ]]; then " >> $install_path/setup.sh
747-
echo " export PATH=\"$flex_install_path/bin\" " >> $install_path/setup.sh
748-
echo "else " >> $install_path/setup.sh
749-
echo " export PATH=\"$flex_install_path/bin\":\$PATH " >> $install_path/setup.sh
750-
echo "fi " >> $install_path/setup.sh
752+
echo "if [[ -z \"\$PATH\" ]]; then " >> setup.sh
753+
echo " export PATH=\"$flex_install_path/bin\" " >> setup.sh
754+
echo "else " >> setup.sh
755+
echo " export PATH=\"$flex_install_path/bin\":\$PATH " >> setup.sh
756+
echo "fi " >> setup.sh
751757
fi
752758
bison_install_path=`./build bison --default --query-path`
753759
if [[ -x "$bison_install_path/bin/yacc" ]]; then
754-
echo "if [[ -z \"\$PATH\" ]]; then " >> $install_path/setup.sh
755-
echo " export PATH=\"$bison_install_path/bin\" " >> $install_path/setup.sh
756-
echo "else " >> $install_path/setup.sh
757-
echo " export PATH=\"$bison_install_path/bin\":\$PATH " >> $install_path/setup.sh
758-
echo "fi " >> $install_path/setup.sh
760+
echo "if [[ -z \"\$PATH\" ]]; then " >> setup.sh
761+
echo " export PATH=\"$bison_install_path/bin\" " >> setup.sh
762+
echo "else " >> setup.sh
763+
echo " export PATH=\"$bison_install_path/bin\":\$PATH " >> setup.sh
764+
echo "fi " >> setup.sh
759765
fi
766+
setup_sh_location=$install_path
767+
$SUDO mv setup.sh $install_path || setup_sh_location=${PWD}
760768
echo "*** Before using caf, cafrun, or build, please execute the following command ***"
761769
echo "*** or add it to your login script and launch a new shell (or the equivalent ***"
762770
echo "*** for your shell if you are not using a bash shell): ***"
763771
echo ""
764-
echo " source $install_path/setup.sh"
772+
echo " source $setup_sh_location/setup.sh"
773+
echo ""
774+
echo "*** Installation complete. ***"
765775

766776
else # Installation failed
767777

install_prerequisites/build

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ else
149149
num_threads=$4
150150
fi
151151

152-
153152
check_prerequisites()
154153
{
155154
# This is a bash 3 hack standing in for a bash 4 hash (bash 3 is the lowest common
@@ -336,6 +335,8 @@ unpack_if_necessary()
336335
fi
337336
}
338337

338+
. ./set_SUDO.sh
339+
339340
# Make the build directory, configure, and build
340341
build_and_install()
341342
{
@@ -344,20 +345,34 @@ build_and_install()
344345
printf "Building $package_to_build $version_to_build.\n" &&
345346
mkdir -p $build_path &&
346347
pushd $build_path &&
348+
set_SUDO_if_necessary &&
347349
if [[ $package_to_build == "gcc" ]]; then
348350
pushd $download_path/$package_source_directory &&
349351
${PWD}/contrib/download_prerequisites &&
350352
popd &&
351353
echo "Configuring with the following command: " &&
352354
echo "$download_path/$package_source_directory/configure --prefix=$install_path --enable-languages=c,c++,fortran,lto --disable-multilib --disable-werror " &&
353355
$download_path/$package_source_directory/configure --prefix=$install_path --enable-languages=c,c++,fortran,lto --disable-multilib --disable-werror &&
356+
echo "Building with the commmand 'make -j $num_threads bootstrap'" &&
354357
make -j $num_threads bootstrap &&
355-
make install
358+
if [[ ! -z $SUDO ]]; then
359+
echo "You do not have write permissions to the installation path $install_path"
360+
echo "If you have administrative privileges, enter your password to install $package_to_build."
361+
fi &&
362+
echo "Installing with the command '$SUDO make install'" &&
363+
$SUDO make install
356364
else
357365
$download_path/$package_source_directory/configure --prefix=$install_path &&
366+
echo "Building with the following command:" &&
367+
echo "CC=$CC CXX=$CXX make -j $num_threads" &&
358368
CC=$CC CXX=$CXX make -j $num_threads &&
359369
printf "Installing $package_to_build in $install_path.\n" &&
360-
make install
370+
if [[ ! -z $SUDO ]]; then
371+
echo "You do not have write permissions to the installation path $install_path"
372+
echo "If you have administrative privileges, enter your password to install $package_to_build."
373+
fi &&
374+
echo "Installing with the command '$SUDO make install'" &&
375+
$SUDO make install
361376
fi &&
362377
popd
363378
}

install_prerequisites/set_SUDO.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Define the sudo command to be used if the installation path requires administrative permissions
2+
set_SUDO_if_necessary()
3+
{
4+
SUDO_COMMAND="sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
5+
printf "$this_script: $package_to_build installation path is $install_path"
6+
printf "Checking whether the $package_to_build installation path exists... "
7+
if [[ -d "$install_path" ]]; then
8+
printf "yes\n"
9+
printf "Checking whether I have write permissions to the installation path... "
10+
if [[ -w "$install_path" ]]; then
11+
printf "yes\n"
12+
else
13+
printf "no\n"
14+
SUDO=$SUDO_COMMAND
15+
fi
16+
else
17+
printf "no\n"
18+
printf "Checking whether I can create the installation path... "
19+
if mkdir -p $install_path >& /dev/null; then
20+
printf "yes.\n"
21+
else
22+
printf "no.\n"
23+
SUDO=$SUDO_COMMAND
24+
fi
25+
fi
26+
}

0 commit comments

Comments
 (0)