Project

General

Profile

Download (3.69 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
        --multi-site) 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] [--multi-site] [--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 "  --multi-site:  Do a multi-site 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 --multi-site 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
# --- backups before any modification
39
TMP=$(mktemp -d)
40

    
41
echo "creating full backup ..."
42
archive_file=../drupal-7-cdm-dataportal-backup-$(date -I).tar.gz
43
tar -czf $archive_file ./
44
echo "backup archive created at "$(readlink -f $archive_file)
45

    
46
echo "back up of settings and config files to ${TMP} ..."
47
# backup modified files
48
cp -a web/.htaccess* ${TMP}/
49
# .htaccess.dist is provided by the drupal/drupal package und must not be in the backup
50
rm -f ${TMP}/.htaccess.dist
51
cp -a web/robots*.txt ${TMP}/
52

    
53
# -- setup 
54

    
55
if [[ "$multisite" == "1" ]]; then
56
    DRUSH=$(which dataportals-drush) 
57
else 
58
    DRUSH=./vendor/drush/drush/drush
59
    if [[ ! -e $DRUSH ]]; then 
60
        echo "Need to install dependencies first ..."
61
        composer install --no-dev --ansi
62
    fi
63
fi 
64

    
65
DRUSH=$DRUSH" -r $(pwd)/web/" 
66
if [[ -n "$site_url" ]]; then
67
    DRUSH=$DRUSH" -l $site_url"
68
fi
69

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

    
74
# turn clean urls off since .htaccess will be overwritten during the update
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 maintenance 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)