updated on Wed Jan 25 20:08:56 UTC 2012
[aur-mirror.git] / fbsplash-themes-arch-banner / cache-icons
blob2497236229ffa9079714fac3aa6c67b85b40671a
1 #!/bin/bash
3 # cache-icons
6 icon_count=13
7 icon_size=32
8 icon_size_small=16
9 images=/lib/splash/arch-banner/images
11 # Directory from which the splash daemon loads
12 # variable theme files (services icons) at startup
13 # which need to be available after mounting the
14 # splash cache even without theme hook script support
15 work_dir=/etc/splash/$SPLASH_THEME/cache
16 # Directory where temporary hook data files are stored
17 # which need to be moved in by the initcpio hook
18 work_dir_hooks=$spl_cachedir/hook-data-$SPLASH_THEME
20 work_dir_umount() {
21 while mountpoint -q "${work_dir}"; do
22 umount "$@" -l "${work_dir}"
23 done
26 set -e
27 case $1
28 in install | uninstall ) # run by pacman package install script
29 work_dir=${work_dir#/}
30 ( cd "${work_dir%/*}" ) # verify theme dir is there
31 work_dir_umount
32 rm -rf "${work_dir}"
33 [[ $1 = uninstall ]] && exit
34 ;; sysinit | shutdown | reboot | suspend )
35 ;; * ) # "rc_init boot"
36 exit
37 esac
38 if [[ $1 = install ]]; then
39 mkdir "${work_dir}"
40 elif [[ $0 = */rc_init-post ]]; then
41 # This does nothing, if the splash daemon was started in the initcpio.
42 work_dir_umount -n
43 exit
44 else
45 mount -n -s -t tmpfs cachedir "${work_dir}" -o rw,mode=0755,noexec,nosuid,nodev,size=4096k
47 set +e
49 # Link invisible dummy icons
50 # Status emblems
51 for state in start stop fail; do
52 ln -sfT $images/dummy.png "${work_dir}"/${state}
53 ln -sfT $images/dummy.png "${work_dir}"/cover-${state}
54 done
55 # Service icons
56 for (( num=1; num<=icon_count; num++ )) do
57 ln -sfT $images/dummy.png "${work_dir}"/svc_${num}_start
58 ln -sfT $images/dummy.png "${work_dir}"/svc_${num}_stop
59 done
61 [[ $1 = install ]] && exit 0
63 ICON_THEME=/usr/share/icons/Tango
64 . /etc/splash/$SPLASH_THEME/icons.conf
65 [[ $ICON_THEME = /* ]] || ICON_THEME=/usr/share/icons/$ICON_THEME
67 # args: <icon-rel-path> <symlink-name>
68 ln_svcicon() {
69 if [[ -f $ICON_THEME/$ICON_SIZE/${1} ]]; then
70 ln -sfT "$ICON_THEME/$ICON_SIZE/${1}" "${work_dir}/${2}"
71 else
72 echo "${0}: File not found: '$ICON_THEME/$ICON_SIZE/${1}'" >&2
73 return 1
77 # Link status emblem icons if available or enable semi transparent covers
79 ICON_SIZE=${icon_size_small}x${icon_size_small}
80 if ! [[ $ICON_start ]] || ! ln_svcicon "${ICON_start}" start; then
81 ln -sfT $images/cover-a50.png "${work_dir}"/cover-start
82 ln -sfT $images/cover-a50.png "${work_dir}"/cover-fail
84 if ! [[ $ICON_stop ]] || ! ln_svcicon "${ICON_stop}" stop; then
85 ln -sfT $images/cover-a50.png "${work_dir}"/cover-stop
86 ln -sfT $images/cover-a50.png "${work_dir}"/cover-fail
88 if ! [[ $ICON_fail ]] || ! ln_svcicon "$ICON_fail" fail; then
89 ln -sfT $images/cover-a50.png "${work_dir}"/cover-fail
92 # Link service icons and save positions for fast lookup
94 ICON_SIZE=${icon_size}x${icon_size}
96 declare -A SERVICE_ICONS_AA=()
97 for (( i=0; i<${#SERVICE_ICONS[@]}; i+=2 )) do
98 svc=${SERVICE_ICONS[i]}
99 icon=${SERVICE_ICONS[i+1]}
100 SERVICE_ICONS_AA[$svc]+=" ${icon}"
101 done
103 # Get first existing icon for service from configuration
104 # args: <svc>
105 svcicon_get() {
106 local icon icons=${SERVICE_ICONS_AA[$1]}
107 for icon in $icons; do
108 [[ -f $ICON_THEME/$ICON_SIZE/$icon ]] || continue
109 echo "${icon}"
110 return
111 done
112 for icon in $icons; do
113 echo "${0}: File not found: '$ICON_THEME/$ICON_SIZE/${icon}'" >&2
114 done
115 return 1
118 # splash_manager runs us without a tmpfs mounted
119 mkdir -p "${work_dir_hooks}"
120 rm -f "${work_dir_hooks}"/svcicon_num_*
122 # args: <service-name> start|stop
123 svc_icon_num() {
124 local svc=$1 icon
125 icon=$( svcicon_get "${svc}" ) || return 0
126 ln_svcicon "${icon}" svc_$(( ++ICON_NUM ))_$2
127 echo $ICON_NUM >|"${work_dir_hooks}"/svcicon_num_"${svc}"_$2
129 # Note: If no UDev in initcpio, process substitution doesn't work
130 splash_svclist_get stop > "${work_dir}"/svcs_stop
131 readarray -t svclist < "${work_dir}"/svcs_stop
132 ICON_NUM=0
133 for (( i=${#svclist[@]}-1; i>=0; i-- )) do
134 svc_icon_num "${svclist[i]}" stop
135 done
136 splash_svclist_get start > "${work_dir}"/svcs_start
137 readarray -t svclist < "${work_dir}"/svcs_start
138 ICON_NUM=0
139 for svc in "${svclist[@]}"; do
140 svc_icon_num "${svc}" start
141 done
143 # EOF #