Created
July 18, 2013 02:01
-
-
Save jamesstout/6026155 to your computer and use it in GitHub Desktop.
Get build dependencies for ImageAlpha
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
#!/usr/bin/env bash | |
#set -o nounset | |
source ./utils.sh | |
ZLIB_VERSION=1.2.8 | |
ZLIB_URL=http://prdownloads.sourceforge.net/libpng/zlib-$ZLIB_VERSION.tar.gz?download | |
ZLIB_DIR=zlib | |
cd .. | |
if ! dir_exists "$ZLIB_DIR" ; then | |
echo "$ZLIB_DIR dir does NOT exist, creating" | |
if ! $(mkdir "$ZLIB_DIR" 2> /dev/null); then | |
echo "ERROR Cannot create $ZLIB_DIR cannot continue" | |
exit 1 | |
fi | |
fi | |
echo "curling...zlib" | |
curl -sL "$ZLIB_URL" -o "$ZLIB_DIR.tar.gz" | |
RC=$? | |
if [ $RC -ne 0 ]; | |
then | |
echo "ERROR curling" | |
exit | |
else | |
echo "all good, extract" | |
gnutar xzf "$ZLIB_DIR.tar.gz" -C "$ZLIB_DIR" --strip-components 1 | |
## errr check | |
cd "$ZLIB_DIR" | |
make distclean | |
./configure | |
make | |
cd .. | |
fi | |
LIBPNG_VERSION=1.6.2 | |
LIBPNG_URL=http://prdownloads.sourceforge.net/libpng/libpng-$LIBPNG_VERSION.tar.gz?download | |
PNGLIB_DIR=libpng | |
if ! dir_exists "$PNGLIB_DIR" ; then | |
echo "$PNGLIB_DIR dir does NOT exist, creating" | |
if ! $(mkdir "$PNGLIB_DIR" 2> /dev/null); then | |
echo "ERROR Cannot create $PNGLIB_DIR cannot continue" | |
exit 1 | |
fi | |
fi | |
echo "curling...libpng" | |
curl -sL "$LIBPNG_URL" -o "$PNGLIB_DIR.tar.gz" | |
RC=$? | |
if [ $RC -ne 0 ]; | |
then | |
echo "ERROR curling" | |
exit | |
else | |
echo "all good, extract" | |
gnutar xzf "$PNGLIB_DIR.tar.gz" -C "$PNGLIB_DIR" --strip-components 1 | |
## errr check | |
cd "$PNGLIB_DIR" | |
# ZLIBLIB=/Users/james/Projects/Github/ImageAlpha-my-fork/zlib export ZLIBLIB | |
# ZLIBINC=/Users/james/Projects/Github/ImageAlpha-my-fork/zlib export ZLIBINC | |
# CPPFLAGS="-I$ZLIBINC" export CPPFLAGS | |
# LDFLAGS="-L$ZLIBLIB" export LDFLAGS | |
# LD_LIBRARY_PATH="$ZLIBLIB:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH | |
./configure --prefix="$PWD" | |
make #check | |
make install | |
cd .. | |
fi | |
PNGQUANT_REPO=https://github.com/pornel/improved-pngquant.git | |
PNGQUANT_DIR=improved-pngquant | |
if dir_exists "$PNGQUANT_DIR" ; then | |
cd "$PNGQUANT_DIR" | |
# check is git repo | |
if ! is_git_repo ; then | |
echo "NOT a git repo, initialising..." | |
$(git_init_repo "$PNGQUANT_REPO") # error check | |
echo "$PNGQUANT_DIR git repo cloned to $PNGQUANT_DIR" | |
else | |
# if main repo remote, regardless of branch, with changes | |
# - leave as is | |
# if main repo remote and local branch | |
# - leave as is | |
# if forked repo | |
# - leave as is | |
if (! is_main_git_repo "$PNGQUANT_REPO" ); then | |
echo "NOT main repo remote - forked - no action" | |
# do nothing | |
fi | |
if (! git_no_changes ); then | |
echo "repo has changes - stashing" | |
git stash | |
# do nothing | |
fi | |
if (! is_master_branch ); then | |
echo "NOT master branch - no action" | |
fi | |
# if main repo remote, master branch, with no changes | |
if (is_main_git_repo "$PNGQUANT_REPO") && (is_master_branch) ; | |
then | |
echo "main repo remote, master branch, with no changes" | |
echo "Pull down the latest changes" | |
echo "git pull -q --rebase origin master" | |
git pull -q --rebase origin master | |
echo "Done" | |
fi | |
fi | |
else | |
echo "$PNGQUANT_DIR dir does NOT exist, creating" | |
if ! $(mkdir "$PNGQUANT_DIR" 2> /dev/null); then | |
echo "ERROR Cannot create $PNGQUANT_DIR cannot continue" | |
exit 1 | |
else | |
cd "$PNGQUANT_DIR" | |
git_init_repo "$PNGQUANT_REPO" | |
RC=$? | |
if [ $RC -ne 0 ]; | |
then | |
echo "ERROR Could not clone $PNGQUANT_DIR git repo" | |
exit 1 | |
else | |
echo "$PNGQUANT_DIR git repo cloned." | |
fi | |
fi | |
fi | |
pwd | |
echo "building....improved-pngquant" | |
make clean | |
make | |
cd .. | |
PNGNQ_VERSION=2.0.1 | |
PNGNQ_URL=http://sourceforge.net/projects/pngnqs9/files/pngnq-s9-$PNGNQ_VERSION.tar.gz/download | |
PNGNQ_DIR=pngnq | |
if ! dir_exists "$PNGNQ_DIR" ; then | |
echo "$PNGNQ_DIR dir does NOT exist, creating" | |
if ! $(mkdir "$PNGNQ_DIR" 2> /dev/null); then | |
echo "ERROR Cannot create $PNGNQ_DIR cannot continue" | |
exit 1 | |
fi | |
fi | |
echo "curling...pngnq" | |
curl -sL "$PNGNQ_URL" -o "$PNGNQ_DIR.tar.gz" | |
RC=$? | |
if [ $RC -ne 0 ]; | |
then | |
echo "ERROR curling" | |
exit | |
else | |
echo "all good, extract" | |
gnutar xzf "$PNGNQ_DIR.tar.gz" -C "$PNGNQ_DIR" --strip-components 2 | |
## errr check | |
cd "$PNGNQ_DIR" | |
make distclean | |
./configure | |
make | |
cd .. | |
fi | |
pwd | |
POSTERIZER_REPO=https://github.com/pornel/mediancut-posterizer.git | |
POSTERIZER_DIR=posterizer | |
if dir_exists "$POSTERIZER_DIR" ; then | |
cd "$POSTERIZER_DIR" | |
pwd | |
# check is git repo | |
if ! is_git_repo ; then | |
echo "NOT a git repo, initialising..." | |
$(git_init_repo "$POSTERIZER_REPO") # error check | |
echo "$POSTERIZER_DIR git repo cloned to $POSTERIZER_DIR" | |
else | |
# if main repo remote, regardless of branch, with changes | |
# - leave as is | |
# if main repo remote and local branch | |
# - leave as is | |
# if forked repo | |
# - leave as is | |
if (! is_main_git_repo "$POSTERIZER_REPO" ); then | |
echo "NOT main repo remote - forked - no action" | |
# do nothing | |
fi | |
if (! git_no_changes ); then | |
echo "repo has changes - stashing" | |
git stash | |
# do nothing | |
fi | |
if (! is_master_branch ); then | |
echo "NOT master branch - no action" | |
fi | |
# if main repo remote, master branch, with no changes | |
if (is_main_git_repo "$POSTERIZER_REPO") && (is_master_branch) ; | |
then | |
echo "main repo remote, master branch, with no changes" | |
echo "Pull down the latest changes" | |
echo "git pull -q --rebase origin master" | |
git pull -q --rebase origin master | |
echo "Done" | |
fi | |
fi | |
else | |
echo "$POSTERIZER_DIR dir does NOT exist, creating" | |
if ! $(mkdir "$POSTERIZER_DIR" 2> /dev/null); then | |
echo "ERROR Cannot create $POSTERIZER_DIR cannot continue" | |
exit 1 | |
else | |
cd "$POSTERIZER_DIR" | |
git_init_repo "$POSTERIZER_REPO" | |
RC=$? | |
if [ $RC -ne 0 ]; | |
then | |
echo "ERROR Could not clone $POSTERIZER_DIR git repo" | |
exit 1 | |
else | |
echo "$POSTERIZER_DIR git repo cloned." | |
fi | |
fi | |
fi | |
pwd | |
echo "building....posterizer" | |
make | |
cd .. | |
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
#!/usr/bin/env bash | |
# Header logging | |
e_header() { | |
printf "\n$(tput setaf 7)%s$(tput sgr0)\n" "$@" | |
} | |
# debug logging | |
e_debug() { | |
printf "$(tput setaf 2)%s$(tput sgr0)\n" "$@" | |
} | |
# Success logging | |
e_success() { | |
printf "$(tput setaf 64)✓ %s$(tput sgr0)\n" "$@" | |
} | |
# Error logging | |
e_error() { | |
printf "$(tput setaf 1)x %s$(tput sgr0)\n" "$@" | |
} | |
# Warning logging | |
e_warning() { | |
printf "$(tput setaf 136)! %s$(tput sgr0)\n" "$@" | |
} | |
# Ask for confirmation before proceeding | |
seek_confirmation() { | |
printf "\n" | |
e_warning "$@" | |
read -p "Continue? (y/n) " -n 1 | |
printf "\n" | |
} | |
# Test whether the result of an 'ask' is a confirmation | |
is_confirmed() { | |
if [[ "$REPLY" =~ ^[Yy]$ ]]; then | |
return 0 | |
fi | |
return 1 | |
} | |
type_exists() { | |
if [ $(type -P $1) ]; then | |
return 0 | |
fi | |
return 1 | |
} | |
dir_exists() { | |
if [ -d "$1" ]; then | |
return 0 | |
fi | |
return 1 | |
} | |
file_exists() { | |
if [ -e "$1" ]; then | |
return 0 | |
fi | |
return 1 | |
} | |
is_git_repo() { | |
$(git rev-parse --is-inside-work-tree &> /dev/null) | |
} | |
get_git_branch() { | |
local branch_name | |
# Get the short symbolic ref | |
branch_name=$(git symbolic-ref --quiet --short HEAD 2> /dev/null) || | |
# If HEAD isn't a symbolic ref, get the short SHA | |
branch_name=$(git rev-parse --short HEAD 2> /dev/null) || | |
# Otherwise, just give up | |
branch_name="(unknown)" | |
printf $branch_name | |
} | |
is_master_branch(){ | |
local branch=$(get_git_branch) | |
if [ "$branch" = "master" ]; then | |
return 0 | |
fi | |
return 1 | |
} | |
is_main_git_repo() { | |
local main_git_repo="$1" | |
local remote_origin_url=$(git config --get remote.origin.url) | |
if [[ "$remote_origin_url" == "$main_git_repo"* ]]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Git status information | |
git_status() { | |
local git_state uc us ut st | |
git update-index --really-refresh -q &>/dev/null | |
# Check for uncommitted changes in the index | |
if ! $(git diff --quiet --ignore-submodules --cached); then | |
uc="+" | |
fi | |
# Check for unstaged changes | |
if ! $(git diff-files --quiet --ignore-submodules --); then | |
us="!" | |
fi | |
# Check for untracked files | |
if [ -n "$(git ls-files --others --exclude-standard)" ]; then | |
ut="?" | |
fi | |
# Check for stashed files | |
if $(git rev-parse --verify refs/stash &>/dev/null); then | |
st="$" | |
fi | |
git_state=$uc$us$ut$st | |
#git_state="" | |
echo $git_state | |
} | |
# Git status information | |
git_no_changes() { | |
local git_state=$(git_status) | |
if [ "$git_state" = "" ]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# must be in th dir,and takes a URL | |
git_init_repo() { | |
if [ $# -eq 0 ] | |
then | |
alf_error "Repo URL param required" | |
return 99 | |
fi | |
main_git_repo="$1" | |
check_url "$main_git_repo" | |
RC=$? | |
if [ $RC -eq 0 ] | |
then | |
git init -q | |
git remote add origin $main_git_repo | |
git fetch -q origin master | |
# Reset the index and working tree to the fetched HEAD | |
git reset -q --hard FETCH_HEAD | |
# Remove any untracked files | |
#git clean -fd | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# check check to see if the URl exists | |
# retCodes: | |
# 99 - missing param | |
# 88 - problem with URL | |
# 0 - all good | |
function check_url(){ | |
if [ $# -eq 0 ] | |
then | |
e_error "URL param required" | |
return 99 | |
fi | |
url="$1" | |
# curl comes with OS X right? | |
# curl params: fsLI | |
# f = Fail silently | |
# s = Silent or quiet mode | |
# L = Follow redirects | |
# I = Fetch the HTTP-header only - we just want to see the url exists | |
if type_exists "curl"; then | |
#e_debug "using curl" | |
curl -fsLI -o "/dev/null" "$url" | |
RC=$? | |
if [ $RC -ne 0 ] | |
then | |
OUTPUT="$url Unavailable, please check" | |
e_error "$OUTPUT" | |
#echo "ERROR $OUTPUT" | |
return 1 | |
else | |
return 0 | |
fi | |
elif type_exists "cURL"; then | |
#e_debug "using cURL" | |
cURL -fsLI -o "/dev/null" "$url" | |
RC=$? | |
if [ $RC -ne 0 ] ; then | |
OUTPUT="$url Unavailable, please check" | |
e_error "$OUTPUT" | |
#echo "ERROR $OUTPUT" | |
return 1 | |
else | |
return 0 | |
fi | |
elif type_exists "wget"; then # not sure wget comes as standard but we'll try it anyway: -q = quiet, -S headers only | |
#e_debug "using wget"; | |
wget -S -q "$url" 2>/dev/null | |
RC=$? | |
if [ $RC -ne 0 ] ; then | |
OUTPUT="$url Unavailable, please check" | |
e_error "$OUTPUT" | |
#echo "ERROR $OUTPUT" | |
return 1 | |
else | |
return 0 | |
fi | |
fi | |
} | |
# code dupe... needs more error checking | |
# retCodes: | |
# 99 - missing param | |
# 88 - problem with URL | |
# 0 - all good | |
function get_url(){ | |
if [ $# -eq 0 ] || [ $# -ne 2 ] | |
then | |
e_error "URL and FILE params required" | |
return 99 | |
fi | |
url="$1" | |
file="$2" | |
# curl comes with OS X right? | |
# curl params: sL | |
# f = Fail silently -- nooo | |
# s = Silent or quiet mode | |
# L = Follow redirects | |
if type_exists "curl"; then | |
e_debug "using curl" | |
curl -sL -o "$file" "$url" | |
RC=$? | |
if [ $RC -ne 0 ] | |
then | |
OUTPUT="$url Unavailable, please check" | |
e_error "$OUTPUT" | |
#echo "ERROR $OUTPUT" | |
return 1 | |
else | |
return 0 | |
fi | |
elif type_exists "cURL"; then | |
#e_debug "using cURL" | |
cURL -sL -o "$file" "$url" | |
RC=$? | |
if [ $RC -ne 0 ] ; then | |
OUTPUT="$url Unavailable, please check" | |
e_error "$OUTPUT" | |
#echo "ERROR $OUTPUT" | |
return 1 | |
else | |
return 0 | |
fi | |
elif type_exists "wget"; then # not sure wget comes as standard but we'll try it anyway: -q = quiet, -S headers only | |
e_debug "using wget"; | |
wget -O "$file" "$url" | |
RC=$? | |
if [ $RC -ne 0 ] ; then | |
OUTPUT="$url Unavailable, please check" | |
e_error "$OUTPUT" | |
#echo "ERROR $OUTPUT" | |
return 1 | |
else | |
return 0 | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment