501 lines
13 KiB
Bash
Executable File
501 lines
13 KiB
Bash
Executable File
#!/bin/bash -eu
|
|
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
#
|
|
# Generate a new DEFAULT.yaml file using hwid_unknown.bmp as a placeholder.
|
|
#
|
|
yaml_file="DEFAULT.yaml"
|
|
|
|
# I'm sorting the locales in more-or-less geographical order. Right should move
|
|
# east, left should move west. Of course we'll start in the US. :-)
|
|
locales="en es_419 pt_BR en_GB fr es pt_PT ca it de el nl da no sv fi et lv "\
|
|
"lt ru pl cs sk hu sl sr hr bg ro uk tr iw ar fa hi th vi id fil zh_CN zh_TW "\
|
|
"ko ja"
|
|
localedir="./locale"
|
|
|
|
# These render right-to-left
|
|
rtol="ar fa iw"
|
|
|
|
# Accept optional args which are the locales to emit. Default is all of 'em.
|
|
if [ -n "$*" ]; then
|
|
# Make sure all the args actually match
|
|
for arg in "$@"; do
|
|
if [ ! -d "$localedir/$arg" ]; then
|
|
echo "$0: locale \"$arg\" is unknown" 1>&2
|
|
exit 1
|
|
fi
|
|
done
|
|
locales="$*"
|
|
fi
|
|
|
|
# Arbitrary padding
|
|
ypad=5
|
|
xpad=5
|
|
|
|
# Globals used to specify location images are inserted.
|
|
cur_x=0
|
|
cur_y=0
|
|
|
|
reset_pos() {
|
|
cur_x=0
|
|
cur_y=0
|
|
}
|
|
|
|
move_pos_up() {
|
|
cur_y=$(expr $cur_y - $1 )
|
|
}
|
|
|
|
move_pos_down() {
|
|
cur_y=$(expr $cur_y + $1 )
|
|
}
|
|
|
|
move_pos_left() {
|
|
cur_x=$(expr $cur_x - $1 )
|
|
}
|
|
|
|
move_pos_right() {
|
|
cur_x=$(expr $cur_x + $1 )
|
|
}
|
|
|
|
# Move insert location to the vertical midline of a specified image.
|
|
# Example: set_centered_y_percent 'some_image' 80
|
|
# Sets insert point to the center of an image specified by a variable name,
|
|
# 80% towards the bottom. Assumes image was inserted at 0,0 so only good
|
|
# for the background image.
|
|
set_centered_y_percent() {
|
|
cur_x=$(expr $(get_width $1) / 2 )
|
|
cur_y=$(expr $(get_height $1) \* $2 / 100 )
|
|
}
|
|
|
|
# Return width of a .bmp file specified by a variable.
|
|
get_width() {
|
|
local filename="$(eval "echo \$$1")"
|
|
identify -format "%[fx:w]" "$filename"
|
|
}
|
|
|
|
# Return the width of a list of images.
|
|
total_width() {
|
|
local width=$(expr 0 - $xpad)
|
|
for filename in "$@"; do
|
|
width=$(expr $width + $(get_width ${filename}) + $xpad)
|
|
done
|
|
echo $width
|
|
}
|
|
|
|
# Return height of a .bmp file specified by a variable.
|
|
get_height() {
|
|
local filename="$(eval "echo \$${1}")"
|
|
identify -format "%[fx:h]" "$filename"
|
|
}
|
|
|
|
# Returns the max height of a list of images.
|
|
get_max_height() {
|
|
local max_height=0
|
|
local height
|
|
for filename in $@; do
|
|
height=$(get_height ${filename})
|
|
[ $max_height -gt $height ] || max_height=$height
|
|
done
|
|
echo $max_height
|
|
}
|
|
|
|
# Guess the locale based on the filename, set a global "newlocales" list
|
|
# accordingly.
|
|
guess_locale() {
|
|
local lc
|
|
local islc
|
|
local matches
|
|
islc=
|
|
|
|
matches=0
|
|
for lc in $locales; do
|
|
case "$1" in
|
|
*[_-]${lc}_* )
|
|
matches=$(expr $matches + 1)
|
|
islc=$lc
|
|
;;
|
|
esac
|
|
done
|
|
if (( $matches != 1 )); then
|
|
islc='en'
|
|
fi
|
|
|
|
local newlist
|
|
newlist="$islc"
|
|
for lc in $locales; do
|
|
if [ "$lc" != "$islc" ]; then
|
|
newlist="$newlist $lc"
|
|
fi
|
|
done
|
|
|
|
newlocales=$newlist
|
|
}
|
|
|
|
# Add a list of images at provided location.
|
|
# Images of different heights are added centered on the tallest image.
|
|
add_images() {
|
|
local x=$1
|
|
local y=$2
|
|
local files=${@:3}
|
|
local max_height=$(get_max_height $files)
|
|
|
|
for fname in $files; do
|
|
tmp_y=$(echo $( expr $y + "(" $max_height - $(get_height $fname) ")" / 2 ) )
|
|
if [ "$fname" = "th_model_text" ]; then
|
|
tmp_y=$(expr $y - 9)
|
|
fi
|
|
echo " - [$x, $tmp_y, $fname]" >> "$yaml_file"
|
|
x=$(expr $x + $(get_width $fname) + $xpad)
|
|
done
|
|
}
|
|
|
|
add_centered_below() {
|
|
local images=$@
|
|
local width
|
|
local height
|
|
local x
|
|
local y
|
|
|
|
height=$(get_max_height $images)
|
|
y=$(expr $cur_y + $height)
|
|
|
|
width=$(total_width $images)
|
|
x=$(expr $cur_x - $width / 2)
|
|
|
|
add_images $x $y $images
|
|
}
|
|
|
|
# This adds a list of images and updates the insert location
|
|
# below the new images with a padding of $xpad.
|
|
insert_centered_below() {
|
|
local images=$@
|
|
local width
|
|
local height
|
|
local x
|
|
local y
|
|
|
|
height=$(get_max_height $images)
|
|
y=$(expr $cur_y + $height)
|
|
|
|
width=$(total_width $images)
|
|
x=$(expr $cur_x - $width / 2)
|
|
|
|
add_images $x $y $images
|
|
move_pos_down $(expr $height + $ypad)
|
|
}
|
|
|
|
add_right_above() {
|
|
local images=$@
|
|
local height
|
|
local x
|
|
local y
|
|
|
|
height=$(get_max_height $images)
|
|
y=$(expr $cur_y - $height)
|
|
|
|
add_images $cur_x $y $images
|
|
}
|
|
|
|
add_right_below() {
|
|
add_images $cur_x $cur_y $@
|
|
}
|
|
|
|
add_left_above() {
|
|
local images=$@
|
|
local width
|
|
local height
|
|
local x
|
|
local y
|
|
|
|
height=$(get_max_height $images)
|
|
y=$(expr $cur_y - $height)
|
|
|
|
width=$(total_width $images)
|
|
x=$(expr $cur_x - $width)
|
|
|
|
add_images $x $y $images
|
|
}
|
|
|
|
add_centered() {
|
|
local images=$@
|
|
local width
|
|
local height
|
|
local x
|
|
local y
|
|
|
|
height=$(get_max_height $images)
|
|
y=$(expr $cur_y - $height / 2)
|
|
|
|
width=$(total_width $images)
|
|
x=$(expr $cur_x - $width / 2)
|
|
|
|
add_images $x $y $images
|
|
}
|
|
|
|
add_header() {
|
|
local lc=$1
|
|
set_centered_y_percent "white_bg" 17
|
|
add_centered_below "divider_top"
|
|
move_pos_left $(expr $(get_width "divider_top") / 2 )
|
|
move_pos_up $ypad
|
|
add_right_above "chrome_logo"
|
|
move_pos_right $(get_width "divider_top")
|
|
add_left_above "arrow_left" "${lc}_language_text" "arrow_right"
|
|
}
|
|
|
|
add_footer_with_url() {
|
|
local lc=$1
|
|
set_centered_y_percent "white_bg" 80
|
|
insert_centered_below "divider_btm"
|
|
insert_centered_below "${lc}_help_left_text" "url" "${lc}_help_right_text"
|
|
if echo "$rtol" | grep -q -w "$lc" ; then
|
|
insert_centered_below 'hwid' "${lc}_model_text"
|
|
else
|
|
insert_centered_below "${lc}_model_text" 'hwid'
|
|
fi
|
|
echo "" >> "$yaml_file"
|
|
}
|
|
|
|
add_footer_without_url() {
|
|
local lc=$1
|
|
set_centered_y_percent "white_bg" 80
|
|
insert_centered_below "divider_btm"
|
|
if echo "$rtol" | grep -q -w "$lc" ; then
|
|
insert_centered_below 'hwid' "${lc}_model_text"
|
|
else
|
|
insert_centered_below "${lc}_model_text" 'hwid'
|
|
fi
|
|
echo "" >> "$yaml_file"
|
|
}
|
|
|
|
# TODO(hungte) Remove the unnecessary hwid_*.bmp loop below.
|
|
# Generate a new yaml file for each specified hwid_*.bmp file.
|
|
for hwid_bmp in hwid_unknown.bmp; do
|
|
echo "$yaml_file"
|
|
|
|
# Global variables matching the yaml definitions
|
|
arrow_left='arrow_left.bmp'
|
|
arrow_right='arrow_right.bmp'
|
|
chrome_logo='chrome_logo.bmp'
|
|
divider_btm='divider_btm.bmp'
|
|
divider_top='divider_top.bmp'
|
|
insert_graphic='Insert_graphic.bmp'
|
|
remove_graphic='Remove_graphic.bmp'
|
|
url='Url.bmp'
|
|
white_bg='Background_white.bmp'
|
|
|
|
asset_BadSD='BadSD.bmp'
|
|
asset_BadUSB='BadUSB.bmp'
|
|
asset_RemoveDevices='RemoveDevices.bmp'
|
|
asset_VerificationOff='VerificationOff.bmp'
|
|
asset_VerificationOn='VerificationOn.bmp'
|
|
asset_Warning='Warning.bmp'
|
|
|
|
hwid=$hwid_bmp
|
|
|
|
# List the images. The major difference is the HWID.
|
|
cat >"$yaml_file" <<EOF1
|
|
bmpblock: 2.0
|
|
|
|
compression: 2
|
|
|
|
images:
|
|
|
|
# We must specify a font blob to use to render the HWID
|
|
\$HWID: hwid_fonts.bin
|
|
|
|
# This URL never changes
|
|
url: $(eval echo \$url)
|
|
|
|
# Various UI elements
|
|
arrow_left: $(eval echo \$arrow_left)
|
|
arrow_right: $(eval echo \$arrow_right)
|
|
chrome_logo: $(eval echo \$chrome_logo)
|
|
divider_btm: $(eval echo \$divider_btm)
|
|
divider_top: $(eval echo \$divider_top)
|
|
remove_graphic: $(eval echo \$remove_graphic)
|
|
insert_graphic: $(eval echo \$insert_graphic)
|
|
white_bg: $(eval echo \$white_bg)
|
|
|
|
asset_VerificationOn: $(eval echo \$asset_VerificationOn)
|
|
asset_VerificationOff: $(eval echo \$asset_VerificationOff)
|
|
asset_BadSD: $(eval echo \$asset_BadSD)
|
|
asset_BadUSB: $(eval echo \$asset_BadUSB)
|
|
|
|
# The following strings must be approved by the localization people
|
|
EOF1
|
|
|
|
|
|
# Enumerate the bitmaps for each locale-specific string.
|
|
for lc in $locales; do
|
|
# Locale-specific variables matching those in the yaml file.
|
|
eval "${lc}_model_text=${localedir}/$lc/model.bmp"
|
|
eval "${lc}_devmode_text=${localedir}/$lc/devmode.bmp"
|
|
eval "${lc}_remove_text=${localedir}/$lc/remove.bmp"
|
|
eval "${lc}_yuck_text=${localedir}/$lc/yuck.bmp"
|
|
eval "${lc}_insert_text=${localedir}/$lc/insert.bmp"
|
|
eval "${lc}_language_text=${localedir}/$lc/language.bmp"
|
|
eval "${lc}_for_help_text=${localedir}/$lc/for_help.bmp"
|
|
eval "${lc}_help_left_text=${localedir}/$lc/for_help_left.bmp"
|
|
eval "${lc}_help_right_text=${localedir}/$lc/for_help_right.bmp"
|
|
eval "${lc}_todev_text=${localedir}/$lc/todev.bmp"
|
|
eval "${lc}_tonorm_text=${localedir}/$lc/tonorm.bmp"
|
|
eval "${lc}_verif_off_text=${localedir}/$lc/verif_off.bmp"
|
|
eval "${lc}_tonorm_confirm_text=${localedir}/$lc/tonorm_confirmation.bmp"
|
|
eval "${lc}_back_help_text=${localedir}/$lc/back_help.bmp"
|
|
eval "${lc}_update_text=${localedir}/$lc/update.bmp"
|
|
|
|
cat >>"$yaml_file" <<EOF2
|
|
${lc}_model_text: $(eval echo \$${lc}_model_text)
|
|
${lc}_devmode_text: $(eval echo \$${lc}_devmode_text)
|
|
${lc}_remove_text: $(eval echo \$${lc}_remove_text)
|
|
${lc}_yuck_text: $(eval echo \$${lc}_yuck_text)
|
|
${lc}_insert_text: $(eval echo \$${lc}_insert_text)
|
|
${lc}_language_text: $(eval echo \$${lc}_language_text)
|
|
${lc}_help_left_text: $(eval echo \$${lc}_help_left_text)
|
|
${lc}_help_right_text: $(eval echo \$${lc}_help_right_text)
|
|
${lc}_todev_text: $(eval echo \$${lc}_todev_text)
|
|
${lc}_tonorm_text: $(eval echo \$${lc}_tonorm_text)
|
|
${lc}_verif_off_text: $(eval echo \$${lc}_verif_off_text)
|
|
${lc}_update_text: $(eval echo \$${lc}_update_text)
|
|
|
|
${lc}_tonorm_confirm_text: $(eval echo \$${lc}_tonorm_confirm_text)
|
|
|
|
EOF2
|
|
|
|
done
|
|
|
|
# List the screens. We need to composite four screens for each locale.
|
|
echo "screens:" >> "$yaml_file"
|
|
|
|
for lc in $locales; do
|
|
echo -n " $lc"
|
|
|
|
# Dev Screen
|
|
echo " ${lc}_devel:" >> "$yaml_file"
|
|
reset_pos
|
|
add_right_below "white_bg"
|
|
add_header ${lc}
|
|
set_centered_y_percent "white_bg" 40
|
|
add_centered "asset_VerificationOff"
|
|
set_centered_y_percent "white_bg" 50
|
|
add_centered_below "${lc}_devmode_text"
|
|
add_footer_without_url ${lc}
|
|
|
|
# Remove Screen
|
|
echo " ${lc}_remove:" >> "$yaml_file"
|
|
reset_pos
|
|
add_right_below "white_bg"
|
|
add_header ${lc}
|
|
set_centered_y_percent "white_bg" 25
|
|
add_centered_below "${lc}_remove_text"
|
|
set_centered_y_percent "white_bg" 50
|
|
add_centered "remove_graphic"
|
|
add_footer_with_url ${lc}
|
|
|
|
# Yuck Screen
|
|
echo " ${lc}_yuck:" >> "$yaml_file"
|
|
reset_pos
|
|
add_right_below "white_bg"
|
|
add_header ${lc}
|
|
set_centered_y_percent "white_bg" 25
|
|
add_centered_below "${lc}_yuck_text"
|
|
set_centered_y_percent "white_bg" 50
|
|
add_centered "asset_BadSD" "asset_BadUSB"
|
|
add_footer_with_url ${lc}
|
|
|
|
# Insert Screen
|
|
echo " ${lc}_insert:" >> "$yaml_file"
|
|
reset_pos
|
|
add_right_below "white_bg"
|
|
add_header ${lc}
|
|
set_centered_y_percent "white_bg" 40
|
|
add_centered "insert_graphic"
|
|
set_centered_y_percent "white_bg" 50
|
|
add_centered_below "${lc}_insert_text"
|
|
add_footer_with_url ${lc}
|
|
|
|
# ToDeveloper Screen
|
|
echo " ${lc}_todev:" >> "$yaml_file"
|
|
reset_pos
|
|
add_right_below "white_bg"
|
|
add_header ${lc}
|
|
set_centered_y_percent "white_bg" 45
|
|
add_centered "${lc}_todev_text"
|
|
add_footer_without_url ${lc}
|
|
|
|
# ToNormal Screen
|
|
echo " ${lc}_tonorm:" >> "$yaml_file"
|
|
reset_pos
|
|
add_right_below "white_bg"
|
|
add_header ${lc}
|
|
set_centered_y_percent "white_bg" 40
|
|
add_centered "asset_VerificationOff"
|
|
set_centered_y_percent "white_bg" 45
|
|
insert_centered_below "${lc}_verif_off_text"
|
|
insert_centered_below "${lc}_tonorm_text"
|
|
add_footer_without_url ${lc}
|
|
|
|
# Update (WAIT) Screen
|
|
echo " ${lc}_update:" >> "$yaml_file"
|
|
reset_pos
|
|
add_right_below "white_bg"
|
|
add_header ${lc}
|
|
set_centered_y_percent "white_bg" 50
|
|
add_centered "${lc}_update_text"
|
|
add_footer_without_url ${lc}
|
|
|
|
# ToNormalConfirm Screen
|
|
echo " ${lc}_tonorm_confirm:" >> "$yaml_file"
|
|
reset_pos
|
|
add_right_below "white_bg"
|
|
add_header ${lc}
|
|
set_centered_y_percent "white_bg" 40
|
|
add_centered "asset_VerificationOn"
|
|
set_centered_y_percent "white_bg" 50
|
|
insert_centered_below "${lc}_tonorm_confirm_text"
|
|
add_footer_without_url ${lc}
|
|
|
|
done
|
|
|
|
# Finally list the localizations.
|
|
|
|
cat >>"$yaml_file" <<EOF2
|
|
localizations:
|
|
|
|
# This determines the order in which the localizations appear. The first
|
|
# one is the default.
|
|
|
|
EOF2
|
|
|
|
# Let's try to use the native one first, if we can.
|
|
guess_locale "$yaml_file"
|
|
|
|
for lc in $newlocales; do
|
|
screen_list="${lc}_devel, ${lc}_remove, ${lc}_yuck, ${lc}_insert"
|
|
# todev/tonorm/update are supported only by newer firmware.
|
|
screen_list="${screen_list}, ${lc}_todev, ${lc}_tonorm, ${lc}_update"
|
|
screen_list="${screen_list}, ${lc}_tonorm_confirm"
|
|
echo " - [ $screen_list ]" >>"$yaml_file"
|
|
done
|
|
|
|
cat >>"$yaml_file" <<EOF3
|
|
|
|
locale_index:
|
|
|
|
# List the locale names in order so we can choose the default at the factory
|
|
|
|
EOF3
|
|
|
|
for lc in $newlocales; do
|
|
echo " - ${lc}" >> "$yaml_file"
|
|
done
|
|
|
|
done
|
|
|
|
# Now replace the 'hwid' string with '$HWID'.
|
|
sed -i 's/\bhwid\b/\$HWID/g' "$yaml_file"
|
|
|
|
echo ""
|