deploy.sh 1.13 KB
Newer Older
Miloš Diviš's avatar
Miloš Diviš committed
1
2
3
4
# /bin/bash


# setup 
Miloš Diviš's avatar
Miloš Diviš committed
5
server='aaaa'
Miloš Diviš's avatar
Miloš Diviš committed
6
7
8
remote_dir='/www/'
rsync_exclude=('/www/images/uploads/*')

Miloš Diviš's avatar
Miloš Diviš committed
9
10
# index.php excluded and send last because of maintenance mode
common_exclude=('*.ssh' '/temp/*' '/log/*' '/nbproject' '/.git' '.gitignore' 'composer.json' '/www/index.php')
Miloš Diviš's avatar
Miloš Diviš committed
11
12
13
14


current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

Miloš Diviš's avatar
Miloš Diviš committed
15
16
cd $current_dir

Miloš Diviš's avatar
Miloš Diviš committed
17
# set maintenance mode
Miloš Diviš's avatar
Miloš Diviš committed
18
echo '* setting maintenance mode on remote app'
19
rsync \
Miloš Diviš's avatar
Miloš Diviš committed
20
"$server:$remote_dir/www/index.php temp/"
Miloš Diviš's avatar
Miloš Diviš committed
21
22
23

sed -i "s/\/\/\s*require '.maintenance.php';/require '.maintenance.php';/" index.php

24
rsync \
Miloš Diviš's avatar
Miloš Diviš committed
25
"temp/index.php $server:$remote_dir/www/"
Miloš Diviš's avatar
Miloš Diviš committed
26
rm temp/index.php
Miloš Diviš's avatar
Miloš Diviš committed
27
28
29
30
31
32
33
34
35
36
37
38

# create exclude text file
for i in "${rsync_exclude[@]}"
do
echo $i >> exclude.txt
done
for i in "${common_exclude[@]}"
do
echo $i >> exclude.txt
done


Miloš Diviš's avatar
Miloš Diviš committed
39
echo '* Starting rsync to $server:$target_dir/test/'
40
rsync \
Miloš Diviš's avatar
Miloš Diviš committed
41
    -r --delete \
Miloš Diviš's avatar
Miloš Diviš committed
42
    --filter "P log/*.log" --filter "P log/*.html" \
Miloš Diviš's avatar
Miloš Diviš committed
43
    --include ".htaccess" --exclude-from exclude.txt \
44
    . "$server:$target_dir"
Miloš Diviš's avatar
Miloš Diviš committed
45
46
47

rm exclude.txt

Miloš Diviš's avatar
Miloš Diviš committed
48
echo '* files uploaded. Sending index.php'
Miloš Diviš's avatar
Miloš Diviš committed
49

50
rsync \
Miloš Diviš's avatar
Miloš Diviš committed
51
52
53
www/index.php "$server:$remote_dir/www/"

echo '* maintance mode off. files uploaded'
Miloš Diviš's avatar
Miloš Diviš committed
54