aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/splash.sh
blob: b9f0dd22a2430c883cc0adb065e944aae18adf1e (plain)
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
#!/bin/bash
#
# splash.sh - script to paint progress bar during
# system startup/shutdown. This script is solely run
# by the init scripts (shell function rc_splash)
#
# (w) 2002-2003 Stefan Reinauer, <stepan@suse.de>
# 2003 Florent Villard, <warly@mandrakesoft.com>
# It's licensed under GPL, of course.
#
# this script expects the following environment variables:
#  nbservices = number of start/stop scripts to be executed for runlevel change
#  progress = number of currently executed start/stop script
#  runlevel = runlevel to be reached.

_procsplash="`cat /proc/splash 2>/dev/null`"
TEXTDOMAIN=bootsplash
TEXTDOMAINDIR=/etc/locale 
LOCPATH=/etc/locale

# execute splash binary utility because we are a wrapper:
if [ "$1" == "-s" -o "$1" == "-u" -o "$1" == "-n" -o "$1" == "-f" ]; then
    exec /sbin/splash $*
else
   ( exec /sbin/splash "$*" )
fi

gprintf() {
    # request translations to be always in UTF-8
    OUTPUT_CHARSET=UTF-8
    if [ -x /bin/gettext -a -n "$1" ]; then
	if [ -n "$GP_LANG" ]; then
	    TEXT=`LANGUAGE=$GP_LANG gettext -e --domain=$TEXTDOMAIN "$1"`
	else
	    TEXT=`gettext -e --domain=$TEXTDOMAIN "$1"`
	fi
    else
	TEXT=$1
    fi
    [ "${1#*\\n}" ] || TEXT="$TEXT\n"
}

# assertions
test -r /proc/splash || exit 0
test -z "`echo $_procsplash|grep on`" && exit 0

if [[ -z $res ]]; then 
    res=`fbresolution`
    if [[ -f /etc/sysconfig/bootsplash ]]; then
        . /etc/sysconfig/bootsplash
	theme=$THEME
	if [[ -f /etc/bootsplash/themes/$theme/config/bootsplash-$res.cfg ]]; then
	    function box() { true; }
            . /etc/bootsplash/themes/$theme/config/bootsplash-$res.cfg
        fi
    fi
fi

_shutdown="no"
_silent="no"
grep -q silent /proc/cmdline && _silent="yes"
test "$runlevel" == "6" -o "$runlevel" == "0" && _shutdown="yes"

if [ "$1" == "stop" -a $_shutdown == "no" ]; then
    if [[ $LOGO_CONSOLE == No ]] || [[ $LOGO_CONSOLE == no ]] || [[ $LOGO_CONSOLE == NO ]]; then                                                        
	if [[ -e /proc/splash ]];then
	    echo 0 > /proc/splash
	    exit 0
	fi 
    else 
	if [[ $LOGO_CONSOLE == vt ]]; then
	    for i in 0 1 2 3 4 5
	    do
		if [[ -f /etc/bootsplash/themes/$theme/config/vt$i-$res.cfg ]]; then
		    splash -s -u $i /etc/bootsplash/themes/$theme/config/vt$i-$res.cfg
		fi
	    done
	fi
    fi
fi

test -z "$progress" -a -z "$nbservices" && exit 0
grep -vq "splash=silent" /proc/cmdline && exit 0 

if [ "$previous" == "3" -o "$previous" == "5" ] ; then
  if [ "$runlevel"  = "3" -o "$runlevel" == "5" ] ; then
    exit 0
  fi
fi

# acquire data
# 
num=$(( $nbservices + 2 ))

# Initialize and print text string..
if [ "$progress" == 1 -o "$1" == "start" ]; then
    # depending on the languages, we need to use a font different of
    # the default one; in such case the font must be accessible, or
    # the translation is disabled.
    # bugs:
    # - RTL languages need a fake *.po file, where bidi reordering and
    #   shaping is already done.
    # - indic languages have not shaping
    case "${GP_LANG}${LANGUAGE}" in
	# languages written in latin that use letters not included in luxi
	az*|cy*|gn*|vi*)
		font=/usr/share/fonts/otf/mdk/mdk_teams.otf ;;
	# basic cyrillic, covered by cp1251
	be*|bg*|mk*|ru*|sr*|uk*)
		font=/usr/share/fonts/default/Type1/a010015l.pfb ;;
	# extended cyrillic, not covered by cp1251
	mn*|tg*|uz*)
		font=/usr/share/fonts/otf/mdk/mdk_teams.otf ;;
	# other scripts
	am*) font=/usr/share/fonts/ttf/ethiopic/gfzemenu.ttf ;;
	ar*|fa*|ur*) font=/usr/share/fonts/ttf/arabic/Kacst-Qr.ttf ;;
	as*|bn*) font=/usr/share/fonts/ttf/bengali/MuktiBold.ttf ;;
	el*) font=/usr/share/fonts/type1/greek/kb.pfb ;;
	he*|yi*) font=/usr/share/fonts/type1/hebrew/Nachlieli-Bold.pfa ;;
	hi*|mr*) font=/usr/share/fonts/otf/mdk/raghu.ttf ;;
	hy*) font=/usr/share/fonts/ttf/armenian/artsnk_b.ttf ;;
	ja*) font=/usr/share/fonts/ttf/japanese/kochi-gothic.ttf ;;
	kn*) font=/usr/share/fonts/ttf/kannada/Sampige.ttf ;;
	ko*) font=/usr/share/fonts/ttf/korean/gulim.ttf ;;
	ml*) font=/usr/share/fonts/otf/mdk/malayalam.ttf ;;
	ta*) font=/usr/share/fonts/ttf/tamil/TSCu_Paranar.ttf ;;
	th*) font=/usr/share/fonts/ttf/thai/norasi_b.ttf ;;
	zh_CN*) font=/usr/share/fonts/ttf/gb2312/gkai00mp.ttf ;;
	zh_TW*) font=/usr/share/fonts/ttf/big5/bkai00mp.ttf ;;
	# languages supported by the default font; latin1
	af*|br*|ca*|da*|de*|es*|et*|eu*|fi*|fr*|ga*|gl*|id*|is*|it*|ms*|nb*)
		font=default ;;
	# languages supported by the default font; latin1, more
	nb*|nl*|nn*|no*|pt*|sv*|wa*)
		font=default ;;
	# languages supported by the default font; latin2
	bs*|cs*|hr*|hu*|pl*|ro*|sk*|sl*|sq*)
		font=default ;;
	# languages supported by the default font; other latin coverages
	eo*|lt*|lv*|mt*|tr*)
		font=default ;;
	# for others, we do a last chance possibility with
	# arial unicode, if the user installed it...
	*) font=/usr/X11R6/lib/X11/fonts/drakfont/ttf/arialuni.ttf ;;
    esac

    if [ "$font" != "default" ]; then
    	if [ -r "$font" ]
		custom_font="-f $font"
	elif [ -r "/etc/locale/`basename $font`" ]; then
		custom_font="/etc/locale/`basename $font`"
	elif [ -r "/etc/locale/default.ttf" ]; then
		custom_font="/etc/locale/default.ttf"
	else
		# no font available, translations are not done
		GP_LANG=C ;
		LANGUAGE=C ;
	fi
    fi

    if test "$_shutdown" == "yes"; then 
        gprintf "Shutting down the system..."
        [[ -f /etc/bootsplash/themes/$theme/config/bootsplash-$res.cfg ]] && /sbin/splash -s -u 0 /etc/bootsplash/themes/$theme/config/bootsplash-$res.cfg
        echo "silent" >/proc/splash
        chvt 1
    else 
        gprintf "Booting the system..."
    fi
    _boot=$TEXT
    if [ "$text_x" != "" -a "$text_y" != "" \
        -a "$text_color" != "" -a "$text_size" != "" -a "$_silent" == "yes" ]; then
        gprintf "Press F2 for verbose mode."
        fbtruetype.static -x $text_x -y $text_y -t $text_color -s $text_size \
  			$custom_font "$_boot $TEXT"
    fi
fi

# Paint progressbar..
test -z "$progress_enable" && exit 0
echo "show $(( 65534 * ( $progress + 1 ) / $num ))" > /proc/splash