forked from opensbli/environment_and_run_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallCMake.sh
More file actions
executable file
·99 lines (90 loc) · 2.22 KB
/
InstallCMake.sh
File metadata and controls
executable file
·99 lines (90 loc) · 2.22 KB
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
#!/bin/bash
##@brief Download and install a specific version of CMake
##@author Jianping Meng
##@contributors
##@details
function usage {
echo "This script will download and install CMake to a specified directory!"
echo "./$(basename $0) -h -> Showing usage"
echo "./$(basename $0) -d -> Specifying the directory for installation"
echo "./$(basename $0) -v -> Specifying the version (3.20.0 by default)"
echo "./$(basename $0) -s -> enable installation in the system directory (e.g., /usr/local/)"
echo "The default directory for installation is \$HOME/CMake in user directory and /usr/local/CMake in system directory"
echo "if choosing system directory to install, sudo is needed"
}
optstring="hd:v:s"
User="Y"
Version="3.20.0"
while getopts ${optstring} options; do
case ${options} in
h)
usage
exit 0
;;
d)
Dir=${OPTARG}
;;
v)
Version=${OPTARG}
;;
s)
User="N"
;;
:)
echo "$0: Must supply an argument to -$OPTARG." >&2
exit 1
;;
?)
echo "Invalid option: -${OPTARG}."
exit 2
;;
esac
done
if [ -z "$Dir" ]
then
if [[ "$User" == "Y" ]]
then
Dir="$HOME/CMake"
fi
if [[ "$User" == "N" ]]
then
Dir="/usr/local/CMake"
fi
fi
if [ $# -eq 0 ]
then
echo "This script will download and install CMake-$Version to ${Dir}!"
fi
wget -c https://github.com/Kitware/CMake/releases/download/v$Version/cmake-$Version-Linux-x86_64.sh
if [ ! -d "$Dir" ]
then
rm -r -f "$Dir"
fi
mkdir $Dir
sh ./cmake-$Version-Linux-x86_64.sh --prefix=$Dir --skip-license
if [[ "$User" == "Y" ]]
then
if [ ! -d "$HOME/bin" ]
then
mkdir -p $HOME/bin
fi
if [ -f "$HOME/bin/cmake" ]
then
rm $HOME/bin/cmake
fi
ln -s $Dir/bin/cmake $HOME/bin/cmake
echo "Please add $HOME/bin to path for enabling CMake"
fi
if [[ "$User" == "N" ]]
then
if [ ! -d "/usr/local/bin" ]
then
mkdir -p /usr/local/bin
fi
if [ -f "/usr/local/bin/cmake" ]
then
rm -r -f /usr/local/bin/cmake
fi
ln -s $Dir/bin/cmake /usr/local/bin/cmake
fi
rm cmake-$Version-Linux-x86_64.sh