Skip to content

Instantly share code, notes, and snippets.

@henriquegogo henriquegogo/luanova.sh
Last active Aug 26, 2019

Embed
What would you like to do?
Install a standalone Lua environment
#!/usr/bin/env sh
# Download this script and run:
# ./luanova.sh $destin_folder
# ($destin_folder is optional)
# THIS SCRIPT BUILD AND INSTALL A STANDALONE LUA AND LUAROCKS PACKAGE
# IF YOU CHANGE THE PATH, PLEASE RUN THIS SCRIPT AGAIN (BECAUSE LUAROCKS ABSOLUTE PATHS)
# FUNCTIONS
clean_old_installation () {
echo "\n########## CLEANING OLD INSTALLATION"
rm -rf $base_path/bin/
rm -rf $base_path/etc/
rm -rf $base_path/include/
rm -rf $base_path/lib/
rm -rf $base_path/man/
rm -rf $base_path/share/
rm -rf $base_path/tmp/
rm -rf $base_path/openresty/
echo "Done"
}
install_lua () {
echo "\n########## INSTALLING LUA $lua_version"
if [ ! -f "/tmp/lua-$lua_version.tar.gz" ]
then
wget http://www.lua.org/ftp/lua-$lua_version\.tar.gz -P /tmp/
fi
mkdir $base_path/tmp
cd $base_path/tmp/
tar -xvf /tmp/lua-$lua_version\.tar.gz
cd lua-$lua_version/
sed -ie 's/\/usr\/local/\./' src/luaconf.h
make $platform install INSTALL_TOP=../../../
echo "Done"
}
install_luarocks () {
echo "\n########## INSTALLING LUAROCKS"
if [ ! -f "/tmp/luarocks-$luarocks_version.tar.gz" ]
then
wget http://luarocks.org/releases/luarocks-$luarocks_version\.tar.gz -P /tmp/
fi
rm -rf $base_path/etc/luarocks/
rm -f $base_path/bin/luarocks*
cd $base_path/tmp/
tar -xvf /tmp/luarocks-$luarocks_version\.tar.gz
cd luarocks-$luarocks_version
./configure --prefix=$base_path --with-lua=$base_path --force-config
make build install
echo "Done"
}
install_luajit () {
echo "\n########## INSTALLING LUAJIT"
if [ ! -f "/tmp/LuaJIT-$luajit_version.tar.gz" ]
then
wget http://luajit.org/download/LuaJIT-$luajit_version\.tar.gz -P /tmp/
fi
rm -f $base_path/bin/luajit*
cd $base_path/tmp/
tar -xvf /tmp/LuaJIT-$luajit_version\.tar.gz
cd LuaJIT-$luajit_version
make PREFIX=.
make install PREFIX=$base_path
echo "Done"
}
install_openresty () {
echo "\n########## INSTALLING OPENRESTY"
if [ ! -f "/tmp/openresty-$openresty_version.tar.gz" ]
then
wget http://openresty.org/download/openresty-$openresty_version\.tar.gz -P /tmp/
fi
cd $base_path/tmp/
tar -xvf /tmp/openresty-$openresty_version\.tar.gz
cd openresty-$openresty_version
./configure --prefix=$base_path/openresty
make
make install
echo "Done"
}
remove_temp_files () {
echo "\n########## REMOVING INSTALLER TEMP FOLDER"
cd $base_path
rm -rf tmp/
echo "Done"
}
update_script () {
echo "\n########## UPDATING SCRIPT"
read -p "Do you want to update this script? (y/N) " answer
if [ "$answer" = "y" ]
then
wget https://gist.githubusercontent.com/henriquegogo/c96cf1728196306360dd/raw -O $script_path._update
if [ -f "$script_path._update" ]
then
mv $script_path._update $script_path
chmod +x $script_path
fi
fi
echo "Done"
}
show_help () {
echo "usage ./luanova.sh [--help] [--luarocks] [--luajit] [--openresty]"
echo " [--no-lua] [--keep-temp] [--skip-update] <path>"
echo
echo "Argument options explanation"
echo " -h, --help this message"
echo " -r, --luarocks install luarocks"
echo " -j, --luajit install luajit"
echo " -o, --openresty install openresty"
echo " -n, --no-lua do not install lua"
echo " -k, --keep-temp do not remove temp installation folder"
echo " -s, --skip-update do not ask to update this script"
echo
echo "http://henriquegogo.github.io"
exit 0
}
# COMMAND LINE OPTIONS
if [ $# = 0 ]
then
show_help
fi
luarocks_will_install=false
luajit_will_install=false
openresty_will_install=false
lua_will_install=true
keep_temp=false
skip_update=false
while [ "$1" != "" ]; do
case $1 in
-h | --help) show_help;;
-r | --luarocks) luarocks_will_install=true;;
-j | --luajit) luajit_will_install=true;;
-o | --openresty) openresty_will_install=true;;
-n | --no-lua) lua_will_install=false;;
-k | --keep-temp) keep_temp=true;;
-s | --skip-update) skip_update=true;;
*) input_path=$1; break;;
esac
shift
done
# VERSIONS AND PATHS
lua_version=5.1.5
luajit_version=2.0.5
luarocks_version=3.1.3
openresty_version=1.15.8.1
platform=linux
base_path=$(pwd)/$input_path
script_path="$( cd "$( dirname "$0" )" && pwd )"/luanova.sh
# RUNNING FUNCTIONS
clean_old_installation
if [ $lua_will_install = true ]; then install_lua; fi
if [ $luarocks_will_install = true ]; then install_luarocks; fi
if [ $luajit_will_install = true ]; then install_luajit; fi
if [ $openresty_will_install = true ]; then install_openresty; fi
if [ $keep_temp = false ]; then remove_temp_files; fi
if [ $skip_update = false ]; then update_script; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.