Project

General

Profile

Download (4.4 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
if [[ -z "${site_url}${multisite}" ]]; then
22
    print_help="1"
23
fi
24

    
25
# -- help
26
if [[ "$print_help" == "1" ]]; then
27
    
28
cat << "EOF"
29
Upadates all composer dependencies including the drupal core code as well as modules.
30
Prior starting the upgrade process a backup of the drupal-cdm-dataportal installation 
31
is created in $HOME/drupal-cdm-dataportal-backups/.
32
Some files in ./web/ which may be modified for specific setups are preserved during the 
33
update process:
34
 * web/.haccess*
35
 * web/robots*.txt
36
 * all symbolic links except for web/polyfills as this is managed through composer.  
37

    
38
USAGE: update-dependencies.sh [--deactivate-install] [--multi-site] [--mailto <ADDRESS>]
39
  --deactivate-install :  The install.php will be hidden by appending '.off' to the filename
40
  -h, --help:  Print this help text    
41
  --mailto <ADDRESS>:  send a email to the ADDRESS with a log of the update process
42
  --multi-site:  Do a multi-site update. Requires dataportals-drush. See https://dev.e-taxonomy.eu/svn/trunk/server-scripts/dataportal-admin/
43
  --site-url:  The site url to be used with drush. This option disables the --multi-site option
44
EOF
45
	exit 0
46
fi
47

    
48
# -- tests
49
if [[ -z "$(grep 'cybertaxonomy.org/drupal-7-dataportal' composer.json)"  ]]; then
50
    echo "ERROR: This script must be executed in the root of the drupal-7-cdm-dataportal folder"
51
    exit -1
52
fi
53

    
54
# --- backups before any modification
55
TMP=$(mktemp -d)
56

    
57
echo "creating full backup ..."
58
backups_folder=$HOME/drupal-cdm-dataportal-backups
59
mkdir -p $backups_folder
60
archive_file=$backups_folder/drupal-cdm-dataportal-backup-$(date -I).tar.gz
61
tar -czf $archive_file ./
62
echo "backup archive created at "$(readlink -f $archive_file)
63

    
64
echo "back up of settings and config files to ${TMP} ..."
65
# backup modified files
66
cp -a web/.htaccess* ${TMP}/
67
# .htaccess.dist is provided by the drupal/drupal package und must not be in the backup
68
rm -f ${TMP}/.htaccess.dist
69
cp -a web/robots*.txt ${TMP}/
70
# preserve all symlinks
71
find web/ -maxdepth 1 -type l -exec cp -a {} ${TMP}/ \;
72

    
73
# -- setup 
74

    
75
if [[ "$multisite" == "1" ]]; then
76
    DRUSH=$(which dataportals-drush) 
77
else 
78
    DRUSH=./vendor/drush/drush/drush
79
    if [[ ! -e $DRUSH ]]; then 
80
        echo "Need to install dependencies first ..."
81
        composer install --no-dev --ansi
82
    fi
83
fi 
84

    
85
DRUSH=$DRUSH" -r $(pwd)/web/" 
86
if [[ -n "$site_url" ]]; then
87
    DRUSH=$DRUSH" -l $site_url"
88
fi
89

    
90
echo "setting dataportals in update mode ..."
91
# set all portals into maintenance mode
92
$DRUSH vset -y maintenance_mode 1
93

    
94
# turn clean urls off since .htaccess will be overwritten during the update
95
$DRUSH vset clean_url -y 0
96

    
97
# turn off cdm_debug_mode in all sites
98
$DRUSH vset -y cdm_debug_mode 0
99

    
100
yes y | $DRUSH updatedb
101

    
102
# run all database updates
103
echo "-------------------------------------------------------------------"
104
echo "Updating dependencies ..."
105

    
106
composer update --no-dev --ansi | tee ${TMP}/composer.log
107

    
108
echo "-------------------------------------------------------------------"
109
echo "restoring settings and config files from temp backup ..."
110

    
111
# restore original settings and files and disable maintenance mode
112
rm -f .htaccess.dist
113
cp web/.htaccess web/.htaccess.dist
114
cp -a ${TMP}/.htaccess* web/
115
cp -a ${TMP}/robots*.txt web/
116
find ${TMP} -maxdepth 1 -type l -exec cp -a {} web/ \;
117

    
118
if (( deactivate_install == 1 )); then
119
    # hide the install.php 
120
    rm -f web/install.php.off
121
    mv web/install.php web/install.php.off 
122
fi 
123

    
124
echo "-------------------------------------------------------------------"
125
echo "Applying pending database updates ..."
126
yes y | $DRUSH updatedb
127

    
128
echo "-------------------------------------------------------------------"
129
echo "dataportal back to production mode ..."
130

    
131
$DRUSH vset clean_url -y 1
132
$DRUSH vset -y maintenance_mode 0
133

    
134
echo "-------------------------------------------------------------------"
135
if [[ -n "$MAILTO" ]]; then
136
    echo "sending email to $MAILTO ..."
137
    cat ${TMP}/composer.log | mail -s "(`hostname`): cdm-dataportal dependencies update" $MAILTO
138
    echo "-------------------------------------------------------------------"
139
fi
140
echo "DONE"
141

    
    (1-1/1)