Project

General

Profile

Download (3.67 KB) Statistics
| Branch: | Tag: | Revision:
1 93513495 Andreas Kohlbecker
#!/bin/bash
2 e728e2eb Andreas Kohlbecker
3
4 173745e8 Andreas Kohlbecker
# -- options
5 e728e2eb Andreas Kohlbecker
while [[ "$#" -gt 0 ]]; do
6
    case $1 in
7 173745e8 Andreas Kohlbecker
        -h|--help) print_help=1;;
8 e728e2eb Andreas Kohlbecker
        --mailto) MAILTO="$2"; shift ;;
9
        --deactivate-install) deactivate_install=1 ;;
10
        --multisite) multisite=1 ;;
11 173745e8 Andreas Kohlbecker
        --site-url) site_url=$2; shift ;;
12 e728e2eb Andreas Kohlbecker
        *) echo "Unknown parameter passed: $1"; exit 1 ;;
13
    esac
14
    shift
15
done
16
17 173745e8 Andreas Kohlbecker
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 e728e2eb Andreas Kohlbecker
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 173745e8 Andreas Kohlbecker
# -- setup 
39
40
TMP=$(mktemp -d)
41 e728e2eb Andreas Kohlbecker
42 173745e8 Andreas Kohlbecker
if [[ "$multisite" == "1" ]]; then
43
    DRUSH=$(which dataportals-drush) 
44
else 
45 e728e2eb Andreas Kohlbecker
    DRUSH=./vendor/drush/drush/drush
46
    if [[ ! -e $DRUSH ]]; then 
47
        echo "Need to install dependencies first ..."
48 a6c0342d Andreas Kohlbecker
        composer install --no-dev --ansi
49 e728e2eb Andreas Kohlbecker
    fi
50
fi 
51
52 173745e8 Andreas Kohlbecker
DRUSH=$DRUSH" -r $(pwd)/web/" 
53
if [[ -n "$site_url" ]]; then
54
    DRUSH=$DRUSH" -l $site_url"
55
fi 
56 e728e2eb Andreas Kohlbecker
57
echo "creating full backup ..."
58
archive_file=../drupal-7-cdm-dataportal-backup-$(date -I).tar.gz
59
tar -czf $archive_file ./
60 173745e8 Andreas Kohlbecker
echo "backup archive created at "$(readlink -f $archive_file)
61 e728e2eb Andreas Kohlbecker
62
echo "backing up settings and config files to temp backup ${TMP} ..."
63
64
# backup modified files
65 173745e8 Andreas Kohlbecker
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 e728e2eb Andreas Kohlbecker
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 a6c0342d Andreas Kohlbecker
composer update --no-dev --ansi | tee ${TMP}/composer.log
87 e728e2eb Andreas Kohlbecker
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 173745e8 Andreas Kohlbecker
cp -a ${TMP}/.htaccess* web/
95
cp -a ${TMP}/robots*.txt web/
96 e728e2eb Andreas Kohlbecker
97
if (( deactivate_install == 1 )); then
98
    # hide the install.php 
99 93513495 Andreas Kohlbecker
    rm -f web/install.php.off
100
    mv web/install.php web/install.php.off 
101 e728e2eb Andreas Kohlbecker
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"