#!/bin/bash -e

BLUE='\E[1;34m'
CYAN='\E[1;36m'
YELLOW='\E[1;33m'
GREEN='\E[1;32m'
RESET='\E[0m'

echo -e "${BLUE}❯ ${CYAN}Building Lua ${YELLOW}${LUA_VERSION}...${RESET}"

cd /tmp
wget "http://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz"
tar -xzf lua-${LUA_VERSION}.tar.gz
mv /tmp/lua-${LUA_VERSION} /tmp/lua
cd /tmp/lua

make linux test
# We have to install Lua for the Luarocks build to succeed, it will be installed again when building the final image
make install

echo -e "${BLUE}❯ ${GREEN}Lua build completed${RESET}"

echo -e "${BLUE}❯ ${CYAN}Building Luarocks ${YELLOW}${LUAROCKS_VERSION}...${RESET}"

cd /tmp
wget "http://luarocks.github.io/luarocks/releases/luarocks-${LUAROCKS_VERSION}.tar.gz"
tar -xzf luarocks-${LUAROCKS_VERSION}.tar.gz
mv /tmp/luarocks-${LUAROCKS_VERSION} /tmp/luarocks
cd /tmp/luarocks

./configure
make

echo -e "${BLUE}❯ ${GREEN}Luarocks build completed${RESET}"