Created
August 29, 2014 11:18
-
-
Save sitano/501f856938e261617f12 to your computer and use it in GitHub Desktop.
hg, fpm, prm, virtualenv rebuild deb package script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The MIT License (MIT) | |
# Copyright (c) 2014 Ivan Prisyazhniy <john.koepi@gmail.com> | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
cd $(dirname "${BASH_SOURCE[0]}")/.. && server_home_dir="$(pwd)" # && cd - >/dev/null | |
usage="Usage: rebuild [-h?bip] | |
\n\t-b - build debian package | |
\n\t-v - install into vagrant local pool | |
\n\t-p - publish into deb@ pool" | |
PACKAGE_TYPE=deb | |
PACKAGE_DEST="/usr/lib/your-package" | |
PACKAGE_VERSION=1.0.`hg summary -q | head -n 1 | awk '{ print $2 }' | sed 's/:.*//'` | |
PACKAGE_NAME=your-package | |
PACKAGE_URL="http://" | |
PACKAGE_DISTRIBUTION="internal" | |
PACKAGE_VENDOR="Inc." | |
PACKAGE_MAINTAINER="Ivan Prisyazhniy <john.koepi@gmail.com>" | |
PACKAGE_DESCRIPTION="" | |
PACKAGE_CONTROL=( | |
--deb-field "Source: your-project" | |
) | |
vag_repo="/path-to-your-deb-pool" | |
die() { echo "$@" 1>&2 ; exit 1; } | |
if [ ! -x $(which hg) ] | |
then | |
echo 'This tool heavely uses mercurial (hg), so' | |
echo 'check/install tools dependencies with:' | |
echo '-> apt-get install mercurial' | |
exit 1 | |
fi | |
if [ ! -x $(which fpm) ] | |
then | |
echo 'This tool heavely uses FPM ruby gem, so' | |
echo 'check/install tools dependencies with:' | |
echo '-> apt-get install make ruby ruby-dev dpkg-dev' | |
echo '-> gem install fpm' | |
exit 1 | |
fi | |
if [ ! -x $(which prm) ] | |
then | |
echo 'This tool heavely uses PRM ruby gem, so' | |
echo 'check/install tools dependencies with:' | |
echo '-> apt-get install make ruby ruby-dev dpkg-dev' | |
echo '-> gem install prm' | |
exit 1 | |
fi | |
if [ ! -x $(which virtualenv) ] | |
then | |
echo 'This tool heavely uses VIRTUALENV python, so' | |
echo 'check/install tools dependencies with:' | |
echo '-> pip install virtualenv' | |
exit 1 | |
fi | |
function makeDebPackage() { | |
# * Prepare files and build directory | |
TEMPDIR=`mktemp -d --suffix=deb-package --tmpdir=.` || die "Failed to create temp directory" | |
mkdir -p ${TEMPDIR}${PACKAGE_DEST} | |
DISTFILES=`ls . | sed '/.*\.deb/d' | sed '/rebuild.sh/d' | sed '/tmp.*/d'` | |
# * Prepare distibution | |
for FILE in ${DISTFILES}; do | |
cp -r ./${FILE} ${TEMPDIR}${PACKAGE_DEST} | |
done | |
# * Prepare changelog for .changes file | |
( | |
cat <<EOF | |
${PACKAGE_NAME} (${PACKAGE_VERSION}) ${PACKAGE_DISTRIBUTION}; urgency=low | |
`hg log -l 1 | sed -e 's/^\(\w\)/ * \1/g'` | |
-- ${PACKAGE_MAINTAINER} `date -R` | |
EOF | |
) > .changelog | |
# * Prepare distribution | |
virtualenv ${TEMPDIR}${PACKAGE_DEST}/../${PACKAGE_NAME} | |
(source ${TEMPDIR}${PACKAGE_DEST}/bin/activate; | |
pip install redis; | |
pip install protobuf;) | |
rm ./tmp.*deb-package${PACKAGE_DEST}/bin/rebuild.sh > /dev/null 2>&1 | |
rm ./tmp.*deb-package${PACKAGE_DEST}/src/*{-,_}{mw,fb,web}{-,_}* > /dev/null 2>&1 | |
sudo chown -R root:root ./tmp.*deb-package/* | |
# * Pack | |
sudo fpm -f -a all -m "${PACKAGE_MAINTAINER}" --vendor "${PACKAGE_VENDOR}" --url "${PACKAGE_URL}" "${PACKAGE_CONTROL[@]}" --description "${PACKAGE_DESCRIPTION}" --deb-changelog ./.changelog -s dir -t ${PACKAGE_TYPE} -n ${PACKAGE_NAME} -v ${PACKAGE_VERSION} -C ${TEMPDIR} . | |
WHOAMI=`whoami` && sudo chown ${WHOAMI}:${WHOAMI} ${PACKAGE_NAME}*${PACKAGE_VERSION}*.deb | |
# * Clear | |
sudo rm -r ./tmp.*deb-package | |
rm .changelog | |
} | |
function installVagrantPackage() { | |
if [ ! -d ${vag_repo} ] ; then | |
echo "Can't locate vagrant repo: $vag_repo" | |
exit 1 | |
fi | |
PACKAGE_TEMPLATE=`ls ${PACKAGE_NAME}*.${PACKAGE_TYPE} | sort -r | head -n 1` | |
if [ ! -f ${PACKAGE_TEMPLATE} ] ; then | |
echo "Can't locate package: ${PACKAGE_TEMPLATE}" | |
exit 1 | |
fi | |
mkdir -p ${vag_repo}/pool/incoming | |
cp ${PACKAGE_TEMPLATE} ${vag_repo}/pool/incoming/ | |
# Pre clear | |
rm ${vag_repo}/pool/dists/precise/dev/binary-amd64/${PACKAGE_NAME}*.${PACKAGE_TYPE} > /dev/null 2>&1 | |
rm ${vag_repo}/pool/dists/precise/dev/binary-amd64/md5-results/${PACKAGE_NAME}*.${PACKAGE_TYPE} > /dev/null 2>&1 | |
# Pool | |
prm -t deb -p ${vag_repo}/pool -c dev -r precise -a amd64 --gpg -d ${vag_repo}/pool/incoming | |
# Rebuild with i386,amd64 and sign | |
prm -t deb -p ${vag_repo}/pool -c dev -r precise -a amd64,i386 --gpg | |
# Old: $(cd ${vag_repo}/pool; dpkg-scanpackages . /dev/null | gzip -c9 > Packages.gz) | |
} | |
function installPackageIntoDebPool() { | |
PACKAGE_TEMPLATE=`ls ${PACKAGE_NAME}*.${PACKAGE_TYPE} | sort -r | head -n 1` | |
if [ ! -f ${PACKAGE_TEMPLATE} ] ; then | |
echo "Can't locate package: ${PACKAGE_TEMPLATE}" | |
exit 1 | |
fi | |
scp ${PACKAGE_TEMPLATE} deb:~/pool/incoming/dev/ | |
ssh deb ~/pool/publish.sh | |
} | |
function show_help { | |
echo -e $usage | |
exit 0 | |
} | |
while getopts "h?bvp" opt; do | |
case "$opt" in | |
h|\?) | |
show_help | |
exit 0 | |
;; | |
b) makeDebPackage | |
good=1 | |
;; | |
v) installVagrantPackage | |
good=1 | |
;; | |
p) installPackageIntoDebPool | |
good=1 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[ "$1" = "--" ] && shift | |
if [ -z "${good}" ] ; then | |
show_help | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment