Skip to content

Instantly share code, notes, and snippets.

@jnwhiteh
Created June 13, 2011 16:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jnwhiteh/1023085 to your computer and use it in GitHub Desktop.
Save jnwhiteh/1023085 to your computer and use it in GitHub Desktop.
lua+luarocks in sandboxed environment
#!/usr/bin/env bash
set -e
die() {
echo "$1";
exit 1;
}
# Fetch and install Lua/LuaRocks/Kepler into the local directory
ROOT=`pwd`
SANDBOX="${ROOT}/sandbox"
TMP_DIR="${ROOT}/sandbox/src"
if [ ! -d "${TMP_DIR}" ]; then mkdir -p "${TMP_DIR}"; fi
pushd "${TMP_DIR}"
PREFIX="${ROOT}"
rm -fr "lua-5.1.4"
wget http://www.lua.org/ftp/lua-5.1.4.tar.gz;
tar -zxf "lua-5.1.4.tar.gz"
pushd lua-5.1.4
# Patch the LUA install to allow LUA_ROOT to be overridden by variable
patch -p0 << ENDPATCH
diff -Naur src_orig/luaconf.h src/luaconf.h
--- src_orig/luaconf.h 2010-05-17 13:30:51.000000000 +0000
+++ src/luaconf.h 2010-05-17 13:31:34.000000000 +0000
@@ -94,9 +94,18 @@
".\\\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
#else
+#ifndef LUA_ROOT
#define LUA_ROOT "/usr/local/"
+#endif
+
+#ifndef LUA_LDIR
#define LUA_LDIR LUA_ROOT "share/lua/5.1/"
+#endif
+
+#ifndef LUA_CDIR
#define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
+#endif
+
#define LUA_PATH_DEFAULT \\
"./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \\
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
ENDPATCH
patch -p0 << ENDPATCH
diff -Naur src.orig/Makefile src/Makefile
--- src.orig/Makefile 2008-03-23 12:28:40.000000000 +0000
+++ src/Makefile 2008-03-23 12:29:07.000000000 +0000
@@ -8,7 +8,7 @@
PLAT= none
CC= gcc
-CFLAGS= -O2 -Wall \$(MYCFLAGS)
+CFLAGS= -O2 -DLUA_ROOT=\"${SANDBOX}/\" -Wall \$(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
ENDPATCH
# Compile and install Lua
case `uname` in
'Linux')
LUA_TARGET="linux"
;;
'Darwin')
LUA_TARGET="macosx"
;;
esac
make ${LUA_TARGET} INSTALL_TOP="${SANDBOX}"
make install INSTALL_TOP="${SANDBOX}"
make clean
# Download and install Luarocks
popd
wget http://luarocks.org/releases/luarocks-2.0.2.tar.gz;
if [ -d "luarocks-2.0.2" ]; then rm -fr luarocks-2.0.2; fi
tar -zxf "luarocks-2.0.2.tar.gz"
pushd luarocks-2.0.2
./configure --with-lua="${SANDBOX}" --prefix="${SANDBOX}" --force-config
make && make install && make clean
popd # Back to tmp
popd # Back to the original directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment