-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnvram_writter.sh
More file actions
165 lines (136 loc) · 4.3 KB
/
Copy pathnvram_writter.sh
File metadata and controls
165 lines (136 loc) · 4.3 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
#!/bin/bash
# =============================================================================
# Huawei B310as-938 NVRAM Writer for Termux
# Unofficial script by FREAKINGDAN
# Original script by Jerome Laliag
# =============================================================================
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print output
show_title() {
clear
echo -e "${BLUE}"
echo "==================================================="
echo " Huawei B310as-938 NVRAM Writter "
echo " Unofficial script for Termux by FREAKINGDAN "
echo " Official script made by Jerome Laliag "
echo "==================================================="
echo -e "${NC}"
}
print_status() {
echo -e "${BLUE}[INFO] $1${NC}"
}
print_success() {
echo -e "${GREEN}[✓] $1${NC}"
}
print_warning() {
echo -e "${YELLOW}[!] $1${NC}"
}
print_error() {
echo -e "${RED}[x] $1${NC}"
}
cancel_script() {
clear
show_title
echo -e "${YELLOW}[✓] NVRAM Writing successfully canceled${NC}"
say_goodbye
echo -e "${NC}"
}
say_goodbye() {
echo -e "${GREEN}Have a good day!"
}
# If the script is cancelled
trap 'cancel_script; exit 0' INT
# Clear screen and show the title
show_title
# Kill existing adb server
print_status "Killing any existing ADB server..."
adb kill-server 2>/dev/null || true
# Connect to device
print_status "Connecting to the device via WiFi or Ethernet"
if adb connect 192.168.8.1:5555 > /dev/null 2>&1; then
output=$(adb connect 192.168.8.1:5555 2>&1)
if echo "$output" | grep -q "error\|unreachable\|failed"; then
print_error "Failed to connect"
print_warning "Make sure your phone is connected to a WiFi or USB Ethernet"
exit 1
fi
fi
print_success "Successfully connected"
read -p "Press Enter to continue or Ctrl+C to cancel"
# Show Title
show_title
# Get IMEI
read -p "Enter IMEI (15 digits): " modemimei
if [[ ! "$modemimei" =~ ^[0-9]{15}$ ]]; then
print_error "Invalid IMEI"
exit 1
fi
adb shell "atc AT^PHYNUM=IMEI,$modemimei,0 > /dev/null 2>&1"
print_success "IMEI set successfully"
# Get Serial Number
read -p "Enter Serial Number: " modemsn
adb shell "atc AT^SN=$modemsn > /dev/null 2>&1"
print_success "Serial Number set successfully"
# Get LAN MAC Address
read -p "Enter LAN MAC Address (XX:XX:XX:XX:XX:XX): " modemmac
if [[ ! "$modemmac" =~ ^([0-9A-Fa-f]{2}){5}[0-9A-Fa-f]{2}$ ]]; then
print_error "Invalid MAC Address!"
exit 1
fi
adb shell "atc AT^PHYNUM=MAC,$modemmac,0 > /dev/null 2>&1"
print_success "MAC Address set successfully"
# Get WiFi SSID
read -p "Enter WiFi SSID: " modemwifi
# Create and push SSID script
cat > modem_ssid.sh << EOF
#!/bin/sh
atc AT^SSID=0,\"$modemwifi\" > /dev/null 2>&1
atc AT^SSID=1,\"$modemwifi-1\" > /dev/null 2>&1
atc AT^SSID=2,\"$modemwifi-2\" > /dev/null 2>&1
atc AT^SSID=3,\"$modemwifi-3\" > /dev/null 2>&1
EOF
# Execute the script
adb push modem_ssid.sh /tmp/ 2> nul
adb shell "chmod +x /tmp/modem_ssid.sh && sh /tmp/modem_ssid.sh '$modemwifi'"
print_success "WiFi SSID set successfully"
# Get WiFi Password
read -sp "Enter WiFi Password: " modempass
echo
# Set password for all 4 slots
for i in 0 1 2 3; do
adb shell "atc AT^WIKEY=$i,\"$modempass\" > /dev/null 2>&1"
done
print_success "WiFi Password set successfully"
# Save to NVRAM
print_status "Saving configuration to NVRAM..."
adb shell "atc AT^INFORBU > /dev/null 2>&1"
print_success "Configuration saved!"
# Reset instruction
echo
echo -e "${YELLOW}"
echo "======================================================"
echo "IMPORTANT: Press and hold the RESET button on the"
echo " back of the router for 5 seconds to"
echo " apply the changes!"
echo "======================================================"
echo -e "${NC}"
adb shell "atc AT^RESET > /dev/null 2>&1"
read -p "Press ENTER after completing the reset..."
show_title
# Cleanup
print_status "Cleaning up..."
adb kill-server 2>/dev/null || true
rm -f /tmp/modem_ssid.sh 2>/dev/null || true
rm -f modem_ssid.sh 2>/dev/null || true
# Finishing up
print_success "NVRAM Writing Complete"
echo
echo -e "${BLUE}Press any key to exit...${NC}"
say_goodbye
read -n 1 -s