about summary refs log tree commit diff stats
path: root/tools/conf/srv/gitolite/deploy-web.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/conf/srv/gitolite/deploy-web.sh')
-rw-r--r--tools/conf/srv/gitolite/deploy-web.sh75
1 files changed, 75 insertions, 0 deletions
diff --git a/tools/conf/srv/gitolite/deploy-web.sh b/tools/conf/srv/gitolite/deploy-web.sh
new file mode 100644
index 0000000..01e92ac
--- /dev/null
+++ b/tools/conf/srv/gitolite/deploy-web.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+pkg_path=$1
+
+www_root="/srv/www"
+www_user="nginx"
+www_group="www"
+
+pkg_file="${pkg_path}/project"
+pkg_rm="${pkg_path}/deleted"
+pkg_files="${pkg_path}/files"
+
+if [ ! -f ${pkg_file} ]; then
+    echo "Deploy web: invalid pkg_file ${pkg_file}"
+    exit 1
+fi
+
+pkg_name=$(head -1 ${pkg_file})
+pkg_new=$(head -3 ${pkg_file} | tail -1)
+pkg_new7=$(echo ${pkg_new} | cut -c1-7)
+
+pkg_www="${www_root}/${pkg_name}"
+pkg_back="${pkg_www}/backup_deploy"
+pkg_last="${pkg_www}/.last_deploy"
+
+if [ ! -d ${pkg_www} ]; then
+    echo "Deploy web: invalid pkg_www ${pkg_www}"
+    exit 1
+fi
+
+# first backup all data
+if [[ ! $(ls ${pkg_www} | grep -v "backup_deploy") = "" ]]; then
+    if [ ! -d ${pkg_back} ]; then
+        sudo -u ${www_user} mkdir -p ${pkg_back}
+    fi
+    backup_file="${pkg_back}/${pkg_name}-$(date '+%Y-%j-%H-%M-%S').tar.gz"
+    echo "Deploy web: making backup ${backup_file}"
+    sudo -u ${www_user} tar --exclude ${pkg_back} --xattrs -zcpf ${backup_file} ${pkg_www}
+fi
+
+# remove files and directories that have been deleted
+if [ -f ${pkg_rm} ]; then
+
+    echo "Deploy web: files to delete:"
+    # first we delete files
+    while read deleted_file; do
+        deleted_file="${pkg_www}/${deleted_file}"
+        if [ -f ${deleted_file} ]; then
+            echo "file      rm ${deleted_file}"
+            rm ${deleted_file}
+        fi
+    done <${pkg_rm}
+
+    # delete directories
+    while read deleted_file; do
+        deleted_file="${pkg_www}/${deleted_file}"
+        if [ -d ${deleted_file} ]; then
+            echo "file      rm ${deleted_file}"
+            rm ${deleted_file}
+        fi
+    done <${pkg_rm}
+
+fi
+
+# copy new files to destination
+if [ -d ${pkg_files} ]; then
+    echo "Deploy web: cp from ${pkg_files} to ${pkg_www}"
+    sudo -u ${www_user} cp -r ${pkg_files}/* ${pkg_www}
+fi
+
+echo ${pkg_new} > ${pkg_last}
+echo "Deploy: scripts/deployweb.sh ${pkg_name} ${pkg_new7} deployed."
+
+#remove temporary package
+rm -r ${pkg_path}
'>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