From 008e34b8b41b6c4ee5b88779141541591a2fa4d7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 14 Jul 2017 11:41:25 -0300 Subject: [PATCH 1/2] Add options --tree and --dependencies --- bin/Alien | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/Alien b/bin/Alien index 0e9a51bc..f2a8769a 100755 --- a/bin/Alien +++ b/bin/Alien @@ -16,13 +16,15 @@ scriptNotes=$( echo " ${alien#Alien-}" done ) -Add_Option_Boolean "" "install" "Install a package, with an optional ." -Add_Option_Boolean "" "getversion" "Get version of a currently installed package." -Add_Option_Boolean "" "getinstallversion" "Get version of a package to be installed." -Add_Option_Boolean "" "greater-than" "Succeeds if installed version is greater than ." -Add_Option_Boolean "" "within-range" "Succeeds if installed version is between and ." -Add_Option_Boolean "" "have-manager" "Succeeds if the package manager for the language is installed." -Add_Option_Boolean "" "get-manager-rule" "Returns a Dependencies rule for the package manager." +Add_Option_Boolean "" "install" "Install a package, with an optional ." +Add_Option_Boolean "" "getversion" "Get version of a currently installed package." +Add_Option_Boolean "" "getinstallversion" "Get version of a package to be installed." +Add_Option_Boolean "" "greater-than" "Succeeds if installed version is greater than ." +Add_Option_Boolean "" "within-range" "Succeeds if installed version is between and ." +Add_Option_Boolean "" "have-manager" "Succeeds if the package manager for the language is installed." +Add_Option_Boolean "" "get-manager-rule" "Returns a Dependencies rule for the package manager." +Add_Option_Entry "t" "tree" "Version-specific tree to use." +Add_Option_Entry "d" "dependencies" "Dependencies file from which to determine a version-specific tree to use." Parse_Options "$@" for mode in install getversion getinstallversion greater-than within-range have-manager get-manager-rule @@ -43,4 +45,4 @@ then Die "missing program name" fi -exec Alien-$alientype $mode $alienpkg "$(Arg 2)" "$(Arg 3)" +exec Alien-$alientype $mode $alienpkg "$(Arg 2)" "$(Arg 3)" "$(Entry "tree")" "$(Entry "dependencies")" From bb11eeb275d986b3ee3793b677c3077447d8e2cc Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 14 Jul 2017 11:41:37 -0300 Subject: [PATCH 2/2] Support --tree and --dependencies in Alien-LuaRocks. As proposed in https://github.com/gobolinux/Scripts/issues/4#issuecomment-315151514 Implemented LuaRocks only first as a proof-of-concept. See discussion in #4 for details. --- bin/Alien-LuaRocks | 145 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 127 insertions(+), 18 deletions(-) diff --git a/bin/Alien-LuaRocks b/bin/Alien-LuaRocks index 832828b9..5bebaa12 100755 --- a/bin/Alien-LuaRocks +++ b/bin/Alien-LuaRocks @@ -5,16 +5,26 @@ . ScriptFunctions Import Alien +alienroot=$goboSystem/Aliens/LuaRocks +alientree= +luarocksbin= + +versions=(5.3 5.2 5.1) + +run_luarocks() { + "$luarocksbin" --tree "$alientree" "$@" +} + getversion() { - prog="$1" - luarocks list "$prog" | awk ' + pkg="$1" + run_luarocks list "$pkg" | awk ' { if (found) { print $1 exit } } - /^'"$prog"'$/ { found=1 }' + /^'"$pkg"'$/ { found=1 }' } in_version_range() { @@ -30,11 +40,11 @@ in_version_range() { } getinstallversion() { - prog="$1" - for V in $(luarocks search "$prog" | awk ' + pkg="$1" + for V in $(run_luarocks search "$pkg" | awk ' /^$/ && found { exit } found { print $1 } - /^'"$prog"'$/ { found=1 }') + /^'"$pkg"'$/ { found=1 }') do if in_version_range "$2" "$V" "$3" then @@ -45,41 +55,140 @@ getinstallversion() { } install() { - prog="$1" + pkg="$1" ver="$2" - luarocks install "$prog" $ver - Symlink_Aliens "$goboExecutables" "$goboSystem"/Aliens/LuaRocks/bin + Log_Normal "Installing $pkg to $alientree..." + run_luarocks install "$pkg" $ver + Symlink_Aliens "$goboExecutables" "${alientree}/bin" } command="$1" -prog="$2" +pkg="$2" +version="$3" +maxversion="$4" +tree="$5" +dependencies="$6" + +set_lua_tree() { + local lua="$1" + lua=${lua%/} + luaver=${lua##%/} + for v in "${versions[@]}" + do + if [ $(GuessLatest "$luaver" "$v") = "$luaver" ] + then + alientree="$alienroot/$v.x" + luarocksbin="luarocks-$v" + break + fi + done +} + +valid_trees() { + echo "Accepted values for --tree are:" + for v in "${versions[@]}" + do + echo -n " $v.x" + if ! type luarocks-$v &> /dev/null + then + echo -n " (requires installing LuaRocks for Lua $v)" + fi + echo + done +} + +if [ -n "$tree" ] +then + for v in "${versions[@]}" + do + if [ "$tree" = "$v.x" ] + then + luarocksbin="luarocks-$v" + if ! type luarocks-$v &> /dev/null + then + Die "LuaRocks for Lua $v is not currently installed." + fi + fi + done + if [ -z "$luarocksbin" ] + then + Die "Tree $tree is not supported. $(valid_trees)" + fi + alientree="$alienroot/$tree" +elif [ -n "$dependencies" ] +then + luajit=$(FindDependencies -d luajit "$dependencies") + if [ -n "$luajit" ] + then + alientree="$alienroot/5.1.x" + luarocksbin="luarocks-$v" + else + lua=$(FindDependencies -d lua "$dependencies") + if [ -n "$lua" ] + then + set_lua_tree "$lua" + fi + fi +fi +if [ -z "$alientree" ] +then + # Autodetect: default to current Lua only if there is only one + luacount="$(FindPackage --types=installed lua --full-list | wc -l)" + luarocks_count() { + local i=0 + for v in "${versions[@]}" + do + type luarocks-$v &>/dev/null && i=$[i+1] + done + echo $i + } + if [ "$luacount" != 1 ] && [ "$(luarocks_count)" != 1 ] + then + Die "Please specify a tree using --tree or --dependencies. $(valid_trees)" + # Not handling yet the case where there is one Lua >= 5.2 and one LuaJIT. + fi + + # Autodetect: default to current Lua + lua="$(FindPackage --types=installed lua)" + if [ -n "$lua" ] + then + set_lua_tree "$lua" + else + luajit="$(FindPackage --types=installed luajit)" + if [ -n "$luajit" ] + then + alientree="$alienroot/5.1.x" + luarocksbin="luarocks-$v" + fi + fi +fi case "$command" in --getversion) - echo $(getversion "$2") + echo $(getversion "$pkg") ;; --getinstallversion) - echo $(getinstallversion "$2" "$3" "$4") + echo $(getinstallversion "$pkg" "$version" "$maxversion") ;; --greater-than) - ver=$(getversion "$2") - latest=$(GuessLatest "$ver" "$3") + ver=$(getversion "$version") + latest=$(GuessLatest "$ver" "$maxversion") [ "$latest" = "$3" ] && exit 1 || exit 0 ;; --met|--within-range|--interval) - prog="$2" + pkg="$2" lower="$3" upper="$4" - ver=$(getversion "$2") + ver=$(getversion "$version") in_version_range "$lower" "$ver" "$upper" ;; --have-manager) - which luarocks >/dev/null 2>&1 || exit 1 + type "$luarocksbin" >/dev/null 2>&1 || exit 1 ;; --get-manager-rule) echo "LuaRocks >= 1.0" ;; --install) - install "$2" "$3" + install "$pkg" "$version" ;; esac # is ridiculous