|
| 1 | +# |
| 2 | +# This is a script containing functions that are used as build rules. You can |
| 3 | +# use the Simple Little Automator (https://github.com/fboender/sla.git) to run |
| 4 | +# these rules, or you can run them directly in your shell: |
| 5 | +# |
| 6 | +# $ bash -c ". build.sla && test" |
| 7 | +# |
| 8 | + |
| 9 | +PROG="ansible-cmdb" |
| 10 | + |
| 11 | +test () { |
| 12 | + # Run tests |
| 13 | + OLD_PWD="$(pwd)" |
| 14 | + cd test && ./test.sh |
| 15 | + cd "$OLD_PWD" |
| 16 | + example/generate.sh |
| 17 | +} |
| 18 | + |
| 19 | +example () { |
| 20 | + # Generate example cmdb |
| 21 | + PYTHONPATH=lib src/ansible-cmdb -q -i example/hosts example/out example/out_custom > cmdb.html |
| 22 | +} |
| 23 | + |
| 24 | +doc () { |
| 25 | + # Generate documentation |
| 26 | + markdown_py README.md > README.html |
| 27 | +} |
| 28 | + |
| 29 | +clean () { |
| 30 | + # Remove build artifacts and other trash |
| 31 | + rm -rf rel_deb |
| 32 | + rm -f README.html |
| 33 | + find ./ -name "*.pyc" -delete |
| 34 | + find ./ -name "__pycache__" -type d -delete |
| 35 | + rm -f example/gen_* |
| 36 | + rm -rf example/cmdb/ |
| 37 | + rm -rf build/ |
| 38 | + rm -rf dist/ |
| 39 | + rm -rf src/ansible_cmdb.egg-info/ |
| 40 | +} |
| 41 | + |
| 42 | +_release_check() { |
| 43 | + # Verify and prepare for release |
| 44 | + |
| 45 | + # Only run this rule once |
| 46 | + if [ -z "$RELEASE_CHECK_DONE" ]; then |
| 47 | + RELEASE_CHECK_DONE=1 |
| 48 | + |
| 49 | + # Prepare project for release |
| 50 | + clean |
| 51 | + doc |
| 52 | + mkdir dist |
| 53 | + |
| 54 | + # Check that REL_VERSION is set |
| 55 | + if [ ! -z "$1" ]; then |
| 56 | + REL_VERSION="$1" |
| 57 | + shift |
| 58 | + else |
| 59 | + echo "REL_VERSION not set. Aborting" >&2 |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + |
| 63 | + echo "$REL_VERSION" > src/ansiblecmdb/data/VERSION |
| 64 | + fi |
| 65 | +} |
| 66 | + |
| 67 | +release_src () { |
| 68 | + # Create release package (source tar.gz) |
| 69 | + _release_check "$*" |
| 70 | + |
| 71 | + # Cleanup. Only on release, since REL_VERSION doesn't exist otherwise |
| 72 | + rm -rf $PROG-$REL_VERSION |
| 73 | + |
| 74 | + # Prepare source |
| 75 | + mkdir $PROG-$REL_VERSION |
| 76 | + cp -a src/* $PROG-$REL_VERSION/ |
| 77 | + cp -r lib/* $PROG-$REL_VERSION/ |
| 78 | + cp LICENSE $PROG-$REL_VERSION/ |
| 79 | + cp README.md $PROG-$REL_VERSION/ |
| 80 | + cp contrib/release_Makefile $PROG-$REL_VERSION/Makefile |
| 81 | + cp contrib/ansible-cmdb.man.1 $PROG-$REL_VERSION/ |
| 82 | + |
| 83 | + # Bump version numbers |
| 84 | + find $PROG-$REL_VERSION/ -type f -print0 | xargs -0 sed -i "s/%%MASTER%%/$REL_VERSION/g" |
| 85 | + |
| 86 | + # Create archives |
| 87 | + zip -q -r dist/$PROG-$REL_VERSION.zip $PROG-$REL_VERSION |
| 88 | + tar -czf dist/$PROG-$REL_VERSION.tar.gz $PROG-$REL_VERSION |
| 89 | + |
| 90 | + # Remove source dir |
| 91 | + rm -rf $PROG-$REL_VERSION |
| 92 | +} |
| 93 | + |
| 94 | +release_deb () { |
| 95 | + # Create release package (debian / ubuntu) |
| 96 | + _release_check "$*" |
| 97 | + |
| 98 | + mkdir -p rel_deb/usr/bin |
| 99 | + mkdir -p rel_deb/usr/lib/${PROG} |
| 100 | + mkdir -p rel_deb/usr/share/doc/$PROG |
| 101 | + mkdir -p rel_deb/usr/share/man/man1 |
| 102 | + |
| 103 | + # Copy the source to the release directory structure. |
| 104 | + cp README.md rel_deb/usr/share/doc/$PROG/ |
| 105 | + cp README.html rel_deb/usr/share/doc/$PROG/ |
| 106 | + cp -r src/* rel_deb/usr/lib/${PROG}/ |
| 107 | + cp -r lib/* rel_deb/usr/lib/${PROG}/ |
| 108 | + ln -s ../lib/$PROG/ansible-cmdb rel_deb/usr/bin/ansible-cmdb |
| 109 | + cp -a contrib/debian/DEBIAN rel_deb/ |
| 110 | + cp contrib/debian/copyright rel_deb/usr/share/doc/$PROG/ |
| 111 | + cp contrib/debian/changelog rel_deb/usr/share/doc/$PROG/ |
| 112 | + gzip -9 rel_deb/usr/share/doc/$PROG/changelog |
| 113 | + cp -a contrib/ansible-cmdb.man.1 rel_deb/usr/share/man/man1/ansible-cmdb.1 |
| 114 | + gzip -9 rel_deb/usr/share/man/man1/ansible-cmdb.1 |
| 115 | + |
| 116 | + # Bump version numbers |
| 117 | + find rel_deb/ -type f -print0 | xargs -0 sed -i "s/%%MASTER%%/$REL_VERSION/g" |
| 118 | + |
| 119 | + # Create debian pacakge |
| 120 | + fakeroot dpkg-deb --build rel_deb > /dev/null |
| 121 | + mv rel_deb.deb dist/$PROG-$REL_VERSION.deb |
| 122 | + |
| 123 | + # Cleanup |
| 124 | + rm -rf rel_deb |
| 125 | + rm -rf $PROG-$REL_VERSION |
| 126 | +} |
| 127 | + |
| 128 | +release_wheel () { |
| 129 | + # Create release package (wheel) |
| 130 | + _release_check "$*" |
| 131 | + |
| 132 | + python setup.py -q bdist_wheel --universal |
| 133 | + rm -rf build |
| 134 | + echo `git rev-parse --abbrev-ref HEAD | tr "[:lower:]" "[:upper:]"` > src/ansiblecmdb/data/VERSION |
| 135 | +} |
| 136 | + |
| 137 | +release () { |
| 138 | + # Create release packages |
| 139 | + release_src "$*" |
| 140 | + release_deb "$*" |
| 141 | + release_wheel "$*" |
| 142 | +} |
| 143 | + |
| 144 | +install () { |
| 145 | + # Install ansible-cmdb |
| 146 | + PREFIX=${PREFIX:-/usr/local} |
| 147 | + umask 0022 && mkdir -p $PREFIX/lib/$PROG |
| 148 | + umask 0022 && mkdir -p $PREFIX/man/man1 |
| 149 | + umask 0022 && cp -a src/* $PREFIX/lib/$PROG |
| 150 | + umask 0022 && cp -r lib/* $PREFIX/lib/$PROG |
| 151 | + umask 0022 && cp LICENSE $PREFIX/lib/$PROG |
| 152 | + umask 0022 && cp README.md $PREFIX/lib/$PROG |
| 153 | + umask 0022 && gzip -9 -c contrib/ansible-cmdb.man.1 > $PREFIX/man/man1/ansible-cmdb.man.1.gz |
| 154 | + if [ -f "$PREFIX/bin/ansible-cmdb" ]; then |
| 155 | + rm "$PREFIX/bin/ansible-cmdb" |
| 156 | + fi |
| 157 | + umask 0022 && ln -s $PREFIX/lib/ansible-cmdb/ansible-cmdb $PREFIX/bin/ansible-cmdb |
| 158 | + echo "Installed in $PREFIX/" |
| 159 | +} |
| 160 | + |
| 161 | +uninstall () { |
| 162 | + # Uninstall ansible-cmdb |
| 163 | + PREFIX=${PREFIX:-/usr/local} |
| 164 | + rm -rf $PREFIX/lib/$PROG |
| 165 | + rm -rf $PREFIX/man/man/ansible-cmdb* |
| 166 | + rm -rf $PREFIX/bin/ansible-cmdb |
| 167 | +} |
0 commit comments