-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·164 lines (123 loc) · 5.09 KB
/
setup.sh
File metadata and controls
executable file
·164 lines (123 loc) · 5.09 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
#!/bin/bash
set -euo pipefail
SETUP_ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$SETUP_ROOT" || {
echo "[!] Cannot cd to script directory: $SETUP_ROOT" >&2
exit 1
}
source "$SETUP_ROOT/lib.sh"
prompt_host_prerequisites
# Burp cert lives next to setup.sh (independent of caller's cwd)
BURP_DER="$SETUP_ROOT/burp.der"
export BURP_DER
if [[ ! -f "$BURP_DER" ]]; then
log_fatal "burp.der not found at $BURP_DER — export Burp CA as DER and save it there"
fi
log_ok "Found burp certificate: $BURP_DER"
log_info "Downloading Cmdlinetools, PlatformTools, Magisk"
bash "$SETUP_ROOT/Tools-downloader.sh" || log_fatal "Download failed"
log_info "Unzipping Cmdlinetools, PlatformTools"
if [[ -f "platform-tools.zip" ]]; then
unzip -q platform-tools.zip || log_fatal "Failed to unzip platform-tools.zip"
else
log_fatal "platform-tools.zip not found"
fi
if [[ -f "cmdline-tools.zip" ]]; then
unzip -q cmdline-tools.zip || log_fatal "Failed to unzip cmdline-tools.zip"
else
log_fatal "cmdline-tools.zip not found"
fi
log_info "Organizing files"
mkdir -p android_sdk/cmdline-tools/latest
mkdir -p android_sdk/platforms
mv cmdline-tools/* android_sdk/cmdline-tools/latest/ 2>/dev/null || log_fatal "Failed to move cmdline-tools"
rm -rf cmdline-tools
mv platform-tools android_sdk/ || log_fatal "Failed to move platform-tools"
# Cleanup zip files
rm -f platform-tools.zip cmdline-tools.zip
log_info "Cloning rootAVD into android_sdk"
if [[ -d "android_sdk/rootAVD" ]]; then
log_info "rootAVD directory already exists, skipping clone"
else
git clone https://gitlab.com/newbit/rootAVD.git android_sdk/rootAVD || \
log_fatal "Failed to clone rootAVD repository"
fi
if [[ -f "Magisk.zip" ]]; then
mv Magisk.zip android_sdk/rootAVD/Magisk.zip
else
log_warn "Magisk.zip not found : A14PR rooting will fail"
fi
# Move SDK to home directory
local_android_home="$HOME/android_sdk"
if [[ -d "$local_android_home" ]]; then
log_warn "$local_android_home already exists, merging files"
cp -rn android_sdk/* "$local_android_home/" 2>/dev/null || true
rm -rf android_sdk
else
mv android_sdk "$HOME/"
fi
# Detect shell and configure environment
rc_file=$(detect_shell_rc)
log_info "Setting up environment in $rc_file"
if ! grep -q 'ANDROID_HOME' "$rc_file" 2>/dev/null; then
cat >> "$rc_file" << 'EOL'
# Android SDK Paths
export ANDROID_HOME=$HOME/android_sdk
export PATH="$HOME/android_sdk/cmdline-tools/latest/bin:$PATH"
export PATH="$HOME/android_sdk/platform-tools:$PATH"
export PATH="$HOME/android_sdk/emulator:$PATH"
# Android Emulator Aliases
alias A10='emulator -avd A10 -writable-system'
alias A14PR='emulator -avd A14PR'
EOL
log_ok "Environment configured in $rc_file"
else
log_info "Android environment already in $rc_file, skipping"
fi
log_info "Applying changes to current shell"
export ANDROID_HOME="$HOME/android_sdk"
export PATH="$HOME/android_sdk/cmdline-tools/latest/bin:$PATH"
export PATH="$HOME/android_sdk/platform-tools:$PATH"
export PATH="$HOME/android_sdk/emulator:$PATH"
# log_info "Installing required packages"
# pkg_install jdk pipx
log_info "Accepting Android SDK licenses (non-interactive)"
yes | sdkmanager --licenses || log_warn "sdkmanager --licenses reported an error — later steps may prompt"
log_info "Installing Android system images"
sdkmanager --install "system-images;android-29;google_apis;x86" || \
log_fatal "Failed to install Android 10 system image"
sdkmanager --install "system-images;android-34;google_apis_playstore;x86_64" || \
log_fatal "Failed to install Android 14 system image"
log_info "Creating Android Virtual Devices"
avdmanager create avd -n "A10" -k "system-images;android-29;google_apis;x86" --force || \
log_fatal "Failed to create A10 AVD"
avdmanager create avd -n "A14PR" -k "system-images;android-34;google_apis_playstore;x86_64" --force || \
log_fatal "Failed to create A14PR AVD"
log_info "Setting up Android configuration"
mkdir -p "$HOME/.config/.android"
ln -sf "$HOME/.config/.android" "$HOME/.android"
log_info "Installing pentesting tools"
pipx install frida-tools || log_warn "frida-tools installation failed"
pipx install objection || log_warn "objection installation failed"
pipx install apkleaks || log_warn "apkleaks installation failed"
pipx install pyapktool || log_warn "pyapktool installation failed"
# log_info "Installing static analysis tools"
# pkg_install jadx apktool || log_warn "Some static analysis tools failed to install"
log_info "Configuring hardware keys for AVDs"
bash "$SETUP_ROOT/HWKeys.sh" A10
bash "$SETUP_ROOT/HWKeys.sh" A14PR
log_info "Setting up A10 with Burp certificate"
bash "$SETUP_ROOT/rootAVD.sh" A10 || log_fatal "A10 Burp certificate setup failed"
# Wait for A10 cleanup before starting A14PR
sleep 5
adb kill-server 2>/dev/null || true
sleep 3
log_info "Rooting A14PR with Magisk"
bash "$SETUP_ROOT/rootAVD.sh" A14PR || log_fatal "A14PR Magisk setup failed"
log_ok "Setup completed successfully!"
echo ""
echo "You can now use:"
echo " A10 - Launch Android 10 emulator (rooted + Burp cert + proxy)"
echo " A14PR - Launch Android 14 emulator (Magisk)"
echo ""
echo "Run: source $rc_file"