forked from jbossorg/bootstrap-community
-
Notifications
You must be signed in to change notification settings - Fork 3
/
publish.sh
169 lines (138 loc) · 3.9 KB
/
publish.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# Define
SANDBOX_URL=".rhcloud.com"
SANDBOX_SSH_USERNAME=""
SANDBOX_REPO="ssh://${SANDBOX_SSH_USERNAME}@${SANDBOX_URL}/~/git/site.git/"
SANDBOX_CHECKOUT_DIR=$DIR/_tmp/sandbox
# team email subject
EMAIL_SUBJECT="CapeDwarf site released at \${PRODUCTION_URL}"
# email To ?
EMAIL_TO=""
EMAIL_FROM="\"CapeDwarf Site Publish Script\" <mluksa@redhat.com>"
SSH_USER="capedwarf"
JBORG_DIR="capedwarf"
SERVER="filemgmt.jboss.org"
STAGING_URL="stg.capedwarf.org"
STAGING_LOCATION="${SSH_USER}@${SERVER}:stg_htdocs/capedwarf"
PRODUCTION_URL="www.capedwarf.org"
PRODUCTION_LOCATION="${SSH_USER}@${SERVER}:www_htdocs/capedwarf"
notify_email()
{
echo "***** Performing CapeDwarf site release notifications"
echo "*** Notifying CapeDwarf dev list"
subject=`eval echo $EMAIL_SUBJECT`
echo "Email from: " $EMAIL_FROM
echo "Email to: " $EMAIL_TO
echo "Subject: " $subject
# send email using sendmail
printf "Subject: $subject\nSee \$subject :)\n" | /usr/bin/env sendmail -f "$EMAIL_FROM" "$EMAIL_TO"
}
shallow_clean() {
echo "**** Cleaning site ****"
rm -rf $DIR/_site
echo "**** Cleaning asciidoc cache ****"
rm -rf $DIR/_tmp/asciidoc
}
deep_clean() {
echo "**** Cleaning site ****"
rm -rf $DIR/_site
echo "**** Cleaning caches ****"
rm -rf $DIR/_tmp/lanyrd
rm -rf $DIR/_tmp/remote_partial
rm -rf $DIR/_tmp/datacache
rm -rf $DIR/_tmp/restcache
rm -rf $DIR/_tmp/asciidoc
}
sandbox() {
shallow_clean
echo "**** Generating site ****"
awestruct -Psandbox
if [ ! -d "$SANDBOX_CHECKOUT_DIR/.git" ]; then
echo "**** Cloning OpenShift repo ****"
mkdir -p $SANDBOX_CHECKOUT_DIR
git clone $SANDBOX_REPO $SANDBOX_CHECKOUT_DIR
fi
cp -rf $DIR/_site/* $SANDBOX_CHECKOUT_DIR/php
echo "**** Publishing site to http://${SANDBOX_URL} ****"
cd $SANDBOX_CHECKOUT_DIR
git add *
git commit -a -m"deploy"
git push -f
shallow_clean
}
production() {
deep_clean
echo "**** Generating site ****"
awestruct -Pproduction
echo "\n**** Publishing site to http://${PRODUCTION_URL} ****"
rsync -Pqr --protocol=28 --delete-after --exclude=presentations $DIR/_site/* ${PRODUCTION_LOCATION}
shallow_clean
read -p "Do you want to send release notifcations to $EMAIL_TO[y/N]? " yn
case $yn in
[Yy]* ) notify_email;;
* ) exit;
esac
}
staging() {
deep_clean
echo "**** Generating site ****"
awestruct -Pstaging
echo "**** Publishing site to http://${STAGING_URL} ****"
rsync -Pqr --protocol=28 --delete-after --exclude=presentations $DIR/_site/* ${STAGING_LOCATION}
shallow_clean
}
clear_staging() {
echo "**** Removing staging site from http://${STAGING_URL}"
rm -rf _site
mkdir _site
rsync -Pqr --protocol=28 --delete $DIR/_site/ ${STAGING_LOCATION}
}
usage() {
cat << EOF
usage: $0 options
This script publishes the CapeDwarf site, either to sandbox, staging or to production
OPTIONS:
-d Publish *sandbox* version of the site to http://${SANDBOX_URL}
-s Publish staging version of the site to http://${STAGING_URL}
-p Publish production version of the site to http://${PRODUCTION_URL}
-c Clear out all caches
-r Remove the staging version of the site from http://${STAGING_URL} - please do this after using staging
EOF
}
while getopts "spdchr" OPTION
do
case $OPTION in
s)
staging
exit
;;
r)
clear_staging
exit
;;
d)
sandbox
exit
;;
p)
production
exit
;;
c)
deep_clean
exit
;;
h)
usage
exit
;;
[?])
usage
exit
;;
esac
done
usage