forked from pdxosgeo/foss4g2014-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_update.sh
executable file
·77 lines (63 loc) · 1.87 KB
/
do_update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# because it sets perms, this should be run as root.
owner="foss4g"
group="foss4g"
localrepo="/home/foss4g/foss4g2014-wordpress"
gitrepo='https://github.com/pdxosgeo/foss4g2014-wordpress.git'
gitbranch='master'
wpdir="/usr/share/wordpress/wp-content"
git=/usr/bin/git
rsync="/usr/bin/rsync -c"
# directories where all content is replaced
overwrite_dirs="themes plugins"
# directories that we copy, but don't delete existing files
save_dirs="uploads"
if [ ! -d ${localrepo} ]; then
if [ -w `dirname ${localrepo}` ]; then
$git clone -q $gitrepo $localrepo
status=$?
if [ $status -ne '0' ]; then
echo "git clone failed in $0"
echo "removing stray ${localrepo}"
/bin/rm -rf ${localrepo}
exit 1
fi
#
# just to be safe
chown -R ${owner}:${group} ${localrepo}
chmod 750 $localrepo
else
echo "could not greate git clone for ${gitrepo} in $0"
exit 1
fi
else
cd $localrepo && $git fetch -q --all > /dev/null 2>&1 && $git reset -q --hard origin/${gitbranch} > /dev/null 2>&1
status=$?
if [ $status -ne '0' ]; then
echo "$0 : fetch from origin failed. bailing"
exit 1
fi
fi
for dir in $overwrite_dirs; do
$rsync -rq --delete ${localrepo}/${dir}/ ${wpdir}/${dir}
chown -R ${owner}:${group} ${wpdir}/${dir}
status=$?
if [ $? -ne "0" ]; then
echo "rsync failed to sync $dir in repository on `hostname` - please investigate"
fi
done
for dir in $save_dirs; do
$rsync -rq ${localrepo}/${dir}/ ${wpdir}/${dir}
status=$?
if [ $? -ne "0" ]; then
echo "rsync failed to sync $dir in repository on `hostname` - please investigate"
fi
done
if [ -e ${localrepo}/sitemap.xml ]; then
/bin/cp ${localrepo}/sitemap.xml ${wpdir}/../sitemap.xml
fi
# make sure perms on uploads are correct
chown -R apache:${group} ${wpdir}/uploads
chmod -R ug+w ${wpdir}/uploads
chmod -R o-w ${wpdir}/uploads
exit 0