git-hacks

git-hacks Commit Details

Date:2012-10-28 21:19:11 (5 years 5 months ago)
Author:Nicola Fontana
Branch:master
Commit:8768fcf630259322a120c8c6283747c590c16384
Parents: 383f6c5cb5010728ef66ef9eff2833dff6384b4b
Message:gitdeploy: corrected some bug

Removed trailing junk from the script and added "return 0" to an empty
function (shell scripts do not accept empty functions).
Changes:
Mgitdeploy (4 diffs)

File differences

gitdeploy
2323
2424
2525
26
26
2727
2828
2929
......
4040
4141
4242
43
43
4444
45
4546
4647
4748
48
49
4950
51
5052
5153
5254
......
7173
7274
7375
74
76
7577
7678
77
78
79
80
7981
8082
81
83
8284
83
84
85
86
85
86
87
88
8789
88
90
8991
90
92
9193
9294
9395
9496
9597
9698
97
9899
99100
100101
101102
102103
103
104
104105
105106
106107
......
124125
125126
126127
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
error() {
echo "** $@" 1>&2;
echo "** $@" 1>&2
}
remote2public() {
echo "Syncing public with remote"
echo -n "Syncing public with remote... "
git checkout -qf
echo done
if [ ! -r "$webdir/bootstrap.cfg" ]; then return 0; fi
# Default bootstrap hook: $webdir/bootstrap can override it
# Default bootstrap hook: $webdir/bootstrap.cfg can override it
bootstrap() {
return 0
}
source $webdir/bootstrap.cfg
refresh_silverstripe() {
local path="$1"
local cfg database server username password
local cfg db host user pwd
for cfg in "$path"/*/_config.php; do
database="$(lookup database $cfg)"
[ -n "$database" ] && break
db="$(lookup database $cfg)"
[ -n "$db" ] && break
done
if [ -z "$database" ]; then return 1; fi
if [ -z "$db" ]; then return 1; fi
server=$(lookup server "$cfg")
[ -z "$server" ] && server=localhost
username=$(lookup username "$cfg")
password=$(lookup password "$cfg")
host=$(lookup server "$cfg")
[ -z "$host" ] && host=localhost
user=$(lookup username "$cfg")
pwd=$(lookup password "$cfg")
mysqldump -h"$server" -u"$username" -p"$password" \
mysqldump -h"$host" -u"$user" -p"$pwd" \
--skip-lock-tables --skip-dump-date \
$database > $(dirname "$path")/"$database".sql
$db > $(dirname "$path")/"$db".sql
return 0
}
refresh_public() {
local dir subdomain
echo Refreshing MySQL dumps in public:
for dir in "$webdir"/*; do
if [ ! -d $dir ]; then continue; fi
subdomain="$(basename $dir)"
echo -ne "\t$subdomain... "
echo -n "Refreshing subdomain $subdomain... "
if refresh_$frontend "$dir" "$webdir/$subdomain.data"; then
echo done
echo done
fi
}
[ -z "$1" ] && error No virtual host directory given
base=$1
export GIT_WORK_TREE="$base"
# Source the configuration file, if found in the virtual host
# directory. Define optional stuff, such as the "writables" array.
[ -r $base/post-receive.silverstripe.cfg ] && source $base/bootstrap.cfg
if [ -n "${writables[*]}" ]; then
echo Changing permissions of the writable directories
chmod 0777 ${writables[*]/#/$base/}
fi
echo Copying the current repository in the virtual host directory
git checkout -qf
echo Backing up MySQL data for every subdomain:
for dir in $base/*; do
if [ ! -d $dir ]; then
continue
fi
echo -ne "\t$(basename $dir)... "
database=
for file in $dir/*/_config.php; do
database=$(lookup database $file)
[ -n "$database" ] && break
done
if [ -z $database ]; then
echo not a subdomain
continue
fi
server=$(lookup server $file)
[ -z "$server" ] && server=localhost
username=$(lookup username $file)
password=$(lookup password $file)
mysqldump -h $server -u"$username" -p"$password" --skip-lock-tables --skip-dump-date $database > $dir.sql
echo $database
done
echo Committing changes on the remote side
git add $base/*.sql
git commit -qm 'Automatic backup'
remote2public
# Source the configuration file, if found in the virtual host
# directory. Define optional stuff, such as the "writables" array.
[ -r $base/post-receive.silverstripe.cfg ] && source $base/bootstrap.cfg
if [ -n "${writables[*]}" ]; then
echo Changing permissions of the writable directories
chmod 0777 ${writables[*]/#/$base/}
fi

Archive Download the corresponding diff file

Branches