~ggouzi/obinstall/obinstall

« back to all changes in this revision

Viewing changes to demos/bin/bundle2local.sh

  • Committer: MMorana
  • Date: 2016-03-24 01:18:40 UTC
  • Revision ID: mass@ubuntu.com-20160324011840-blxydmf7ca4ggle0
Splitting out demos from install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
#   bundle2local
4
 
#    Copyright (C) 2014 Canonical Ltd.
5
 
#
6
 
#    Authors:         Nicolas Thomas <nicolas.thomas@canonical.com>
7
 
#  
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.
11
 
#
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.
16
 
#
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/>.
19
 
 
20
 
## TODO start from juju-deployer to do the same but more beautifully .. 
21
 
set -ex
22
 
 
23
 
 
24
 
bundle2local()
25
 
{
26
 
 
27
 
[ -d charmstore/trusty ] || mkdir -p charmstore/trusty
28
 
[ -d charmstore/precise ] || mkdir -p charmstore/precise
29
 
TMPFILE=`mktemp`
30
 
CACHEDIRS=`mktemp`
31
 
ROOTDIR=$PWD
32
 
 
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
35
 
 
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
41
 
do           
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/ 
46
 
cd $ROOTDIR
47
 
done <$TMPFILE
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
51
 
cat <<EOF
52
 
You can now do:
53
 
export JUJU_REPOSITORY=$ROOTDIR/charmstore
54
 
juju-deployer -c ${BASEFILE}-local.yaml
55
 
 
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
58
 
EOF
59
 
 
60
 
}
61
 
 
62
 
usage()
63
 
{
64
 
cat << EOF
65
 
 
66
 
bundle2local - create a local usable copy of charms and create a local version of the bundle
67
 
 
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.
72
 
EOF
73
 
exit 0
74
 
}
75
 
 
76
 
 
77
 
[ $# -lt 1 ] && usage
78
 
[ -f $1 ] || usage
79
 
BUNDLE=$1
80
 
 
81
 
bundle2local $1
82