Project

General

Profile

Download (4.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
        --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
# -- requirements
55

    
56
COMPOSER=$(which composer)
57
if [[ -z "$COMPOSER" ]]; then
58
    # try local composer
59
    if [[ -x ./composer ]]; then
60
        COMPOSER=./composer
61
    else
62
        echo "composer not found. Please see https://github.com/cybertaxonomy/cdm-dataportal#preparation"
63
        exit -1
64
    fi
65
fi
66

    
67
# -- backups before any modification
68
TMP=$(mktemp -d)
69

    
70
echo "creating full backup ..."
71
backups_folder=$HOME/drupal-cdm-dataportal-backups
72
mkdir -p $backups_folder
73
archive_file=$backups_folder/drupal-cdm-dataportal-backup-$(date +%F_%T).tar.gz
74
tar -czf $archive_file ./
75
echo "backup archive created at "$(readlink -f $archive_file)
76

    
77
echo "back up of settings and config files to ${TMP} ..."
78
# backup modified files
79
cp -a web/.htaccess* ${TMP}/
80
# .htaccess.dist is provided by the drupal/drupal package und must not be in the backup
81
rm -f ${TMP}/.htaccess.dist
82
cp -a web/robots*.txt ${TMP}/
83
# preserve all symlinks
84
find web/ -maxdepth 1 -type l -exec cp -a {} ${TMP}/ \;
85

    
86
# -- setup 
87

    
88
if [[ "$multisite" == "1" ]]; then
89
    DRUSH=$(which dataportals-drush) 
90
else 
91
    DRUSH=./vendor/drush/drush/drush
92
    if [[ ! -e $DRUSH ]]; then 
93
        echo "Need to install dependencies first ..."
94
        $COMPOSER install --no-dev --ansi
95
    fi
96
fi 
97

    
98
DRUSH=$DRUSH" -r $(pwd)/web/" 
99
if [[ -n "$site_url" ]]; then
100
    DRUSH=$DRUSH" -l $site_url"
101
fi
102

    
103
echo "setting dataportals in update mode ..."
104
# set all portals into maintenance mode
105
$DRUSH vset -y maintenance_mode 1
106

    
107
# turn clean urls off since .htaccess will be overwritten during the update
108
$DRUSH vset clean_url -y 0
109

    
110
# turn off cdm_debug_mode in all sites
111
$DRUSH vset -y cdm_debug_mode 0
112

    
113
yes y | $DRUSH updatedb
114

    
115
# run all database updates
116
echo "-------------------------------------------------------------------"
117
echo "Updating dependencies ..."
118

    
119
$COMPOSER update --no-dev --ansi | tee ${TMP}/composer.log
120

    
121
echo "-------------------------------------------------------------------"
122
echo "restoring settings and config files from temp backup ..."
123

    
124
# restore original settings and files and disable maintenance mode
125
rm -f .htaccess.dist
126
cp web/.htaccess web/.htaccess.dist
127
cp -a ${TMP}/.htaccess* web/
128
cp -a ${TMP}/robots*.txt web/
129
find ${TMP} -maxdepth 1 -type l -exec cp -a {} web/ \;
130

    
131
if (( deactivate_install == 1 )); then
132
    # hide the install.php 
133
    rm -f web/install.php.off
134
    mv web/install.php web/install.php.off 
135
fi 
136

    
137
echo "-------------------------------------------------------------------"
138
echo "Applying pending database updates ..."
139
yes y | $DRUSH updatedb
140

    
141
echo "-------------------------------------------------------------------"
142
echo "dataportal back to production mode ..."
143

    
144
$DRUSH vset clean_url -y 1
145
$DRUSH vset -y maintenance_mode 0
146

    
147
echo "-------------------------------------------------------------------"
148
if [[ -n "$MAILTO" ]]; then
149
    echo "sending email to $MAILTO ..."
150
    cat ${TMP}/composer.log | mail -s "(`hostname`): cdm-dataportal dependencies update" $MAILTO
151
    echo "-------------------------------------------------------------------"
152
fi
153
echo "DONE"
154

    
(2-2/2)