-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload-to-website.sh
executable file
·323 lines (254 loc) · 9.85 KB
/
upload-to-website.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/bin/sh
#*******************************************#
# upload-to-website #
# written by: Scott Biersdorff #
# July 15 2005 #
# #
# Automaticlly upload docbook #
# files to a website #
#*******************************************#
#*******************************************#
#*******************************************#
# #
# Path varibles are define like: #
# des_full = des + dir_name #
# source_full = source + dir_name #
# #
# ALL UPPERCASE varibles are the script's #
# arguments. #
# #
#*******************************************#
#current directory
current_dir=`pwd`
#*******************************************#
# Function: help #
# Arguments: none #
# returns: none #
# #
#DESCRIPTION: print out help page then exits#
# #
#*******************************************#
help()
{
cat <<HELP
upload-to-website -- Automaticlly upload docbook files to a website.
USAGE: upload-to-website [-f [directory name]] [-vh] [source directory] [destination directory]
NOTE: when uploading to a remote directory the destination directory must
be of the form: [user@][host]:[path] (same as scp).
DESCRIPTION: upload-to-website script is designed to easily publish
docbook's xml documents to a web server. this script does the
following:
1.issue 'make html-chunked' on these xml files
2.create aappropriate directory structure
3.place each of the different html pages with the required
images into a separate directories
4. copy all the web-pages to the web server.
if the xml files are structure like this:
/docbook/user-guide/user-guide.xml
/docbook/new/tau/tutorial.xml
and 'upload-to-website -r /docbook web-server.com:/www/docs' is issued
then the resulting directory structure on web-server.com would be:
/www/docs/user-guide/
/www/docs/tutorial/
OPTIONS: -f [directory name] Specifes the name of the destiation directory.
Cannot be used with -r option.
-r Recursivly uploads docbook file to the website. ie. every
subdirectoy of [source directory] called _ -chunked is added
to the website. Cannot be used with -f option.
-h help.
EXAMPLES: publish xml documentation in 'ktau' directory to
'[email protected]:/www/website/documentation'
'upload-to-website ktau [email protected]:/www/website/documentation'
publish all xml documents in '/User/docbook' to 'Sites/docs'
'upload-to-website -r /User/docbook Sites/docs'
BUGS: The docbook html files must be chunked into the directory called,
[source directory]-chunked. This is only true if the $TARGET
varible set in the docbook makefile is set to the same name as the
directory in which it resides. This problem should be solved when
the recursive feature is intergrated.
The script does not produce any useful error messages.
DIAGNOSIS:upload-to-website exit with error number 1 if any errors occurs.
HELP
exit 0
}
#****************************************************#
# #
# Function: recurse #
# Arguments: none #
# Returns: none #
# #
# Calls copy-files and move_file sript on every #
# subdirectoy, with chunked html files, of #
# the specifed source file. #
# #
#****************************************************#
recurse()
{
echo "recursing..."
for DIR in `find $current_dir -type d | grep chunked`;
do
DIR_NAME=`echo $DIR | sed 's/[A-Za-z\/]*\/\([A-Za-z]*\)-chunked/\1/'`
echo "DIR_NAME: $DIR_NAME"
copy_files $DIR $DESTINATION/$DIR_NAME $DIR_NAME
done
move_files $DESTINATION
}
#****************************************************#
# #
# Copy the generated html files to the web host. #
# #
# arguments: source destiation and directory name. #
# #
#****************************************************#
copy_files()
{
#copy file securily to website host.
source=$1
des_full=$2
dir_name=$3
#****************************************************#
# #
# Frist create directory structure on remote host. #
# #
# There are three possiblite formats for the: #
# destination locatation: #
# 1. host:dir #
# 2. dir (local transfer) #
# #
#****************************************************#
#parse destiation by spliting on ':'
str=$(echo $des_full | awk -F, 'BEGIN { FS=":" } { print $1 "\n" $2 }' )
array=($str);
host=${array[0]}
dir=${array[1]}
#*************************************************************
#make temp directory .temp
#*************************************************************
mkdir -p $current_dir/.temp/$dir_name
if [ -n "$host" ] && [ -n "$dir" ] ; then
mkdir -p .temp/$dir
else
mkdir .temp/$DIR_NAME
fi
#*************************************************************
#copy html files
#*************************************************************
for file in `ls $source`
do
#if file needs to be updated.
if [ $source/$file -nt $des/$file ]
then
echo "copy file: $file to: .temp/$dir_name"
arg=`echo $current_dir/.temp/$dir_name/. | sed -e 's_\/\/_\/_g' -e 's_\/-_-_g'`
echo "cp $source/$file $arg"
cp $source/$file $arg
fi
done
#*************************************************************
#copy docbook image files
#*************************************************************
for file in `ls $current_dir/tools/docbook-xsl-1.68.1/images/ | grep *.tiff`
do
#if images need to be updated.
if [ $current_dir/tools/docbook-xsl-1.68.1/images/$file -nt $des/$file ]
then
echo "copy file: $file to: .temp/$dir_name"
arg=`echo $current_dir/.temp/$dir_name/. | sed -e 's_\/\/_\/_g' -e 's_\/-_-_g'`
echo "cp $current_dir/tools/docbook-xsl-1.68.1/images/$file $arg"
cp $current_dir/tools/docbook-xsl-1.68.1/images/$file $arg
fi
done
}
#*************************************************************
#
# Function: move_files
# Arguments: destination directory (can be remote)
# Returns: none
# uses scp to copy files from source to destiation
#
#*************************************************************
move_files()
{
des=$1
#securely copy file from .temp directory to destination directory.
scp -r $current_dir/.temp/* $des/.
#remove temp files
rm -rf $current_dir/.temp
}
#**************************************************************
#begain scripting
#**************************************************************
#if we have less than two arguments print help text.
if [ $# -lt 2 ] ; then
help
fi
#**************************************************************
#parse options
#**************************************************************
while [ -n "$1" ]; do
case $1 in
-r) r=1; shift 1;;
-f) DIR_NAME=$2; shift 2;; # -f takes an argument
-h) help; shift 1;;
--) shift;break;; # end of options
-*) echo "error: no such option $1. -h for help";exit 1;;
*) break;;
esac
done
#**************************************************************
#handle arguments
#**************************************************************
#if -f is not set.
# -f option is set.
if [ -n "$DIR_NAME" ] ; then
#confrim that there are three arguments
if [ $# -lt 2 ] ; then
echo "ERR: option -f requires a thrid argument."
exit 1 #exit with error
fi
#set source and destination varibles.
SOURCE=$1
DESTINATION=$2
else # -f option is not set.
SOURCE=$1
DESTINATION=$2
#defult destination directory name.
DIR_NAME=$SOURCE
fi
#**************************************************************
#check for input errors
#**************************************************************
if [ ! -d "$SOURCE" ]
then
echo "SOUCRE directory not found."
exit 1
fi
#**************************************************************
#debuging output
#**************************************************************
echo "DIR_NAME is = $DIR_NAME"
echo "SOURCE is = $SOURCE"
echo "DESTINATION is = $DESTINATION"
#Makes docbook docuemnets into html.
cd $SOURCE ; make html-chunked ; cd $current_dir
if [ "$r" = "1" ] ; then
recurse
else
#find *-chunked directory
full_source=`find $current_dir/$SOURCE -type d | grep chunked`
#remove ending '/' from source varible. -SB: is there a consistant way to do this?
len=`expr "$SOURCE" : '.*'`
short=`echo $SOURCE | cut -c 1-$len`
full_soucre=`echo $full_source | sed 's_ [^ ]*__g'`
echo $full_source
if [ ! -d "$full_source" ]
then
echo "ERR: cannot find xml files in SOURCE directory."
exit 1
fi
#remove any double '/'. or '/-'
arg=`echo $full_source | sed -e 's_\/\/_\/_g' -e 's_\/-_-_g'`
copy_files $arg $DESTINATION/$DIR_NAME $DIR_NAME
move_files $DESTINATION
fi
exit 0