updated on Wed Jan 25 20:08:56 UTC 2012
[aur-mirror.git] / fbsplash-themes-arch-banner / make-theme.sh
blob26b8a6e9b78a933e4b5bb521ce1cfd3a2c9f0c4e
1 #!/bin/bash
3 # make-theme.sh for fbsplash-themes-arch-banner #
4 # #
5 author_name="Kurt J. Bosch"
6 author_email="kjb-temp-2009 at alpenjodel.de"
7 # #
8 # Distributed under the terms of the GNU General Public License #
10 work_dir=cache
12 arg_names=(
13 theme_name
14 flavour style color verbose_flavour
15 icon_size
16 font_file font_size
17 lib_dir
18 version url theme_license
21 if (( $# < ${#arg_names[@]} + 1 )); then
22 echo "Usage: ${0##*/} ${arg_names[*]} screen-size..." >&2
23 exit 1
26 for var in ${arg_names[@]}; do
27 read -r $var < <( echo "$1" )
28 shift
29 done
31 set -e
32 set -u
34 logo_file=archlinux-${flavour}-${style}.png
36 description="Theme with ArchLinux logo '${flavour}-${style}' and customizable services-icons"
38 # separator images dimensions
39 separator_w=640
40 separator_h=3
41 # width of the vertical progress bar
42 progress_w=20
44 msg() {
45 echo "${0##*/}: $*" >&2
48 err() {
49 msg "ERROR: $*"
50 exit 1
53 check_file() {
54 [[ -f $1 ]] && return 0
55 msg "cwd: $( pwd )"
56 err "File not found: '$1'"
59 png_args="-define png:color-type=6" # png:bit-depth=8"
61 _msg() {
62 # aligned to appear below makepkg msg2()
63 echo " $*" >&2
66 make_logo() {
67 local file_name=$1
68 [[ -f images/$file_name ]] && return 0
70 _msg images/"$file_name"
71 mkdir -p images
72 convert $png_args -depth 8 -background none \
73 /usr/share/archlinux/logos/"${file_name/%.*/.svg}" -trim +repage \
74 images/"${file_name}"
77 # make separator line images
78 make_separator() {
79 local file_name=$1 color_1=$2 color_2=$3
80 [[ -f images/$file_name ]] && return 0
82 _msg images/"$file_name"
83 mkdir -p images
84 convert $png_args -type TrueColorMatte -depth 8 \
85 -size "\
86 $(( separator_w ))x$(( separator_h ))" xc:black \
87 -fill "${color_1}" \-draw "rectangle \
88 $(( 1 )),$(( 0 )) \
89 $(( separator_w - 2 )),$(( separator_h ))" \
90 -fill "${color_2}" -draw "line \
91 $(( 0 )),$(( separator_h/2 )) \
92 $(( separator_w )),$(( separator_h/2 ))" \
93 images/"${file_name}"
96 make_helpers() {
97 mkdir -p images
99 # make services placeholder icon
100 local file_name=dummy.png
101 if ! [[ -f images/$file_name ]]; then
102 _msg images/"$file_name"
103 convert $png_args -type TrueColorMatte -depth 8 -size 1x1 xc:transparent \
104 images/$file_name
107 # make black (background) services icons cover
108 local file_name=cover.png
109 if ! [[ -f images/$file_name ]]; then
110 _msg images/"$file_name"
111 convert $png_args -type TrueColorMatte -depth 8 -size ${icon_size}x${icon_size} \
112 xc:black -fill black -draw 'color 0,0 reset' \
113 images/$file_name
116 # make semi transparent services icons cover
117 local file_name=cover-a50.png
118 if ! [[ -f images/$file_name ]]; then
119 _msg images/"$file_name"
120 convert $png_args -type TrueColorMatte -depth 8 -size ${icon_size}x${icon_size} \
121 xc:transparent -fill 'RGBA(0,0,0,0.5)' -draw 'color 0,0 reset' \
122 images/$file_name
126 # make animated progress bar backgrounds
127 make_anims() {
128 local postfix=$1 color=$2
129 local file_name_start=progress-bkgd-start-$postfix.mng
130 local file_name_stop=progress-bkgd-stop-$postfix.mng
131 if ! [[ -f images/$file_name_start && -f images/$file_name_stop ]]; then
132 _msg images/"$file_name_start" images/"$file_name_stop"
133 mkdir -p images
134 local tmpdir
135 tmpdir=$( mktemp -d spl_banner_anims_XXXXXX ) || return 1
136 local digits=$(( ${#progress_h} + 1 ))
137 local stripe_h=2
138 local i a=0 b=$(( progress_h - 1 ))
139 for (( i=a; i<=b; i++ )) do
140 local ii_start=$( printf "%0${digits}i" $(( b - i )) )
141 local ii_stop=$( printf "%0${digits}i" $(( i )) )
142 convert $png_args -type TrueColorMatte -depth 8 \
143 -size \
144 $(( progress_w ))x$(( progress_h )) xc:black \
145 -fill "$color" -draw "rectangle \
146 $(( 0 )),$(( 0 )) \
147 $(( progress_w )),$(( progress_h ))" \
148 -fill '#000000' -draw "polygon \
149 $(( progress_w/3 )),$(( i )) \
150 $(( progress_w )),$(( i - stripe_h/2 )) \
151 $(( progress_w )),$(( i + stripe_h/2 ))" \
152 -fill '#000000' -draw "polygon \
153 $(( progress_w*2/3 )),$(( i - progress_h/2 )) \
154 $(( 0 )),$(( i - stripe_h/2 - progress_h/2 )) \
155 $(( 0 )),$(( i + stripe_h/2 - progress_h/2 ))" \
156 -fill '#000000' -draw "polygon \
157 $(( progress_w*2/3 )),$(( i + progress_h/2 )) \
158 $(( 0 )),$(( i - stripe_h/2 + progress_h/2 )) \
159 $(( 0 )),$(( i + stripe_h/2 + progress_h/2 ))" \
160 $tmpdir/spinner-stop-${ii_stop}.png
161 cp $tmpdir/spinner-stop-${ii_stop}.png \
162 $tmpdir/spinner-start-${ii_start}.png
163 done
164 convert -delay 1x30 $tmpdir/spinner-start-*.png images/$file_name_start
165 convert -delay 1x30 $tmpdir/spinner-stop-*.png images/$file_name_stop
166 rm -rf $tmpdir
168 echo $file_name_start $file_name_stop
171 # screen backgrounds
173 make_silent() {
174 local file_name=silent-$screen_size.png
175 if ! [[ -f images/$file_name ]]; then
176 _msg images/"$file_name"
177 mkdir -p images
178 convert $png_args -type TrueColorMatte -depth 8 -size $screen_size xc:black -fill black -draw 'color 0,0 reset' \
179 images/silent-$screen_size.png
181 echo "$file_name"
184 make_verbose() {
185 local flavour=$1 color_name=$2 color=$3
186 local file_name=verbose-${flavour}-${color_name}-${screen_size}.png
187 if ! [[ -f images/$file_name ]]; then
188 _msg images/"$file_name"
189 mkdir -p .tmp/images
190 ( cd .tmp && make_logo archlinux-${flavour}-black.png )
192 [[ -f .tmp/backgrnd-${color_name}-${screen_size}.png ]] ||
193 convert $png_args -type TrueColorMatte -depth 8 -size $screen_size xc:black -fill "${color}" -draw 'color 0,0 reset' \
194 .tmp/images/backgrnd-${color_name}-${screen_size}.png
196 local x=$(( screen_w - 20 - logo_w )) y=$(( screen_h - 20 - logo_h ))
197 # If wide screen, avoid logo hidden behind [DONE]
198 (( x >= 6*8*2 )) && x=$(( x - 6*8 ))
199 composite $png_args -geometry +${x}+${y} \
200 .tmp/images/archlinux-${flavour}-black.png \
201 .tmp/images/backgrnd-${color_name}-${screen_size}.png \
202 images/$file_name
204 echo "$file_name"
207 case $style
208 in light )
209 progress_colors='#5dbded #106691'
210 text_color='#e0e0e0'
211 ;; dark ) # doesn't look good on black background
212 progress_colors='#5dbded #4d4d4d'
213 text_color='#4d4d4d'
214 ;; white )
215 progress_colors='#f0f0f0 #808080'
216 text_color='#ffffff'
217 esac
219 #check_file "$logo_file"
221 make_logo "${logo_file}"
223 # logo/banner size
224 [[ $( convert images/"${logo_file}" -identify /dev/null ) =~ [[:space:]]([0-9]+)x([0-9]+)[[:space:]] ]] ||
225 err "Unable to determine banner image size"
226 logo_w=${BASH_REMATCH[1]}
227 logo_h=${BASH_REMATCH[2]}
229 # progress bar length
230 progress_h=$logo_h
232 case $color
233 in blue )
234 read anim_start_file anim_stop_file < <( make_anims $color '#0a3f5a' )
235 make_separator separator-$color.png '#2979a2' '#5dbded'
236 ;; white )
237 read anim_start_file anim_stop_file < <( make_anims $color '#404040' )
238 make_separator separator-$color.png '#e0e0e0' '#ffffff'
239 esac
241 make_separator separator-red.png '#a22929' '#ed5d5d'
243 make_helpers
245 mkdir $theme_name
246 cd $theme_name
247 mkdir images
249 INDENT=' '
251 svc_format=$INDENT
252 for f in icon $work_dir/some-long-file-name 9999 9999 svc_inactive_start fbsplash-dummy 'blendout(9999)'; do
253 svc_format+="%-${#f}s "
254 done
255 svc_format+='\n'
257 # args: <rel-path>
258 add_link() {
259 [[ -h $1 ]] && return 0
260 #check_file "$1"
261 ln -sT ${lib_dir}/"$1" "$1"
264 # args: <prefix> <file> [<arg>...]
265 add_image() {
266 local prefix=$1 file=$2
267 shift 2
268 add_link images/"$file"
269 echo "${prefix}images/${file}" "${@}"
272 add_separator_red() {
273 printf "$svc_format" $( add_image "icon " separator-red.png $separator_x $separator_y svc_stop_failed fbsplash-dummy )
274 printf "$svc_format" $( add_image "icon " separator-red.png $separator_x $separator_y svc_start_failed fbsplash-dummy )
277 add_icon_bar() {
278 local cover cover_a50 n icon_x stat_icon_x
279 cover=$( add_image "icon " cover.png )
280 #cover_a50=$( add_image "icon " cover-a50.png )
281 for (( n=1; n<=icon_count; n++ )); do
282 icon_x=$(( icon_bar_x + (n-1) * icon_step ))
283 stat_icon_x=$(( icon_x + icon_size/2 ))
284 printf "$svc_format" icon ${work_dir}/svc_${n}_stop $icon_x $icon_bar_y
285 # printf "$svc_format" icon ${work_dir}/svc_${n} $icon_x $icon_bar_y svc_inactive_start _icon_svc_${n}
286 # printf "$svc_format" $cover_a50 $icon_x $icon_bar_y svc_inactive_start _icon_svc_${n}
287 printf "$svc_format" icon ${work_dir}/cover-stop $icon_x $icon_bar_y svc_stop _icon_svc_${n} #'blendin(125)'
288 printf "$svc_format" icon ${work_dir}/stop $stat_icon_x $icon_bar_y svc_stop _icon_svc_${n}
289 printf "$svc_format" $cover $icon_x $icon_bar_y svc_stopped _icon_svc_${n} #'blendin(125)'
290 printf "$svc_format" icon ${work_dir}/svc_${n}_stop $icon_x $icon_bar_y svc_stop_failed _icon_svc_${n}
291 printf "$svc_format" icon ${work_dir}/cover-fail $icon_x $icon_bar_y svc_stop_failed _icon_svc_${n} #'blendin(125)'
292 printf "$svc_format" icon ${work_dir}/fail $stat_icon_x $icon_bar_y svc_stop_failed _icon_svc_${n}
293 printf "$svc_format" icon ${work_dir}/svc_${n}_start $icon_x $icon_bar_y svc_start _icon_svc_${n}
294 printf "$svc_format" icon ${work_dir}/cover-start $icon_x $icon_bar_y svc_start _icon_svc_${n} #'blendout(125)'
295 printf "$svc_format" icon ${work_dir}/start $stat_icon_x $icon_bar_y svc_start _icon_svc_${n}
296 printf "$svc_format" icon ${work_dir}/svc_${n}_start $icon_x $icon_bar_y svc_started _icon_svc_${n}
297 printf "$svc_format" icon ${work_dir}/svc_${n}_start $icon_x $icon_bar_y svc_start_failed _icon_svc_${n}
298 printf "$svc_format" icon ${work_dir}/cover-fail $icon_x $icon_bar_y svc_start_failed _icon_svc_${n} #'blendin(125)'
299 printf "$svc_format" icon ${work_dir}/fail $stat_icon_x $icon_bar_y svc_start_failed _icon_svc_${n}
300 echo
301 done
304 add_link $font_file
306 for screen_size; do
307 # screen size
308 screen_w="${screen_size%x*}"
309 screen_h="${screen_size#*x}"
311 silent_background=$( cd .. && make_silent )
313 case $color
314 in blue ) verbose_background=$( cd .. && make_verbose $verbose_flavour blue '#051e2a' )
315 ;; white ) verbose_background=$( cd .. && make_verbose $verbose_flavour white '#1e1e1e' )
316 esac
318 # fixed point for placement
319 anchor_x=$(( screen_w / 2 ))
320 anchor_y=$(( screen_h / 2 ))
322 # separator postion
323 separator_x=$(( anchor_x - separator_w/2 ))
324 separator_y=$(( anchor_y - separator_h/2 ))
326 # icon bar
327 icon_bar_w=$(( separator_w - icon_size ))
328 icon_bar_x=$(( anchor_x - icon_bar_w/2 ))
329 icon_bar_y=$(( separator_y + 20 ))
330 icon_step=$(( icon_size*3/2 ))
331 icon_count=$(( ( icon_bar_w + icon_step - icon_size ) / icon_step ))
333 # main area (logo image + progress bar)
334 main_w=$(( logo_w + 20 + progress_w ))
336 # status message font size
337 status_text_font_size=${font_size}
339 # estimated height of 1000 lines of text
340 status_text_h_1000=$(( 15600 * status_text_font_size / 12 ))
342 # status message text heigth
343 status_text_h=$(( status_text_h_1000/1000 ))
345 # status message bar
346 status_h=$(( status_text_h + 20 ))
347 status_x=$(( anchor_x - main_w/2 ))
348 status_y=$(( separator_y - separator_h/2 - status_h ))
350 # status message text position
351 status_text_x=$(( status_x + 15 ))
352 status_text_y=$(( status_y + status_h/2 - status_text_h/2 ))
354 # logo/banner position
355 logo_x=$(( anchor_x - main_w/2 ))
356 logo_y=$(( status_y - logo_h ))
358 # progress bar position
359 progress_x=$(( anchor_x + main_w/2 - progress_w ))
360 progress_y=$logo_y
362 # progress bar bottom right corner
363 progress_x2=$(( anchor_x + main_w/2 - 1 ))
364 progress_y2=$(( progress_y + progress_h - 1 ))
366 # message log
367 message_log_x=$(( status_text_x ))
368 message_log_y=$(( icon_bar_y + icon_size + 20 ))
369 message_log_font_size=${font_size}
370 # estimated height of 1000 lines of text
371 message_log_text_h_1000=$(( 15600 * message_log_font_size / 12 ))
373 #echo " Message log y is ${message_log_y}"
375 # number of message log lines
376 message_log_lines=$(( 1000 * ( screen_h - message_log_y - 10 ) / message_log_text_h_1000 ))
378 #echo " Number of msglog textbox lines icon_size ${message_log_lines}"
381 echo
382 add_image "pic=" $verbose_background
384 cat <<EOT
386 bgcolor=0
387 tx=0
388 ty=0
389 tw=$screen_w
390 th=$screen_h
393 add_image "silentpic=" $silent_background
394 echo
395 add_image "icon " $logo_file $logo_x $logo_y
396 cat <<EOT
398 text_font=$font_file
399 text_size=$status_text_font_size
400 text_x=$status_text_x
401 text_y=$status_text_y
402 text_color=$text_color
405 add_image "icon " separator-$color.png $separator_x $separator_y
406 cat <<EOT
408 # This type is used by fbcondecor_helper in initcpio
409 <type other>
410 </type>
412 <type bootup>
414 add_image "${INDENT}anim loop " $anim_start_file $progress_x $progress_y "blendin(125)"
415 cat <<EOT
416 box silent inter $progress_x $progress_y2 $progress_x2 $progress_y2 $progress_colors $progress_colors blendin(125)
417 box silent $progress_x $progress_y $progress_x2 $progress_y2 $progress_colors $progress_colors blendin(125)
418 </type>
420 <type reboot shutdown>
422 add_image "${INDENT}anim loop " $anim_stop_file $progress_x $progress_y
423 cat <<EOT
424 box silent inter $progress_x $progress_y $progress_x2 $progress_y2 $progress_colors $progress_colors
425 box silent $progress_x $progress_y2 $progress_x2 $progress_y2 $progress_colors $progress_colors
426 </type>
428 <type suspend>
429 box silent $progress_x $progress_y $progress_x2 $progress_y2 #0a3f5a
430 box silent inter $progress_x $progress_y $progress_x2 $progress_y2 $progress_colors $progress_colors
431 box silent $progress_x $progress_y2 $progress_x2 $progress_y2 $progress_colors $progress_colors
432 </type>
434 <type bootup reboot shutdown suspend>
436 add_separator_red
437 echo
438 (( icon_count > 0 )) && add_icon_bar
439 cat <<EOT
440 </type>
442 # 'tuxoniceui_fbsplash' (version 1.0) doesn't know anything about types.
443 # It seems to show allways simply the last item defined on top.
444 # With this one at the end we allways get an upward growing progress
445 # whether suspend or resume it done.
446 <type resume>
447 box silent $progress_x $progress_y $progress_x2 $progress_y2 #0a3f5a
448 box silent inter $progress_x $progress_y2 $progress_x2 $progress_y2 $progress_colors $progress_colors
449 box silent $progress_x $progress_y $progress_x2 $progress_y2 $progress_colors $progress_colors
450 </type>
453 if (( message_log_lines < 3 )); then
454 msg "WARNING: Not including message log."
455 else
456 cat <<EOT
457 log_lines=$message_log_lines
458 # Don't truncate log messages - We only show errors here and don't use a mono spaced font
459 log_cols=9999
460 <textbox>
461 text silent $font_file $message_log_font_size $message_log_x $message_log_y $text_color msglog
462 </textbox>
466 } >${screen_size}.cfg
467 done
469 cat > metadata.xml <<EOF
470 <?xml version="1.0" encoding=\"UTF-8\"?>
471 <thememeta xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
472 xsi:schemaLocation="http://fbsplash.berlios.de/schemas/1.0/thememeta.xsd">
473 <name>${theme_name}</name>
474 <version>${version}</version>
475 <author>
476 <name>${author_name}</name>
477 <email>${author_email}</email>
478 </author>
479 <description>${description}</description>
480 <license>${theme_license}</license>
481 <url>${url}</url>
482 </thememeta>
485 # EOF #