-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.sh
executable file
·334 lines (291 loc) · 10.4 KB
/
setup.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/data/data/com.termux/files/usr/bin/bash
## Termux Desktop i3 : Setup GUI in Termux
## ANSI Colors (FG & BG)
RED="$(printf '\033[31m')" GREEN="$(printf '\033[32m')" ORANGE="$(printf '\033[33m')" BLUE="$(printf '\033[34m')"
MAGENTA="$(printf '\033[35m')" CYAN="$(printf '\033[36m')" WHITE="$(printf '\033[37m')" BLACK="$(printf '\033[30m')"
REDBG="$(printf '\033[41m')" GREENBG="$(printf '\033[42m')" ORANGEBG="$(printf '\033[43m')" BLUEBG="$(printf '\033[44m')"
MAGENTABG="$(printf '\033[45m')" CYANBG="$(printf '\033[46m')" WHITEBG="$(printf '\033[47m')" BLACKBG="$(printf '\033[40m')"
## Reset terminal colors
reset_color() {
printf '\033[37m'
}
## Script Termination
exit_on_signal_SIGINT() {
{ printf "${RED}\n\n%s\n\n" "[!] Program Interrupted." 2>&1; reset_color; }
exit 0
}
exit_on_signal_SIGTERM() {
{ printf "${RED}\n\n%s\n\n" "[!] Program Terminated." 2>&1; reset_color; }
exit 0
}
trap exit_on_signal_SIGINT SIGINT
trap exit_on_signal_SIGTERM SIGTERM
## Banner
banner() {
clear
cat <<- EOF
${RED}┌──────────────────────────────────────────────────────────┐
${RED}│${GREEN}░░░▀█▀░█▀▀░█▀▄░█▄█░█░█░█░█░░░█▀▄░█▀▀░█▀▀░█░█░▀█▀░█▀█░█▀█░░${RED}│
${RED}│${GREEN}░░░░█░░█▀▀░█▀▄░█░█░█░█░▄▀▄░░░█░█░█▀▀░▀▀█░█▀▄░░█░░█░█░█▀▀░░${RED}│
${RED}│${GREEN}░░░░▀░░▀▀▀░▀░▀░▀░▀░▀▀▀░▀░▀░░░▀▀░░▀▀▀░▀▀▀░▀░▀░░▀░░▀▀▀░▀░░░░${RED}│
${RED}└──────────────────────────────────────────────────────────┘
EOF
}
## Show usages
usage() {
banner
echo -e ${ORANGE}"\nInstall GUI (i3 Desktop) on Termux"
echo -e ${ORANGE}"Usages : $(basename $0) --install | --uninstall | --termux-boot | --termux-boot-uninstall\n"
}
## Update, X11-repo, Program Installation
_pkgs=(bc bmon calc calcurse curl dbus elinks feh desktop-file-utils fontconfig-utils \
fsmon geany gtk2 gtk3 htop imagemagick jq leafpad man mpc mpd mutt ncmpcpp \
ncurses-utils neofetch otter-browser obconf openssl-tool polybar ranger rofi \
startup-notification termux-api pcmanfm tigervnc neovim wget xarchiver xbitmaps \
xfce4-terminal xmlstarlet audacious xorg-font-util xorg-xrdb zsh i3 picom which)
setup_base() {
echo -e ${RED}"\n[*] Installing Termux Desktop..."
echo -e ${CYAN}"\n[*] Updating Termux Base... \n"
{ reset_color; pkg update; pkg upgrade -y; pkg autoremove; pkg autoclean; }
echo -e ${CYAN}"\n[*] Enabling Termux X11-repo... \n"
{ reset_color; pkg install -y x11-repo; }
echo -e ${CYAN}"\n[*] Installing required programs... \n"
for package in "${_pkgs[@]}"; do
{ reset_color; }
if [[ "$(which $package)" == "" ]]; then
echo -e ${GREEN}"\n[*] Installing Package ${ORANGE}$package \n"
{ reset_color; }
pkg install -y $package
else
echo "${ORANGE}$package Already Installed"
{ reset_color; }
fi
done
reset_color
}
## Setup OMZ and Termux Configs
setup_omz() {
# backup previous termux and omz files
echo -e ${RED}"[*] Setting up OMZ and termux configs..."
omz_files=(.oh-my-zsh .termux .zshrc)
for file in "${omz_files[@]}"; do
echo -e ${CYAN}"\n[*] Backing up $file..."
if [[ -f "$HOME/$file" || -d "$HOME/$file" ]]; then
{ reset_color; mv -u ${HOME}/${file}{,.old}; }
else
echo -e ${MAGENTA}"\n[!] $file Doesn't Exist."
fi
done
# installing omz
echo -e ${CYAN}"\n[*] Installing Oh-my-zsh... \n"
{ reset_color; git clone https://github.com/robbyrussell/oh-my-zsh.git --depth 1 $HOME/.oh-my-zsh; }
cp $HOME/.oh-my-zsh/templates/zshrc.zsh-template $HOME/.zshrc
sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="sorin"/g' $HOME/.zshrc
sed -i -e 's|# export PATH=.*|export PATH=$HOME/.local/bin:$PATH|g' $HOME/.zshrc
# ZSH theme
cat > $HOME/.oh-my-zsh/custom/themes/sorin.zsh-theme <<- _EOF_
# Default OMZ theme
if [[ "\$USER" == "root" ]]; then
PROMPT="%(?:%{\$fg_bold[red]%}%{\$fg_bold[yellow]%}%{\$fg_bold[red]%} :%{\$fg_bold[red]%} )"
PROMPT+='%{\$fg[cyan]%} %c%{\$reset_color%} \$(git_prompt_info)'
else
PROMPT="%(?:%{\$fg_bold[red]%}%{\$fg_bold[green]%}%{\$fg_bold[yellow]%} :%{\$fg_bold[red]%} )"
PROMPT+='%{\$fg[cyan]%} %c%{\$reset_color%} \$(git_prompt_info)'
fi
ZSH_THEME_GIT_PROMPT_PREFIX="%{\$fg_bold[blue]%} git:(%{\$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{\$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{\$fg[blue]%}) %{\$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{\$fg[blue]%})"
_EOF_
# Append some aliases
cat >> $HOME/.zshrc <<- _EOF_
#------------------------------------------
alias l='ls -lh'
alias ll='ls -lah'
alias la='ls -a'
alias ld='ls -lhd'
alias p='pwd'
#alias rm='rm -rf'
alias u='cd $PREFIX'
alias h='cd $HOME'
alias :q='exit'
alias grep='grep --color=auto'
alias open='termux-open'
alias lc='lolcat'
alias xx='chmod +x'
alias rel='termux-reload-settings'
#------------------------------------------
# SSH Server Connections
# linux (Arch)
#alias arch='ssh UNAME@IP -i ~/.ssh/id_rsa.DEVICE'
# linux sftp (Arch)
#alias archfs='sftp -i ~/.ssh/id_rsa.DEVICE UNAME@IP'
#------------------------------------------
# Print system information
neofetch
#------------------------------------------
_EOF_
# configuring termux
echo -e ${CYAN}"\n[*] Configuring Termux..."
if [[ ! -d "$HOME/.termux" ]]; then
mkdir $HOME/.termux
fi
# copy font
cp $(pwd)/files/.fonts/icons/dejavu-nerd-font.ttf $HOME/.termux/font.ttf
# color-scheme
cat > $HOME/.termux/colors.properties <<- _EOF_
background : #000000
foreground : #eceff1
color0 : #000000
color8 : #37474f
color1 : #ff9800
color9 : #ffa74d
color2 : #8bc34a
color10 : #9ccc65
color3 : #ffc107
color11 : #ffa000
color4 : #03a9f4
color12 : #81d4fa
color5 : #e91e63
color13 : #ad1457
color6 : #009688
color14 : #26a69a
color7 : #cfd8dc
color15 : #eceff1
_EOF_
# button config
cat > $HOME/.termux/termux.properties <<- _EOF_
extra-keys = [ \\
['ESC','|', '/', '~','HOME','UP','END'], \\
['CTRL', 'TAB', '=', '-','LEFT','DOWN','RIGHT'] \\
]
_EOF_
# remove welcome texts
rm -rf /data/data/com.termux/files/usr/etc/motd
# change shell, reload settings, and enable access to /storage.
{ chsh -s zsh; termux-reload-settings; termux-setup-storage; }
}
## Configuration
setup_config() {
# backup
configs=($(ls -A $(pwd)/files))
echo -e ${RED}"\n[*] Backing up your files and dirs... "
for file in "${configs[@]}"; do
echo -e ${CYAN}"\n[*] Backing up $file..."
if [[ -f "$HOME/$file" || -d "$HOME/$file" ]]; then
{ reset_color; mv -u ${HOME}/${file}{,.old}; }
else
echo -e ${MAGENTA}"\n[!] $file Doesn't Exist."
fi
done
# Copy config files
echo -e ${RED}"\n[*] Copying config files... "
for _config in "${configs[@]}"; do
echo -e ${CYAN}"\n[*] Copying $_config..."
{ reset_color; cp -rf $(pwd)/files/$_config $HOME; }
done
}
## Setup VNC Server
setup_vnc() {
# backup old dir
if [[ -d "$HOME/.vnc" ]]; then
mv $HOME/.vnc{,.old}
fi
echo -e ${RED}"\n[*] Setting up VNC Server..."
{ reset_color; vncserver; }
sed -i -e 's/# geometry=.*/geometry=1920x1080/g' $HOME/.vnc/config
cat > $HOME/.vnc/xstartup <<- _EOF_
#!/data/data/com.termux/files/usr/bin/bash
## This file is executed during VNC server
## startup.
# Launch I3 Window Manager.
i3 &
_EOF_
{ vncserver -kill :1; vncserver; }
}
## Finish Installation
post_msg() {
echo -e ${GREEN}"\n[*] ${RED}Termux Desktop ${GREEN}Installed Successfully.\n"
cat <<- _MSG_
[-] In VNC Viewer, enter ${ORANGE}localhost:1 ${GREEN}as Address and Password you created to connect.
[-] To connect via PC over Wifi or Hotspot, use it's IP (if wi-fi = wlan0 inet, if ethernet = eth inet).
[-] If you wish to kill a server enter ${RED}"vncserver -kill :(server's number)".${GREEN}
[-] Have Fun!
_MSG_
{ reset_color; exit 0; }
}
## Install Termux Desktop
install_td() {
banner
setup_base
setup_omz
setup_config
setup_vnc
post_msg
}
## Uninstall Termux Desktop
uninstall_td() {
banner
# remove pkgs
echo -e ${RED}"\n[*] Unistalling Termux Desktop..."
echo -e ${CYAN}"\n[*] Removing Packages..."
for package in "${_pkgs[@]}"; do
echo -e ${GREEN}"\n[*] Removing Packages ${ORANGE}$package \n"
{ reset_color; apt-get remove -y --purge --autoremove $package; }
done
# delete files
echo -e ${CYAN}"\n[*] Deleting config files...\n"
_homefiles=(.fehbg .icons .mpd .ncmpcpp .fonts .gtkrc-2.0 .mutt .themes .vnc)
_configfiles=(pcmanfm geany gtk-3.0 leafpad i3 polybar ranger rofi xfce4 otter)
_localfiles=(bin lib 'share/backgrounds' 'share/pixmaps')
for i in "${_homefiles[@]}"; do
if [[ -f "$HOME/$i" || -d "$HOME/$i" ]]; then
{ reset_color; rm -rf $HOME/$i; }
else
echo -e ${MAGENTA}"\n[!] $file Doesn't Exist.\n"
fi
done
for j in "${_configfiles[@]}"; do
if [[ -f "$HOME/.config/$j" || -d "$HOME/.config/$j" ]]; then
{ reset_color; rm -rf $HOME/.config/$j; }
else
echo -e ${MAGENTA}"\n[!] $file Doesn't Exist.\n"
fi
done
for k in "${_localfiles[@]}"; do
if [[ -f "$HOME/.local/$k" || -d "$HOME/.local/$k" ]]; then
{ reset_color; rm -rf $HOME/.local/$k; }
else
echo -e ${MAGENTA}"\n[!] $file Doesn't Exist.\n"
fi
done
echo -e ${CYAN}"\n[*] Deleting Termux-Boot scripts.\n"
rm -rf ~/.termux/boot
echo -e ${RED}"\n[*] Termux Desktop Unistalled Successfully.\n"
}
configure_termux_boot() {
echo -e ${RED}"[*] Configuring Termux-Boot"
mkdir ~/.termux/boot
cat > ~/.termux/boot/boot.sh <<- _EOF_
#!/data/data/com.termux/files/usr/bin/sh
termux-wake-lock
sshd
_EOF_
echo -e ${GREEN}"[*] Done"
}
uninstall_tb() {
echo -e ${RED}"[*] Uninstalling Termux-Boot"
rm -rf ~/.termux/boot
echo -e ${GREEN}"[*] Done"
}
## Main
if [[ "$1" == "--install" ]]; then
install_td
elif [[ "$1" == "--termux-boot" ]]; then
configure_termux_boot
elif [[ "$1" == "--uninstall" ]]; then
uninstall_td
elif [[ "$1" == "--termux-boot-uninstall" ]]; then
uninstall_tb
{ usage; reset_color; exit 0; }
fi