Termux使用记录
Termux 基本使用
禁用欢迎语:touch .hushlogin
修改欢迎语:vi $PREFIX/etc/motd
允许访问存储:termux-setup-storage
显示扩展功能按键:从左向右滑动,显示隐藏式导航栏,长按左下角的 KEYBOARD
定制拓展功能按键:
mkdir ~/.termux
echo "extra-keys = [ ['ESC', '/', '~', '^', 'HOME', 'UP', 'END', 'PGUP'], ['TAB', 'CTRL', 'ALT', '\`', 'LEFT', 'DOWN', 'RIGHT', 'PGDN'] ]" >> ~/.termux/termux.properties
reset
Termux 环境中的 pkg instal package
等于 apt update && apt install package
Apt 使用清华源:
# apt edit-sources
cp $PREFIX/etc/apt/sources.list $PREFIX/etc/apt/sources.list.bak
sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list
cp $PREFIX/etc/apt/sources.list.d/game.list $PREFIX/etc/apt/sources.list.d/game.list.bak
sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable@' $PREFIX/etc/apt/sources.list.d/game.list
cp $PREFIX/etc/apt/sources.list.d/science.list $PREFIX/etc/apt/sources.list.d/science.list.bak
sed -i 's@^\(deb.*science stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list
apt update && apt upgrade
安装常用软件包和依赖:
pkg install -y --install-recommends --install-suggests -y build-essential
pkg install -y proot curl wget openssh git subversion
pkg install -y clang cmake python rust golang
pkg install -y zsh vim vim-python ffmpeg gnupg
pkg install -y graphviz doxygen tree expect patchelf
pkg install -y nginx nmap metasploit
安装 mariadb
pkg install mariadb
mysql --version
# 初始化
mysql_install_db
# 安全设置
mysql_secure_installation
# 启动服务
mysqld_safe -u $(whoami) &
# 关闭服务
mysqladmin shutdown
# 普通登录
mysql -u $(whoami)
MariaDB [(none)]> use mysql;
MariaDB [mysql]> set password for 'root'@'localhost' = password('pass4sql');
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> quit;
# 密码登录
mysql -u root -p
使用 nginx
nginx
pgrep nginx
# http://127.0.0.1:8080
nginx -s reload
nginx -s stop
下载 pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Pip 使用镜像源:
# 1. 直接指定 URL
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 2. 手动编辑 pip.conf
mkdir ~/.pip && vi ~/.pip/pip.conf
pip.conf
的内容如下:
[global]
timeout = 300
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = tsinghua.edu.cn
安装 lxml
pkg update
pkg install libxml2 libxslt
pip install lxml
安装 jupyter
pkg install fftw libzmq freetype libpng pkg-config
pip install wheel jupyter pandas matplotlib
安装 pillow
pkg install libjpeg-turbo libcrypt ndk-sysroot
pip install pillow
模拟 root 环境:
pkg install proot
termux-chroot
proot-distro 安装 Linux 发行版
Termux 官方提供了基于proot 实现的安装 Linux 发行版的工具 proot-distro
pkg install proot-distro
# show the supported distributions and their status
proot-distro list
# install a distribution
proot-distro install <distro-alias>
# start a root shell for the distribution
# proot-distro login <distro-alias>
proot-distro 实际上是一个脚本程序,可通过查看 $PREFIX/bin/proot-distro
来了解这个工具具体怎么实现的
ArchLinux
安装 ArchLinux:proot-distro install archlinux
下载 ArchLinux rootfs:wget https://eu.mirror.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz $PREFIX/var/lib/proot-distro/dlcache/
登录 ArchLinux:proot-distro login archlinux
进入 ArchLinux 环境内操作:
# 修改时区和语言
cp /etc/localtime /etc/localtime.bak
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp /etc/locale.conf /etc/locale.conf.bak
echo 'LANG=en_US.UTF-8' > /etc/locale.conf
# 添加镜像源
sed -i '1i\Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxarm/$arch/$repo' /etc/pacman.d/mirrorlist
# Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxarm/$arch/$repo
# Server = https://mirrors.ustc.edu.cn/archlinuxarm/$arch/$repo
# Server = https://mirrors.stuhome.net/archlinuxarm/$arch/$repo
pacman -Syu
pacman -S base-devel
pacman -S gcc-fortran clang openmp llvm
pacman -S python python-pip python-setuptools python-pysocks python-brotli python-pyopenssl python-lockfile python-lxml python-beautifulsoup4
pacman -S vim neofetch
pacman -S hdf5 qt5-base opencv
pip install numpy
Ubuntu
安装 Ubuntu:proot-distro install ubuntu
下载 Ubuntu rootfs:wget https://partner-images.canonical.com/core/focal/current/ubuntu-focal-core-cloudimg-arm64-root.tar.gz $PREFIX/var/lib/proot-distro/dlcache/
登录 Ubuntu:proot-distro login ubuntu
进入 Ubuntu 环境内操作:
apt update && apt upgrade -y
apt install -y vim-nox
# apt edit-sources
# 添加镜像源
mv /etc/apt/sources.list /etc/apt/sources.list.ubuntu
cat > /etc/apt/sources.list << EOF
# 默认注释源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
EOF
# 安装常用软件
apt install -y build-essential gfortran git cmake wget curl
apt install -y python3 python3-pip julia
apt install -y stress sysstat dstat htop tree tcpdump iperf
# 安装 Swift
apt install -y binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 libz3-dev pkg-config tzdata zlib1g-dev
wget --content-disposition https://packagecloud.io/swift-arm/release/packages/ubuntu/focal/swift-lang_5.2.5-6-ubuntu-focal_arm64.deb/download.deb
dpkg -i swift-lang_5.2.5-6-ubuntu-focal_arm64.deb
# 安装 Caffe
apt install -y libopenblas-dev liblapack-dev libatlas-base-dev
apt install -y --no-install-recommends libboost-all-dev
apt install -y libprotobuf-dev libgoogle-glog-dev libgflags-dev libhdf5-serial-dev protobuf-compiler
apt install -y liblmdb-dev libleveldb-dev libsnappy-dev
apt install -y python3-dev python3-numpy python3-opencv libopencv-dev
pkg-config --modversion opencv4
pip3 install protobuf
apt install caffe-cpu