1 | #!/bin/bash |
---|
2 | # $Id: install.sh 4371 2012-10-26 09:52:50Z olle $ |
---|
3 | |
---|
4 | # Copyright (C) 2009 Gregory Vincic |
---|
5 | |
---|
6 | # Files are copyright by their respective authors. The contributions to |
---|
7 | # files where copyright is not explicitly stated can be traced with the |
---|
8 | # source code revision system. |
---|
9 | |
---|
10 | # This file is part of Proteios. |
---|
11 | # Available at http://www.proteios.org/ |
---|
12 | |
---|
13 | # Proteios is free software; you can redistribute it and/or |
---|
14 | # modify it under the terms of the GNU General Public License |
---|
15 | # as published by the Free Software Foundation; either version 2 |
---|
16 | # of the License, or (at your option) any later version. |
---|
17 | |
---|
18 | # Proteios is distributed in the hope that it will be useful, |
---|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | # GNU General Public License for more details. |
---|
22 | |
---|
23 | # You should have received a copy of the GNU General Public License |
---|
24 | # along with this program; if not, write to the Free Software |
---|
25 | # Foundation, Inc., 59 Temple Place - Suite 330, |
---|
26 | # Boston, MA 02111-1307, USA. |
---|
27 | |
---|
28 | |
---|
29 | # Installation of files only. |
---|
30 | # Configuration and database initialization is done by configure |
---|
31 | . www/WEB-INF/config |
---|
32 | force=$1 |
---|
33 | # CATALINA_HOME validation |
---|
34 | if [ ! -d "$CATALINA_HOME" ]; then |
---|
35 | CATALINA_HOME=/srv/tomcat6 |
---|
36 | if [ ! -d "$CATALINA_HOME" ]; then |
---|
37 | echo "Stopped: CATALINA_HOME must be set before running $0" |
---|
38 | exit |
---|
39 | fi |
---|
40 | fi |
---|
41 | |
---|
42 | if [ ! -z $PREFIX ]; then |
---|
43 | CATALINA_HOME=$PREFIX$CATALINA_HOME |
---|
44 | SERVICE_PATH=$PREFIX$SERVICE_PATH |
---|
45 | mkdir -p $CATALINA_HOME $SERVICE_PATH |
---|
46 | fi |
---|
47 | |
---|
48 | # Check permissions |
---|
49 | if [ ! -w $CATALINA_HOME ]; then |
---|
50 | echo "Stopped: You need write access to $CATALINA_HOME" |
---|
51 | exit |
---|
52 | fi |
---|
53 | |
---|
54 | if [ -e $SERVICE_PATH ]; then |
---|
55 | if [ ! -w $SERVICE_PATH ]; then |
---|
56 | echo "Stopped: You need write access to $SERVICE_PATH" |
---|
57 | exit |
---|
58 | fi |
---|
59 | fi |
---|
60 | |
---|
61 | root=$CATALINA_HOME/webapps/proteios |
---|
62 | |
---|
63 | if [ "$force" != "--force" ]; then |
---|
64 | if [ -e $root ]; then |
---|
65 | echo "Stopped: $root exists already, either remove it or use $0 --force" |
---|
66 | exit |
---|
67 | fi |
---|
68 | fi |
---|
69 | |
---|
70 | # The action is the name of the script without any path or suffix |
---|
71 | action=${0##\./} |
---|
72 | action=${action%%\.*} |
---|
73 | |
---|
74 | install() |
---|
75 | { |
---|
76 | source=$1 |
---|
77 | dest=$2 |
---|
78 | if [ ! -e $dest ]; then |
---|
79 | cp $source $dest |
---|
80 | if [ ! -z $PREFIX ]; then |
---|
81 | dest=${dest##$PREFIX} |
---|
82 | fi |
---|
83 | echo $dest |
---|
84 | else |
---|
85 | if [ "$force" == "--force" ]; then |
---|
86 | cp $source $dest |
---|
87 | if [ ! -z $PREFIX ]; then |
---|
88 | dest=${dest##$PREFIX} |
---|
89 | fi |
---|
90 | echo $dest |
---|
91 | fi |
---|
92 | fi |
---|
93 | } |
---|
94 | |
---|
95 | uninstall() |
---|
96 | { |
---|
97 | source=$1 |
---|
98 | dest=$2 |
---|
99 | if [ -f $dest ]; then |
---|
100 | rm $dest |
---|
101 | echo $dest |
---|
102 | fi |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | cd www |
---|
107 | if [ "$action" == "install" ]; then |
---|
108 | # Create directory structure |
---|
109 | dirs=`find . -type d` |
---|
110 | for dir in $dirs |
---|
111 | do |
---|
112 | dir=${dir##\./} |
---|
113 | mkdir -p $root/$dir |
---|
114 | done |
---|
115 | mkdir -p $USER_FILES_DIR $TEMP_FILES_DIR $USER_FILES_DIR/conf |
---|
116 | fi |
---|
117 | |
---|
118 | # Copy files into place |
---|
119 | files=`find . -type f` |
---|
120 | for file in $files |
---|
121 | do |
---|
122 | # Relative path |
---|
123 | file=${file##\./} |
---|
124 | dest=$root/$file |
---|
125 | $action $file $dest |
---|
126 | done |
---|
127 | cd .. |
---|
128 | $action ./Replace.jar $root/WEB-INF/lib/Replace.jar |
---|
129 | $action ./GetHostName.jar $root/WEB-INF/lib/GetHostName.jar |
---|
130 | $action ./proteios_ftp_server.sh.in $SERVICE_PATH/proteios_ftp_server.sh.in |
---|
131 | |
---|
132 | # Set owner and permissions |
---|
133 | chown $TOMCAT_USER -R $USER_FILES_DIR $TEMP_FILES_DIR $root |
---|
134 | chgrp $TOMCAT_GROUP -R $USER_FILES_DIR $TEMP_FILES_DIR $root |
---|
135 | chown root $root/WEB-INF/update.sh $root/WEB-INF/init.sh |
---|
136 | chgrp root $root/WEB-INF/update.sh $root/WEB-INF/init.sh |
---|
137 | chmod u+x $root/WEB-INF/update.sh $root/WEB-INF/init.sh |
---|
138 | |
---|
139 | # Remove unused files |
---|
140 | # We also remove files that are no longer part of this package here |
---|
141 | FILES_TO_REMOVE="\ |
---|
142 | $root/WEB-INF/init \ |
---|
143 | $root/WEB-INF/update \ |
---|
144 | $root/WEB-INF/updatedb.sh \ |
---|
145 | $root/WEB-INF/update_proteios-linux.sh \ |
---|
146 | $root/WEB-INF/set_classpath.sh \ |
---|
147 | $root/WEB-INF/lib/commons-math-1.1.jar \ |
---|
148 | $root/WEB-INF/install-linux.sh" |
---|
149 | for file in $FILES_TO_REMOVE |
---|
150 | do |
---|
151 | if [ -e $file ]; then |
---|
152 | rm $file |
---|
153 | fi |
---|
154 | done |
---|