Enabling the "remove CD" prompt in splashy.
[live-boot-grml.git] / scripts / live-functions
1
2 . /scripts/functions
3 . /live.vars
4
5 # Override log_*_msg until #494257 is merged
6
7 _log_msg()
8 {
9         if [ "$quiet" = "y" ]; then return; fi
10         printf "$@"
11 }
12
13 log_success_msg()
14 {
15         _log_msg "Success: $@\n"
16 }
17
18 log_failure_msg()
19 {
20         _log_msg "Failure: $@\n"
21 }
22
23 log_warning_msg()
24 {
25         _log_msg "Warning: $@\n"
26 }
27
28 log_begin_msg()
29 {
30         if [ -x /sbin/usplash_write ]; then
31                 /sbin/usplash_write "TEXT $@"
32         fi
33         _log_msg "Begin: $@ ... "
34 }
35
36 log_end_msg()
37 {
38         if [ -x /sbin/usplash_write ]; then
39                 /sbin/usplash_write "SUCCESS ok"
40         fi
41         _log_msg "done.\n"
42 }
43
44 ##
45
46 log_wait_msg ()
47 {
48         # Print a message and wait for enter
49         if [ -x /sbin/usplash_write ]
50         then
51                 /sbin/usplash_write "INPUTENTER ${@}"
52                 read nunya < /dev/.initramfs/usplash_outfifo
53         else if [ -x /sbin/splashy_update ] ; then
54                 /sbin/splashy_update "getstring ${@}" | read nunya
55         fi ; fi
56
57         _log_msg "Waiting: ${@} ... \n"
58 }
59
60 really_export ()
61 {
62         STRING="${1}"
63         VALUE="$(eval echo -n \${$STRING})"
64
65         if [ -f /live.vars ] && cat /live.vars | grep -sq "export ${STRING}"
66         then
67                 sed -i -e 's/\('${STRING}'=\).*$/\1'${VALUE}'/' /live.vars
68         else
69                 echo "export ${STRING}=\"${VALUE}\"" >> /live.vars
70         fi
71
72         eval export "${STRING}"="${VALUE}"
73 }
74
75 lang2locale() {
76         langpart="${1%%_*}"
77         if [ "$1" != "C" ]; then
78                 # Match the language code with 3rd field in languagelist
79                 line=$(grep -v "^#" /root/usr/share/live-initramfs/languagelist | cut -f3,4,5 -d\; | grep -v ';C$' | grep "^$langpart;")
80                 if [ -n "$line" ]; then
81                         if [ "$(echo "$line" | grep -c '')" -gt 1 ]; then
82                                 # More than one match; try matching the
83                                 # country as well.
84                                 countrypart="${1#*_}"
85                                 if [ "$countrypart" = "$1" ]; then
86                                         countryline="$(echo "$line" | head -n1)"
87                                         echo "${countryline##*;}"
88                                         return
89                                 fi
90                                 countrypart="${countrypart%%[@.]*}"
91                                 countryline="$(echo "$line" | grep ";$countrypart;" | head -n1 || true)"
92                                 if [ "$countryline" ]; then
93                                         echo "${countryline##*;}"
94                                         return
95                                 fi
96                         fi
97                         echo "${line##*;}"
98                 fi
99         else
100                 echo "C"
101         fi
102 }
103
104 # Override panic from scripts/functions
105 panic() {
106
107         DEB_1="\033[1;31m .''\`.  \033[0m"
108         DEB_2="\033[1;31m: :'  : \033[0m"
109         DEB_3="\033[1;31m\`. \`'\`  \033[0m"
110         DEB_4="\033[1;31m  \`-    \033[0m"
111
112         LIVELOG="\033[1;37m/live.log\033[0m"
113         DEBUG="\033[1;37mdebug\033[0m"
114
115         # Reset redirections to avoid buffering
116         exec 1>&6 6>&-
117         exec 2>&7 7>&-
118         kill ${tailpid}
119
120         printf "\n\n"
121         printf "     ${DEB_1}\n"
122         printf "     ${DEB_2}  \033[1;37mBOOT FAILED!\033[0m\n"
123         printf "     ${DEB_3}\n"
124         printf "     ${DEB_4}  This Debian Live image failed to boot.\n\n"
125
126         printf "  Please file a bug against the 'live-initramfs' package or email the Debian\n"
127         printf "  Live mailing list at <debian-live-devel@lists.alioth.debian.org>, making\n"
128         printf "  sure to note the exact version, name and distribution of the image you were\n"
129         printf "  attempting to boot.\n\n"
130
131         printf "  The file ${LIVELOG} contains some debugging information but booting with the\n"
132         printf "  ${DEBUG} command-line parameter will greatly increase its verbosity which is\n"
133         printf "  extremely useful when diagnosing issues.\n\n"
134
135         if [ -n "${panic}" ]; then
136                 printf "  live-initramfs will now restart your system. "
137         else
138                 printf "  live-initramfs will now start a shell. "
139         fi
140         printf "The error message was:\n\n    "
141
142         # Call original panic
143         . /scripts/functions
144         panic "$@"
145 }