diff --git a/luaver b/luaver index c232aad..c57f350 100755 --- a/luaver +++ b/luaver @@ -8,6 +8,19 @@ __luaver_VERSION="1.0.0" +alias cd=" echo $LINENO; exit 1" +alias command=" echo $LINENO; exit 1" +alias printf=" echo $LINENO; exit 1" + +curl() { echo $LINENO; exit 1; } +grep() { echo $LINENO; exit 1; } +make() { echo $LINENO; exit 1; } +mkdir() { echo $LINENO; exit 1; } +rm() { echo $LINENO; exit 1; } +sed() { echo $LINENO; exit 1; } +tar() { echo $LINENO; exit 1; } +wget() { echo $LINENO; exit 1; } + # Directories and files to be used __luaver_LUAVER_DIR="${HOME}/.luaver" # The luaver directory @@ -28,7 +41,7 @@ __luaver_verbose=0 # Error handling function __luaver_error() { - printf "%s\n" "${1}" 1>&2 + 'printf' "%s\n" "${1}" 1>&2 } # Printing bold text - TODO @@ -36,16 +49,16 @@ __luaver_print() { if [ ! $__luaver_verbose = 0 ] then - tput bold - printf "==> %s\n" "${1}" - tput sgr0 + 'command' tput bold + 'printf' "==> %s\n" "${1}" + 'command' tput sgr0 fi } # Printing formatted text __luaver_print_formatted() { - printf "%s\n" "${1}" + 'printf' "%s\n" "${1}" } # A wrapper function to execute commands on the terminal and exit on error @@ -63,27 +76,27 @@ __luaver_init() { if [ ! -e "${__luaver_LUAVER_DIR}" ] then - 'mkdir' "${__luaver_LUAVER_DIR}" + 'command' mkdir "${__luaver_LUAVER_DIR}" fi if [ ! -e "${__luaver_SRC_DIR}" ] then - 'mkdir' "${__luaver_SRC_DIR}" + 'command' mkdir "${__luaver_SRC_DIR}" fi if [ ! -e "${__luaver_LUA_DIR}" ] then - 'mkdir' "${__luaver_LUA_DIR}" + 'command' mkdir "${__luaver_LUA_DIR}" fi if [ ! -e "${__luaver_LUAJIT_DIR}" ] then - 'mkdir' "${__luaver_LUAJIT_DIR}" + 'command' mkdir "${__luaver_LUAJIT_DIR}" fi if [ ! -e "${__luaver_LUAROCKS_DIR}" ] then - 'mkdir' "${__luaver_LUAROCKS_DIR}" + 'command' mkdir "${__luaver_LUAROCKS_DIR}" fi if [ -f "${__luaver_LUA_DEFAULT_FILE}" ] @@ -114,7 +127,7 @@ __luaver_init() # Synopsis: # __luaver_download url [archive_path] # Exit status: -# 0 if already exists or successfully downloaded +# 0 if al'read'y exists or successfully downloaded # 1 if any error is occurred __luaver_download() { @@ -125,18 +138,18 @@ __luaver_download() __luaver_print "Downloading from ${url}" if { - if 'curl' -V >/dev/null 2>&1 + if 'command' curl -V >/dev/null 2>&1 then - 'curl' -fsSL "${url}" # cURL + 'command' curl -fsSL "${url}" # cURL else - 'wget' -qO- "${url}" # GNU wget or busybox + 'command' wget -qO- "${url}" # GNU wget or busybox fi } >"${archive_path}" then __luaver_print "Download successful" return 0 else - rm -f "${archive_path}" + 'command' rm -f "${archive_path}" __luaver_error "'wget' or 'curl' must be installed" return 1 fi @@ -146,7 +159,7 @@ __luaver_download() # Synopsis: # __luaver_unpack url unpack_dir_name [basedir] # Exit status: -# 0 if already exists or successfully unpacked +# 0 if al'read'y exists or successfully unpacked # 1 if any error is occurred __luaver_unpack() { @@ -157,12 +170,12 @@ __luaver_unpack() [ -e "${basedir}/${unpack_dir_name}" ] && return 0 __luaver_print "Unpacking ${url}" - if 'tar' -xzf "${url}" -C "${basedir}" # GNU tar, BSD tar or busybox + if 'command' tar -xzf "${url}" -C "${basedir}" # GNU tar, BSD tar or busybox then __luaver_print "Unpack successful" return 0 else - rm -rf "${basedir:?}/${unpack_dir_name}" + 'command' rm -rf "${basedir:?}/${unpack_dir_name}" __luaver_error "'tar' must be installed" return 1 fi @@ -174,7 +187,7 @@ __luaver_remove_previous_paths() local prefix=$1 local new_path - new_path=$(echo "${PATH}" | sed \ + new_path=$('echo' "${PATH}" | 'command' sed \ -e "s#${prefix}/[^/]*/bin[^:]*:##g" \ -e "s#:${prefix}/[^/]*/bin[^:]*##g" \ -e "s#${prefix}/[^/]*/bin[^:]*##g") @@ -208,7 +221,7 @@ __luaver_uninstall() return 1 fi - 'rm' -r "${package_path:?}/${package_dir}" && __luaver_print "Successfully uninstalled ${package_name}" + 'command' rm -r "${package_path:?}/${package_dir}" && __luaver_print "Successfully uninstalled ${package_name}" } # Returns the platform# Returns the platform @@ -239,8 +252,8 @@ __luaver_get_platform() # 1 if lua was not found __luaver_get_current_lua_version() { - case "$(command -v lua)" in - "${__luaver_LUA_DIR}"/*/bin/lua ) command -v lua | 'awk' -F/ '{ print $(NF-2) }' ;; + case "$('command' -v lua)" in + "${__luaver_LUA_DIR}"/*/bin/lua ) 'command' -v lua | 'command' awk -F/ '{ print $(NF-2) }' ;; * ) return 1 esac } @@ -253,7 +266,7 @@ __luaver_get_current_lua_version() # 1 if lua was not found __luaver_get_current_lua_version_short() { - __luaver_get_current_lua_version | 'awk' -F. -vOFS=. '{ print $1, $2 }' + __luaver_get_current_lua_version | 'command' awk -F. -vOFS=. '{ print $1, $2 }' } # Returns the current luajit version @@ -265,7 +278,7 @@ __luaver_get_current_lua_version_short() __luaver_get_current_luajit_version() { case "$(command -v luajit)" in - "${__luaver_LUAJIT_DIR}"/*/bin/luajit ) command -v luajit | 'awk' -F/ '{ print $(NF-2) }' ;; + "${__luaver_LUAJIT_DIR}"/*/bin/luajit ) 'command' -v luajit | 'command' awk -F/ '{ print $(NF-2) }' ;; * ) return 1 esac } @@ -278,8 +291,8 @@ __luaver_get_current_luajit_version() # 1 if luarocks was not found __luaver_get_current_luarocks_version() { - case "$(command -v luarocks)" in - "${__luaver_LUAROCKS_DIR}"/*/bin/luarocks ) command -v luarocks | 'awk' -F/ '{ print $(NF-2) }' | 'awk' -F_ '{ print $1 }';; + case "$('command' -v luarocks)" in + "${__luaver_LUAROCKS_DIR}"/*/bin/luarocks ) 'command' -v luarocks | 'command' awk -F/ '{ print $(NF-2) }' | 'command' awk -F_ '{ print $1 }';; * ) return 1 esac } @@ -292,8 +305,8 @@ __luaver_get_current_luarocks_version() # 1 if luarocks was not found __luaver_get_lua_version_by_current_luarocks() { - case "$(command -v luarocks)" in - "${__luaver_LUAROCKS_DIR}"/*/bin/luarocks ) command -v luarocks | 'awk' -F/ '{ print $(NF-2) }' | 'awk' -F_ '{ print $2 }';; + case "$('command' -v luarocks)" in + "${__luaver_LUAROCKS_DIR}"/*/bin/luarocks ) 'command' -v luarocks | 'command' awk -F/ '{ print $(NF-2) }' | 'command' awk -F_ '{ print $2 }';; * ) return 1 esac } @@ -362,11 +375,11 @@ __luaver_install_lua() if ( __luaver_print "Compiling ${lua_dir_name}" 'cd' "${__luaver_SRC_DIR}/${lua_dir_name}" && - 'make' "$(__luaver_get_platform || echo "posix")" install INSTALL_TOP="${__luaver_LUA_DIR}/${version}" + 'command' make "$(__luaver_get_platform || 'echo' "posix")" install INSTALL_TOP="${__luaver_LUA_DIR}/${version}" ) then __luaver_print "${lua_dir_name} successfully installed. Do you want to switch to this version? [Y/n]: " - read -r choice + 'read' -r choice case $choice in [yY][eE][sS] | [yY] ) __luaver_use_lua "${version}" @@ -396,7 +409,7 @@ __luaver_use_lua() if [ ! -e "${__luaver_LUA_DIR}/${version}" ] then __luaver_print "${lua_name} is not installed. Want to install it? [Y/n]: " - read -r choice + 'read' -r choice case $choice in [yY][eE][sS] | [yY] ) __luaver_install_lua "${version}" @@ -436,7 +449,7 @@ __luaver_set_default_lua() __luaver_unset_default_lua() { - 'rm' "${__luaver_LUA_DEFAULT_FILE}" && + 'command' rm "${__luaver_LUA_DEFAULT_FILE}" && __luaver_print "Removed default version for lua" } @@ -464,7 +477,7 @@ __luaver_uninstall_lua() __luaver_list_lua() { __luaver_print "Installed versions: (currently $(__luaver_get_current_lua_version || echo none))" - 'find' "${__luaver_LUA_DIR}" -name '*.*' -prune | 'awk' -F/ '{ print $NF }' + 'command' find "${__luaver_LUA_DIR}" -name '*.*' -prune | 'command' awk -F/ '{ print $NF }' } # Synopsis: @@ -486,12 +499,12 @@ __luaver_install_luajit() if ( __luaver_print "Compiling ${lua_dir_name}" 'cd' "${__luaver_LUAJIT_DIR}/${lua_dir_name}" && - 'make' PREFIX="${__luaver_LUAJIT_DIR}/${version}" && - 'make' install PREFIX="${__luaver_LUAJIT_DIR}/${version}" + 'command' make PREFIX="${__luaver_LUAJIT_DIR}/${version}" && + 'command' make install PREFIX="${__luaver_LUAJIT_DIR}/${version}" ) then __luaver_print "${lua_dir_name} successfully installed. Do you want to switch to this version? [Y/n]: " - read -r choice + 'read' -r choice case $choice in [yY][eE][sS] | [yY] ) __luaver_use_luajit "${version}" @@ -520,7 +533,7 @@ __luaver_use_luajit() if [ ! -e "${__luaver_LUAJIT_DIR}/${version}" ] then __luaver_print "${luajit_name} is not installed. Want to install it? [Y/n]: " - read -r choice + 'read' -r choice case $choice in [yY][eE][sS] | [yY] ) __luaver_install_lua "${version}" @@ -546,7 +559,7 @@ __luaver_set_default_luajit() __luaver_unset_default_luajit() { - 'rm' "${__luaver_LUAJIT_DEFAULT_FILE}" && + 'command' rm "${__luaver_LUAJIT_DEFAULT_FILE}" && __luaver_print "Removed default version for LuaJIT" } @@ -574,7 +587,7 @@ __luaver_uninstall_luajit() __luaver_list_luajit() { __luaver_print "Installed versions: (currently $(__luaver_get_current_luajit_version || echo none))" - 'find' "${__luaver_LUAJIT_DIR}" -name '*.*' -prune | 'awk' -F/ '{ print $NF }' + 'command' find "${__luaver_LUAJIT_DIR}" -name '*.*' -prune | 'command' awk -F/ '{ print $NF }' } # Synopsis: @@ -603,19 +616,19 @@ __luaver_install_luarocks() if ( __luaver_print "Compiling ${luarocks_dir_name}" 'cd' "${__luaver_SRC_DIR}/${luarocks_dir_name}" && - './configure' \ + ./configure \ --prefix="${__luaver_LUAROCKS_DIR}/${version}_$(__luaver_get_current_lua_version_short)" \ --with-lua="${__luaver_LUA_DIR}/$(__luaver_get_current_lua_version)" \ --with-lua-bin="${__luaver_LUA_DIR}/$(__luaver_get_current_lua_version)/bin" \ --with-lua-include="${__luaver_LUA_DIR}/$(__luaver_get_current_lua_version)/include" \ --with-lua-lib="${__luaver_LUA_DIR}/$(__luaver_get_current_lua_version)/lib" \ --versioned-rocks-dir && - 'make' build && - 'make' install + 'command' make build && + 'command' make install ) then __luaver_print "${luarocks_dir_name} successfully installed. Do you want to switch to this version? [Y/n]: " - read -r choice + 'read' -r choice case $choice in [yY][eE][sS] | [yY] ) __luaver_use_luarocks "${version}" @@ -650,7 +663,7 @@ __luaver_use_luarocks() if [ ! -e "${__luaver_LUAROCKS_DIR}/${version}_$(__luaver_get_current_lua_version_short)" ] then __luaver_print "${luarocks_name} is not installed with lua version $(__luaver_get_current_lua_version_short). Want to install it? [Y/n]: " - read -r choice + 'read' -r choice case $choice in [yY][eE][sS] | [yY] ) __luaver_install_luarocks "${version}" @@ -679,7 +692,7 @@ __luaver_set_default_luarocks() __luaver_unset_default_luarocks() { - 'rm' "${__luaver_LUAROCKS_DEFAULT_FILE}" && + 'command' rm "${__luaver_LUAROCKS_DEFAULT_FILE}" && __luaver_print "Removed default version for luarocks" } @@ -707,7 +720,7 @@ __luaver_uninstall_luarocks() __luaver_list_luarocks() { __luaver_print "Installed versions: (currently $(__luaver_get_current_luarocks_version || echo none) in lua $(__luaver_get_lua_version_by_current_luarocks || echo none))" - 'find' "${__luaver_LUAROCKS_DIR}" -name '*.*' -prune | 'awk' -F/ '{ print $NF }' | 'awk' -F_ '{ print $1 "\tlua:" $2}' + 'command' find "${__luaver_LUAROCKS_DIR}" -name '*.*' -prune | 'command' awk -F/ '{ print $NF }' | 'command' awk -F_ '{ print $1 "\tlua:" $2}' } __luaver_current() @@ -743,10 +756,10 @@ __luaver_init luaver() { - local command="${1}" + local cmd="${1}" shift - case $command in + case $cmd in "help" ) __luaver_usage;; "install" ) __luaver_install_lua "${@}";;