forked from openkampus/mkshrc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
372 lines (311 loc) · 14.6 KB
/
install.sh
File metadata and controls
372 lines (311 loc) · 14.6 KB
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/system/bin/sh
# =============================================================================
# Android Environment Installer Script
# =============================================================================
# @name Android Environment Installer
# @namespace https://github.com/user/mkshrc/
# @version 1.2
# @description Comprehensive development and debugging environment setup for Android devices
# @author user
# @match Android
#
# Purpose: Installs a complete shell environment with development tools, debugging utilities,
# and system binaries on Android devices via ADB or terminal.
#
# Features:
# - mkshrc shell environment customization
# - Frida dynamic instrumentation toolkit
# - BusyBox multi-call binary with Unix utilities
# - Vim advanced text editor with configuration
# - htop interactive process viewer
# - Git version control system
# - curl and OpenSSL for network operations
# - Architecture-specific binary support (ARM, x86)
# =============================================================================
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Color functions
_info() { echo -e "${BLUE}[I]${NC} $1"; }
_success() { echo -e "${GREEN}[✓]${NC} $1"; }
_warning() { echo -e "${YELLOW}[W]${NC} $1"; }
_error() { echo -e "${RED}[E]${NC} $1"; }
_step() { echo -e "${CYAN}[→]${NC} $1"; }
_highlight() { echo -e "${WHITE}${1}${NC}"; }
# Check if a command exists in PATH
_exist() {
command -v "$1" >/dev/null 2>&1
}
# =============================================================================
# CONFIGURATION SETTINGS
# =============================================================================
TMPDIR='/data/local/tmp' # Temporary directory for installation
CPU_ABI="$(getprop ro.product.cpu.abi)" # Detect device CPU architecture
FRIDA=${1:-'17.2.16'} # Default Frida version if not provided
rc_package="$TMPDIR/package" # Source package folder
rc_bin="$TMPDIR/bin" # Destination folder for binaries
echo ""
_info "Temporary directory: $TMPDIR"
_info "Detected CPU ABI: $CPU_ABI"
_info "Frida version: $FRIDA"
# =============================================================================
# ARCHITECTURE DETECTION AND VALIDATION
# =============================================================================
# Map Android ABI to package directory structure
# Supported architectures: arm64-v8a, armeabi-v7a, x86, x86_64
case "$CPU_ABI" in
arm64-v8a)
PACKAGE_ABI="arm64-v8a"
;;
armeabi-v7a)
PACKAGE_ABI="armeabi-v7a"
;;
x86)
PACKAGE_ABI="x86"
;;
x86_64)
PACKAGE_ABI="x86_64"
;;
*)
_error "Unsupported CPU ABI architecture: $CPU_ABI"
_info "Supported architectures: arm64-v8a, armeabi-v7a, x86, x86_64"
exit 1
;;
esac
_success "Using package architecture: $PACKAGE_ABI"
# Verify CPU ABI support and exit if not supported
[ ! -d "$rc_package/$PACKAGE_ABI" ] && {
_error "Package directory not found for architecture: $PACKAGE_ABI"
_error "Expected directory: $rc_package/$PACKAGE_ABI"
_info "Available architectures:"
ls -1 "$rc_package/" 2>/dev/null | grep -E '^(arm|x86)' | sed 's/^/ /'
exit 1
}
# =============================================================================
# CLEANUP AND INITIALIZATION
# =============================================================================
rm -rf "$rc_bin"
mkdir -p "$rc_bin"
_success "Clean installation directory prepared"
# =============================================================================
# SUPOLICY INSTALLATION (Magisk compatibility)
# =============================================================================
# Provides policy manipulation utilities for rooted devices
_exist() {
command -v "$1" >/dev/null 2>&1
}
_exist supolicy || {
cp -f "$rc_package/$PACKAGE_ABI/supolicy/supolicy" "$rc_bin/supolicy" 2>/dev/null || _warning "supolicy not found for $PACKAGE_ABI"
cp -f "$rc_package/$PACKAGE_ABI/supolicy/libsupol.so" "$rc_bin/libsupol.so" 2>/dev/null || _warning "libsupol.so not found for $PACKAGE_ABI"
_success "Security policy tools installed"
}
# =============================================================================
# FRIDA SERVER INSTALLATION
# =============================================================================
# Dynamic instrumentation toolkit for developers and reverse engineers
frida=$(find "$rc_package/$PACKAGE_ABI/frida" -type f -name "frida-server-$FRIDA*android-*" 2>/dev/null | sort -V | tail -n 1)
if [ -z "$frida" ]; then
_warning "Frida version $FRIDA not available for $PACKAGE_ABI"
_info "Available Frida versions:"
find "$rc_package/$PACKAGE_ABI/frida" -type f -name "frida-server-*" 2>/dev/null | sed 's/.*frida-server-//' | sed 's/-android.*//' | sort -u | sed 's/^/ /'
else
cp -f "$frida" "$rc_bin/frida-server"
chmod +x "$rc_bin/frida-server"
_success "Installed: $(basename "$frida")"
fi
# Install frida wrapper script
if [ -f "$rc_package/$PACKAGE_ABI/frida/frida" ]; then
cp -f "$rc_package/$PACKAGE_ABI/frida/frida" "$rc_bin/frida"
chmod +x "$rc_bin/frida"
_success "Frida wrapper script installed"
else
_warning "Frida wrapper script not found for $PACKAGE_ABI"
fi
# =============================================================================
# CORE UTILITIES INSTALLATION
# =============================================================================
# BusyBox - Multi-call binary combining many common Unix utilities
cp -f "$rc_package/$PACKAGE_ABI/busybox/libbusybox.so" "$rc_bin/busybox" 2>/dev/null || _warning "busybox not found for $PACKAGE_ABI"
# curl - Command line tool for transferring data with URL syntax
cp -f "$rc_package/$PACKAGE_ABI/curl/curl" "$rc_bin/curl" 2>/dev/null || _warning "curl not found for $PACKAGE_ABI"
# OpenSSL - Cryptography and SSL/TLS toolkit
cp -f "$rc_package/$PACKAGE_ABI/openssl/openssl" "$rc_bin/openssl" 2>/dev/null || _warning "openssl not found for $PACKAGE_ABI"
_success "Core utilities installed"
# =============================================================================
# TCPDUMP NETWORK PACKET ANALYZER
# =============================================================================
cp -f "$rc_package/$PACKAGE_ABI/tcpdump/tcpdump" "$rc_bin/tcpdump" 2>/dev/null || _warning "tcpdump not found for $PACKAGE_ABI"
_success "tcpdump installed"
# =============================================================================
# SSH SECURE SHELL CLIENT AND SERVER
# =============================================================================
# SSH client and related tools
[ -f "$rc_package/$PACKAGE_ABI/ssh/ssh" ] && {
cp -f "$rc_package/$PACKAGE_ABI/ssh/ssh" "$rc_bin/ssh"
chmod +x "$rc_bin/ssh"
_success "SSH client installed"
}
[ -f "$rc_package/$PACKAGE_ABI/ssh/scp" ] && cp -f "$rc_package/$PACKAGE_ABI/ssh/scp" "$rc_bin/scp"
[ -f "$rc_package/$PACKAGE_ABI/ssh/sftp" ] && cp -f "$rc_package/$PACKAGE_ABI/ssh/sftp" "$rc_bin/sftp"
[ -f "$rc_package/$PACKAGE_ABI/ssh/ssh-keygen" ] && cp -f "$rc_package/$PACKAGE_ABI/ssh/ssh-keygen" "$rc_bin/ssh-keygen"
[ -f "$rc_package/$PACKAGE_ABI/ssh/ssh-keyscan" ] && cp -f "$rc_package/$PACKAGE_ABI/ssh/ssh-keyscan" "$rc_bin/ssh-keyscan"
[ -f "$rc_package/$PACKAGE_ABI/ssh/sshd" ] && cp -f "$rc_package/$PACKAGE_ABI/ssh/sshd" "$rc_bin/sshd"
_success "SSH utilities installed"
# =============================================================================
# NGROK SECURE TUNNELS TO LOCALHOST
# =============================================================================
[ -f "$rc_package/$PACKAGE_ABI/ngrok/ngrok" ] && {
cp -f "$rc_package/$PACKAGE_ABI/ngrok/ngrok" "$rc_bin/ngrok"
chmod +x "$rc_bin/ngrok"
_success "Ngrok installed"
} || _warning "ngrok not found for $PACKAGE_ABI"
# =============================================================================
# GIT VERSION CONTROL SYSTEM
# =============================================================================
[ -f "$rc_package/$PACKAGE_ABI/git/git" ] && {
cp -f "$rc_package/$PACKAGE_ABI/git/git" "$rc_bin/git"
chmod +x "$rc_bin/git"
# Install git shared libraries if available
if [ -d "$rc_package/$PACKAGE_ABI/git/lib" ]; then
mkdir -p "$rc_bin/../lib"
cp -f "$rc_package/$PACKAGE_ABI/git/lib"/* "$rc_bin/../lib/" 2>/dev/null || true
_success "Git installed with shared libraries"
else
_success "Git version control system installed"
fi
# Create git wrapper script for library dependencies
if [ -d "$rc_bin/../lib" ] && [ "$(ls -A "$rc_bin/../lib" 2>/dev/null)" ]; then
cat > "$rc_bin/git-wrapper" << 'EOF'
#!/system/bin/sh
# Git wrapper script to handle shared library dependencies
# Set library path for git dependencies
export LD_LIBRARY_PATH="/data/local/tmp/lib:$LD_LIBRARY_PATH"
# Execute git with proper library path
exec /data/local/tmp/bin/git "$@"
EOF
chmod +x "$rc_bin/git-wrapper"
_success "Git wrapper script created for library dependencies"
fi
# Install additional git utilities
[ -f "$rc_package/$PACKAGE_ABI/git/git-upload-pack" ] && cp -f "$rc_package/$PACKAGE_ABI/git/git-upload-pack" "$rc_bin/git-upload-pack"
[ -f "$rc_package/$PACKAGE_ABI/git/git-receive-pack" ] && cp -f "$rc_package/$PACKAGE_ABI/git/git-receive-pack" "$rc_bin/git-receive-pack"
[ -f "$rc_package/$PACKAGE_ABI/git/git-shell" ] && cp -f "$rc_package/$PACKAGE_ABI/git/git-shell" "$rc_bin/git-shell"
}
# =============================================================================
# TEXT EDITORS AND SYSTEM TOOLS
# =============================================================================
# Vim - Advanced text editor with extensive customization
[ -f "$rc_package/$PACKAGE_ABI/vim/vim" ] && {
cp -f "$rc_package/$PACKAGE_ABI/vim/vim" "$rc_bin/vim"
chmod +x "$rc_bin/vim"
# Vimtutor - Interactive tutorial for learning Vim
[ -f "$rc_package/$PACKAGE_ABI/vim/vimtutor" ] && cp -f "$rc_package/$PACKAGE_ABI/vim/vimtutor" "$rc_bin/vimtutor"
# Vim configuration files and runtime environment
if [ -d "$rc_package/$PACKAGE_ABI/vim/vim_config/usr/share/vim" ]; then
mkdir -p "$rc_bin/../share"
cp -rf "$rc_package/$PACKAGE_ABI/vim/vim_config/usr/share/vim" "$rc_bin/../share/"
# Set VIM environment variables
echo "export VIM=\"$rc_bin/../share/vim\"" >> "$rc_bin/../.vimrc_env"
echo "export VIMRUNTIME=\"\$VIM/vim91\"" >> "$rc_bin/../.vimrc_env"
# Install basic vimrc configuration
[ -f "$rc_package/$PACKAGE_ABI/vim/vimrc_basic" ] && cp -f "$rc_package/$PACKAGE_ABI/vim/vimrc_basic" "$rc_bin/../.vimrc"
fi
_success "Vim editor installed (with vimtutor and configuration)"
}
# vi - Simple text editor from BusyBox
[ -f "$rc_package/$PACKAGE_ABI/vi/vi" ] && {
cp -f "$rc_package/$PACKAGE_ABI/vi/vi" "$rc_bin/vi"
chmod +x "$rc_bin/vi"
_success "Vi editor installed"
}
# htop - Interactive process viewer and system monitor
[ -f "$rc_package/$PACKAGE_ABI/htop/htop" ] && {
cp -f "$rc_package/$PACKAGE_ABI/htop/htop" "$rc_bin/htop"
chmod +x "$rc_bin/htop"
# Install ncursesw terminfo files for proper terminal support
if [ -d "$rc_package/$PACKAGE_ABI/htop/usr/share" ]; then
mkdir -p "$rc_bin/../share"
cp -rf "$rc_package/$PACKAGE_ABI/htop/usr/share"/* "$rc_bin/../share/"
# Set TERMINFO environment variable
echo "export TERMINFO=\"$rc_bin/../share/terminfo\"" >> "$rc_bin/../.htoprc_env"
_success "Htop installed with terminfo support"
else
_success "Htop process viewer installed"
fi
}
# =============================================================================
# SECURITY AND CERTIFICATE MANAGEMENT
# =============================================================================
# Certificate update script for managing trusted CA certificates
[ -f "$rc_package/update-ca-certificate.sh" ] && {
cp "$rc_package/update-ca-certificate.sh" "$rc_bin/update-ca-certificate"
chmod +x "$rc_bin/update-ca-certificate"
_success "Certificate management script installed"
}
# =============================================================================
# PERMISSIONS AND FINAL SETUP
# =============================================================================
# Set ownership and permissions for security and accessibility
chown -R shell:shell "$rc_bin"
chmod -R 755 "$rc_bin"
_success "Permissions set correctly"
# BusyBox applet setup - Create symlinks for all available utilities
if [ -f "$rc_bin/busybox" ]; then
busybox="$rc_bin/busybox"
chmod +x "$busybox"
for applet in $("$busybox" --list | grep -v '^man$'); do
[ -f "$rc_bin/$applet" ] || ln -s "$busybox" "$rc_bin/$applet" 2>/dev/null || true
done
_success "BusyBox applets configured"
else
_warning "BusyBox not available for setting up applets"
fi
# =============================================================================
# SHELL ENVIRONMENT CONFIGURATION
# =============================================================================
# Install and load mkshrc configuration script
rc_path="$TMPDIR/mkshrc"
rm -f "$rc_path"
[ -f "$rc_package/mkshrc.sh" ] && {
cp -f "$rc_package/mkshrc.sh" "$rc_path"
_success "RC script installed at $rc_path"
# Load environment configuration
. "$rc_path"
_success "Shell environment loaded"
}
# =============================================================================
# INSTALLATION SUMMARY
# =============================================================================
echo ""
_info "Available tools:"
[ -f "$rc_bin/vim" ] && _highlight " ✦ vim - Advanced text editor (:q to quit, :wq to save)"
[ -f "$rc_bin/vi" ] && _highlight " ✦ vi - Simple text editor (from BusyBox)"
[ -f "$rc_bin/htop" ] && {
_highlight " ✦ htop - Interactive process viewer (q to quit, F1 for help)"
}
[ -f "$rc_bin/git" ] && {
_highlight " ✦ git - Version control system"
}
[ -f "$rc_bin/curl" ] && _highlight " ✦ curl - Data transfer tool"
[ -f "$rc_bin/openssl" ] && _highlight " ✦ openssl - Cryptography toolkit"
[ -f "$rc_bin/frida-server" ] && _highlight " ✦ frida-server - Dynamic instrumentation"
[ -f "$rc_bin/busybox" ] && _highlight " ✦ busybox - Unix utilities collection"
[ -f "$rc_bin/tcpdump" ] && _highlight " ✦ tcpdump - Network packet analyzer"
[ -f "$rc_bin/ssh" ] && _highlight " ✦ ssh - Secure shell client"
[ -f "$rc_bin/ngrok" ] && _highlight " ✦ ngrok - Secure tunnels to localhost"
# =============================================================================
# CLEANUP AND COMPLETION
# =============================================================================
echo ""
# Note: Cleanup moved to end to avoid removing script while running
rm -rf "$rc_package"
_success "Cleanup completed"
_success "mkshrc environment is now active!"
_highlight "✨ Enjoy your enhanced development environment! ✨"
echo ""