Skip to content

Instantly share code, notes, and snippets.

@trinitronx
Created July 18, 2012 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trinitronx/3133046 to your computer and use it in GitHub Desktop.
Save trinitronx/3133046 to your computer and use it in GitHub Desktop.
A simple tarball creation script for packaging bundler apps with a vendor/cache dir
Vcs-Git: https://github.com/TracksApp/tracks.git
Vcs-Browser: https://github.com/TracksApp/tracks
#!/bin/bash
# Copyright 2012 James Cuzella <james.cuzella@lyraphase.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 3 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/>.
#
RESULT_ERROR=32
# Some simple logging and output functions
debug(){
echo -e "DEBUG $1" 1>&2
}
info(){
echo -e "INFO $1" 1>&2
}
warn(){
echo -e "WARN $1" 1>&2
}
error() {
echo -e "ERROR $1" 1>&2
exit $RESULT_ERROR
}
pause()
{
echo "Press enter to continue..."
read -n1 a
}
#=== FUNCTION ================================================================
# NAME: usage
# DESCRIPTION: Display usage of script
# PARAMETERS:
# RETURNS:
#===============================================================================
usage ()
{
echo ""
echo "USAGE: ./mktarball appname version"
echo ""
}
APP_NAME="$1"
APP_VERSION="$2"
APP_ARCHIVE="${APP_NAME}-${APP_VERSION}.tar.bz2"
APP_EXTRACT_DIR="$APP_NAME"
GIT_VERSION_TAG="v${APP_VERSION}"
if [ -z "$APP_VERSION" -o -z "$APP_NAME" ]; then
[ -z "$APP_VERSION" ] && warn "No app version passed."
[ -z "$APP_NAME" ] && warn "No app name passed."
usage
exit $RESULT_ERROR
fi
if [ ! -e "${APP_EXTRACT_DIR}" ]; then
warn "${APP_EXTRACT_DIR} dir not found... Doing checkout from VCS"
[ ! -e "control" ] && error "control file not found... Don't know where to get source from!"
## Sample control file (debian-esqe) like 'debian/control'
#Vcs-Git: https://github.com/TracksApp/tracks.git
#Vcs-Browser: https://github.com/TracksApp/tracks
#
git_url=$(grep -i Vcs-Git control | awk '{ print $2 }')
## TODO: Vcs-Svn support?
[ -z "$git_url" ] && error "Vcs-Git url not found in control file"
git clone $git_url ${APP_EXTRACT_DIR}
fi
(
cd ${APP_EXTRACT_DIR}
git fetch
git co ${GIT_VERSION_TAG} || error "Could not checkout ${APP_NAME} version tag: v${APP_VERSION}"
if [ -e "Gemfile.lock" ]; then
bundle install && bundle package || error "Could not bundle install gems for package..."
sync
fi
# This does not do what we want unless `vendor/cache` is committed to the project repo
#git archive --prefix=${APP_EXTRACT_DIR}/ ${GIT_VERSION_TAG} | bzip2 >../${APP_ARCHIVE} && info "Successfully created tarball: ${APP_ARCHIVE}" || error "Could not create tarball: ${APP_ARCHIVE} FROM ${APP_EXTRACT_DIR}"
)
tar --exclude=.DS_Store --exclude=.git -cjf ${APP_ARCHIVE} ${APP_EXTRACT_DIR} && info "Successfully created tarball: ${APP_ARCHIVE}" || error "Could not create tarball: ${APP_ARCHIVE} FROM ${APP_EXTRACT_DIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment