├── README.md └── setup.sh /README.md: -------------------------------------------------------------------------------- 1 | # termux-auto-setup 2 | auto setup your termux from the very first installed 3 | 4 | # Installation tutorial 5 | 1. Download setup.sh to mobile directory 6 | 2. Select to open the file with Termux 7 | 3. ```cd ./download``` enter the directory where the script exists 8 | 4. ```chmod +x ./setup.sh``` give the script executable permission 9 | # Instructions for useage 10 | 1. ```./setup.sh``` view help 11 | 2. ```./setup.sh info``` view script details 12 | 3. ```./setup.sh all``` install and configure all software and settings 13 | 4. Select the corresponding parameters in the help to configure (install) the software 14 | 5. This script is from and dedicated to open source. It refers to and modifies the script according to personal preferences and learning process 15 | 6. There is no code damaging the mobile phone in this script. In the worst case, you can choose to clear all data in the application settings of termux 16 | 7. When you run this script, you should be aware of the impact of your actions 17 | 8. The termux version targeted by this script is 0.118.0 as of the release date of this script 18 | 19 | # More Detail 20 | 1. https://www.sqlsec.com/2018/05/termux.html#toc-heading-23 21 | 2. https://github.com/sahilsehwag/android-termux-setup-script 22 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/data/data/com.termux/files/usr/bin/bash 2 | #/bin/sh 3 | 4 | function printll() { 5 | i=1 6 | while [ ${i} -lt 5 ] #https://www.cnblogs.com/sidesky/p/10679427.html 7 | do 8 | let i++ 9 | printf " " 10 | done 11 | echo -e "\033[47;30m $* \033[0m" 12 | } 13 | if [[ "$*" =~ help || ! -n "$1" ]]; then 14 | printll all = INSTALLS AND SETUP EVERYTHING 15 | printll chs = CHANGE SOFTWARE SOURCE TO TSINGHUA TUNA 16 | printll omz = INSTALLS OH-MY-ZSH AND SETUP .zshrc. 17 | printll vim = INSTALLS vim-python AND SETUP .vimrc 18 | printll fasd = INSTALL AND SETUP FASD 19 | printll fzf = INSTALL FZF AND ADD COMMON ALIASES LIKE fcd AND fv 20 | printll neovim = INSTALL NEOVIM AND SETUP init.vim 21 | printll eks = CUSTOMIZE EXTRA-KEY 22 | printll info = PRINT BASIC INFO 23 | printll yg = INSTALL YOU-GET 24 | printll basic = INSTALL BASIC TOOLS 25 | printll zas = INSTALL ZSH-AUTOSUGGESTIONS 26 | printll ss = SETUP STORAGE 27 | printll fun = INSTALL FUN SOFTWARES 28 | printll b = Backing up 29 | printll r = Restoring 30 | printll sl = Create soft links 31 | fi 32 | 33 | if [[ "$*" =~ info ]]; then 34 | printll "The main content of this script is based on open source code." 35 | printll "The content of this script may not be suitable for everyone." 36 | printll "The original information please visit the following links" 37 | printll "And thanks to the authors for their efforts" 38 | printll "https://www.sqlsec.com/2018/05/termux.html#toc-heading-23" 39 | printll "https://github.com/sahilsehwag/android-termux-setup-script" 40 | printll "And all the open source projects used in the scripts" 41 | fi 42 | 43 | #Change source (for Chinese user) 44 | if [[ "$*" =~ chs || "$*" =~ all ]]; then 45 | echo "Start to change software source to tsinghua tuna" 46 | 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 47 | 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 48 | 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 49 | echo "Done! Start to update source list" 50 | pkg update 51 | fi 52 | 53 | #enable storage 54 | if [[ "$*" =~ ss || "$*" =~ all ]]; then 55 | termux-setup-storage 56 | # echo $HOME #/data/data/com.termux/files/home 57 | # echo $PREFIX #/data/data/com.termux/files/usr 58 | fi 59 | 60 | 61 | #Backing up 62 | if [[ "$*" =~ b ]]; then 63 | termux-setup-storage 64 | printll "Backing up & Restoring" 65 | printll "https://wiki.termux.com/wiki/Backing_up_Termux" 66 | tar -zcf /storage/emulated/0/Download/termux-backup.tar.gz -C /data/data/com.termux/files ./home ./usr 67 | fi 68 | 69 | #Restoring 70 | if [[ "$*" =~ r ]]; then 71 | termux-setup-storage 72 | printll "Backing up & Restoring" 73 | printll "https://wiki.termux.com/wiki/Backing_up_Termux" 74 | tar -zxf /storage/emulated/0/Download/termux-backup.tar.gz -C /data/data/com.termux/files --recursive-unlink --preserve-permissions 75 | fi 76 | 77 | #SOFT-LINK 78 | if [[ "$*" =~ sl || "$*" =~ all ]]; then 79 | #QQ 80 | ln -s /storage/emulated/0/Android/data/com.tencent.mobileqq/Tencent/QQfile_recv ~/qq 81 | fi 82 | 83 | #Install baisc tools 84 | if [[ "$*" =~ basic || "$*" =~ all ]]; then 85 | pkg update 86 | pkg install vim curl wget git tree openssh neofetch man htop -y 87 | fi 88 | 89 | #Install fun softwares 90 | if [[ "$*" =~ fun || "$*" =~ all ]]; then 91 | apt install fortune 92 | apt install ruby -y 93 | gem install cowsay 94 | gem install lolcat 95 | echo "for fun just type: fortune | cowsay | lolcat or fun" 96 | echo "alias fun='fortune | cowsay | lolcat'" >> "$HOME/.zshrc" 97 | fi 98 | 99 | #Install you-get _Will not be automatically installed 100 | if [[ "$*" =~ yg ]]; then 101 | pkg install python3 ffmpeg -y 102 | pip3 install you-get -i https://pypi.tuna.tsinghua.edu.cn/simple some-package 103 | fi 104 | 105 | #OH-MY-ZSH 106 | if [[ "$*" =~ omz || "$*" =~ all ]]; then 107 | #sh -c "$(curl -fsSL https://github.com/Cabbagec/termux-ohmyzsh/raw/master/install.sh)" 108 | # install zsh 109 | pkg update 110 | pkg install -y git zsh 111 | git clone https://github.com/Cabbagec/termux-ohmyzsh.git "$HOME/termux-ohmyzsh" --depth 1 112 | 113 | mv "$HOME/.termux" "$HOME/.termux.bak.$(date +%Y.%m.%d-%H:%M:%S)" 114 | cp -R "$HOME/termux-ohmyzsh/.termux" "$HOME/.termux" 115 | 116 | git clone git://github.com/robbyrussell/oh-my-zsh.git "$HOME/.oh-my-zsh" --depth 1 117 | mv "$HOME/.zshrc" "$HOME/.zshrc.bak.$(date +%Y.%m.%d-%H:%M:%S)" 118 | cp "$HOME/.oh-my-zsh/templates/zshrc.zsh-template" "$HOME/.zshrc" 119 | sed -i '/^ZSH_THEME/d' "$HOME/.zshrc" 120 | sed -i '1iZSH_THEME="agnoster"' "$HOME/.zshrc" 121 | echo "alias chcolor='$HOME/.termux/colors.sh'" >> "$HOME/.zshrc" 122 | echo "alias chfont='$HOME/.termux/fonts.sh'" >> "$HOME/.zshrc" 123 | { 124 | echo "bindkey -v" 125 | echo "alias la='ls -a'" 126 | echo "alias ll='ls -l'" 127 | echo "alias lla='ls -al'" 128 | echo "alias src='source ~/.zshrc'" 129 | 130 | echo "alias ai='apt install'" 131 | echo "alias ala='apt list-all'" 132 | echo "alias aii='apt list-installed'" 133 | echo "alias au='apt uninstall'" 134 | echo "alias ash='apt show'" 135 | echo "alias ase='apt search'" 136 | } >> ~/.zshrc 137 | #git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.zsh-syntax-highlighting" --depth 1 138 | git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting 139 | echo "source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc 140 | 141 | chsh -s zsh 142 | 143 | printll "The default color theme is Tango,run chcolor to change it." 144 | printll "The default font is Ubuntu font,run chfont to change it." 145 | 146 | echo -e "\033[42;37m Please restart Termux app... \033[0m" 147 | fi 148 | 149 | #zsh-autosuggestions 150 | if [[ "$*" =~ zas || "$*" =~ all ]]; then 151 | git clone git://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions #this is ok 152 | #git clone https://github.com/zsh-users/zsh-autosuggestions.git "'$ZSH_CUSTOM'/plugins/zsh-autosuggestions" --depth 1 #bad run 153 | #git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/2/zsh-autosuggestions --depth 1 #bad run 154 | 155 | awk -v line=$(awk '$1!="#" && /plugins=\(/ && !/zsh-autosuggestions/ {print NR}' "$HOME/.zshrc") '{if(NR==line) gsub(/\)/," zsh-autosuggestions)");print > "'${HOME}'/.zshrc"}' "$HOME/.zshrc" 156 | #在awk内用print输出内容到某个文件,要写权路径,且整个文件名加路径要用双引号括起来; 157 | #即:print > "/tmp/aa" 对于变量 print >> "'${filenamePath}'/aa" 158 | fi 159 | 160 | #VIM 161 | if [[ "$*" =~ vim || "$*" =~ all ]]; then 162 | pkg install -y vim 163 | touch ~/.vimrc 164 | { 165 | echo '"PREFERENCES' 166 | echo 'set tabstop=4' 167 | echo 'set shiftwidth=4' 168 | echo 'set autoindent' 169 | echo 'set ignorecase' 170 | echo 'set smartcase' 171 | echo 'set nobackup' 172 | echo 'set noswapfile' 173 | echo 'set number' 174 | echo 'set relativenumber' 175 | echo 'set incsearch' 176 | echo 'set hlsearch' 177 | echo 'set nowrap' 178 | echo '' 179 | 180 | echo '"LEADER MAPPINGS' 181 | echo 'let mapleader=" "' 182 | echo 'let maplocalleader=","' 183 | echo 'nnoremap :' 184 | echo '' 185 | 186 | echo '"BUFFER MAPPINGS' 187 | echo 'nnoremap ba :badd ' 188 | echo 'nnoremap be :edit ' 189 | echo 'nnoremap bd :bdelete' 190 | echo 'nnoremap bw :w' 191 | echo 'nnoremap bfw :w!' 192 | echo 'nnoremap bn :bnext' 193 | echo 'nnoremap bp :bprevious' 194 | echo "" 195 | 196 | echo '"WINDOWS MAPPINGS' 197 | echo 'nnoremap wo :only' 198 | echo 'nnoremap ws :split ' 199 | echo 'nnoremap wv :vsplit ' 200 | echo 'nnoremap wj ' 201 | echo 'nnoremap wk ' 202 | echo 'nnoremap wl ' 203 | echo 'nnoremap wh ' 204 | echo "" 205 | 206 | echo '"TAB MAPPINGS' 207 | echo 'nnoremap ta :tabnew ' 208 | echo 'nnoremap tc :tabclose ' 209 | echo 'nnoremap tn :tabnext ' 210 | echo 'nnoremap tp :tabprevious' 211 | echo 'nnoremap th :tabmove - ' 212 | echo 'nnoremap tl :tabmove + ' 213 | echo "" 214 | 215 | echo '"VIM MAPPINGS' 216 | echo 'nnoremap vrc :edit ~/.vimrc' 217 | echo 'nnoremap vs :source ~/.vimrc' 218 | echo 'nnoremap vq :q' 219 | echo 'nnoremap vfq :q!' 220 | echo 'nnoremap vc :normal! 0i"' 221 | echo 'nnoremap vu :normal! 0x' 222 | } >> ~/.vimrc 223 | { 224 | set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1 225 | set enc=utf8 226 | set fencs=utf8,gbk,gb2312,gb18030 227 | } >> ~/.vimrc 228 | fi 229 | 230 | #NEOVIM 231 | if [[ "$*" =~ neovim || "$*" =~ all ]]; then 232 | pkg install -y neovim 233 | mkdir ~/.config 234 | mkdir ~/.config/nvim 235 | touch ~/.config/nvim/init.vim 236 | { 237 | echo '"PREFERENCES' 238 | echo 'set tabstop=4' 239 | echo 'set shiftwidth=4' 240 | echo 'set autoindent' 241 | echo 'set ignorecase' 242 | echo 'set smartcase' 243 | echo 'set nobackup' 244 | echo 'set noswapfile' 245 | echo 'set number' 246 | echo 'set relativenumber' 247 | echo 'set incsearch' 248 | echo 'set hlsearch' 249 | echo 'set nowrap' 250 | echo '' 251 | 252 | echo '"LEADER MAPPINGS' 253 | echo 'let mapleader=" "' 254 | echo 'let maplocalleader=","' 255 | echo 'nnoremap :' 256 | echo '' 257 | 258 | echo '"BUFFER MAPPINGS' 259 | echo 'nnoremap ba :badd ' 260 | echo 'nnoremap be :edit ' 261 | echo 'nnoremap bd :bdelete' 262 | echo 'nnoremap bw :w' 263 | echo 'nnoremap bfw :w!' 264 | echo 'nnoremap bn :bnext' 265 | echo 'nnoremap bp :bprevious' 266 | echo "" 267 | 268 | echo '"WINDOWS MAPPINGS' 269 | echo 'nnoremap wo :only' 270 | echo 'nnoremap ws :split ' 271 | echo 'nnoremap wv :vsplit ' 272 | echo 'nnoremap wj ' 273 | echo 'nnoremap wk ' 274 | echo 'nnoremap wl ' 275 | echo 'nnoremap wh ' 276 | echo "" 277 | 278 | echo '"TAB MAPPINGS' 279 | echo 'nnoremap ta :tabnew ' 280 | echo 'nnoremap tc :tabclose ' 281 | echo 'nnoremap tn :tabnext ' 282 | echo 'nnoremap tp :tabprevious' 283 | echo 'nnoremap th :tabmove - ' 284 | echo 'nnoremap tl :tabmove + ' 285 | echo "" 286 | 287 | echo '"VIM MAPPINGS' 288 | echo 'nnoremap vrc :edit ~/.vimrc' 289 | echo 'nnoremap vs :source ~/.vimrc' 290 | echo 'nnoremap vq :q' 291 | echo 'nnoremap vfq :q!' 292 | echo 'nnoremap vc :normal! 0i"' 293 | echo 'nnoremap vu :normal! 0x' 294 | } >> ~/.config/nvim/init.vim 295 | fi 296 | 297 | #Custom extra-key 298 | if [[ "$*" =~ eks || "$*" =~ all ]]; then 299 | # extra-keys = [ \ 300 | # extra-keys = [ \ 301 | # ['ESC','|','/','`','UP','QUOTE','APOSTROPHE'], \ 302 | # ['TAB','CTRL','~','LEFT','DOWN','RIGHT','ENTER'] \ 303 | # ]' 304 | cp "$HOME/.termux/termux.properties" "$HOME/.termux/termux.properties.bak.$(date +%Y.%m.%d-%H:%M:%S)" 305 | tempfile=`mktemp temp.XXXXXX` 306 | echo 'ICAgIGV4dHJhLWtleXMgPSBbIFwKICAgIFsnRVNDJywnfCcsJy8nLCdgJywnVVAnLCdRVU9URScsJ0FQ' > $tempfile 307 | sed -i 's/$/T1NUUk9QSEUnXSwgXAogICAgWydUQUInLCdDVFJMJywnficsJ0xFRlQnLCdET1dOJywnUklHSFQnLCdFTlRFUiddIFwKICAgIF0n/' $tempfile 308 | cat $tempfile|base64 -d >> ~/.termux/termux.properties 309 | rm -f $tempfile 2>/dev/null 310 | fi 311 | 312 | #FASD 313 | if [[ "$*" =~ fasd || "$*" =~ all ]]; then 314 | pkg install -y git 315 | pkg install -y make 316 | git clone https://github.com/clvv/fasd ~/fasd 317 | cd ~/fasd 318 | make install 319 | 320 | if [[ -f ~/.zshrc && -x /usr/bin/fasd ]]; then 321 | echo 'eval "$(fasd --init auto)"' >> ~/.zshrc 322 | echo "alias v='f -e vim'" >> ~/.zshrc 323 | fi 324 | if [[ -f ~/.bashrc && -x /usr/bin/fasd ]]; then 325 | echo 'eval "$(fasd --init auto)"' >> ~/.bashrc 326 | echo "alias v='f -e vim'" >> ~/.bashrc 327 | fi 328 | fi 329 | 330 | #FZF 331 | if [[ "$*" =~ 'fzf' || "$*" =~ all ]]; then 332 | pkg install -y fzf 333 | touch ~/.bashrc 334 | touch ~/.zshrc 335 | 336 | [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh 337 | [ -f ~/.fzf.bash ] && source ~/.fzf.bash 338 | 339 | { 340 | echo "export FZF_DEFAULT_COMMAND='find'" 341 | echo "export FZF_DEFAULT_OPTS='--height 50% --reverse --margin 0,0,0,2 --color fg:-1,bg:-1,hl:33,fg+:254,bg+:235,hl+:33 --color info:136,prompt:136,pointer:230,marker:230,spinner:136'" 342 | echo $'alias fcd=\'cd "$(find -L -type d | fzf)"\'' 343 | echo $'alias fv=\'vim "$(find -L -type f | fzf)"\'' 344 | } >> ~/.zshrc 345 | { 346 | echo "export FZF_DEFAULT_COMMAND='find'" 347 | echo "export FZF_DEFAULT_OPTS='--height 50% --reverse --margin 0,0,0,2 --color fg:-1,bg:-1,hl:33,fg+:254,bg+:235,hl+:33 --color info:136,prompt:136,pointer:230,marker:230,spinner:136'" 348 | echo $'alias fcd=\'cd "$(find -L -type d | fzf)"\'' 349 | echo $'alias fv=\'vim "$(find -L -type f | fzf)"\'' 350 | } >> ~/.bashrc 351 | fi 352 | 353 | exit 354 | 355 | --------------------------------------------------------------------------------