eaa4c859cb41163eaf34492f4ff8e6b67fa7e099
[pkg-boinc/boinc-server-autodock.git] / bin / autodockvina_install_apps.sh
1 #!/bin/bash
2
3 set -e
4
5 version=0.0.0
6 if [ "-version" = "$1" -o "--version" = "$1" ]; then
7    echo "$version"
8    exit 1
9 fi
10
11 if ! which realpath; then
12         echo "E (autodock_vina_install_apps.sh): This application needs the tool realpath in its path."
13         echo "                                   It is provided by a cognate Debian package or with the";
14         echo "                                   coreutils >= 8.23."
15         exit 1
16 fi
17
18 if [ -z "$BOINC_SOURCEDIR" ]; then BOINC_SOURCEDIR=$(dirname $(realpath $0)); fi
19
20 if [ -r  "$BOINC_SOURCEDIR"/autodockvina_set_config.sh ]; then 
21    . "$BOINC_SOURCEDIR"/autodockvina_set_config.sh
22 fi 
23
24 if [ "-h" = "$1" -o "-help" = "$1" -o "--help" = "$1" ]; then
25   cat <<EOHELP
26 $(basename $0|tr "a-z" "A-Z")                   BOINC-SERVER-AUTODOCK                   $(basename $0|tr "a-z" "A-Z")
27
28 NAME
29
30   $(basename $0) - installation of AutoDock Vina application
31
32 SYNOPSIS
33
34   $(basename $0) [--help]
35
36 DESCRIPTION
37
38   This script installs AutoDock Vina application for the existing BOINC project
39   with the specified name. The final BOINC application contains of the AutoDock
40   Vina scientific application and the wrapper. 
41
42   All parameters are specified by environment variables.
43
44     BOINC_PROJECTNAME       defines the unique short name of the project, which 
45                             also serves as the database name ($BOINC_PROJECTNAME).
46     BOINC_SOURCEDIR         defines the path to directory with intermediate scripts 
47                             to install and configure the BOINC project ($BOINC_SOURCEDIR).
48     BOINC_INSTALLROOT       defines the path to the directory where the project is 
49                             installed ($BOINC_INSTALLROOT).
50     BOINC_FETCHAPPSSCRIPT   defines the location of the script that fetches BOINC
51                             example applications ($BOINC_FETCHAPPSSCRIPT).
52
53 SEE ALSO
54
55   http://wiki.debian.org/BOINC
56   http://mgltools.scripps.edu
57   http://autodock.scripps.edu
58
59 COPYRIGHT
60
61   This script is released under the same license as BOINC.
62
63 AUTHORS
64
65   Natalia Nikitina
66
67 EOHELP
68         exit
69 fi
70
71 if [ ! -r "$BOINC_SOURCEDIR"/autodockvina_set_config.sh ]; then
72    echo "E (autodockvina_install_apps.sh): Could not read '$BOINC_SOURCEDIR/autodockvina_set_config.sh'"
73    exit 1
74 fi
75
76 ## Install autodock-vina application 
77 echo "I (autodockvina_install_apps.sh): Installing AutoDock Vina application..."
78
79 longappver=$(apt-cache show autodock-vina | grep ^Version | tail -1 | cut -f2 -d\  )
80 appver=$(echo $longappver|cut -d . -f-2)
81
82 longappverwrapper=$(apt-cache show boinc-app-examples | grep ^Version | tail -1 | cut -f2 -d\  )
83 appverwrapper=$(echo $longappverwrapper|cut -d . -f-2)
84
85 #Create temporary directories
86 TEMPDIR=/tmp/boinc-server-autodock
87 TEMPDIR_VINA=${TEMPDIR}/fetch-vina
88 TEMPDIR_APPS=${TEMPDIR}/fetch-app
89 mkdir -p ${TEMPDIR_APPS} ${TEMPDIR_VINA}
90
91 #Get current Vina versions in Debian:
92 echo "I (autodockvina_install_apps.sh): (autodockvina_install_apps.sh): Call own script to collect vina for many platforms"
93 cd ${TEMPDIR_VINA}
94 packagename="autodock-vina" ${BOINC_SOURCEDIR}/fetch_autodock_vina.sh .
95 echo "I (autodockvina_install_apps.sh): (autodockvina_install_apps.sh): Call boinc-server-maker script to collect wrapper for many platforms"
96 cd ${TEMPDIR_APPS}
97 packagename="boinc-app-examples" /usr/share/boinc-server-maker/fetch_example_applications.sh .
98
99 #Create temporary directory and get current wrapper versions:
100
101 for boincplat in `ls ${TEMPDIR_APPS}/apps/wrapper/${appverwrapper}/`
102 do
103   appfileswrapper=`ls -1 ${TEMPDIR_APPS}/apps/wrapper/${appverwrapper}/${boincplat}/ | wc -l`
104   if [ $appfileswrapper -eq 0 ]; then
105     rm -rf ${TEMPDIR_APPS}/apps/wrapper/${appverwrapper}/${boincplat}
106     rm -rf ${TEMPDIR_VINA}/apps/vina/${appver}/${boincplat}
107   fi    
108 done
109
110 for boincplat in `ls ${TEMPDIR_VINA}/apps/vina/${appver}/`
111 do
112   appfiles=`ls -1 ${TEMPDIR_VINA}/apps/vina/${appver}/${boincplat}/ | wc -l`
113   if [ $appfiles -eq 0 ]; then
114     rm -rf ${TEMPDIR_APPS}/apps/wrapper/${appverwrapper}/${boincplat}
115     rm -rf ${TEMPDIR_VINA}/apps/vina/${appver}/${boincplat}
116   fi
117 done
118
119 appdir=${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/apps/autodock-vina
120 echo "I (autodockvina_install_apps.sh): Executing sudo mkdir '$appdir'"
121 sudo mkdir -p $appdir
122 # during installation the permissions are somewhat too permissive
123 sudo chmod 777 $appdir
124
125 #for boincplat in `ls ${appdir}/${appver}/`
126 for boincplat in `ls ${TEMPDIR_VINA}/apps/vina/*`
127 do
128   # Check if autodock-vina or vina
129   for f in ${appdir}/${appver}/${boincplat}/vina_*
130   do
131     fname=`basename $f`
132     source="${appdir}"/"${appver}"/"${boincplat}"/"${fname}"
133     target="${appdir}"/"${appver}"/"${boincplat}"/"autodock-${fname}"
134     if ! mv $source $target ; then
135        echo "E (autodockvina_install_apps.sh): Failed moving '$source' to '$target'."
136        exit 1
137     fi
138   done
139 done
140 cp -r ${TEMPDIR_VINA}/apps/vina/* ${appdir}/
141
142 ## Copy wrapper binaries to appropriate directories
143 for boincplat in `ls apps/wrapper/${appverwrapper}/`
144 do
145   cp ${TEMPDIR_APPS}/apps/wrapper/${appverwrapper}/${boincplat}/wrapper_${appverwrapper}_${boincplat} ${appdir}/${appver}/${boincplat}/wrapper_${appver}_${boincplat}
146   echo "<job_desc>
147     <task>
148         <application>autodock-vina</application>
149         <append_cmdline_args/>
150         <stdout_filename>stdout</stdout_filename>
151         <fraction_done_filename>fraction.done</fraction_done_filename>
152     </task>
153 </job_desc>" > ${appdir}/${appver}/${boincplat}/autodock-vina_job_${appver}_${boincplat}.xml
154 done
155
156 echo "I (autodockvina_install_apps.sh): Installing Windows and Mac binaries side by side"
157
158 ## Separate way to install binaries for Windows and Mac since outside Debian
159 TEMPDIR_WIN_MAC=/tmp/boinc-server-autodock/windows_mac
160 mkdir -p ${TEMPDIR_WIN_MAC}
161 cd ${TEMPDIR_WIN_MAC}
162 /usr/share/boinc-server-maker/get_latest_windows_wrappers.sh
163 mkdir -p ${TEMPDIR_WIN_MAC}/fetch-app-win/windows_intelx86
164 mkdir -p ${TEMPDIR_WIN_MAC}/fetch-app-win/windows_x86_64
165 echo "I (autodockvina_install_apps.sh): getting directory structure for apps"
166 mv ${TEMPDIR_WIN_MAC}/wrapper_windows_intelx86.exe \
167    ${TEMPDIR_WIN_MAC}/fetch-app-win/windows_intelx86/wrapper_${appver}_windows_intelx86.exe
168 mv ${TEMPDIR_WIN_MAC}/wrapper_windows_x86_64.exe \
169    ${TEMPDIR_WIN_MAC}/fetch-app-win/windows_x86_64/wrapper_${appver}_windows_x86_64.exe
170 cp ${BOINC_SOURCEDIR}/autodockvina_binaries/autodock-vina_windows_intelx86.exe \
171    ${TEMPDIR_WIN_MAC}/fetch-app-win/windows_intelx86/autodock-vina_${appver}_windows_intelx86.exe
172 cp ${BOINC_SOURCEDIR}/autodockvina_binaries/autodock-vina_windows_x86_64.exe \
173    ${TEMPDIR_WIN_MAC}/fetch-app-win/windows_x86_64/autodock-vina_${appver}_windows_x86_64.exe
174
175 echo "I (autodockvina_install_apps.sh): Copying to windows apps to '${appdir}/${appver}/'"
176 cp -r ${TEMPDIR_WIN_MAC}/fetch-app-win/* ${appdir}/${appver}/
177
178 for boincplat in windows_intelx86 windows_x86_64 i686-apple-darwin x64_64-apple-darwin
179 do
180   mkdir -p "${appdir}"/"${appver}"/"$boincplat"
181   echo "<job_desc>
182     <task>
183         <application>autodock-vina</application>        
184         <append_cmdline_args/>
185         <stdout_filename>stdout</stdout_filename>
186         <fraction_done_filename>fraction.done</fraction_done_filename>
187     </task>
188 </job_desc>" > "${appdir}"/"${appver}"/"$boincplat"/"autodock-vina_job_${appver}_${boincplat}.xml"
189 done
190
191 rm -f ${TEMPDIR_WIN_MAC}/*windows*.pdb
192
193 echo "I (autodockvina_install_apps.sh): Preparing version.xml files"
194
195
196 for boincplat in `ls ${appdir}/${appver}/`
197 do
198 if [[ $boincplat =~ windows* ]]; then
199    # Windows - because of the .exe suffix
200    echo "<version>
201    <file>
202       <physical_name>wrapper_${appver}_${boincplat}.exe</physical_name>
203       <main_program/>
204    </file>
205    <file>
206       <physical_name>autodock-vina_${appver}_${boincplat}.exe</physical_name>
207       <logical_name>autodock-vina</logical_name>
208    </file>
209    <file>
210       <physical_name>autodock-vina_job_${appver}_${boincplat}.xml</physical_name>
211       <logical_name>job.xml</logical_name>
212    </file>
213    </version>" > ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/apps/autodock-vina/$appver/$boincplat/version.xml
214 else
215    # Linux and Mac
216    echo "<version>
217    <file>
218       <physical_name>wrapper_${appver}_${boincplat}</physical_name>
219       <main_program/>
220    </file>
221    <file>
222       <physical_name>autodock-vina_${appver}_${boincplat}</physical_name>
223       <logical_name>autodock-vina</logical_name>
224    </file>
225    <file>
226       <physical_name>autodock-vina_job_${appver}_${boincplat}.xml</physical_name>
227       <logical_name>job.xml</logical_name>
228    </file>
229    </version>" > ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/apps/autodock-vina/$appver/$boincplat/version.xml
230 fi
231 done
232
233 echo "I (autodockvina_install_apps.sh): Editing project.xml file"
234
235 ## Edit project.xml file to register autodock-vina application to the BOINC project
236 echo "<boinc>
237   <app>
238      <name>autodock-vina</name>
239      <user_friendly_name>autodock-vina</user_friendly_name>
240   </app>" > ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/project.xml
241
242 for boincplat in `ls ${appdir}/${appver}/`
243 do
244   echo "<platform>
245   <name>$boincplat</name>
246   <user_friendly_name>$boincplat</user_friendly_name>
247   </platform>" >> ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/project.xml
248 done
249
250 echo "</boinc>" >> "$BOINC_INSTALLROOT"/"$BOINC_PROJECTNAME"/project.xml
251
252 echo "I (autodockvina_install_apps.sh): Invoking bin/xadd"
253 cd ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}
254 ./bin/xadd >> ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/install.log
255
256 yes | ./bin/update_versions >> ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/install.log
257
258 ## Create templates
259 cp $BOINC_SOURCEDIR/autodockvina_templates/autodockvina_wu_template.xml ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/templates/
260 cp $BOINC_SOURCEDIR/autodockvina_templates/autodockvina_result_template.xml ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}/templates/
261
262 ## Create assimilator and validator
263 cd ${BOINC_INSTALLROOT}/${BOINC_PROJECTNAME}
264 if [ -f ./config.xml ]; then
265   headconfigfile=$(mktemp /tmp/boinc_head_config_XXXXXX)
266   tailconfigfile=$(mktemp /tmp/boinc_tail_config_XXXXXX)
267   head -n -3 config.xml > $headconfigfile
268   tail -n  3 config.xml > $tailconfigfile
269   echo "I (autodockvina_install_apps.sh): Creating assimilator..."
270   echo "<daemon>
271       <cmd>
272          sample_assimilator --app autodock-vina --sleep_interval 310 -d 3
273       </cmd>
274     </daemon>" >> $headconfigfile
275   echo "I (autodockvina_install_apps.sh): Creating validator..."
276   echo "<daemon>
277       <cmd>
278          sample_trivial_validator --app autodock-vina --sleep_interval 300 -d 3
279       </cmd>
280     </daemon>" >> $headconfigfile
281   cat $tailconfigfile >> $headconfigfile
282   mv $headconfigfile config.xml
283   chmod 0644 config.xml
284   rm $tailconfigfile
285 else
286   echo "E (autodockvina_install_apps.sh): Configuration file 'config.xml' does not exist! Please check that the project directory exists."
287   exit 1
288 fi
289
290 # restricting permissions
291 #echo "I (autodockvina_install_apps.sh): restricting permissions of directories and files in '$BOINC_INSTALLROOT/$BOINC_PROJECTNAME/apps'"
292 #find "$BOINC_INSTALLROOT"/"$BOINC_PROJECTNAME"/apps -type d | xargs -r sudo chmod go-w
293 #find "$BOINC_INSTALLROOT"/"$BOINC_PROJECTNAME"/apps -type f | xargs -r sudo chmod go-w
294 #echo "I (autodockvina_install_apps.sh): Not touching ownership of files in '$BOINC_INSTALLROOT/$BOINC_PROJECTNAME/app'"
295 #echo " (autodockvina_install_apps.sh)I (autodockvina_install_apps.sh): executing sudo chown -R $BOINC_USER '$BOINC_INSTALLROOT'/'$BOINC_PROJECTNAME'/app"
296 #sudo chown -R $BOINC_USER "$BOINC_INSTALLROOT"/"$BOINC_PROJECTNAME"/app
297
298 echo "I (autodockvina_install_apps.sh): cleaning up temp directories"
299 #rm -r ${TEMPDIR_VINA} ${TEMPDIR_APPS} ${TEMPDIR}