4
# Copyright (C) 2014 Canonical Ltd.
6
# Authors: Nicolas Thomas <nicolas.thomas@canonical.com>
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, version 3 of the License.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
## TODO start from juju-deployer to do the same but more beautifully ..
27
[ -d charmstore/trusty ] || mkdir -p charmstore/trusty
28
[ -d charmstore/precise ] || mkdir -p charmstore/precise
33
### this is THE biggest hack deployer know how to match charmstore to specific version reuse that and turn it into local charms. bonus it is super fast
34
juju-deployer -vbu -c $1 2>&1 | grep "Cache dir" |awk '{print $5}' > $CACHEDIRS
36
## regex to get serie and charm name.
37
grep "charm:" $1 | sed -r 's!.*charm\s*.*.*(trusty|precise)\/(.*)!\1:\2!' > $TMPFILE
38
#normalise if there is " or ' some bundle don't have them
39
sed -ie 's|["'\'']||g' $TMPFILE
40
while IFS=: read serie charm
42
canonicalcharm=`echo $charm | sed -r 's!(.*)-.*[0-9]$!\1!'`
43
CHARMDIR=`grep $serie_$charm $CACHEDIRS`
44
[ -d charmstore/$serie/$charm ] || mkdir -p charmstore/$serie/$charm
45
cp -rf $CHARMDIR/* charmstore/$serie/$charm/
48
## Now create a -local version of the bundle:
49
BASEFILE=`basename $1 .yaml`
50
cat $1 | sed -r 's!(^.*\s)charm:\s*(.*)*(trusty|precise)\/(.*)*"$!\1charm: local:\3/\4!' > ${BASEFILE}-local.yaml
53
export JUJU_REPOSITORY=$ROOTDIR/charmstore
54
juju-deployer -c ${BASEFILE}-local.yaml
56
To use your locally copied charms
57
If your bundle was already using some local charms you will have to copy them in $ROOTDIR/charmstore
66
bundle2local - create a local usable copy of charms and create a local version of the bundle
68
USAGE: bundle2local mybundle.yaml
69
Be sure to have charm-tools installed
70
If already downloaded a pull request will be done.
71
the charmstore will be local to the directory you run the script in.