forked from zerothi/ts-tbt-sisl-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_tutorial.sh
executable file
·331 lines (293 loc) · 8.44 KB
/
install_tutorial.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash
url=www.student.dtu.dk/~nicpa/sisl/workshop/18
function _help {
echo "This script may be used to install the dependencies for the"
echo "tutorial such as Python, numpy, scipy matplotlib, jupyter and sisl."
echo ""
echo "This script is a two-step script. Please read below."
echo ""
echo "If you do not have Python, numpy, scipy, jupyter, matplotlib or sisl installed"
echo "you should probably run this script in installation mode:"
echo ""
echo " $0 install"
echo ""
echo "If you have a working Python installation with pip you may only need"
echo "to run"
echo ""
echo " pip install --upgrade numpy scipy matplotlib netCDF4 jupyter pyamg sisl"
echo ""
echo "Once the above steps are fulfilled you should run the download part"
echo "of the script. It will download the required files for the tutorial:"
echo ""
echo " $0 download"
echo ""
echo "During the download part a new directory will be created:"
echo " $HOME/TBT-TS-sisl-workshop"
echo ""
}
if [ $# -eq 0 ]; then
_help
exit 1
fi
# First we get the current directory
cwd=$(pwd)
# Figure out if we are dealing with UNIX or MacOS
os=linux
case "x$OSTYPE" in
xlinux*)
os=linux
;;
xdarwin*)
os=macos
;;
x*)
# Try and determine using uname
case "$(uname -s)" in
Linux*)
os=linux
;;
Darwin*)
os=macos
;;
*)
echo "Are you using MingGW or FreeBSD? Or a third?"
echo "Either way this installation script does not work for your distribution..."
exit 1
;;
esac
;;
esac
action=install
case $1 in
install)
# do nothing, we use the OS to determine stuff
action=install
;;
update)
# Update this script
# Try and update
base=$(basename $0)
cp $cwd/$0 $cwd/old_$base
wget -O $cwd/new_$base $url/install_tutorial.sh
if [ $? -eq 0 ]; then
mv $cwd/new_$base $cwd/$base
chmod u+x $cwd/$base
echo ""
echo "Successfully updated script..."
rm $cwd/old_$base
fi
exit 0
;;
download)
action=download
;;
*)
echo "###########################################"
echo "# Unknown argument: $1"
echo "#"
echo "# Should be either 'install', 'update' or 'download'"
echo "#"
echo "###########################################"
echo ""
_help
exit 1
;;
esac
# Function for installation on Linux
function linux_install {
# Update lists
sudo apt-get update
# First ensure that the correct packages are installed
for p in gcc gfortran libhdf5-dev libnetcdf-dev libnetcdff-dev python-dev python-tk python-pip python-pip-whl libatlas3-base liblapack3 libfreetype6-dev libpng-dev
do
sudo apt-get install $p
done
# Perform the Python installation
pip install --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl
if [ $? -ne 0 ]; then
echo "pip failed to install the packages, will try to install"
echo "in your user directory, if this fails you will have to fix it"
pip install --user --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl
if [ $? -ne 0 ]; then
echo ""
echo "pip failed to install the packages, in either the global or user domain."
echo "Please try and get pip to work and re-run the installation proceduce."
fi
fi
# Figure out the local pip version
# Note that sometimes this may be wrong since Python should be `python3`.
local py_v=$(pip -V | awk '{print $NF}' | tr -d ')')
echo ""
echo "This script assumes you are using Python $py_v"
echo ""
# You probably need to add to the path, this is a simplistic way of
# adding the default ubuntu installation directories
grep "/.local/bin" ~/.bashrc > /dev/null
if [ $? -eq 1 ]; then
echo "" >> ~/.bashrc
echo "export PATH=\$HOME/.local/bin:\$PATH" >> ~/.bashrc
echo ""
echo "PLEASE RESTART YOUR SHELL!"
fi
grep "/.local/lib/python$py_v" ~/.bashrc > /dev/null
if [ $? -eq 1 ]; then
echo "" >> ~/.bashrc
echo "export PYTHONPATH=\$HOME/.local/lib/python$py_v/site-packages:\$PYTHONPATH" >> ~/.bashrc
echo ""
echo "PLEASE RESTART YOUR SHELL!"
fi
}
# Function for installation on Linux
function my_brew {
brew $@
if [ $? -ne 0 ]; then
echo "Running:"
echo " brew $@"
echo "failed."
echo "If this requests you should do a link brew:"
echo " brew link ..."
echo "then most probably your write access to this folder is prohibited:"
echo " /usr/local/include/Frameworks"
echo "If the folder does not exist, create it."
exit 1
fi
}
function macos_install {
# Check that brew is installed?
which brew 2>/dev/null
if [ $? -ne 0 ]; then
echo "You have not installed brew, this script requires that you have brew installed"
exit 1
fi
# First we need to install xcode-select
xcode-select --install
# Now try and install gcc (it should also include gfortran)
my_brew install gcc
# Ensure wget is installed
my_brew install wget --with-libressl
# Add the science tap (it HAS been deprecated, so probably not needed
#my_brew tap homebrew/science
my_brew install szip hdf5
my_brew install netcdf --with-fortran
my_brew install python
sudo easy_install pip
pip install --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl
if [ $? -ne 0 ]; then
echo "pip failed to install the packages, will try to install"
echo "in your user directory, if this fails you will have to fix it"
pip install --user --upgrade six numpy scipy matplotlib netCDF4 jupyter pyamg sisl
if [ $? -ne 0 ]; then
echo ""
echo "pip failed to install the packages, in either the global or user domain."
echo "Please try and get pip to work and re-run the installation proceduce."
fi
fi
}
function install_warning {
echo "RUNNING THIS SCRIPT IS AT YOUR OWN RISK!!!"
echo "THIS SCRIPT IS MADE FOR HELPFUL PURPOSE, BUT YOU ARE"
echo "RESPONSIBLE FOR ANY ERRORS/DATALOSSES THIS SCRIPT MAY INFER."
echo "IF YOU DO NOT WANT TO RUN THIS SCRIPT PRESS:"
echo ""
echo " CTRL+^C"
echo ""
sleep 3
}
function install_test_sisl {
echo ""
echo " Will try and run sisl"
echo " import sisl ; print(sisl.geom.graphene())"
python -c "import sisl ; print(sisl.geom.graphene())"
if [ $? -ne 0 ]; then
echo "Failed running sisl, please mail the organizer with the error message (unless some of the installations failed)"
fi
}
if [ $action == install ]; then
# os will be download
case $os in
linux)
install_warning
linux_install
;;
macos)
install_warning
macos_install
;;
esac
install_test_sisl
exit 0
fi
# Now create a common folder in the top-home directory
function download_warning {
echo ""
echo "This script will create a folder in your $HOME directory:"
echo " $HOME/TBT-TS-sisl-workshop"
echo "where all the tutorials and executable files will be downloaded."
echo ""
}
function dwn_file {
local rname=$1
local outname=$1
if [ $# -eq 2 ]; then
outname=$2
fi
if [ ! -e $outname ]; then
wget -O $outname $url/$(basename $rname)
if [ $? -eq 0 ]; then
chmod u+x $outname
else
rm -f $outname
fi
fi
}
download_warning
indir=$HOME/TBT-TS-sisl-workshop
mkdir -p $indir
pushd $indir
# Now download the executables
mkdir -p bin
# Download latest tutorial files
if [ -e sisl-TBT-TS.tar.gz ]; then
rm sisl-TBT-TS.tar.gz
fi
dwn_file sisl-TBT-TS.tar.gz
# Determine the optimization level for the current architecture
_suffix=
case $os in
linux)
# Figure out if the user has AVX
if $(grep "avx2" /proc/cpuinfo > /dev/null) ; then
_suffix=_avx2
elif $(grep "avx" /proc/cpuinfo > /dev/null) ; then
_suffix=_avx
elif $(grep "sse2" /proc/cpuinfo > /dev/null) ; then
_suffix=_sse
fi
;;
esac
case $os in
linux)
dwn_file bin/siesta$_suffix bin/siesta
dwn_file bin/tbtrans$_suffix bin/tbtrans
;;
macos)
dwn_file bin/siesta_mac bin/siesta
dwn_file bin/tbtrans_mac bin/tbtrans
;;
esac
# We will simply add it if it does not exist
# We also assume the SHELL is BASH
if ! `grep $indir ~/.bashrc` ; then
echo "" >> ~/.bashrc
echo "# Variable for the TBT-TS-sisl workshop" >> ~/.bashrc
echo "export PATH=$indir/bin:\$PATH" >> ~/.bashrc
echo "" >> ~/.bashrc
fi
echo ""
echo "In folder"
echo " $indir"
echo "you will find everything needed for the tutorial"
echo "If you use BASH (most likely) you should have siesta and tbtrans in your path."
echo "Run (after you have restarted your shell):"
echo " which tbtrans"
echo "and check it returns $indir/bin/tbtrans"