forked from askeing/B2G-flash-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_ota_url.sh
executable file
·99 lines (83 loc) · 2.1 KB
/
change_ota_url.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
#!/bin/bash
#==========================================================================
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#==========================================================================
# Description:
# This script was written for change OTA update URL.
#
# Author: Askeing [email protected]
#==========================================================================
function find_prefs_path(){
# distinguish platform
case `uname` in
"Linux")
prefs_path=$(adb shell ls /data/b2g/mozilla/*.default/prefs.js | tr -d '\n' | tr -d '\r');;
"Darwin")
prefs_path=$(adb shell ls /data/b2g/mozilla/*.default/prefs.js | tr -d '\n' | tr -d '\r');;
esac
}
function helper_config(){
echo -e "-h, --help\tShow usage."
echo -e "-p\t\tShow prefs file of device."
echo -e "-u, --url\tThe update.xml URL."
}
function show_prefs(){
set -e
if [ 'unknown' == $(adb get-state) ]; then
echo "Unknown device"
exit -1
fi
find_prefs_path
adb shell cat ${prefs_path}
}
# argument parsing
while [ $# -gt 0 ]; do
case "$1" in
"-u"|"--url")
URL="$2"
shift
;;
"-p")
show_prefs
exit 0
;;
"-h"|"-?"|"--help")
helper_config
exit 0
;;
esac
shift
done
if [ "$URL" == "" ]; then
helper_config
exit -1
fi
echo "Updated URL: $URL"
####################
# Start
####################
cur_dir=$(pwd)
set -e
if [ 'unknown' == $(adb get-state) ]; then
echo "Unknown device"
exit -1
fi
####################
# Start
####################
TODAY=$(date +%s)
TWO_DAY_AGO=$((${TODAY} - 172800))
dir=$(mktemp -d -t captive.XXXXXXXXXXXX)
cd ${dir}
find_prefs_path
adb pull ${prefs_path}
cp prefs.js prefs.js.bak
echo -e "user_pref(\"app.update.url.override\", \"$URL\");" >> prefs.js
echo -e "user_pref(\"app.update.lastUpdateTime.background-update-timer\", $TWO_DAY_AGO);" >> prefs.js
adb push prefs.js ${prefs_path}
sleep 5
adb reboot
cd ${cur_dir}
rm -rf ${dir}