Skip to content

Instantly share code, notes, and snippets.

@BoniLindsley
Last active January 26, 2022 16:57
Show Gist options
  • Save BoniLindsley/a938220612ccf8ec76b9f38ed53e3a10 to your computer and use it in GitHub Desktop.
Save BoniLindsley/a938220612ccf8ec76b9f38ed53e3a10 to your computer and use it in GitHub Desktop.
Downloads, builds and installs TclX for Termux
#!/usr/bin/env bash
main() {
: "${XDG_DATA_HOME:="${HOME}/.local/share"}"
local local_dir
local_dir="$(readlink -f "${XDG_DATA_HOME}/..")"
: "${PREFIX="${local_dir}"}"
local src_dir="${local_dir}/src/tclx"
printf 'Using source directory: %s\n' "${src_dir}"
case $# in
0)
download || exit
build || exit
install || exit
;;
1)
case "$1" in
'download') download ;;
'remove-source') remove_source ;;
'build') build ;;
'clean') clean ;;
'install') install ;;
'uninstall') uninstall ;;
*)
printf 'Unrecognised command: %s\n' "$1" 1>&2
exit 1
;;
esac
;;
*)
printf 'Too many arguments.\n' 1>&2
;;
esac
}
download() {
local repo_path='https://github.com/flightaware/tclx.git'
mkdir -p "${src_dir}" || exit
pushd "${src_dir}" 1>/dev/null || exit
if [[ -d "${src_dir}/.git" ]]; then
printf 'Updating from %s\n' "${repo_path}"
git fetch || exit
git rebase origin/master || exit
else
printf 'Cloning from %s.\n' "${repo_path}"
git clone "${repo_path}" "${src_dir}" || exit
apply_patch || exit
fi
popd 1>/dev/null || exit
}
remove_source() {
rm -dfr "${src_dir}" || exit
}
build() {
pushd "${src_dir}" 1>/dev/null || exit
printf 'Running configure.\n'
./configure --with-tcl="${PREFIX}/lib" || exit
printf 'Running make.\n'
make || exit
popd 1>/dev/null || exit
}
clean() {
pushd "${src_dir}" 1>/dev/null || exit
git clean -dfx || exit
popd 1>/dev/null || exit
}
install() {
pushd "${src_dir}" 1>/dev/null || exit
make install || exit
popd 1>/dev/null || exit
}
uninstall() {
local tclx_prefix="${PREFIX}/lib/tclx8.6"
local installed_files=(
"${tclx_prefix}/libtclx8.6.so"
"${tclx_prefix}/tclx.tcl"
"${tclx_prefix}/autoload.tcl"
"${tclx_prefix}/arrayprocs.tcl"
"${tclx_prefix}/compat.tcl"
"${tclx_prefix}/convlib.tcl"
"${tclx_prefix}/edprocs.tcl"
"${tclx_prefix}/events.tcl"
"${tclx_prefix}/forfile.tcl"
"${tclx_prefix}/globrecur.tcl"
"${tclx_prefix}/help.tcl"
"${tclx_prefix}/profrep.tcl"
"${tclx_prefix}/pushd.tcl"
"${tclx_prefix}/setfuncs.tcl"
"${tclx_prefix}/showproc.tcl"
"${tclx_prefix}/stringfile.tcl"
"${tclx_prefix}/tcllib.tcl"
"${tclx_prefix}/fmath.tcl"
"${tclx_prefix}/buildhelp.tcl"
"${tclx_prefix}/pkgIndex.tcl"
"${PREFIX}/include/tclExtend.h"
"${PREFIX}/share/man/mann/TclX.n"
)
local file
for file in "${installed_files[@]}"; do
rm -f "${file}"
done
rmdir --ignore-fail-on-non-empty "${tclx_prefix}"
}
apply_patch() {
git am <<EOF
From 6d5e6bf070471bad724949e0572e9e411275d1d4 Mon Sep 17 00:00:00 2001
From: Boni Lindsley <boni@lindsley.xyz>
Date: Thu, 28 Oct 2021 09:28:50 +0100
Subject: [PATCH] build: remove use of rresvport
Reserving a priviledged port is not possible without root.
---
unix/tclXunixSock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/unix/tclXunixSock.c b/unix/tclXunixSock.c
index 826abbf..b038ff4 100644
--- a/unix/tclXunixSock.c
+++ b/unix/tclXunixSock.c
@@ -195,7 +195,7 @@ TclX_ServerCreateCmd (ClientData clientData,
*/
if (getReserved) {
int port;
- if (rresvport (&port) < 0)
+ //if (rresvport (&port) < 0)
goto unixError;
local.sin_port = port;
}
--
2.33.1
EOF
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment