rc.country 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #!/bin/sh
  2. #(c) Copyright 2012 Barry Kauler
  3. #2012 GPL licence v3 (refer: /usr/share/doc/legal)
  4. #120328 rewrite script.
  5. #120627 use keymaps from kbd pkg if present.
  6. #120629 raspberry pi does not have a hw clock, set date to reasonable value.
  7. #130501 passed param from rc.sysinit.
  8. #130513 modify handling of "ask" passed param.
  9. . /etc/rc.d/PUPSTATE
  10. . /etc/DISTRO_SPECS #has DISTRO_XORG_AUTO
  11. STATUS=0
  12. . /etc/clock
  13. ARCH=`uname -m`
  14. [ "$ARCH" = "x86_64" ] && lsuffix=64 || lsuffix=
  15. [ $pkeys ] && PKEYS=$pkeys #boot parameter
  16. ASKKMAP="yes"; ASKLANG="yes"; ASKCLOCK="no"
  17. [ "$DISTRO_XORG_AUTO" = "yes" ] && ASKKMAP="no" && ASKLANG="no"
  18. [ -f /tmp/bootcnt.txt ] && ASKKMAP="yes" && ASKLANG="yes" #file created in 'init' if pfix=nox.
  19. #130501 passed param from rc.sysinit (rc.country is called 2nd time)... 130513 no, only one call.
  20. if [ $1 ];then
  21. ASKKMAP="yes"
  22. ASKLANG="yes"
  23. fi
  24. #120627
  25. KMAPPATH='/lib/keymaps'
  26. [ -d /usr/share/kbd/keymaps/i386 ] && KMAPPATH='/usr/share/kbd/keymaps/i386'
  27. [ -d /usr/share/keymaps/i386 ] && KMAPPATH='/usr/share/keymaps/i386' #debian, gentoo. note, debian files have extension .kmap.gz, gentoo have .map.gz
  28. KEXT=''
  29. [ -f ${KMAPPATH}/qwerty/us.map ] && KEXT='.map'
  30. [ -f ${KMAPPATH}/qwerty/us.map.gz ] && KEXT='.map'
  31. [ -f ${KMAPPATH}/qwerty/us.kmap ] && KEXT='.kmap'
  32. [ -f ${KMAPPATH}/qwerty/us.kmap.gz ] && KEXT='.kmap'
  33. ######keyboard section######
  34. askkbdlayout ()
  35. {
  36. echo -n "us${KEXT}" > /etc/keymap #default.
  37. echo -n "" > /etc/codepage # "
  38. FIRSTITEM="us \"(USA)\""
  39. echo -n "" >/tmp/keybdlist.txt
  40. case $KMAPPATH in #120627
  41. /lib/keymaps) KMAPFILES="`find /lib/keymaps -mindepth 1 -maxdepth 1 -name '*.gz' | sort`" ;; #ex: us.gz
  42. *) KMAPFILES="`find ${KMAPPATH}/[^i]* -name '*.map' -o -name '*.kmap' -o -name '*.map.gz' -o -name '*.kmap.gz' -not -name 'defkeymap*' | sort`" ;;
  43. esac
  44. for AFILE in $KMAPFILES
  45. do
  46. AKMAP="`basename $AFILE .gz`" #us, fr, br, etc.
  47. AKMAP="`basename $AKMAP .kmap`" #120627
  48. AKMAP="`basename $AKMAP .map`" #120627
  49. case $AKMAP in
  50. us*) ACNTRY="(USA)";;
  51. fr*) ACNTRY="(France)";;
  52. it*) ACNTRY="(Italy)";;
  53. ba*) ACNTRY="(Bashkir)";;
  54. be*) ACNTRY="(Belgium)";;
  55. bg*) ACNTRY="(Bulgaria)";;
  56. br*) ACNTRY="(Brazil)";;
  57. by*) ACNTRY="(Byelorussian)";;
  58. cf*) ACNTRY="(French-Canadian)";;
  59. croat*) ACNTRY="(Croatia)";;
  60. cz*) ACNTRY="(Czech)";;
  61. de) ACNTRY="(Germany)";;
  62. de_*) ACNTRY="(Germany)";;
  63. de-*) ACNTRY="(Germany)";;
  64. dk*) ACNTRY="(Denmark)";;
  65. es*) ACNTRY="(Spain)";;
  66. fi*) ACNTRY="(Finland)";;
  67. hu*) ACNTRY="(Hungary)";;
  68. ka*) ACNTRY="(Kazakhstan)";;
  69. ky*) ACNTRY="(Kyrgyzstan)";;
  70. et*) ACNTRY="(Estonia)";;
  71. lt*) ACNTRY="(Lithuania)";;
  72. mk*) ACNTRY="(Macedonia)";;
  73. sr*) ACNTRY="(Serbia)";;
  74. tr*) ACNTRY="(Turkey)";;
  75. tt*) ACNTRY="(Tatar)";;
  76. sg*) ACNTRY="(Sango)";;
  77. ua*) ACNTRY="(Ukraine)";;
  78. gr*) ACNTRY="(Greece)";;
  79. il*) ACNTRY="(Israel)";;
  80. is*) ACNTRY="(Iceland)";;
  81. jp*) ACNTRY="(Japan)";;
  82. pc*) ACNTRY="(Japanese/English)";;
  83. la*) ACNTRY="(Latin_America)";;
  84. nl*) ACNTRY="(Netherlands)";;
  85. no*) ACNTRY="(Norway)";;
  86. pl*) ACNTRY="(Poland)";;
  87. pt*) ACNTRY="(Portugal)";;
  88. ro*) ACNTRY="(Romania)";;
  89. ru*) ACNTRY="(Russia)";;
  90. se*) ACNTRY="(Sweden)";;
  91. sv*) ACNTRY="(Sweden)";;
  92. sk*) ACNTRY="(Slovakia)";;
  93. sl*) ACNTRY="(Slovenia)";;
  94. uk*) ACNTRY="(UK)";;
  95. wangbe*) ACNTRY="(Belgium)";;
  96. azerty) ACNTRY="(Tandon)";;
  97. dvorak-r) ACNTRY="(Right_single-handed)";;
  98. dvorak-l) ACNTRY="(Left_single-handed)";;
  99. *) ACNTRY="-";;
  100. esac
  101. echo -e "$AKMAP \"${ACNTRY}\"" >> /tmp/keybdlist.txt
  102. done
  103. KEYLIST="${FIRSTITEM} `sort /tmp/keybdlist.txt | tr '\n' ' '`"
  104. echo '#!/bin/sh' >/tmp/keydlg
  105. echo 'dialog --aspect 10 --no-cancel --menu "Select the keyboard layout:\n(UP/DOWN arrows then ENTER key)" 0 0 0 \' >>/tmp/keydlg #' geany fix
  106. echo "$KEYLIST 2> /tmp/kbdextlayout.txt" >>/tmp/keydlg
  107. echo 'exit $?' >>/tmp/keydlg
  108. chmod 755 /tmp/keydlg
  109. /tmp/keydlg >/dev/console
  110. [ $? != 0 ] && return 1
  111. clear > /dev/console 2>&1 #clear screen
  112. KMAP=`cat /tmp/kbdextlayout.txt`
  113. case $KMAP in #note, same/similar code in /usr/sbin/input-wizard, init, quicksetup.
  114. de*|be*|br*|dk*|es*|fi*|fr*|it*|no*|se*|sv*|pt*) echo -n "850" > /etc/codepage ;;
  115. cz*|hu*|pl*|ro*|sk*|croat*|slovene*) echo -n "852" > /etc/codepage ;;
  116. esac
  117. echo -n "${KMAP}${KEXT}" > /etc/keymap
  118. return 0
  119. }
  120. if [ "$ASKKMAP" = "no" ];then
  121. #'quicksetup' is run 1st time X starts.
  122. [ ! -f /etc/keymap ] && echo -n "us${KEXT}" > /etc/keymap
  123. [ ! -f /etc/codepage ] && echo -n "" > /etc/codepage
  124. else
  125. [ ! -e /etc/keymap ] && askkbdlayout #creates /etc/keymap, /etc/codepage.
  126. fi
  127. if [ -s /etc/codepage ];then
  128. CODEPAGE="`cat /etc/codepage`"
  129. case $CODEPAGE in
  130. 850) modprobe nls_cp850 ;;
  131. 852) modprobe nls_cp852 ; modprobe nls_iso8859-2 ;;
  132. esac
  133. fi
  134. #note, "keymap-set --xopt" is run in xorgwizard and xorgwizard-automatic,
  135. # "keymap-set --load" is run in quicksetup.
  136. if [ -s /etc/keymap ];then
  137. NEED2LOADKMAP="yes"
  138. [ -d /initrd -a "$PKEYS" ] && NEED2LOADKMAP="no" #already done in initrd.
  139. if [ "$NEED2LOADKMAP" = "yes" ];then
  140. KMAP="`cat /etc/keymap`"
  141. case $KMAPPATH in #120627
  142. /lib/keymaps) gzip -dcf /lib/keymaps/$KMAP.gz | loadkmap ;;
  143. *) loadkeys $KMAP ;; #note i think don't need to specify the extension (but it is in KMAP).
  144. esac
  145. fi
  146. fi
  147. ######end keyboard section######
  148. ######locale section######
  149. LANG="`grep '^LANG=' /etc/profile | cut -f 2 -d '='`"
  150. CLANG="`echo "$LANG" | sed -e 's/\.UTF-8/\.utf8/'`" #fix, locale -a always prints .utf8
  151. if [ "$ASKLANG" = "no" ];then
  152. #'quicksetup' is run 1st time X starts.
  153. #need this default locale for X to start first time...
  154. # added $lsuffix 140113
  155. [ ! -d /usr/lib${lsuffix}/locale/en_US ] && localedef -f ISO-8859-1 -i en_US --no-archive en_US >/dev/null
  156. [ ! -d /usr/lib${lsuffix}/locale/${CLANG} ] && /usr/sbin/chooselocale cli quiet #ask no questions, will run localedef.
  157. else
  158. #localedef creates locale files in /usr/lib/locale...
  159. if [ "`locale -a | grep "$CLANG"`" = "" ];then
  160. if [ "$LANG" = "en_US" ];then
  161. /usr/sbin/chooselocale cli > /dev/console
  162. else
  163. /usr/sbin/chooselocale cli quiet #ask no questions, will run localedef.
  164. fi
  165. /sbin/load_consolefont #note, also called from rc.sysinit, xwin.
  166. ASKCLOCK="yes"
  167. fi
  168. fi
  169. ######end locale section######
  170. ######clock section######
  171. #120629 raspberry pi does not have a hw clock, set date to reasonable value...
  172. HWDATE="`hwclock --show 2>/dev/null`" #ex: "Fri 29 Jun 2012 07:45:28 AM WST -0.725833 seconds"
  173. if [ "$HWDATE" = "" ];then
  174. if [ -f /var/local/shutdown_date_saved ];then #see /etc/rc.d/rc.shutdown
  175. date -s "`cat /var/local/shutdown_date_saved`"
  176. else
  177. #either of these formats can set the date: "29 JUN 2012 10:00:00" "2012-06-28 16:20:08"
  178. HWDATE="`stat --format=%z /etc/DISTRO_SPECS | cut -f 1 -d '.' | cut -f 1,2 -d ' '`" #creation date of build. ex: "2012-06-28 16:20:08"
  179. date -s "$HWDATE"
  180. [ ! -e /etc/localtime ] && ln -s /usr/share/zoneinfo/Australia/Perth /etc/localtime
  181. fi
  182. else
  183. if [ "$ASKCLOCK" = "yes" ];then
  184. /usr/sbin/timezone-set cli > /dev/console
  185. #choose hardware clock set to local or UTC...
  186. dialog --title "Set hardware-clock type" --yes-label "Local" --no-label "UTC" --yesno "Is the hardware clock on the computer set to the local time, or to UTC? Note, most PCs with Windows installed have the hardware clock set to the local time, so if in doubt choose that..." 0 0 > /dev/console
  187. if [ $? -eq 1 ];then #UTC
  188. HWCLOCKTIME='utc'
  189. hwPATTERN="s/^HWCLOCKTIME=[^#]*/HWCLOCKTIME='utc'/"
  190. sed -i "$hwPATTERN" /etc/clock #note, it is default 'localtime'.
  191. fi
  192. fi
  193. [ ! -e /etc/localtime ] && ln -s /usr/share/zoneinfo/Australia/Perth /etc/localtime
  194. #Ref: http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html
  195. TZ=$(readlink /etc/localtime|sed -e 's,/usr/share/zoneinfo/,,' -e 's,Etc/,,') #shinobar
  196. export TZ
  197. HWCLOCKTIME="localtime"
  198. [ -s /etc/clock ] && grep -qw '^[^#]*utc' /etc/clock && HWCLOCKTIME="utc" #shinobar
  199. #need to set Linux system time/date, from hardware clock...
  200. #hwclock --hctosys --localtime
  201. hwclock --hctosys --${HWCLOCKTIME}
  202. #...--hctosys reads cmos clock to system.
  203. #...--localtime means that cmos clock is set to local-time.
  204. fi
  205. ######end clock section######
  206. exit $STATUS
  207. ###END###