1 | #!/bin/bash -e
|
---|
2 |
|
---|
3 | ### Change the values below
|
---|
4 | path_to_live_site="/home/members/fflic/sites/fflic.org/web"
|
---|
5 | path_to_dev_site="/home/members/fflic/sites/dev.fflic.org/web"
|
---|
6 |
|
---|
7 | ## optionally file in the following database info if you want to
|
---|
8 | ## copy the dev database over the live database
|
---|
9 | live_site_db_name=
|
---|
10 | dev_site_db_user=
|
---|
11 | dev_site_db_pass=
|
---|
12 | dev_site_db_name=
|
---|
13 |
|
---|
14 | ### Optionally change the value below - by default the script will create
|
---|
15 | ### a directory in the live-user's home directory called sync-staging which
|
---|
16 | ### will hold temporary copies of the various sites
|
---|
17 | path_to_sync_staging=~/sync-staging
|
---|
18 |
|
---|
19 | ### Optionally change the path below if you have a read protected settings
|
---|
20 | ### file on your dev site. If you dev site does not have a read protected
|
---|
21 | ### settings file, then comment out this line
|
---|
22 | #settings_file="sites/default/settings.php"
|
---|
23 |
|
---|
24 | ### No need to change any other values
|
---|
25 |
|
---|
26 | if [ ! -f ~/.my.cnf ]; then
|
---|
27 | echo "I didn't find a .my.cnf file - which means "
|
---|
28 | echo "I won't be able to automatically login to your "
|
---|
29 | echo "database. Please create a .my.cnf file with your "
|
---|
30 | echo "database details or request help from support.mayfirst.org"
|
---|
31 | exit
|
---|
32 | fi
|
---|
33 |
|
---|
34 | if [ ! -d "$path_to_live_site" ]; then
|
---|
35 | echo "Path to live site ($path_to_live_site) doesn't exist"
|
---|
36 | exit
|
---|
37 | fi
|
---|
38 |
|
---|
39 | if [ ! -d "$path_to_dev_site" ]; then
|
---|
40 | echo "Path to dev site ($path_to_dev_site) doesn't exist"
|
---|
41 | exit
|
---|
42 | fi
|
---|
43 |
|
---|
44 | # remove trailing slash from web variables
|
---|
45 | path_to_live_site=$(echo $path_to_live_site|sed "s/\\/$//")
|
---|
46 | path_to_dev_site=$(echo $path_to_dev_site|sed "s/\\/$//")
|
---|
47 |
|
---|
48 | live_backup="$path_to_sync_staging/live-backup"
|
---|
49 | dev_staging="$path_to_sync_staging/dev-staging"
|
---|
50 |
|
---|
51 | if [ ! -d "$path_to_sync_staging" ]; then
|
---|
52 | echo "Creating $path_to_sync_staging"
|
---|
53 | mkdir "$path_to_sync_staging"
|
---|
54 | fi
|
---|
55 |
|
---|
56 | if [ ! -d "$live_backup" ]; then
|
---|
57 | echo "Creating $live_backup"
|
---|
58 | mkdir "$live_backup"
|
---|
59 | fi
|
---|
60 |
|
---|
61 | if [ ! -d "$dev_staging" ]; then
|
---|
62 | echo "Creating $dev_staging"
|
---|
63 | mkdir "$dev_staging"
|
---|
64 | fi
|
---|
65 |
|
---|
66 | function interpret_reply() {
|
---|
67 | if [ "$REPLY" = "y" ] || [ "$REPLY" == "Y" ] || [ -z "$REPLY" ]; then
|
---|
68 | echo "Executing...."
|
---|
69 | REPLY=y
|
---|
70 | else
|
---|
71 | echo "Not executing"
|
---|
72 | REPLY=n
|
---|
73 | fi
|
---|
74 | }
|
---|
75 |
|
---|
76 | echo
|
---|
77 | echo "Path to dev site: $path_to_dev_site"
|
---|
78 | echo "Path to live site: $path_to_live_site"
|
---|
79 | echo "Live backup: $live_backup"
|
---|
80 | echo "Dev staging: $dev_staging"
|
---|
81 |
|
---|
82 | echo
|
---|
83 |
|
---|
84 | read -p "Back up live site files? [Yn] "
|
---|
85 | interpret_reply
|
---|
86 | if [ "$REPLY" = "y" ]; then
|
---|
87 | rsync -av "$path_to_live_site" "$live_backup/"
|
---|
88 | fi
|
---|
89 |
|
---|
90 | if [ -n "$live_site_db_name" ]; then
|
---|
91 | read -p "Back up live site database? [Yn] "
|
---|
92 | interpret_reply
|
---|
93 | if [ "$REPLY" = "y" ]; then
|
---|
94 | mysqldump "$live_site_db_name" > "$live_backup/${live_site_db_name}.sql"
|
---|
95 | fi
|
---|
96 | fi
|
---|
97 |
|
---|
98 | echo
|
---|
99 | read -p "Synchronizing files from dev site to staging area? [Yn] "
|
---|
100 | interpret_reply
|
---|
101 | if [ "$REPLY" = "y" ]; then
|
---|
102 | exclude=
|
---|
103 | if [ -n "$settings_file" ]; then
|
---|
104 | exclude="--exclude '*{$settings_file}'"
|
---|
105 | fi
|
---|
106 | rsync -av $exclude "${path_to_dev_site}" "${dev_staging}/"
|
---|
107 | fi
|
---|
108 |
|
---|
109 | if [ -n "$dev_site_db_user" ]; then
|
---|
110 | echo
|
---|
111 | read -p "Dump dev database to staging area? [Yn] "
|
---|
112 | interpret_reply
|
---|
113 | if [ "$REPLY" = "y" ]; then
|
---|
114 | mysqldump -u "$dev_site_db_user" -p${dev_site_db_pass} "$dev_site_db_name" > "${dev_staging}/${dev_site_db_name}.sql"
|
---|
115 | fi
|
---|
116 | fi
|
---|
117 |
|
---|
118 | if [ -n "$settings_file" ]; then
|
---|
119 | echo
|
---|
120 | read -p "Copy live site settings.php to dev staging area? [Yn] "
|
---|
121 | interpret_reply
|
---|
122 | if [ "$REPLY" = "y" ]; then
|
---|
123 | cp "${path_to_live_site}/$settings_file" "${dev_staging}/web/$settings_file"
|
---|
124 | fi
|
---|
125 | fi
|
---|
126 |
|
---|
127 | echo
|
---|
128 | echo
|
---|
129 | echo "Your live site has been backed up and the dev site is staged to be moved"
|
---|
130 | echo "Please carefully examine:"
|
---|
131 | echo $path_to_sync_staging
|
---|
132 | echo "to make sure everything is in place"
|
---|
133 | echo
|
---|
134 | read -p "Press any key to make the dev site live or hit ctl-cancel to abort"
|
---|
135 |
|
---|
136 | echo
|
---|
137 | read -p "Delete live web site files? [Yn] "
|
---|
138 | interpret_reply
|
---|
139 | if [ "$REPLY" = "y" ]; then
|
---|
140 | rm -rf $path_to_live_site/*
|
---|
141 | rm -f $path_to_live_site/.htaccess
|
---|
142 | fi
|
---|
143 |
|
---|
144 | echo
|
---|
145 | read -p "Copy in dev files? [Yn] "
|
---|
146 | interpret_reply
|
---|
147 | if [ "$REPLY" = "y" ]; then
|
---|
148 | rsync -av "${dev_staging}/web/" "$path_to_live_site/"
|
---|
149 | fi
|
---|
150 |
|
---|
151 | if [ -n "$dev_site_db_name" ]; then
|
---|
152 | echo
|
---|
153 | read -p "Import database? [Yn] "
|
---|
154 | interpret_reply
|
---|
155 | if [ "$REPLY" = "y" ]; then
|
---|
156 | # drop all tables in the existing database
|
---|
157 | mysqldump --add-drop-table --no-data "$live_site_db_name" | grep ^DROP | mysql
|
---|
158 | mysql < "$dev_staging/${dev_db_name}.sql"
|
---|
159 | fi
|
---|
160 | fi
|
---|
161 |
|
---|
162 | echo "All done."
|
---|
163 |
|
---|