-
-
Save omar-azmi/9510958fe24a7374856ccc75217330d5 to your computer and use it in GitHub Desktop.
| # NOTE: to run this script remotely (without copy and pasting) simply execute: | |
| # curl -fsSL "https://gist.githubusercontent.com/omar-azmi/9510958fe24a7374856ccc75217330d5/raw/setup_deno_on_termux.sh" | sh | |
| # the following shell script will install the deno javascript runtime to your termux environment on android. | |
| # after that, it will patch the deno binary to use android/termux compatible libc shared libraries (which we will download beforehand) | |
| # finally, we will append the path to the deno library onto the PATH environment variable in your local `./.bachrc` file, so that `deno` will be available as a command on every terminal session. | |
| # the proceedure for making deno compatible with termux was gathered from the following resources: | |
| # - "https://github.com/denoland/deno/issues/19759" | |
| # - "https://gist.github.com/CodeIter/ccdcc840e432288ef1e01cc15d66c048" | |
| # 1. install pre-requisites: | |
| # - `glibc-repo` and `glibc` provide the termux-compatible shared libraries for libc (a dynamic dependency of deno) | |
| # - `patchelf` lets us patch the deno binary to use an alternate location for its dynamic dependencies on libc | |
| pkg install --yes glibc-repo | |
| pkg install --yes glibc | |
| pkg install --yes patchelf | |
| # 2. download and install deno. | |
| # we don't use the official script because it immediately executes deno to carry out additional tasks. | |
| # but we cannot run the deno binary here until it has been patched. | |
| target="aarch64-unknown-linux-gnu" | |
| deno_version="$(curl -s https://dl.deno.land/release-latest.txt)" | |
| deno_uri="https://dl.deno.land/release/${deno_version}/deno-${target}.zip" | |
| deno_install="${DENO_INSTALL:-$HOME/.deno}" | |
| bin_dir="${deno_install}/bin" | |
| exe="${bin_dir}/deno" | |
| if [ ! -d "${bin_dir}" ]; then mkdir -p "${bin_dir}"; fi | |
| curl --fail --location --progress-bar --output "${exe}.zip" "${deno_uri}" | |
| unzip -d "${bin_dir}" -o "${exe}.zip" | |
| chmod +x "${exe}" | |
| rm "${exe}.zip" | |
| echo "Deno was installed successfully to: \"${exe}\"" | |
| # 3. patch the deno binary to use the termux-compatible libc shared libraries | |
| patchelf --set-rpath "${HOME}/../usr/glibc/lib" --set-interpreter "${HOME}/../usr/glibc/lib/ld-linux-aarch64.so.1" "${exe}" | |
| # 4. adding shell configurations to your `~/.bashrc` | |
| bashrc_file="${HOME}/.bashrc" | |
| touch "${bashrc_file}" | |
| echo "export DENO_INSTALL=\"${deno_install}\"" >> "${bashrc_file}" | |
| echo "export PATH=\"\${PATH}:${bin_dir}\"" >> "${bashrc_file}" | |
| echo "unset LD_PRELOAD" >> "${bashrc_file}" # I think this disables dynamic library preloading, which is necessary for any patched binaries | |
| # 5. apply variable declarations and configurations to the current session as well | |
| export DENO_INSTALL="${deno_install}" | |
| export PATH="${PATH}:${bin_dir}" | |
| unset LD_PRELOAD | |
Could you try installing this on the latest version of termux (v0.119-beta3)?
I just tried using my script on an old phone running an old version of termux (v0.101), and it was failing to recognise the glibc-repo package, leading to there being no dynamic version of libc being installed.
But after updating my termux (clean re-installation) to the latest version on my old phone, the script worked just fine.
Also, do note that the deno command will not be immediately available on the terminal session in which you run the script.
It'll only become available in the next new terminal session.
Could you try installing this on the latest version of termux (
v0.119-beta3)? I just tried using my script on an old phone running an old version of termux (v0.101), and it was failing to recognise theglibc-repopackage, leading to there being no dynamic version oflibcbeing installed. But after updating my termux (clean re-installation) to the latest version on my old phone, the script worked just fine.
Thanks, idk why but from version 118 the update is telling me that its conflicting... Should i wait for version 120 of termux or something? 😂
That seems unusual; because I just tried my script on a clean installation of termux 0.118.3 (from F-Droid), and it worked as expected.
And then, I also updated (without uninstalling) to 0.119-beta3, and the apk installer never complained about a conflict between the two versions.
More so, the pre-exising installation of deno continued working after the update.
I think you might be installing your apk from a source that is different from the original installation source.
For instance, you generally cannot download an apk update from F-Droid or Github when the original apk was installed through the Play Store, and vice versa. (this is often due to a signature mismatch. which happens because (i think) google signs the play store apks with their own keys)
Moreover, when running termux for the first time after a fresh installation, make absolutely sure not to press any button nor tap on the phone while the "installing bootstrap packages" dialog (or something similar) is on the screen. Because I've read a few posts that claim that interupting termux during its first boot leads to the apt package manager not working correctly.
Hope this help, because otherwise I don't know much about termux (nor the package manager) myself to help you diagnose further.
Thank you for your thorough response haha! Well my build is from fdroid, and i dont know where exactly things went wrong, if in the first bootstrap or in some incompatibilities with the oem distro im testing on (its nothing os 3.something). Along the elf patcher not working, i also experience this annoying crash of the app alltogether at times (im going seriously off topic here). Ill post some updates in this thread if i have any success with your script or, roughly, your method!
Its giving me:
deno: error while loading shared libraries: /data/data/com.termux/files/usr/glibc/lib/libc.so: invalid ELF header