Skip to content

Commit e045478

Browse files
author
Ignasi Barrera
committed
Install Kahuna in a virtualenv
Now Kahuna is installed on a virtual environment to isolate the libraries and dependencies it uses. Also the setup script has been modified to allow to install Kahuna in an existing Jython runtime.
1 parent cc290a4 commit e045478

File tree

3 files changed

+107
-44
lines changed

3 files changed

+107
-44
lines changed

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ You can install Kahuna with the setup script:
2525

2626
git clone git://github.com/nacx/kahuna.git
2727
cd kahuna
28-
sudo sh setup.sh
28+
chmod u+x setup.sh
29+
sudo ./setup.sh
2930

30-
**This will install Jython 2.5.2** on your system and configure it to be used by Kahuna.
31+
By default the setup script will install Jython 2.5.3. on your system. If you already have a
32+
Jython runtime and want to install Kahuna in it, you can execute the setup script as follows:
3133

32-
If you have an existing Jython installation <= 2.5.2, Kahuna won't work. If you
33-
have a newer Jython version and you want to keep it, you can just remove the */opt/jython-2.5.2*
34-
directory and the link that the setup script will create in */usr/local/bin/jython* to
35-
make sure your version will be used. You may also need to manually install the *redis*
36-
egg in your Jython runtime.
34+
sudo ./setup.sh -j /your/jython/install/directory
35+
36+
If you are installing Kahuna in an already existing Jython runtime, you may need to install
37+
**easy_install** and **virtualenv** in it.
3738

3839

3940
Running

kahuna.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
[ -z "$KAHUNA_HOME" ] && export KAHUNA_HOME="/usr/local/lib/kahuna"
4+
35
# Exit code to be used when opening an interactive shell
46
EXIT_OPEN_SHELL=10
57

@@ -13,17 +15,18 @@ fi
1315

1416
# Enter the real directori before performing any operation
1517
cd $BASEDIR
18+
export JYTHONPATH=$BASEDIR
1619

1720
# Ensure the classpath file exist
1821
CPFILE=kahuna/abiquo-jars.pth
1922
! [ -f $CPFILE ] && mvn clean compile -U
2023

2124
# Export the classpath and run the command line script
2225
export CLASSPATH=`cat $CPFILE`
23-
jython kahuna/cli.py $*
26+
${KAHUNA_HOME}/bin/jython kahuna/cli.py $*
2427

2528
# Tricky: If the CLI returns this code, open an interactive shell
2629
if [ $? -eq $EXIT_OPEN_SHELL ]; then
27-
jython
30+
${KAHUNA_HOME}/bin/jython
2831
fi
2932

setup.sh

+94-35
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,97 @@
11
#!/bin/bash
22

3-
JYTHON_VERSION=2.5.2
4-
JYTHON_TARGET=/opt/jython-${JYTHON_VERSION}
5-
6-
echo "Downloading Jython ${JYTHON_VERSION}..."
7-
JYTHON_URL=http://sourceforge.net/projects/jython/files/jython/${JYTHON_VERSION}/jython_installer-${JYTHON_VERSION}.jar/download
8-
JYTHON_TMP=/tmp/jython_installer-${JYTHON_VERSION}.jar
9-
wget -q ${JYTHON_URL} -O ${JYTHON_TMP}
10-
11-
echo "Installing Jython ${JYTHON_VERSION} to ${JYTHON_TARGET}..."
12-
java -jar ${JYTHON_TMP} -s -t standard -d ${JYTHON_TARGET}
13-
ln -s ${JYTHON_TARGET}/jython /usr/local/bin/jython
14-
15-
echo "Addind Easy Install for Jython..."
16-
wget -q http://peak.telecommunity.com/dist/ez_setup.py -O /tmp/ez_setup.py
17-
${JYTHON_TARGET}/jython /tmp/ez_setup.py
18-
19-
echo "Installing Redis egg..."
20-
${JYTHON_TARGET}/bin/easy_install --quiet redis
21-
22-
echo "Installing Kahuna..."
23-
chmod -R 777 ${JYTHON_TARGET}/cachedir
24-
chmod u+x kahuna.sh
25-
ln -s $(pwd)/kahuna.sh /usr/local/bin/kahuna
26-
export JYTHONPATH=$(pwd)
27-
28-
echo "Done!"
29-
echo
30-
echo "To finish the installation, add the following line to the end of your ~/.bashrc:"
31-
echo "export JYTHONPATH=$(pwd)"
32-
echo
33-
echo "Now you are ready to run 'kahuna'. This will print the available commands and copy"
34-
echo "all default configuration to ~/.kahuna/"
35-
echo "Feel free to edit those files to adapt them to your needs."
36-
echo
37-
echo "Have fun!"
3+
JYTHON_VERSION=2.5.3
4+
PREFIX=/usr/local
5+
6+
JYTHON=${PREFIX}/lib/jython-${JYTHON_VERSION}
7+
KAHUNA_VERSION=$(git log -1 --format=format:%h)
8+
KAHUNA=${PREFIX}/lib/kahuna-${KAHUNA_VERSION}
9+
10+
function install_jython() {
11+
echo "Downloading Jython ${JYTHON_VERSION}..."
12+
JYTHON_URL=http://repo1.maven.org/maven2/org/python/jython-installer/${JYTHON_VERSION}/jython-installer-${JYTHON_VERSION}.jar
13+
JYTHON_TMP=/tmp/jython_installer-${JYTHON_VERSION}.jar
14+
wget -q ${JYTHON_URL} -O ${JYTHON_TMP}
15+
16+
echo "Installing Jython ${JYTHON_VERSION} to ${JYTHON}..."
17+
mkdir -p ${PREFIX}/lib
18+
mkdir -p ${PREFIX}/bin
19+
java -jar ${JYTHON_TMP} -s -t standard -d ${JYTHON}
20+
ln -s ${JYTHON}/bin/jython ${PREFIX}/bin/jython
21+
JYTHON_DIR=${JYTHON}
22+
}
23+
24+
function install_packages() {
25+
echo "Adding Easy Install for Jython..."
26+
wget -q http://peak.telecommunity.com/dist/ez_setup.py -O /tmp/ez_setup.py
27+
${JYTHON}/bin/jython /tmp/ez_setup.py
28+
29+
echo "Installing virtualenv..."
30+
${JYTHON}/bin/easy_install --quiet virtualenv
31+
}
32+
33+
function install_kahuna() {
34+
echo "Creating the Kahuna virtual environment..."
35+
36+
if ! [[ -f ${1}/bin/easy_install ]]; then
37+
echo "Missing easy_install. Please install it to continue."
38+
exit 1
39+
fi
40+
if ! [[ -f ${1}/bin/virtualenv ]]; then
41+
echo "Missing virtualenv. Please install it to continue."
42+
exit 1
43+
fi
44+
45+
${1}/bin/virtualenv ${KAHUNA}
46+
47+
echo "Installing Redis egg..."
48+
${KAHUNA}/bin/easy_install --quiet redis
49+
50+
echo "Installing Kahuna..."
51+
chmod -R 777 ${KAHUNA}/cachedir
52+
chmod u+x kahuna.sh
53+
[[ -L ${KAHUNA}/../kahuna ]] && unlink ${KAHUNA}/../kahuna
54+
[[ -L /usr/local/bin/kahuna ]] && unlink /usr/local/bin/kahuna
55+
ln -s ${KAHUNA} ${KAHUNA}/../kahuna
56+
ln -s $(pwd)/kahuna.sh /usr/local/bin/kahuna
57+
}
58+
59+
function print_summary() {
60+
echo "Done!"
61+
echo
62+
echo "To finish the installation, add the following line to the end of your ~/.bashrc:"
63+
echo "export KAHUNA_HOME=${PREFIX}/lib/kahuna"
64+
echo
65+
echo "Now you are ready to run 'kahuna'. This will print the available commands and copy"
66+
echo "all default configuration to ~/.kahuna/"
67+
echo "Feel free to edit those files to adapt them to your needs."
68+
echo
69+
echo "Have fun!"
70+
}
71+
72+
function usage() {
73+
cat << EOF
74+
Usage: ${0} [-j <jython home>]
75+
Options:
76+
-j: If set, Jython will not be installed and Kahuna will use
77+
the provided Jython installation.
78+
EOF
79+
exit 1
80+
}
81+
82+
83+
while getopts "j:" OPT; do
84+
case ${OPT} in
85+
j) JYTHON_DIR=${OPTARG} ;;
86+
?) usage ;;
87+
esac
88+
done
89+
90+
if [[ -z ${JYTHON_DIR} ]]; then
91+
install_jython
92+
install_packages
93+
fi
94+
95+
install_kahuna ${JYTHON_DIR}
96+
print_summary
3897

0 commit comments

Comments
 (0)