Project

General

Profile

Download (3.7 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/bash
2

    
3

    
4
# -- options
5
while [[ "$#" -gt 0 ]]; do
6
    case $1 in
7
        -h|--help) print_help=1;;
8
        --mailto) MAILTO="$2"; shift ;;
9
        --deactivate-install) deactivate_install=1 ;;
10
        --multisite) multisite=1 ;;
11
        --site-url) site_url=$2; shift ;;
12
        *) echo "Unknown parameter passed: $1"; exit 1 ;;
13
    esac
14
    shift
15
done
16

    
17
if [[ -n "$site_url" ]]; then
18
    unset multisite
19
fi 
20

    
21
# -- help
22
if [[ "$print_help" == "1" ]]; then
23
	echo "USAGE: update-dependencies.sh [--deactivate-install] [--multisite] [--mailto <ADDRESS>]"
24
	echo "  --deactivate-install :  The install.php will be hidden by appending '.off' to the filename"
25
	echo "  -h, --help:  Print this help text"
26
	echo "  --mailto <ADDRESS>:  send a email to the ADDRESS with a log of the update process"
27
	echo "  --multisite:  Do a multisite update. Requires dataportals-drush. See https://dev.e-taxonomy.eu/svn/trunk/server-scripts/dataportal-admin/"
28
	echo "  --site-url:  The site url to be used with drush. This option disables the --multisite option"
29
	exit 0
30
fi
31

    
32
# -- tests
33
if [[ -z "$(grep 'cybertaxonomy.org/drupal-7-dataportal' composer.json)"  ]]; then
34
    echo "ERROR: This script must be executed in the root of the drupal-7-cdm-dataportal folder"
35
    exit -1
36
fi
37

    
38
# --- full backup before any modification
39
echo "creating full backup ..."
40
archive_file=../drupal-7-cdm-dataportal-backup-$(date -I).tar.gz
41
tar -czf $archive_file ./
42
echo "backup archive created at "$(readlink -f $archive_file)
43

    
44
# -- setup 
45

    
46
TMP=$(mktemp -d)
47

    
48
if [[ "$multisite" == "1" ]]; then
49
    DRUSH=$(which dataportals-drush) 
50
else 
51
    DRUSH=./vendor/drush/drush/drush
52
    if [[ ! -e $DRUSH ]]; then 
53
        echo "Need to install dependencies first ..."
54
        composer install --no-dev --ansi
55
    fi
56
fi 
57

    
58
DRUSH=$DRUSH" -r $(pwd)/web/" 
59
if [[ -n "$site_url" ]]; then
60
    DRUSH=$DRUSH" -l $site_url"
61
fi 
62

    
63
echo "back up of settings and config files to ${TMP} ..."
64
# backup modified files
65
cp -a web/.htaccess* ${TMP}/
66
# .htaccess.dist is provieded by the drupal/drupal package und must not be in the backup
67
rm -f ${TMP}/.htaccess.dist
68
cp -a web/robots*.txt ${TMP}/
69

    
70
echo "setting dataportals in update mode ..."
71
# set all portals into maintainance mode
72
$DRUSH vset -y maintenance_mode 1
73

    
74
# turn clean urls off since .htaccess will be overwritten during the updatecode
75
$DRUSH vset clean_url -y 0
76

    
77
# turn off cdm_debug_mode in all sites
78
$DRUSH vset -y cdm_debug_mode 0
79

    
80
yes y | $DRUSH updatedb
81

    
82
# run all database updates
83
echo "-------------------------------------------------------------------"
84
echo "Updating dependencies ..."
85

    
86
composer update --no-dev --ansi | tee ${TMP}/composer.log
87

    
88
echo "-------------------------------------------------------------------"
89
echo "restoring settings and config files from temp backup ..."
90

    
91
# restore original settings and files and disable maintainance mode
92
rm -f .htaccess.dist
93
cp web/.htaccess web/.htaccess.dist
94
cp -a ${TMP}/.htaccess* web/
95
cp -a ${TMP}/robots*.txt web/
96

    
97
if (( deactivate_install == 1 )); then
98
    # hide the install.php 
99
    rm -f web/install.php.off
100
    mv web/install.php web/install.php.off 
101
fi 
102

    
103
echo "-------------------------------------------------------------------"
104
echo "Applying pending database updates ..."
105
yes y | $DRUSH updatedb
106

    
107
echo "-------------------------------------------------------------------"
108
echo "dataportal back to production mode ..."
109

    
110
$DRUSH vset clean_url -y 1
111
$DRUSH vset -y maintenance_mode 0
112

    
113
echo "-------------------------------------------------------------------"
114
if [[ -n "$MAILTO" ]]; then
115
    echo "sending email to $MAILTO ..."
116
    cat ${TMP}/composer.log | mail -s "(`hostname`): cdm-dataportal dependencies update" $MAILTO
117
    echo "-------------------------------------------------------------------"
118
fi
119
echo "DONE"
120

    
    (1-1/1)