-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_and_deploy.sh
executable file
·127 lines (111 loc) · 2.44 KB
/
build_and_deploy.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
#!/bin/sh
source config.sh
if [ ! $upload_server ]; then
echo 'upload_server not assigned'
exit 1
fi
if [ ! $upload_user ]; then
echo 'upload_user not assigned'
exit 1
fi
if [ ! $upload_dir ]; then
echo 'upload_dir not assigned'
exit 1
fi
project=cocos-benchmark
distr_files=(cocos2d.js main.js index.html submit.php errno.php rank.php update.php)
rm_files=(lib/phpbrowscap/cache.php)
# DO NOT ADD the last '/'
distr_dirs=(res engines)
distr_lib_dirs=(lib/jqplot lib/jquery lib/phpbrowscap)
root_dir=$(pwd)
archive_dir=$(pwd)/archive
usage()
{
echo "Usage: $0 version"
exit 1
}
check_error()
{
result=$?
if [ $result -ne 0 ]; then
echo error occurred, exit: $result
exit $result
fi
}
create_dir()
{
echo create_dir $1
if [ ! -d $1 ]; then
mkdir $1
check_error;
fi
}
if [ $# -lt 1 ]; then
usage
fi
version=$1
if [[ $compile_target = dev ]]; then
if [[ $version != *dev* ]]; then
echo "invalid dev version: $version"
exit 1
fi
fi
single_file_name=$project-v$version.js
single_file=$root_dir/$single_file_name
version_dir=$archive_dir/v$version
tar_file_name=$project-v$version.tar.gz
tar_file=$archive_dir/$tar_file_name
create_version_dir()
{
create_dir $archive_dir
create_dir $version_dir
}
echo 'start'
create_version_dir
echo 'setting SINGLE_FILE...'
sed -i "" "s/SINGLE_FILE = false/SINGLE_FILE = true/g" cocos2d.js
check_error
echo 'compiling...'
ant $compile_target
if [ $? -ne 0 ]; then
exit $?
fi
echo $single_file
if [ ! -f $single_file ]; then
echo $single_file_name NOT found, check build.xml
exit 1
else
cp -fv $single_file $version_dir/
check_error
# delete the file after archived
rm -f $single_file
fi
for file in ${distr_files[@]}; do
cp -fv $file $version_dir/
check_error
done
for dir in ${distr_dirs[@]}; do
rsync -av --exclude=".*" $dir $version_dir/
check_error
done
for dir in ${distr_lib_dirs[@]}; do
rsync -av --exclude=".*" $dir $version_dir/lib/
check_error
done
rsync -av --exclude=".*" $root_dir/Resources-html5/ $version_dir/
for file in ${rm_files[@]}; do
echo "removing $file..."
rm -rf $version_dir/$file
check_error
done
cd $version_dir
echo "removing hidden file(s)..."
rm -rf .DS_Store
echo packaging...
tar -zcf $tar_file *
echo uploading...
scp $tar_file $upload_user@$upload_server:$upload_dir/
echo deploying...
deploy_cmd="cd $upload_dir; rm -rf `ls | grep -v .tar.gz`; tar -xvf $tar_file_name; ls"
ssh $upload_user@$upload_server $deploy_cmd