-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patha0-android-termux.sh
executable file
·144 lines (119 loc) · 4.23 KB
/
a0-android-termux.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env sh
# android-termux.sh v1.1
# collection of hackjobs to enable basic functionality on Termux for Android
# and paper over inconsistencies between standard Linux environments and the
# ones provided by unrooted Android devices
# some changes are ugly or incompatible with every other platform and will be
# applied manually so as to not pollute other scripts
! is-termux && exit 0
# install prerequisites
cat <<- EOF | sed 's/#.*$//g' | xargs apt install -y
wget git # req'd for bootstrap
clang binutils # provides cpp
openssl-tool openssh iproute2 # nano-overlay, ssh server
termux-api jq # provides fingerprint auth
busybox # httpd
n-t-roff-sc # provides sc
man moreutils # misc comforts
ledger gnuplot
imagemagick
bash-completion
EOF
# update existing
for f in update upgrade autoremove autoclean clean; do
yes y | apt $f
done
# setup hardware keystore with 'default' key for use with termux-ssh-askpass
# assumes you've already installed Termux:API add-on app
termux-keystore list | jq -r '.[].alias' | fgrep -q 'default' || \
termux-keystore generate 'default' -a RSA -s 4096 -u 10
# setup internal and external storage symlinks
yes y | termux-setup-storage
# prevent termux from sourcing .bashrc twice every login
# note: termux sources .bashrc before .profile on all logins
sed -ni ~/.profile -e '/## login shell/q;p'
# ~/.bashrc
# changes to shell startup, entry point for termux
# force a normal-ish bash login shell
! fgrep -q '$TERMUX' < ~/.bashrc && {
# simulate FHS standard locations w/o termux-chroot
sed -i ~/.profile -E \
-e 's,^(export XDG_RUNTIME_DIR).*,\1="$PREFIX/tmp",'
# ssh-agent tweaks
# android 11+ kills background daemons, run ssh-agent as parent process
sed -i ~/.bashrc \
-e '1s/^/[ ! -z "$TERMUX" ] || \\\n\t{ export TERMUX=1; exec ssh-agent -t 3600 bash -l; }\n/'
# use fingerprint lock and android keystore instead of passphrase
cat <<- EOF >> ~/.profile
# $0: use fingerprint lock and android keystore with ssh-agent
export SSH_ASKPASS='termux-ssh-askpass'
export SSH_ASKPASS_REQUIRE='force'
EOF
# disable $OLDPWD persistence
sed -i ~/.bashrc -e '/LASTDIR/d'
# bash-completion is already sourced at startup
sed -i ~/.bashrc -e '/bash-completion/d'
# shorten output of path-gitstatus
# break $PS1 into 2 lines on narrow displays
sed -i ~/.bashrc -E \
-e 's,(git_path.*)\),\1${TERMUX:+s}\),g' \
-e 's,(PS1.*)\\\$,\1\${TERMUX:+\\n}\\\$,g'
# make nano more bearable on narrow displays
cat <<- EOF >> ~/.nanorc
## changes for termux
set minibar
set stateflags
unset softwrap
EOF
}
# rewrite terminal ESC with octal ver as '\e' doesn't always work
# allow use of standard file descriptors on devices without root
script='s,\\e,\\33,g'
fd=0; for f in stdin stdout stderr; do
script="$script;s,/dev/$f,/proc/self/fd/$fd,g"
fd=$((fd + 1))
done
find ~/Scripts ~/.local -type f | xargs sed -e "$script" -i
# remove splash screen
rm -f /etc/motd*
# reset meta upstream
~/.once.d/02-meta-config.sh
# termux-specific
# install fonts
CONF="$HOME/.termux"
SOURCE='https://packages.debian.org/sid/all/fonts-go/download'
SOURCE="$(wget -q -O - "$SOURCE" | egrep -o '<a href=.*>' \
| tr '"' '\t' | cut -f2 | grep 'deb$' | head -n 1)"
DEB="${SOURCE##*/}"
mkdir -p "$CONF"
if wget "$SOURCE" -O "$CONF/$DEB" || exit 1; then
sleep 1 # termux will crash otherwise
ar -p "$CONF/$DEB" 'data.tar.xz' | xz -d \
| tar -xO --wildcards '*Go-Mono.ttf' > "$CONF/font.ttf"
rm -f "$CONF/$DEB"
fi
# import color scheme
colors='#include <colors/nightdrive.h>
cursor=FGCOLOR
foreground=FGCOLOR
background=BGCOLOR'
for f in $(seq 0 15); do
colors="$colors
color$f=COLOR$f"
done
echo "$colors" | cpp -P > "$CONF/colors.properties"
# configure soft key layout
cat <<- EOF > "$CONF/termux.properties"
# make full use of display in landscape mode
# disable extra keys with VolUp+q
#fullscreen=true
enforce-char-based-input = false
extra-keys-style = arrows-all
extra-keys = [ \
[ ESC, '~', '/', HOME, UP, END, PGUP, DEL ], \
[ TAB, CTRL, ALT, LEFT, DOWN, RIGHT, PGDN, BKSP ] \
]
EOF
# save changes to .patch file
# use 'patch -p1' to reapply without re-running script
git meta diff --color=never > "$CONF/diff.patch"