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


4
5
6
7
8
# Deply script for Nette application
#
# minified nette version expected in ./Nette-minified/nette.min.php
#

Miloš Diviš's avatar
Miloš Diviš committed
9
# setup 
10
11
12
13
server='195.210.29.9'
user='k-architekt.cz'
remote_dir='/web'
key_path='/home/mario/.ssh/websupport_key'
Miloš Diviš's avatar
Miloš Diviš committed
14
rsync_exclude=('/www/images/uploads/*')
15
16
17

# index.php excluded from project files sync and send last because of maintenance mode
common_exclude=('*.ssh' '/temp/*' '/log/*' '/nbproject' '/.git' 'deploy.sh' '*~'\
18
19
    '.gitignore' 'composer.json' '/www/index.php' \
    'config.local.neon' 'config.production.neon')
Miloš Diviš's avatar
Miloš Diviš committed
20

21
# check options
22
delete_logs=0
23
24
25
26
27
28
29
30
31
32
33
34
35
while getopts ":d" opt; do
  case $opt in
    d)
      delete_logs=1
;;
    \?)
      echo 'Invalid option!' 
      echo '-d to delete remote logs and exceptions'
      echo 'exiting with no action'
      exit 1
;;
  esac
done
Miloš Diviš's avatar
Miloš Diviš committed
36
37
38

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

Miloš Diviš's avatar
Miloš Diviš committed
39
40
cd $current_dir

Miloš Diviš's avatar
Miloš Diviš committed
41
# set maintenance mode
Miloš Diviš's avatar
Miloš Diviš committed
42
echo '* setting maintenance mode on remote app'
Miloš Diviš's avatar
Miloš Diviš committed
43

44
scp -q -i $key_path $user@$server:$remote_dir/www/index.php temp/
Miloš Diviš's avatar
Miloš Diviš committed
45

46
47
48
49
50
# set maintance mode if app is on remote
if [ -f temp/index.php ] 
    then
    sed -i "s/\/\/\s*require '.maintenance.php';/require '.maintenance.php';/" \
        temp/index.php
51

52
53
54
55
56

    rsync -az \
    temp/index.php $user@$server:$remote_dir/www/
    rm temp/index.php
fi
Miloš Diviš's avatar
Miloš Diviš committed
57
58
59
60
61
62
63
64
65
66
67
68

# 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


69
echo "* Starting rsync to $server:$remote_dir"
70
echo "   * sendig project files"
71
72
rsync -az \
    --delete \
Miloš Diviš's avatar
Miloš Diviš committed
73
    --filter "P log/*.log" --filter "P log/*.html" \
Miloš Diviš's avatar
Miloš Diviš committed
74
    --include ".htaccess" --exclude-from exclude.txt \
75
    . $user@$server:$remote_dir/
Miloš Diviš's avatar
Miloš Diviš committed
76
77
78

rm exclude.txt

79
80
81
82
83
84
85
86
echo '   * sending production config'

cp app/config/config.production.neon temp/config.local.neon
rsync -az \
    temp/config.local.neon $user@$server:$remote_dir/app/config/
rm temp/config.local.neon

echo '   * sending index.php'
Miloš Diviš's avatar
Miloš Diviš committed
87

88
89
rsync -az \
www/index.php $user@$server:$remote_dir/www/
Miloš Diviš's avatar
Miloš Diviš committed
90

91
echo '* rsync completed, maitenance mode off.'
92
93
94
95
96
97
98
99
100
101
102
103

if [ $delete_logs -eq 1 ]
    then
    echo '* removing logs and stored exceptions'
    sftp -q -i $key_path $user@$server >/dev/null 2>&1 << SFTPDELIM
         cd $remote_dir
         rm log/*.log
         rm log/*.html
         bye
SFTPDELIM
fi

104
echo '*** Deploy completed! Yeeeeah! ***'
Miloš Diviš's avatar
Miloš Diviš committed
105

106
exit 0