* updated krdc (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / base / stone / stone_mod_general.sh
blobd14f9d3f50a420652f4d99ee8827e729c0b6e40e
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/stone/stone_mod_general.sh
3 # Copyright (C) 2004 - 2022 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 # [MAIN] 10 general,main Various general system configurations
14 # [SETUP] 10 general set_tmarea
15 # [SETUP] 15 general set_dtime
16 # [SETUP] 20 general set_locale
17 # # [SETUP] 30 general set_vcfont
19 set_keymap() {
20 keymap=$(ls -l /etc/default.keymap 2> /dev/null | sed 's,.*/,,')
21 [ -z "$keymap" ] && keymap="none" ; keymap="${keymap%.map.gz}"
23 # ReneR: Attention: although this reads i386, this is nowadays valid
24 # for all (? - at least also on PowerPC where this was a long ugly
25 # bug in ROCK times) - the input layer does pass "unified" events ...
26 mapdir="`echo /usr/share/kbd/keymaps/i386`"
28 cmd="gui_menu 'general_keymap' 'Select one of the following keyboard mappings.'"
29 if [ "$keymap" != none ]; then
30 cmd="$cmd 'Current: $keymap' 'loadkeys defkeymap'"
32 cmd="$cmd 'none (kernel defaults)' 'rm -f /etc/default.keymap ; loadkeys defkeymap'"
34 cmd="$cmd $( find $mapdir -type f ! -path '*/include/*' -name '*.map.gz' -printf '%P\n' | sed 's,\(.*\)/\(.*\).map.gz$,"\2 (\1)" "ln -sf '$mapdir'/& /etc/default.keymap ; loadkeys \2",' | expand -t30 | sort | tr '\n' ' ')"
36 eval "$cmd"
39 set_vcfont() {
40 vcfont=$(ls -l /etc/default.vcfont 2> /dev/null | sed 's,.*/,,')
41 if [ -z "$vcfont" ] ; then vcfont="none"
42 else vcfont="`echo $vcfont | sed -e "s,\.\(fnt\|psf.*\)\.gz$,,"`" ; fi
43 fontdir="/usr/share/kbd/consolefonts"
45 cmd="gui_menu 'general_vcfont' 'Select one of the following console fonts.'"
46 if [ "$vcfont" != none ]; then
47 cmd="$cmd 'Current: $vcfont' 'setfont'"
49 cmd="$cmd 'none (kernel defaults)' 'rm -f /etc/default.vcfont ; setfont'"
51 cmd="$cmd $( find $fontdir -type f \( -name '*.fnt.gz' -or -name '*.psf*.gz' \) -printf '%P\n' | sed 's,\(.*\).\(fnt\|psf.*\)\.gz$,"\1" "ln -sf '$fontdir'/& /etc/default.vcfont ; setfont \1",' | expand -t30 | sort | tr '\n' ' ')"
53 eval "$cmd"
56 store_kbd(){
57 if [ -f /etc/conf/kbd ] ; then
58 sed -e "s/kbd_rate=.*/kbd_rate=$kbd_rate/" \
59 -e "s/kbd_delay=.*/kbd_delay=$kbd_delay/" < /etc/conf/kbd \
60 > /etc/conf/kbd.tmp
61 grep -q kbd_rate= /etc/conf/kbd.tmp || echo kbd_rate=$kbd_rate \
62 >> /etc/conf/kbd.tmp
63 grep -q kbd_delay= /etc/conf/kbd.tmp || echo kbd_delay=$kbd_delay \
64 >> /etc/conf/kbd.tmp
65 mv /etc/conf/kbd.tmp /etc/conf/kbd
66 else
67 echo -e "kbd_rate=$kbd_rate\nkbd_delay=$kbd_delay" \
68 > /etc/conf/kbd
70 [ "$kbd_rate" -a "$kbd_delay" ] && kbdrate -r $kbd_rate -d $kbd_delay
73 set_kbd_rate() {
74 gui_input "Set new console keyboard auto-repeat rate" \
75 "$kbd_rate" "kbd_rate"
76 store_kbd
79 set_kbd_delay() {
80 gui_input "Set new console keyboard auto-repeat delay" \
81 "$kbd_delay" "kbd_delay"
82 store_kbd
85 store_con() {
86 if [ -f /etc/conf/console ] ; then
87 sed -e "s/con_term=.*/con_term=$con_term/" \
88 -e "s/con_blank=.*/con_blank=$con_blank/" \
89 -e "s/con_blength=.*/con_blength=$con_blength/" \
90 -i /etc/conf/console
92 touch /etc/conf/console # make sure the file exists
93 grep -q con_term= /etc/conf/console ||
94 echo con_term=$con_term >> /etc/conf/console
95 grep -q con_blank= /etc/conf/console ||
96 echo con_blank=$con_blank >> /etc/conf/console
97 grep -q con_blength= /etc/conf/console ||
98 echo con_blength=$con_blength >> /etc/conf/console
100 [ "$con_term" -a "$con_blank" -a "$con_blength" ] &&
101 setterm -term $con_term -blank $con_blank -blength $con_blength \
102 > /dev/console
105 set_con_term() {
106 gui_input "Set new console screen terminal type" \
107 "$con_term" "con_term"
108 store_con
111 set_con_blank() {
112 gui_input "Set new console screen blank interval" \
113 "$con_blank" "con_blank"
114 store_con
117 set_con_blength() {
118 gui_input "Set new console screen beep interval" \
119 "$con_blength" "con_blength"
120 store_con
123 set_tmzone() {
124 tz="$( ls -l /etc/localtime | cut -f8 -d/ )"
125 cmd="gui_menu 'general_tmzone' 'Select one of the following time zones.'"
127 if [ -n "$tz" -a -f ../usr/share/zoneinfo/$1/$tz ]; then
128 cmd="$cmd 'Current: $tz' 'ln -sf ../usr/share/zoneinfo/$1/$tz \
129 /etc/localtime'"
131 cmd="$cmd $( grep "$1/" /usr/share/zoneinfo/zone.tab | cut -f3 | \
132 cut -f2 -d/ | sort -u | tr '\n' ' ' | sed 's,[^ ]\+,& '`
133 `'"ln -sf ../usr/share/zoneinfo/$1/& /etc/localtime",g' )"
135 eval "$cmd"
138 set_tmarea() {
139 tz="$( ls -l /etc/localtime | cut -f7 -d/ )"
140 cmd="gui_menu 'general_tmarea' 'Select one of the following time areas.'"
142 cmd="$cmd 'Current: $tz' 'if set_tmzone $tz ; then tzset=1 ; fi'"
143 cmd="$cmd $( grep '^[^#]' /usr/share/zoneinfo/zone.tab | cut -f3 | \
144 cut -f1 -d/ | sort -u | tr '\n' ' ' | sed 's,[^ ]\+,& '`
145 `'"if set_tmzone & ; then tzset=1 ; fi",g' )"
147 tzset=0
148 while eval "$cmd" && [ $tzset = 0 ] ; do : ; done
151 set_dtime() {
152 local set=0
153 while [ $set = 0 ]; do
154 dtime="`date '+%m-%d %H:%M %Y'`" ; newdtime="$dtime"
155 [ -f /etc/conf/clock ] && . /etc/conf/clock
156 [ "$clock_tz" != localtime ] && clock_tz=utc
157 gui_input "Set new date and time (MM-DD hh:mm YYYY, $clock_tz)" \
158 "$dtime" "newdtime"
159 if [ "$dtime" != "$newdtime" ] ; then
160 echo "Setting new date and time ($newdtime) ..."
161 if ! date "$( echo $newdtime | sed 's,[^0-9],,g' )"; then
162 gui_message "Error setting time, invalid timespec?"
163 else
164 set=1
166 hwclock --systohc --$clock_tz
167 else
168 set=1
170 done
173 set_locale_sub() {
174 rm -f /etc/profile.d/locale
175 if [ "$1" != "none" ]; then
176 localedef -i ${1%.*} -c -f ${1#*.} $1
177 echo "export LANG='$1'" > /etc/profile.d/locale
181 set_locale() {
182 unset LANG ; [ -f /etc/profile.d/locale ] && . /etc/profile.d/locale
183 locale="${LANG:-none}" ; cmd="gui_menu 'general_locale' 'Select one of the following locales.'"
185 if [ "$locale" != none ]; then
186 title=$(grep -a ^title /usr/share/i18n/locales/${locale%.*} | \
187 sed -e 's,.*"\(.*\)".*,\1,g' -e "s,',´,g")
188 x="$( echo -e "Current: ${title:0:41}\t$locale" | expand -t52 )"
189 cmd="$cmd '$x' 'true'"
191 x="$( echo -e "none\tnone" | expand -t52 )"
192 cmd="$cmd '$x' 'set_locale_sub none'"
194 x="$( echo -e "POSIX\tC" | expand -t52 )"
195 cmd="$cmd '$x' 'set_locale_sub C' $(
196 grep -Ha ^title /usr/share/i18n/locales/* | \
197 sed -e 's,.*/\(.*\):.*"\(.*\)",\1\t\2,g' \
198 -e "s,',´,g" | while read key title; do
199 key="$key.UTF-8"
200 echo "'${title:0:50} $key' 'set_locale_sub $key'" | expand -t53 | tr '\n' ' '
201 done
204 eval "$cmd"
207 main() {
208 while
209 unset LANG ; [ -f /etc/profile.d/locale ] && . /etc/profile.d/locale
210 locale="${LANG:-none}" ; tz="$( ls -l /etc/localtime | cut -f7- -d/ )"
211 keymap=$(ls -l /etc/default.keymap 2> /dev/null | sed 's,.*/,,')
212 [ "$keymap" ] || keymap="none" ; keymap="${keymap%.map.gz}"
213 vcfont=$(ls -l /etc/default.vcfont 2> /dev/null | sed 's,.*/,,')
214 if [ -z "$vcfont" ] ; then vcfont="none"
215 else vcfont="`echo $vcfont | sed -e "s,\.\(fnt\|psf.*\)\.gz$,,"`" ; fi
216 dtime="`date '+%m-%d %H:%M %Y'`"
217 [ -f /etc/conf/kbd ] && . /etc/conf/kbd
218 [ "$kbd_rate" ] || kbd_rate=30
219 [ "$kbd_delay" ] || kbd_delay=250
220 [ -f /etc/conf/console ] && . /etc/conf/console
221 [ "$con_term" ] || con_term=linux
222 [ "$con_blank" ] || con_blank=0
223 [ "$con_blength" ] || con_blength=0
225 gui_menu general 'Various general system configurations' \
226 "Set console keyboard mapping ....... $keymap" "set_keymap" \
227 "Set console screen font ............ $vcfont" "set_vcfont" \
228 "Set system-wide time zone .......... $tz" "set_tmarea" \
229 "Set date and time (utc/localtime) .. $dtime" "set_dtime" \
230 "Set system-wide locale (language) .. $locale" "set_locale" \
231 "Set console keyboard repeat rate ... $kbd_rate" "set_kbd_rate" \
232 "Set console keyboard repeat delay .. $kbd_delay" "set_kbd_delay" \
233 "Set console screen terminal type ... $con_term" "set_con_term" \
234 "Set console screen blank interval .. $con_blank" "set_con_blank" \
235 "Set console screen beep interval ... $con_blength" "set_con_blength" \
236 "Run the (daily) 'cron.run' script now" "cron.run"
237 do : ; done