Last active
September 22, 2018 23:52
-
-
Save virajkanwade/0fe8f73651694d82286b to your computer and use it in GitHub Desktop.
Script to install redis inside virtualenv. Adds a wrapper script redis-server-ve. Downloads stable version by default. Else you can pass the version as an argument.
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 | |
######################################## | |
# AUTHOR: Viraj Kanwade # | |
# http://viraj-workstuff.blogspot.com/ # | |
######################################## | |
# Inspired from https://gist.github.com/pterk/3923177 | |
set -e | |
# set -x | |
VERSION=$1 | |
if [ -z $VERSION ] | |
then | |
VERSION=stable | |
fi | |
ARCHIVE=redis-${VERSION}.tar.gz | |
REDIS_BASE_URL=http://download.redis.io/releases/ | |
if [ -z "${VIRTUAL_ENV}" ] | |
then | |
echo "Please activate a virtualenv first" | |
exit 1 | |
fi | |
pushd /tmp/ | |
if [ ! -f $ARCHIVE ] | |
then | |
{ | |
wget ${REDIS_BASE_URL}${ARCHIVE} | |
} || { | |
curl ${REDIS_BASE_URL}${ARCHIVE} -o $ARCHIVE | |
} || { | |
echo 'Could not find wget or curl' | |
exit 1 | |
} | |
fi | |
DIRNAME=`tar tzf ${ARCHIVE} 2>/dev/null | head -n 1` | |
tar xzf ${ARCHIVE} | |
pushd ${DIRNAME} | |
make PREFIX=${VIRTUAL_ENV} | |
make PREFIX=${VIRTUAL_ENV} install | |
mkdir -p ${VIRTUAL_ENV}/etc/ | |
mkdir -p ${VIRTUAL_ENV}/var/run/ | |
# sed -i 's/daemonize no/daemonize yes/' redis.conf | |
VIRTUAL_ENV_ESC="${VIRTUAL_ENV//\//\\/}" | |
sed -i '' "s/\/var\/run/${VIRTUAL_ENV_ESC}\/var\/run/" redis.conf | |
sed -i '' "s/dir \.\//dir ${VIRTUAL_ENV_ESC}\/var\/run\//" redis.conf | |
cp redis.conf ${VIRTUAL_ENV}/etc/ | |
echo "set -x | |
redis-server ${VIRTUAL_ENV}/etc/redis.conf" > ${VIRTUAL_ENV}/bin/redis-server-ve | |
chmod +x ${VIRTUAL_ENV}/bin/redis-server-ve | |
popd | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment