使用 Termux 在手机中运行 Perl 6

之前介绍过在安卓手机上运行 Perl 6, 那是一种很费劲的折腾, 你得下载一个完整的 Ubuntu 系统, 然后自行编译安装 Perl 6。虽然现在 Docker 很方便, 但是我不想用它。 有了 Termux 就发现下面这个操作更清凉, 更环保。 我们到 https://github.com/its-pointless/gcc_termux 看到里面的 readme 说得语焉不详, 对于刚接触 Termux 的人来说有点毫无头绪, 但是作者依然提供了一个傻瓜式一键设置脚本, 我拿来改造下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/data/data/com.termux/files/usr/bin/sh
# Get some needed tools. coreutils for mkdir command, gnugp for the signing key, and apt-transport-https to actually connect to the repo
# and clang and make for installing Zef

apt-get update
apt-get --assume-yes upgrade
apt-get --assume-yes install coreutils gnupg wget clang make git

# Make the sources.list.d directory
mkdir $PREFIX/etc/apt/sources.list.d

# Write the needed source file
if apt-cache policy | grep -q "https://dl.bintray.com/termux/termux-packages-24" ; then
echo "deb https://its-pointless.github.io/files/24 termux extras" > $PREFIX/etc/apt/sources.list.d/pointless.list
else
echo "deb https://its-pointless.github.io/files/ termux extras" > $PREFIX/etc/apt/sources.list.d/pointless.list
fi

# Download signing key from https://its-pointless.github.io/pointless.gpg
wget https://its-pointless.github.io/pointless.gpg
apt-key add pointless.gpg

# Update apt
apt update

# Install rakudo
apt-get install rakudo

# Install Zef
git clone https://github.com/ugexe/zef.git
cd zef
perl6 -I. bin/zef install .
echo "export PATH=$PATH:/data/data/com.termux/files/usr/share/perl6/site/bin" >> ~/.bashrc
zef install Linenoise

# start sshd when enter terminal
echo "sshd" >> ~/.bashrc
source ~/.bashrc

我顺便在这个 issue 下面评论了一下解决方法, 希望帮助到更多的人。