Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash -eu
# functions
function showHelp {
cat << EOS
Usage: carthage_hack.sh [bootstrap|update|symlink] [Release|Debug]
EOS
}
function run_carthage {
ACTION=$1
BUILD_CONFIGURATION=$2
# prepare Carthage directory
if [ -L Carthage ]; then
unlink Carthage
fi
trap catchError ERR
function catchError {
echo "Error occurred. Reverting directory."
if [ -e .Carthage ]; then
mv {.,}Carthage
fi
}
# run carthage
carthage ${ACTION} --configuration ${BUILD_CONFIGURATION} --platform ios
# rename output directory to chechsum of Cartfile.resolved
RESOLVED_CHECKSUM=`checksum ${BUILD_CONFIGURATION}`
# create cache directory if not exists
mkdir -p ${CACHE_DIR}/${RESOLVED_CHECKSUM}/Build/iOS
rm -rf ${CACHE_DIR}/${RESOLVED_CHECKSUM}/Build/iOS/*
mv Carthage/Build/iOS/*.framework ${CACHE_DIR}/${RESOLVED_CHECKSUM}/Build/iOS/
rm -rf Carthage
}
function checksum {
BUILD_CONFIGURATION=$1
echo "`shasum -a 256 Cartfile.resolved | awk '{print $1}'`-${BUILD_CONFIGURATION}"
}
function create_symlink {
BUILD_CONFIGURATION=$1
if [ -L Carthage ]; then
unlink Carthage
fi
ln -s ${CACHE_DIR}/`checksum ${BUILD_CONFIGURATION}` Carthage
}
# Global configuration
CACHE_DIR="CarthageCache"
# if $1 = "help", show help
if [ $1 = "help" ]; then
showHelp
exit 0
fi
# validate arguments
ACTION=$1
BUILD_CONFIGURATION=$2
if [ ! ${BUILD_CONFIGURATION} = "Release" ] && [ ! ${BUILD_CONFIGURATION} = "Debug" ]; then
showHelp
exit 1
fi
if [ ${ACTION} = "bootstrap" ] || [ ${ACTION} = "update" ]; then
run_carthage ${ACTION} ${BUILD_CONFIGURATION}
create_symlink ${BUILD_CONFIGURATION}
elif [ ${ACTION} = "symlink" ]; then
create_symlink ${BUILD_CONFIGURATION}
else
showHelp
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment