-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.sh
executable file
·201 lines (186 loc) · 5.82 KB
/
menu.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
function alternate_buffer {
local state=$1
case $state in
off)
echo -ne "\033[?1049l" ;;
on)
echo -ne "\033[?1049h" ;;
esac
}
function build {
configure
gum spin --title Building -- \
apktool build --force-all --use-aapt2 RetroRazr
gum spin --title Signing -- \
java -jar bin/uber-apk-signer.jar --apks RetroRazr/dist/*.apk --allowResign --overwrite
mv RetroRazr/dist/*.apk .
rm -rf RetroRazr/{build,dist}
}
function configure {
[ -d RetroRazr ] && rm -rf RetroRazr
7z x src/RetroRazr.zip &>/dev/null
cp src/wallpaper/"$wallpaper".png RetroRazr/res/drawable/homescreen_wallpaper.png
cp -r src/main/* src/skin/"$skin"/* RetroRazr
if [ "$device_height" -ne 2142 ] ; then
scale_factor=$(bc -l <<< "($device_height / 2142)")
xmlstarlet ed -L -u "//dimen[contains(text(), 'px')]" \
-x "concat(substring-before(., 'px') * $scale_factor, 'px')" \
RetroRazr/res/values/dimens.xml
xmlstarlet ed -L -u "//dimen[contains(@name, 'idle_main_border')]" \
-x ". * $scale_factor" \
RetroRazr/res/values/dimens.xml
fi
version=$(grep 'versionCode' RetroRazr/apktool.yml | awk -F"'" '{print $2}')
case $option_mode in
Default)
sed -i "s/RetroRazr/RetroRazr\-$version\-${device_height}px/" \
RetroRazr/apktool.yml ;;
Custom)
rm RetroRazr/res/drawable/center_soft_key_icon.xml
cp -r src/res RetroRazr
if [ "$shortcuts" = Invisible ] ; then
sed -i 's/visible/invisible/' RetroRazr/res/layout/idle_main_fragment.xml
sed -i 's/ff103184/00103184/' RetroRazr/res/values/colors.xml
fi
sed -i \
"s/RetroRazr/RetroRazr\-$version\-$wallpaper\-$skin\-$shortcuts\-${device_height}px/" \
RetroRazr/apktool.yml ;;
esac
find RetroRazr/res -name "strings.xml" -exec sed -i 's/Verizon/V3 Wireless/' {} +
find RetroRazr -type f -exec sed -i \
"s#com\.motorola\.retrorazr#com\.motorola\.retrorazr$version#g" {} +
find RetroRazr -type f -exec sed -i \
"s#com\/motorola\/retrorazr#com\/motorola\/retrorazr$version#g" {} +
mv RetroRazr/smali/com/motorola/retrorazr RetroRazr/smali/com/motorola/retrorazr"$version"
}
function cursor {
local state=$1
case $state in
off)
echo -ne "\033[?25l" ;;
on)
echo -ne "\033[?25h" ;;
zero)
echo -ne "\033[0;0H" ;;
esac
}
function customize_ui {
case $option_menu in
Wallpaper)
wallpaper=$(gum choose --header Wallpaper --selected "$wallpaper" \
Caribbean Food HigherPlane Moto Pacific Scarlet Silver) ;;
Skin)
skin=$(gum choose --header Skin --selected "$skin" \
Moto Scarlet Silver) ;;
esac
refresh
gum confirm "$(gum style "Save" --align center --width $COLUMNS --bold)" && menu
customize_ui
}
function menu {
case $option_mode in
Default)
option_menu=$(gum choose --header "Default menu" --selected "$option_menu" \
Mode "Device height" Build Exit) ;;
Custom)
option_menu=$(gum choose --header "Custom menu" --selected "$option_menu" \
Mode Wallpaper Skin Shortcuts "Device height" Build Exit) ;;
esac
case $option_menu in
Mode)
option_mode=$(gum choose --header Mode --selected "$option_mode" Default Custom)
set_vars
refresh
menu ;;
Wallpaper|Skin)
customize_ui ;;
Shortcuts)
shortcuts=$(gum choose --header Shortcuts --selected "$shortcuts" Visible Invisible)
menu ;;
"Device height")
device_height=$(gum input \
--placeholder "$device_height" --char-limit 4 --header "Device height (px)")
set_vars
menu ;;
Build)
gum confirm "$(summary)" && build
menu ;;
Exit)
alternate_buffer off
clear
exit ;;
esac
}
function refresh {
cursor off
cursor zero
ui
cursor on
}
function set_vars {
[ -z "$option_mode" ] && option_mode=Default
case $option_mode in
Default)
wallpaper=Default
skin=Default ;;
Custom)
[ "$wallpaper" = Default ] && wallpaper=Moto
[ "$skin" = Default ] && skin=Moto ;;
esac
[ -z "$shortcuts" ] && shortcuts=Visible
[[ $device_height =~ ^[0-9]{4}$ ]] || device_height=2142
}
function summary {
gum style "$(gum join \
"$(summary_keys)" "$(summary_values)" \
--horizontal)" --align center --width $COLUMNS --bold
}
function summary_keys {
case $option_mode in
Default)
gum style "$(printf "Device height: ")" --align left ;;
Custom)
gum style "$(printf \
"Wallpaper: \nSkin: \nShortcuts: \nDevice height: ")" \
--align left ;;
esac
}
function summary_values {
case $option_mode in
Default)
gum style "$(printf "%s" "${device_height}px")" --align right ;;
Custom)
gum style "$(printf "%s\n %s\n %s\n %s" \
"$wallpaper" "$skin" "$shortcuts" "${device_height}px")" \
--align right ;;
esac
}
function title {
gum style "RetroRazr launcher" --align center --width $COLUMNS --bold
}
function ui {
gum join "$(title)" "$(view)" --vertical
}
function view {
gum style "$(gum style "$(timg -g${LINES}x$LINES \
"src/wallpaper/$wallpaper.png" \
"src/skin/$skin/res/drawable/softkey_normal_notext.png")" \
--border rounded)" --align center --width $COLUMNS
}
color=#005eb8 # moto blue
export GUM_CHOOSE_CURSOR_FOREGROUND=$color
export GUM_CHOOSE_HEADER_FOREGROUND=$color
export GUM_CHOOSE_HEIGHT=7
export GUM_CHOOSE_SELECTED_FOREGROUND=$color
export GUM_CONFIRM_SELECTED_BACKGROUND=$color
export GUM_INPUT_CURSOR_FOREGROUND=$color
export GUM_INPUT_HEADER_FOREGROUND=$color
export GUM_SPIN_ALIGN=right
export GUM_SPIN_SPINNER=points
export GUM_SPIN_SPINNER_FOREGROUND=$color
alternate_buffer on
clear
set_vars
ui
menu