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