-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup_shell.sh
176 lines (139 loc) · 3.27 KB
/
backup_shell.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
###shell
meName=`basename "$0"`
verbose="false"
use_data_format="false"
command="show_usage"
echo_out="stdout"
port=5556
GetOpt(){
args="$@"
index=0
for arg in $args
do
index=$(($index + 1 ))
paramName="${arg%%=*}"
paramVal="${arg#*=}"
case "$paramName" in
"-l"|"--list")
command="list_partitons";;
"-gs"|"--get-system-partiton")
command="get_system_partiton";;
"-v"|"--verbose")
verbose="true";;
"-d"|"--use_data_format")
use_data_format="true";;
"-o"|"--output")
echo_out="$paramVal";;
"-p"|"--port")
port="$paramVal";;
"--force")
ForceUpdate=1;;
*)
case $index in
1) File="${arg}";;
2) PC="${arg}";;
3) IP="${arg}";;
*) Usage; exit 1;;
esac
;;
esac
done
}
function set_output(){
case "$echo_out" in
"stdout")
echo "Output will be sent to the stdout";;
"host")
echo "Output will be sent to host(incomming connection):$port";;
esac
}
function list_partitons{
WriteVerbose "List partitons"
partitions=`ls -l /dev/block/platform/*1/*name/ | sed 's/.* \(.*\) -> \(.*\)/\1{>_>}\2/'`
WriteData Partitions "$partitions"
}
function get_system_partiton{
if [ x"$partitions" -eq x"" ]; then
list_partitons();
fi
WriteVerbose "Find system partition"
system=`echo "$partitions" | sed -n 's/system{>_>}\(.*\)/\1/p'`
WriteData System "$system"
}
function attach_busybox{
if [ x"$system" -eq x"" ]; then
get_system_partiton();
fi
WriteVerbose "Attach busybox"
mkdir sys_dir
mount -o rw -t ext4 $system /sys_dir
cp /sys_dir/xbin/busybox /system
umount /sys_dir
}
function list_mount{
#List mounted fs
mounts=`mount | awk '/^\/dev\/block/{print $3}'`
WriteVerbose "Phone mounted files systems: \n $mounts"
}
function unmount_system{
if [ x"$mounts" -eq x"" ]; then
list_mount();
fi
#umount all /dev/block/ partitions
WriteVerbose "Unmount file systems"
for mount_point in $mounts
do
WriteVerbose "Unmount $mount_point"
umount $mount_point;
done
}
function get_part_info{
if [ x"$partitions" -eq x"" ]; then
list_partitons();
fi
#get partitions size via /system/busybox fdisk -l /dev/block/mmcblk0p{0}
for partition in `echo "$partitions" | sed -n 's/.*{>_>}//p'`
do
partInfo=`fdisk -l $partition | sed -n "s/Disk \(.*\): \(.*\), \(.*\)/\1{>_>}\2{>_>}\3/p"`
WriteVerbose "Partition info: $partInfo"
WriteData partInfo "$partInfo"
done
}
function send_host{
#send selected partitons
/system/busybox nc -l -p 5555 -e /system/busybox dd if=$1
}
function send_host_all{
echo "$partitions" | sed -n 's/' | sed '$!N; /^\(.*\)\n\1$/!P; D'
}
function send_host_all{
/system/busybox nc -l -p 5555 -e /system/busybox dd if=/dev/block/mmcblk0
/system/busybox nc -l -p 5555 -e /system/busybox dd if=/dev/block/mmcblk1
}
function WriteVerbose {
if [x"$verbose" -eq x"true"]; then
write-host ----====$@====----
fi
}
function WriteData{
if [x"$use_data_format" -eq x"true"]; then
write-host "_________________"
write-host "$1:"
write-host "$@"
write-host "_________________"
else
write-host "$@" | sed 's/{>_>}/ /'
fi
}
function write-host(){
case "$echo_out" in
"stdout")
echo "$@";;
"host")
/system/busybox nc -l -p $port -e echo "$@"
esac
}
GetOpt "$@"
set_output()
`$command`;
return;