/
manage.sh
executable file
·238 lines (225 loc) · 6.02 KB
/
manage.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
#!/usr/bin/env bash
# Copyright (c) 2012 - Thomas Spura <thomas.spura@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##################################################
# macros for each kind of buildsystem
CFLAGS="-O2 -pipe -march=native -mtune=native"
# virtualenv.py --no-site-packages --never-download ~/venv/mpcd
# where to install the venv
VENV=~/venv
function configure () {
echo "RUNNING VIRTUAL_ENV CONFIGURE"
./configure $@ --prefix=$VIRTUAL_ENV --enable-optimized
}
##################################################
set -e
function usage {
echo "Usage: `basename $0` cmd [file]"
echo " where cmd is one of:"
echo " * create_env $name"
echo " creates virtualenv \$name at $VENV/\$name"
echo " * clone \$repo_file"
echo " clones all repositories from \$repo_file"
echo " * pull \$folder_with_cloned_repos"
echo " pulls all new changes inside the given folder"
echo " * build \$repo_file"
echo " builds each repository from \$repo_file"
echo " * install \$repo_file"
echo " installs each repository from \$repo_file into $VENV/\$name"
echo " * build \$repo_file"
echo " builds and installs each repository from \$repo_file directly"
echo " directly in one step into $VENV/\$name"
exit 11
}
if [ $# -ne 2 ]
then
usage
fi
function assert_venv {
if [ "x$VIRTUAL_ENV" = 'x' ]; then
echo "Not inside of virtualenv. Aborting..."
exit 7
fi
}
function clone {
echo "Cloning $1 repository into $2"
if ! test -d $4; then
mkdir -p $4
fi
cd $4
if ! test -d $2; then
case $1 in
git )
git clone $3 $2
# TODO submodules?
;;
hg )
hg clone $3 $2
;;
svn )
svn co $3 $2
;;
* )
echo "What kind of repo is $1 ?"
;;
esac
else
echo "$2 already exists. Skipping..."
fi
cd ..
}
function pull {
echo "Pulling inside of $PWD"
if test -d .git; then
git pull
# TODO submodules?
fi
if test -d .hg; then
hg pull && hg update
fi
if test -d .svn; then
svn update
fi
}
function build {
venv=$1
scm=$2
pkg=$3
url=$4
assert_venv
cd $3 || (echo "The package $pkg doesn't seem to be cloned here." && exit 3)
echo "Building $3 inside of $PWD"
if test -e ../$pkg.BUILD; then
echo "Running custom build script from ../$pkg.BUILD"
../$pkg.BUILD
cd ..
return
fi
case $(ls setup.py autogen.sh configure 2>/dev/null) in
*setup.py* )
CFLAGS=$CFLAGS python setup.py build
;;
*autogen.sh* )
CFLAGS=$CFLAGS ./autogen.sh
CFLAGS=$CFLAGS configure
make -j$(getconf _NPROCESSORS_ONLN) VERBOSE=1
;;
*configure* )
CFLAGS=$CFLAGS configure
make -j$(getconf _NPROCESSORS_ONLN) VERBOSE=1
;;
* )
echo "Buildsystem not recognized. Aborting..."
exit 9
esac
cd ..
}
function install {
venv=$1
scm=$2
folder=$3
url=$4
assert_venv
cd $3
echo "Installing inside of $PWD"
if test -e ../$pkg.INSTALL; then
echo "Running custom build script from ../$pkg.INSTALL"
../$pkg.INSTALL
return
fi
case $(ls setup.py autogen.sh configure 2>/dev/null) in
*setup.py* )
python setup.py install
;;
*configure* )
# includes autogen.sh case from build
make install
;;
* )
echo "Buildsystem not recognized. Aborting..."
exit 9
esac
cd ..
assert_venv
}
function create {
# creates venv
# TODO if existent remove first?
if test -d $VENV/$1; then
echo "virtualenv $1 already exists. Aborting..."
exit 8
fi
if test -d ./virtualenv/virtualenv/; then
./virtualenv/virtualenv/virtualenv.py \
--never-download \
--no-site-packages \
$VENV/$1
else
echo "Did you checkout virtualenv repo?"
echo "Are you in the root of clones.git repository?"
echo "Aborting..."
exit 9
fi
}
##################################################
case $1 in
clone )
cat $2 | while read LINE ; do
env=$(echo ${2} | sed 's/.repo//')
clone $LINE $env
done
;;
pull )
env=$(echo ${2} | sed 's/.repo//')
cd $env
for folder in * ; do
cd $folder
pull
cd ..
done
cd ..
;;
build )
env=$(echo ${2} | sed 's/.repo//')
cd $env
cat ../$2 | while read LINE ; do
build $env $LINE
done
cd ..
;;
install )
env=$(echo ${2} | sed 's/.repo//')
cd $env
cat ../$2 | while read LINE ; do
install $env $LINE
done
cd ..
;;
binstall )
env=$(echo ${2} | sed 's/.repo//')
cd $env
cat ../$2 | while read LINE ; do
build $env $LINE
install $env $LINE
done
cd ..
;;
create_env )
create $2
;;
* )
usage
;;
esac