Project

General

Profile

Download (4.69 KB) Statistics
| Branch: | Tag: | Revision:
1 6dc2f272 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 6dc2f272 Andreas Kohlbecker
        --multi-site) 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 6dc2f272 Andreas Kohlbecker
    unset multisite
19 173745e8 Andreas Kohlbecker
fi 
20
21 8716981b Andreas Kohlbecker
if [[ -z "${site_url}${multisite}" ]]; then
22
    print_help="1"
23
fi
24
25 173745e8 Andreas Kohlbecker
# -- help
26
if [[ "$print_help" == "1" ]]; then
27 8716981b Andreas Kohlbecker
    
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 173745e8 Andreas Kohlbecker
	exit 0
46
fi
47
48
# -- tests
49 e728e2eb Andreas Kohlbecker
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 a59edf6c Andreas Kohlbecker
# -- 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 6dc2f272 Andreas Kohlbecker
TMP=$(mktemp -d)
69
70 fd9f41ae Andreas Kohlbecker
echo "creating full backup ..."
71 5accd008 Andreas Kohlbecker
backups_folder=$HOME/drupal-cdm-dataportal-backups
72
mkdir -p $backups_folder
73
archive_file=$backups_folder/drupal-cdm-dataportal-backup-$(date -I).tar.gz
74 fd9f41ae Andreas Kohlbecker
tar -czf $archive_file ./
75
echo "backup archive created at "$(readlink -f $archive_file)
76
77 b2e56eb8 Andreas Kohlbecker
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 8716981b Andreas Kohlbecker
# preserve all symlinks
84
find web/ -maxdepth 1 -type l -exec cp -a {} ${TMP}/ \;
85 173745e8 Andreas Kohlbecker
86 b2e56eb8 Andreas Kohlbecker
# -- setup 
87 e728e2eb Andreas Kohlbecker
88 6dc2f272 Andreas Kohlbecker
if [[ "$multisite" == "1" ]]; then
89 173745e8 Andreas Kohlbecker
    DRUSH=$(which dataportals-drush) 
90
else 
91 e728e2eb Andreas Kohlbecker
    DRUSH=./vendor/drush/drush/drush
92
    if [[ ! -e $DRUSH ]]; then 
93
        echo "Need to install dependencies first ..."
94 a6c0342d Andreas Kohlbecker
        composer install --no-dev --ansi
95 e728e2eb Andreas Kohlbecker
    fi
96
fi 
97
98 173745e8 Andreas Kohlbecker
DRUSH=$DRUSH" -r $(pwd)/web/" 
99
if [[ -n "$site_url" ]]; then
100
    DRUSH=$DRUSH" -l $site_url"
101 6dc2f272 Andreas Kohlbecker
fi
102 e728e2eb Andreas Kohlbecker
103
echo "setting dataportals in update mode ..."
104 b2e56eb8 Andreas Kohlbecker
# set all portals into maintenance mode
105 e728e2eb Andreas Kohlbecker
$DRUSH vset -y maintenance_mode 1
106
107 b2e56eb8 Andreas Kohlbecker
# turn clean urls off since .htaccess will be overwritten during the update
108 e728e2eb Andreas Kohlbecker
$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 a6c0342d Andreas Kohlbecker
composer update --no-dev --ansi | tee ${TMP}/composer.log
120 e728e2eb Andreas Kohlbecker
121
echo "-------------------------------------------------------------------"
122
echo "restoring settings and config files from temp backup ..."
123
124 b2e56eb8 Andreas Kohlbecker
# restore original settings and files and disable maintenance mode
125 e728e2eb Andreas Kohlbecker
rm -f .htaccess.dist
126
cp web/.htaccess web/.htaccess.dist
127 173745e8 Andreas Kohlbecker
cp -a ${TMP}/.htaccess* web/
128
cp -a ${TMP}/robots*.txt web/
129 8716981b Andreas Kohlbecker
find ${TMP} -maxdepth 1 -type l -exec cp -a {} web/ \;
130 e728e2eb Andreas Kohlbecker
131
if (( deactivate_install == 1 )); then
132
    # hide the install.php 
133 93513495 Andreas Kohlbecker
    rm -f web/install.php.off
134
    mv web/install.php web/install.php.off 
135 e728e2eb Andreas Kohlbecker
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"