This repository has been archived by the owner on Mar 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
autodeploy-moodle.sh
executable file
·78 lines (59 loc) · 1.67 KB
/
autodeploy-moodle.sh
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
#!/bin/bash
#set -x
E_BADARGS=65
EXPECTED_ARGS=3
if [ $# -ne $EXPECTED_ARGS ]
then
echo " This script expect $EXPECTED_ARGS arguments instead of $#"
exit $E_BADARGS
fi
MV=$(which mv)
RM=$(which rm)
DATE=$(which date)
SED=$(which sed)
GREP=$(which grep)
CAT=$(which cat)
DRUSH=$(which drush)
### CONFIG
DEP_NAME=$1
DEP_BRANCH=$2
DEP_USER=$3
. $($(which dirname) $($(which readlink) -f "$0"))/autodeploy-common.sh
# Clonar RAMA REPO con submoduless en dir tmp
# clone-with-subs.sh $REPO $BRANCH $TARGET
. $LIB/clone-with-subs.sh $REPO_BARE $DEP_BRANCH $TMP_DIR $TAG
# Copiar files y settings
# copy-files-settings.sh $SOURCE $TARGET
. $LIB/moodle-copy-files-settings.sh $DST_DIR $TMP_DIR
# Arreglar permisos
# fix-drupal-perms.sh $TARGET
if [ "${FIX_PERMS}" = 'true' ]; then
. $LIB/moodle-fix-perms.sh $TMP_DIR
fi
# Firmar Robots
REPO_HASH=$($CAT $TMP_DIR/.git_hash)
REPO_DATE=$($CAT $TMP_DIR/.git_date)
SIGN="# Environment generated by $DEP_USER from $DEP_BRANCH (hash: $REPO_HASH, date: $REPO_DATE) for site $SITE_NAME on $($DATE '+%Y-%m-%d %H:%M %Z')"
ROBOTS="$TMP_DIR/robots.txt"
if [ -e $ROBOTS ]; then
$SED -i '1{s|^|'"${SIGN}\n"'|}' $ROBOTS
else
echo $SIGN > $ROBOTS
fi
# Eliminar archivos no para produccion
$RM $TMP_DIR/.git*
# Loggear despliegue
LOG_DIR=$($(which dirname) "${LOG_FILE}")
if [ ! -d $LOG_DIR ]; then
mkdir -p $LOG_DIR
fi
echo -e "$($DATE '+%Y-%m-%d %H:%M %Z')\t$DEP_BRANCH\t$REPO_DATE\t$REPO_HASH\t$DEP_USER" >> $LOG_FILE
$RM -r $DST_DIR
$MV $TMP_DIR $DST_DIR
# Reload apache
restartServerIfNecesary
# Borrar caches
pushd $(pwd) && cd $DST_DIR && sudo -u $WWW_US /usr/bin/php admin/cli/purge_caches.php && popd
# Clean Varnish
cleanVarnishIfNecesary
exit 0