b6d04fb6bd69fbbcb8f4515fa72ed49e3c26e769
[live-boot-grml.git] / scripts / live-functions
1 #!/bin/sh
2
3 . /scripts/functions
4 . /live.vars
5
6 log_wait_msg ()
7 {
8         # Print a message and wait for enter
9         if [ -x /sbin/usplash_write ]
10         then
11                 /sbin/usplash_write "INPUTENTER ${@}"
12                 read nunya < /dev/.initramfs/usplash_outfifo
13         fi
14
15         _log_msg "Waiting: ${@} ..."
16 }
17
18 really_export ()
19 {
20         STRING="${1}"
21         VALUE="$(eval echo -n \${$STRING})"
22
23         if [ -f /live.vars ] && cat /live.vars | grep -sq "export ${STRING}"
24         then
25                 sed -i -e 's/\('${STRING}'=\).*$/\1'${VALUE}'/' /live.vars
26         else
27                 echo "export ${STRING}=\"${VALUE}\"" >> /live.vars
28         fi
29
30         eval export "${STRING}"="${VALUE}"
31 }
32
33 lang2locale() {
34         langpart="${1%%_*}"
35         if [ "$1" != "C" ]; then
36                 # Match the language code with 3rd field in languagelist
37                 line=$(grep -v "^#" /root/usr/share/localechooser/languagelist | cut -f3,4,5 -d\; | grep -v ';C$' | grep "^$langpart;")
38                 if [ -n "$line" ]; then
39                         if [ "$(echo "$line" | grep -c '')" -gt 1 ]; then
40                                 # More than one match; try matching the
41                                 # country as well.
42                                 countrypart="${1#*_}"
43                                 if [ "$countrypart" = "$1" ]; then
44                                         countryline="$(echo "$line" | head -n1)"
45                                         echo "${countryline##*;}"
46                                         return
47                                 fi
48                                 countrypart="${countrypart%%[@.]*}"
49                                 countryline="$(echo "$line" | grep ";$countrypart;" | head -n1 || true)"
50                                 if [ "$countryline" ]; then
51                                         echo "${countryline##*;}"
52                                         return
53                                 fi
54                         fi
55                         echo "${line##*;}"
56                 fi
57         else
58                 echo "C"
59         fi
60 }