-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_arrays
executable file
·124 lines (110 loc) · 3.39 KB
/
merge_arrays
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
#!/bin/bash
# Copyright (c) 2015, Redmaner
# Define bash colors for Mac OSX / Linux
case `uname -s` in
Darwin)
txtrst='\033[0m' # Color off
txtred='\033[0;31m' # Red
txtgrn='\033[0;32m' # Green
txtblu='\033[0;34m' # Blue
;;
*)
txtrst='\e[0m' # Color off
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtblu='\e[0;36m' # Blue
;;
esac
up=$PWD
MergeArrays () {
mkdir -p $new_array_dir
grep '<array\|<integer-array\|<string-array' $orig_array | uniq --unique | while read array; do
array_type=$(echo $array | cut -d'<' -f2 | cut -d' ' -f1)
array_name=$(echo $array | cut -d'"' -f2)
if [ $(sed -e '/name="'$array_name'"/!d' $targ_array | wc -l) -gt 0 ]; then
if [ $(sed -e '/name="'$array_name'"/!d' $targ_array | grep '/>' | wc -l) -gt 0 ]; then
sed -e '/<'$array_type' name="'$array_name'"/!d' $targ_array >> $new_array; continue
else
sed -e '/<'$array_type' name="'$array_name'"/,/'$array_type'>/!d' $targ_array >> $new_array; continue
fi
else
if [ $(sed -e '/name="'$array_name'"/!d' $orig_array | grep '/>' | wc -l) -gt 0 ]; then
sed -e '/<'$array_type' name="'$array_name'"/!d' $orig_array >> $new_array; continue
else
sed -e '/<'$array_type' name="'$array_name'"/,/'$array_type'>/!d' $orig_array >> $new_array; continue
fi
fi
done
if [ "$dual_merge" == true ]; then
grep '<array\|<integer-array\|<string-array' $orig_array_second | uniq --unique | while read array; do
array_type=$(echo $array | cut -d'<' -f2 | cut -d' ' -f1)
array_name=$(echo $array | cut -d'"' -f2)
if [ $(sed -e '/name="'$array_name'"/!d' $orig_array | wc -l) -gt 0 ]; then
continue
elif [ $(sed -e '/name="'$array_name'"/!d' $targ_array | wc -l) -gt 0 ]; then
if [ $(sed -e '/name="'$array_name'"/!d' $targ_array | grep '/>' | wc -l) -gt 0 ]; then
sed -e '/<'$array_type' name="'$array_name'"/!d' $targ_array >> $new_array; continue
else
sed -e '/<'$array_type' name="'$array_name'"/,/'$array_type'>/!d' $targ_array >> $new_array; continue
fi
else
if [ $(sed -e '/name="'$array_name'"/!d' $orig_array_second | grep '/>' | wc -l) -gt 0 ]; then
sed -e '/<'$array_type' name="'$array_name'"/!d' $orig_array_second >> $new_array; continue
else
sed -e '/<'$array_type' name="'$array_name'"/,/'$array_type'>/!d' $orig_array_second >> $new_array; continue
fi
fi
done
fi
if [ -s $new_array ]; then
echo -e "<?xml version='1.0' encoding='UTF-8'?>\n<resources>" > $new_array_final
cat $new_array >> $new_array_final
echo '</resources>' >> $new_array_final
rm -f $new_array
echo -e "${txtblu}>> Merged ${txtgrn}arrays${txtrst} $apk_file to $new_array_final"
fi
}
ShowHelp () {
echo -e "
Script requires three arguments
First argument: path to original arrays.xml
Second argument: path to target arrays.xml
Third argument: path to new arrays.xml
Fourth argument: apk name
"
exit
}
if [ -f "$1" ]; then
orig_array=$1
else
ShowHelp; exit
fi
if [ -f "$2" ]; then
targ_array=$2
else
ShowHelp; exit
fi
if [ "$3" != "" ]; then
new_array=$3.new
new_array_final=$3
new_array_dir=$(dirname $new_array)
else
ShowHelp; exit
fi
if [ "$4" != "" ]; then
apk_file=$4
else
ShowHelp; exit
fi
if [ "$5" != "" ]; then
untranslateable_list=$5
else
untranslateable_list=undefined
fi
if [ "$6" != "" ]; then
dual_merge=$6
fi
if [ "$7" != "" ]; then
orig_array_second=$7
fi
MergeArrays