summarylogtreecommitdiffstats
path: root/eman2-installer
blob: b3982b335125f40f0cebc2c90a97f4290f2a0b69 (plain)
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
#!/bin/bash

# Purpose: Assist to install eman2 binary release.
# Usage: eman2-installer
# Date: 9/1/2004, by Liwei Peng
# Date: 10/25/2007, modified by Grant Tang for EMAN2
# Date: 1/28/2009, modified by Grant Tang for EMAN2 Pythn2.6
# Date: 2/12/2009, change back to Python 2.5.4, Grant Tang
# Date: 9/1/2009, --disable_cache, Grant Tang
# Date: 6/30/2013, Significant updates by Ian Rees for new build system.
# Date: 8/01/2013, changed disable_cache to disable_gui
# Date: 1/23/2017, altered eman2.[bashrc/cshrc] files to include new matplotlibrc file in extlib
usage()
{
	echo "usage: `basename $0` [--disable_gui]"
	echo "       --disable_gui: no GUI"
	exit 0
}

setup_shell() {
	# Setup bashrc or cshrc
	MYSHELL=`basename ${SHELL}`
	RCFILE=""
	if test ${MYSHELL} = "tcsh" || test ${MYSHELL} = "csh"; then
		RCFILE=".cshrc"
		setup_csh ${EMAN2DIR}/eman2${RCFILE}
	elif test ${MYSHELL} = "bash" || test ${MYSHELL} = "sh"; then
		RCFILE=".bashrc"
		setup_bash ${EMAN2DIR}/eman2$RCFILE
	elif test ${MYSHELL} = "zsh"; then
		RCFILE=".zshrc"
		setup_bash ${EMAN2DIR}/eman2$RCFILE
	else
		echo "Unkown shell. You will need set up your enviroment variables manually."
	fi
	if test "X${RCFILE}" != "X"; then
    	#echo "Please add the following line to the end of your ${HOME}/${RCFILE} :"
    	#echo "source ${EMAN2DIR}/eman2${RCFILE}"
	#echo ""
	#echo "If you experience any problems after installation, please see for tips:"
	#echo "http:/eman2.org/Install/BinaryInstall"
	fi
}

setup_csh() {
	OUT=$1
	echo "setenv EMAN2DIR ${EMAN2DIR}" > ${OUT}
	echo 'setenv PATH ${EMAN2DIR}/bin:${EMAN2DIR}/extlib/bin:${PATH}' >> ${OUT}
	echo 'if ($?PYTHONPATH == 0) then' >> ${OUT}
	echo '    setenv PYTHONPATH ${EMAN2DIR}/lib:${EMAN2DIR}/bin' >> ${OUT}
	echo 'else' >> ${OUT}
	echo '    setenv PYTHONPATH ${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}' >> ${OUT}
	echo 'endif' >> ${OUT}
	echo 'setenv MATPLOTLIBRC ${EMAN2DIR}/extlib' >> ${OUT}
	echo 'alias sparx sx.py' >> ${OUT}
	echo "setenv LC_CTYPE=en_US.utf8"
	echo "setenv LC_ALL=en_US.utf8"
}

setup_bash()
{
	OUT=$1
	echo "export EMAN2DIR=${EMAN2DIR}" > ${OUT}
	echo 'export PATH=${EMAN2DIR}/bin:${EMAN2DIR}/extlib/bin:$PATH' >> ${OUT}
	echo 'export PYTHONPATH=${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}' >> ${OUT}
	echo 'export MATPLOTLIBRC=${EMAN2DIR}/extlib' >> ${OUT}
	echo 'export LC_CTYPE=en_US.utf8'
	echo 'export LC_ALL=en_US.utf8'
	echo 'alias sphire=sxgui.py' >> ${OUT}
	echo 'alias sparx=sx.py' >> ${OUT}
}

setup_python()
{
	EMAN2PYTHON=$1
    # Update python interpreter
	find ${EMAN2DIR}/extlib/bin -name "ipython" \
		-exec sed -i "s%^\#\!.*python.*$%\#\!$/opt/eman2/extlib/bin/python%" {} \;
	find ${EMAN2DIR}/test ${EMAN2DIR}/bin ${EMAN2DIR}/lib ${EMAN2DIR}/examples -name "*.py" \
		-exec sed -i "s%^\#\!.*python.*$%\#\!$/opt/eman2/extlib/bin/python%" {} \;
	find ${EMAN2DIR}/test ${EMAN2DIR}/bin ${EMAN2DIR}/lib ${EMAN2DIR}/examples -name "*.py" \
		-exec chmod a+x {} \;
    # ... and for SPARX
	# sed -i "s%^\#\!.*python.*$%\#\!${EMAN2PYTHON}%" ${EMAN2DIR}/bin/sparx
}

disable_cache()
{
	cd ${EMAN2DIR}/lib
	echo "start substituting..."
	mv global_def.py global_def.py.bak
	sed -e 's/CACHE_DISABLE = False/CACHE_DISABLE = True/'  global_def.py.bak > global_def.py
	rm -f  global_def.py.bak
	cd ${EMAN2DIR}/bin
	mv sx_real.py sx_real.py.bak
	sed  -e 's/GUIUSE = True/GUIUSE = False/' sx_real.py.bak > sx_real.py
	rm -f  sx_real.py.bak
	cd ${EMAN2DIR}
}

main()
{
	# Use the run directory as the EMAN2DIR.
	export EMAN2DIR=`pwd`
	export EMAN2PYTHON=${EMAN2DIR}/extlib/bin/python
	
	# Setup the Python interpreter
	if [ -f $EMAN2PYTHON ]
		then
			setup_python $EMAN2PYTHON
		fi

	# Setup bashrc or cshrc
	setup_shell

	# This is for Fedora Linux's SELinux limitation on shared libraries
	cd ${EMAN2DIR}/lib
	if [ -x /usr/bin/chcon ]; then
		chcon -t texrel_shlib_t *.so 2>/dev/null >/dev/null
	fi
	cd ${EMAN2DIR}

	# # This is for Pawel's cluster working
	local value1=$1	
	if [[ "${value1}" = "--disable_gui" ]]; then
		disable_cache
	fi

	#for mpi_eman compilation
	# cd ${EMAN2DIR}/mpi_eman
    # sed -i 's,/usr/include/python2.6,${EMAN2DIR}/Python/include/python2.7,g' Makefile.*
}

main $1
exit 0