Skip to content

Commit

Permalink
bump(gpkg/glibc-runner): 2.0
Browse files Browse the repository at this point in the history
new pkg gpkg/patchelf
new pkg gpkg/strace
  • Loading branch information
Maxython committed Feb 24, 2024
1 parent 9ae5d9f commit 62380c7
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 85 deletions.
27 changes: 21 additions & 6 deletions gpkg/glibc-runner/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@ TERMUX_PKG_HOMEPAGE="https://github.com/termux-pacman/glibc-packages/wiki/About-
TERMUX_PKG_DESCRIPTION="Tool for convenient use of Glibc"
TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_MAINTAINER="@termux-pacman"
TERMUX_PKG_VERSION=1.4
TERMUX_PKG_DEPENDS="glibc, termux-exec-glibc, bash-glibc, bash, patchelf"
TERMUX_PKG_VERSION=2.0
TERMUX_PKG_DEPENDS="glibc, termux-exec-glibc, bash-glibc, bash, patchelf-glibc, binutils-glibc"
TERMUX_PKG_RECOMMENDS="coreutils-glibc, util-linux-glibc"
TERMUX_PKG_CONFFILES="etc/glibc-runner.bashrc"
TERMUX_PKG_SKIP_SRC_EXTRACT=true
TERMUX_PKG_PLATFORM_INDEPENDENT=true
TERMUX_PKG_ESSENTIAL=true

termux_step_make_install() {
install -m755 ${TERMUX_PKG_BUILDER_DIR}/glibc-runner ${TERMUX_PREFIX_CLASSICAL}/bin
sed -i "s|@TERMUX_PREFIX@|$TERMUX_PREFIX|g; s|@TERMUX_PREFIX_CLASSICAL@|$TERMUX_PREFIX_CLASSICAL|g; s|@TERMUX_PKG_VERSION@|$TERMUX_PKG_VERSION|g" \
${TERMUX_PREFIX_CLASSICAL}/bin/glibc-runner
ln -sf ${TERMUX_PREFIX_CLASSICAL}/bin/glibc-runner ${TERMUX_PREFIX_CLASSICAL}/bin/grun
mkdir -p ${TERMUX_PREFIX_CLASSICAL}/opt/glibc-runner
install -m644 ${TERMUX_PKG_BUILDER_DIR}/glibc-runner.sh ${TERMUX_PREFIX_CLASSICAL}/opt/glibc-runner
install -m644 ${TERMUX_PKG_BUILDER_DIR}/glibc-runner.bashrc ${TERMUX_PREFIX_CLASSICAL}/etc
ln -sf ${TERMUX_PREFIX_CLASSICAL}/etc/glibc-runner.bashrc ${TERMUX_PREFIX}/etc/glibc-runner.bashrc

sed -i "s|@TERMUX_PREFIX_CLASSICAL@|$TERMUX_PREFIX_CLASSICAL|g; s|@TERMUX_PKG_VERSION@|$TERMUX_PKG_VERSION|g" \
${TERMUX_PREFIX_CLASSICAL}/opt/glibc-runner/glibc-runner.sh

sed -i "s|@TERMUX_PREFIX_CLASSICAL@|$TERMUX_PREFIX_CLASSICAL|g" \
${TERMUX_PREFIX_CLASSICAL}/etc/glibc-runner.bashrc

local _PATH_PREFIX=""
for _PATH_PREFIX in ${TERMUX_PREFIX_CLASSICAL} ${TERMUX_PREFIX}; do
install -m755 ${TERMUX_PKG_BUILDER_DIR}/glibc-runner ${_PATH_PREFIX}/bin
sed -i "s|@SHELL_PATH@|${_PATH_PREFIX}/bin/bash|g; s|@TERMUX_PREFIX_CLASSICAL@|${TERMUX_PREFIX_CLASSICAL}|g" \
${_PATH_PREFIX}/bin/glibc-runner
ln -sf ${_PATH_PREFIX}/bin/glibc-runner ${_PATH_PREFIX}/bin/grun
done
}
82 changes: 3 additions & 79 deletions gpkg/glibc-runner/glibc-runner
Original file line number Diff line number Diff line change
@@ -1,81 +1,5 @@
#!@TERMUX_PREFIX_CLASSICAL@/bin/bash
#!@SHELL_PATH@

# version: 1.4
# This script allows you to:
# - run glibc-based binaries with ld.so.
# - configure glibc-based binaries to work in Termux.
# - start a special shell with access to glibc commands.
# version: 2.0

if [[ -z "$1" ]]; then
echo "Help message from $0-@TERMUX_PKG_VERSION@"
echo ""
echo "This script allows you to:"
echo " - run glibc-based binaries with ld.so."
echo " - configure glibc-based binary to work in Termux."
echo " - start a special shell with access to glibc commands."
echo ""
echo "Flags:"
echo " --shell - launching a customized shell"
echo " --set - binary setup"
echo " --help - print help text from ld.so command"
echo ""
echo "Variables:"
echo " WITH_LIBTERMUX_EXEC_GLIBC=[false|true] - enable the termux-exec-glibc library (default: false)"
echo ""
echo "Example: grun [--set] ./binary || [WITH_LIBTERMUX_EXEC=true|false] grun --shell [gcc -v]"
echo "Bug report: https://github.com/termux-pacman/glibc-packages/issues"
exit 0
fi

unset LD_PRELOAD
export GLIBC_PREFIX="@TERMUX_PREFIX@"
export LIBTERMUX_EXEC="${GLIBC_PREFIX}/lib/libtermux-exec.so"
export PATH="${GLIBC_PREFIX}/bin:${PATH}"

if [ -f "${GLIBC_PREFIX}/etc/locale.conf" ]; then
source "${GLIBC_PREFIX}/etc/locale.conf"
fi

if [ "$WITH_LIBTERMUX_EXEC_GLIBC" = "true" ]; then
if [ ! -f $LIBTERMUX_EXEC ]; then
echo "Error: not found '$LIBTERMUX_EXEC'"
exit 1
fi
export LD_PRELOAD=$LIBTERMUX_EXEC
fi

if [ "$1" = "--shell" ]; then
if [[ -z "$2" ]]; then
exec $SHELL
else
commands="$@"
exec bash -c "${commands#* }"
fi
elif [ "$1" = "--set" ]; then
if [ -z "$2" ]; then
echo "Error: binary not specified"
exit 1
fi
if [ ! -f "$2" ]; then
echo "Error: binary not found"
exit 1
fi
if $(type patchelf &> /dev/null); then
LD_FILE=$(ls $GLIBC_PREFIX/lib/ld-* 2> /dev/null)
if [ -n "$LD_FILE" ]; then
patchelf --set-rpath $GLIBC_PREFIX/lib \
--set-interpreter $LD_FILE \
"$2"
else
echo "Error: interpreter not found in lib directory"
exit 1
fi
else
@TERMUX_PREFIX_CLASSICAL@/libexec/termux/command-not-found patchelf
exit 1
fi
else
exec ld.so $@
fi

exit $?
@SHELL_PATH@ @TERMUX_PREFIX_CLASSICAL@/opt/glibc-runner/glibc-runner.sh $@
8 changes: 8 additions & 0 deletions gpkg/glibc-runner/glibc-runner.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @TERMUX_PREFIX_CLASSICAL@/etc/glibc-runner.bashrc
# this script is for setting up the glibc-runner shell environment

if [ -f "${GLIBC_PREFIX}/etc/locale.conf" ]; then
source "${GLIBC_PREFIX}/etc/locale.conf"
fi

#unset SHELL
Loading

0 comments on commit 62380c7

Please sign in to comment.