Skip to content

Commit

Permalink
Support running ronin-dev.sh on Android Termux (closes #15).
Browse files Browse the repository at this point in the history
* Workaround nokogiri/libxml2 tar archive hardlinks issue on Termux, by
  checking if nokogiri isn't already installed, and explicitly compiling
  it against the system's `libxml2` and `libxslt` packages.
* Install `binutils` on Termux for the missing `ar` command.
  • Loading branch information
postmodern committed May 8, 2024
1 parent 1fae65d commit 4cce38c
Showing 1 changed file with 59 additions and 11 deletions.
70 changes: 59 additions & 11 deletions ronin-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ function detect_package_manager()
elif command -v zypper >/dev/null; then
package_manager="zypper"
fi
elif [[ "$HOME" == *"com.termux"* ]]; then
package_manager="termux"
fi
;;
Darwin)
Expand Down Expand Up @@ -229,6 +231,7 @@ function install_packages()
fi
;;
zypper) $sudo zypper -n in -l $* || return $? ;;
termux) pkg install -y "$@" || return $? ;;
"") warn "Could not determine Package Manager. Proceeding anyway." ;;
esac
}
Expand Down Expand Up @@ -305,26 +308,52 @@ function auto_install_rubygems()
#
# Install gcc if there's no C compiler on the system.
#
function auto_install_gcc()
function auto_install_cc()
{
if ! command -v cc >/dev/null; then
log "Installing gcc ..."
install_packages gcc || fail "Failed to install gcc!"
case "$package_manager" in
termux)
log "Installing clang ..."
install_packages clang || \
fail "Failed to install clang!"
;;
*)
log "Installing gcc ..."
install_packages gcc || \
fail "Failed to install gcc!"
;;
esac
fi
}

#
# Install g++ if there's no C++ compiler on the system.
#
function auto_install_gpp()
function auto_install_cpp()
{
if ! command -v c++ >/dev/null; then
log "Installing g++ ..."
case "$package_manager" in
dnf|yum) install_packages gcc-g++ ;;
zypper) install_packages gcc-c++ ;;
*) install_packages g++ ;;
esac || fail "Failed to install g++!"
dnf|yum)
log "Installing g++ ..."
install_packages gcc-g++ || \
fail "Failed to install g++!"
;;
zypper)
log "Installing g++ ..."
install_packages gcc-c++ || \
fail "Failed to install g++!"
;;
termux)
log "Installing clang ..."
install_packages clang || \
fail "Failed to install clang!"
;;
*)
log "Installing g++ ..."
install_packages g++ || \
fail "Failed to install g++!"
;;
esac
fi
}

Expand Down Expand Up @@ -370,6 +399,19 @@ function auto_install_bundler()
fi
}

#
# Explicitly install nokogiri on Termux by building it against the system's
# libxml2 and libxslt packages.
#
function termux_install_nokogiri()
{
# XXX: compile nokogiri against the system's libxml2 library,
# to workaround issue with the libxml2 tar archive containing
# hardlinks.
$gem install nokogiri --platform ruby -- --use-system-libraries || \
warn "Failed to compile nokogiri. Proceeding anyways."
}

#
# Install external dependencies for ronin.
#
Expand All @@ -379,12 +421,18 @@ function install_dependencies()
dnf|yum)libraries=(libyaml-devel zip) ;;
zypper) libraries=(awk libyaml-devel zip) ;;
apt) libraries=(libyaml-dev zip) ;;
termux) libraries=(binutils libyaml libxml2 libxslt zip) ;;
*) libraries=(libyaml zip) ;;
esac

log "Installing external dependencies ..."
install_packages "${libraries[@]}" || \
warn "Failed to install external dependencies. Proceeding anyways."

if [[ "$package_manager" == "termux" ]] && \
[[ -z "$(gem which nokogiri 2>/dev/null)" ]]; then
termux_install_nokogiri
fi
}

#
Expand Down Expand Up @@ -444,8 +492,8 @@ function parse_options()
parse_options "$@" || exit $?
detect_system
auto_install_git
auto_install_gcc
auto_install_gpp
auto_install_cc
auto_install_cpp
auto_install_make
auto_install_pkg_config
auto_install_ruby
Expand Down

0 comments on commit 4cce38c

Please sign in to comment.