updated on Wed Jan 25 08:34:36 UTC 2012
[aur-mirror.git] / opengrok / deploy.sh
blob647c68f23e149a4ae9c32e68a40cd0c3392c4898
1 #!/bin/sh
3 do_exec() {
4 echo "[exec]:" "$@"
5 if ! "$@"; then
6 echo "[exec]: FAILED." >&2
7 exit 2
8 fi
11 full_filename() {
12 local FILE="$1"
14 # file dot relative
15 # ./file dot relative
16 # ../file parent relative
17 # /file absolute
18 while true; do
19 case "$FILE" in
20 ( /* )
21 # Remove /./ inside filename:
22 while echo "$FILE" |fgrep "/./" >/dev/null 2>&1; do
23 FILE=`echo "$FILE" | sed "s/\\/\\.\\//\\//"`
24 done
25 # Remove /../ inside filename:
26 while echo "$FILE" |grep "/[^/][^/]*/\\.\\./" >/dev/null 2>&1; do
27 FILE=`echo "$FILE" | sed "s/\\/[^/][^/]*\\/\\.\\.\\//\\//"`
28 done
29 echo "$FILE"
30 exit 0
33 (*)
34 FILE=`pwd`/"$FILE"
36 esac
37 done
40 EXEC=do_exec
42 myopts="-o dn: -l name:,static:,git:,rootdir:"
43 getopt -Q $myopts -- "$@" || exit 2
44 eval set -- `getopt -q $myopts -- "$@"`
46 DEPLOY_DIR=/opt/tomcat/webapps
47 OPENGROK_WAR=/opt/opengrok/lib/source.war
49 PROJECT=`basename \`pwd\``
50 [ -z "$PROJECT" ] && PROJECT="project"
51 ROOTDIR=
52 URL=
53 VCS=
54 REPO=
56 while [ $# -gt 0 ]; do
57 case "$1" in
58 -d|--rootdir)
59 ROOTDIR="$2"
60 shift
62 -n|--name)
63 PROJECT="$2"
64 shift
66 --static)
67 VCS=static
68 REPO="`full_filename \"$2\"`"
69 shift
71 --git)
72 VCS=git
73 REPO="$2"
74 shift
76 --)
79 exit 1
81 esac
82 shift
83 done
85 if [ -z "$VCS" ]; then
86 echo "Source data not set" >&2
87 exit 1;
90 [ -z "$ROOTDIR" ] && ROOTDIR="/var/opengrok/$PROJECT"
91 [ -z "$URL" ] && URL="source-$PROJECT"
93 $EXEC mkdir -p "$ROOTDIR"
95 case "$VCS" in
96 static)
97 ($EXEC cd $ROOTDIR; $EXEC cp -R "$REPO" src; ) || exit "$?"
99 git)
100 ($EXEC cd $ROOTDIR; $EXEC git clone "$REPO" src; ) || exit "$?"
102 esac
103 SRCDIR="$ROOTDIR/src"
105 $EXEC cp "$OPENGROK_WAR" "${DEPLOY_DIR}/${URL}.war"
107 $EXEC cd "${DEPLOY_DIR}"
108 $EXEC unzip -q -d "$URL" "${URL}.war"
110 $EXEC cd "$URL/WEB-INF"
111 cat >config.tmp <<EXTRA_CONFIG_EOF
112 <context-param>
113 <param-name>DATA_ROOT</param-name>
114 <param-value>/var/opengrok/DATA_ROOT</param-value>
115 <description>REQUIRED: Full path of the directory where data files generated by OpenGrok are stored</description>
116 </context-param>
118 <context-param>
119 <param-name>SRC_ROOT</param-name>
120 <param-value>/var/opengrok/SRC_ROOT</param-value>
121 <description>REQUIRED: Full path to source tree</description>
122 </context-param>
123 EXTRA_CONFIG_EOF
125 $EXEC sed \
126 -e '/<\/listener>/r config.tmp' \
127 -i "web.xml"
128 rm -f config.tmp
130 $EXEC sed \
131 -e 's:/var/opengrok/\(etc/configuration.xml\):'"${ROOTDIR}"'/\1:' \
132 -e 's:/var/opengrok/DATA_ROOT:'"${ROOTDIR}"'/data:' \
133 -e 's:/var/opengrok/SRC_ROOT:'"${SRCDIR}"'/:' \
134 -i "web.xml"
135 ) || exit "$?"
138 $EXEC cd /opt/opengrok/bin
139 $EXEC export OPENGROK_VERBOSE=true
140 $EXEC export OPENGROK_EXTRA_PARAMS="-w $URL"
141 $EXEC export OPENGROK_INSTANCE_BASE="${ROOTDIR}"
142 $EXEC ./OpenGrok index "$SRCDIR"
143 ) || exit "$?"
146 echo '#!/bin/sh'
147 echo "cd '${ROOTDIR}'"
148 echo "cd src"
149 case "$VCS" in
150 static)
151 echo "# no way to update"
153 git)
154 echo "git pull"
156 esac
157 echo
158 echo "cd /opt/opengrok/bin"
159 echo "export OPENGROK_VERBOSE=true"
160 echo "export OPENGROK_INSTANCE_BASE='${ROOTDIR}'"
161 echo "export OPENGROK_EXTRA_PARAMS='-w $URL'"
162 echo "./OpenGrok index '$SRCDIR'"
163 echo
164 ) >"$ROOTDIR/update.sh"
167 chmod +x "$ROOTDIR/update.sh"