-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
106 lines (84 loc) · 2.46 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# This script creates a user 'mpi', adds it to the sudoers group, and sets a default password.
# It also installs Open MPI and ensures the commands are available in the user's shell.
# Variables
USERNAME="mpi"
PASSWORD="cluster123" # Replace with the desired default password
set -e
# Create the user with a home directory and default shell
sudo useradd -m -s /bin/bash "$USERNAME"
# Set the user's password
echo "${USERNAME}:${PASSWORD}" | sudo chpasswd
# Add the user to the sudo group
sudo usermod -aG sudo "$USERNAME"
echo "User '$USERNAME' has been created and added to the sudo group."
# Install Open MPI
# Variables
URL="https://download.open-mpi.org/release/open-mpi/v5.0/openmpi-5.0.5.tar.gz"
TARFILE="openmpi-5.0.5.tar.gz"
DIR="openmpi-5.0.5"
PREFIX="/usr/local"
NUM_JOBS=$(nproc)
# Function to print usage
usage() {
echo "Usage: $0 [-p prefix] [-j jobs]"
echo " -p prefix Installation prefix (default: /usr/local)"
echo " -j jobs Number of make jobs (default: number of processors)"
exit 1
}
# Parse command line options
while getopts ":p:j:" opt; do
case $opt in
p)
PREFIX="$OPTARG"
;;
j)
NUM_JOBS="$OPTARG"
;;
\?)
echo "Invalid option -$OPTARG"
usage
;;
:)
echo "Option -$OPTARG requires an argument."
usage
;;
esac
done
echo "Downloading Open MPI from $URL..."
if command -v wget >/dev/null 2>&1; then
wget $URL
elif command -v curl >/dev/null 2>&1; then
curl -O $URL
else
echo "Error: Neither wget nor curl is installed."
exit 1
fi
echo "Extracting $TARFILE..."
tar -xzf $TARFILE
cd "$DIR"
echo "Configuring with prefix=$PREFIX..."
./configure --prefix="$PREFIX"
echo "Building with $NUM_JOBS jobs..."
make -j"$NUM_JOBS"
echo "Installing to $PREFIX..."
if [ "$EUID" -ne 0 ] && [ "$PREFIX" == "/usr/local" ]; then
echo "You may be prompted for your password to install to $PREFIX"
sudo make install
else
make install
fi
echo "Updating shared library cache..."
if [ "$EUID" -ne 0 ]; then
sudo ldconfig
else
ldconfig
fi
cd ..
echo "Cleaning up..."
rm -rf "$TARFILE" "$DIR"
echo "Open MPI installed successfully to $PREFIX."
# Ensure Open MPI commands are available in the user's shell
echo "Updating $USERNAME's .bashrc to include Open MPI in PATH..."
echo "export PATH=\"$PREFIX/bin:\$PATH\"" | sudo tee -a "/home/$USERNAME/.bashrc" > /dev/null
echo "Setup complete. Open MPI commands are now available for user '$USERNAME'."