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