OSDN Git Service

d5ef190b3ca0d716353a2170d222948d4db40408
[avyssos/66-voidlinux.git] / srcpkgs / boot-66serv / files / 66boot-rcdotconf
1 #!/bin/sh
2 # Copyright 2021 mobinmob <mobinmob@disroot.org>
3 # Use of this source code is governed by the 2-Clause BSD License
4 # that can be found in the LICENSE file.
5 # SPDX short identifier: BSD-2-Clause
6
7 # This script reads a **valid** rc.conf and writes the values to the 
8 # corresponding configuration options in the boot@system environment file.
9
10 # Script must run as root.
11 user=$(id -u)
12 [ "$user" != "0" ] && printf "You need to run this script as root! \n" && exit 1
13
14 HOSTNAME=
15 HOSTNAME1=
16 HARDWARECLOCK=
17 TIMEZONE=
18 KEYMAP=
19 FONT=
20 FONT_MAP=
21 FONT_UNIMAP=
22 TTYS=
23
24
25 # Variables for 66-yeller
26 export PROG="66boot-storage-autoconf"
27 export COLOR_ENABLED="1"
28 export CLOCK_ENABLED="0"
29
30 apply_conf_from_to(){
31         # Set configuration value ${3} from ${1} to ${2}
32         # ${1} is the conf option from /etc/rc.conf
33         # ${2} is the conf option from the boot@ conf file
34         # ${3} is the value from the /etc/rc.conf option/var
35         if [ -n "${3}" ]
36         then
37                 66-env -t boot -r "${2}"=!"${3}" boot@system
38                 66-yeller %g "${2} set to [${3}]." %n
39         fi
40 }
41
42 set_hostname() { 
43         # ${1} HOSTNAME value
44         [ -r /etc/hostname ] && export HOSTNAME1="$( cat /etc/hostname )"
45         
46         if [ -n "${1}" ]
47         then
48                 66-env -t boot -r HOSTNAME=!"${1}" boot@system
49                 66-yeller %g "HOSTNAME set to [${1}]." %n
50         elif [ -n "$HOSTNAME1" ]
51         then
52                 66-env -t boot -r HOSTNAME=!"$HOSTNAME1" boot@system
53                 66-yeller %g "HOSTNAME set to [$HOSTNAME1]." %n
54         elif [ -z "${1}" ] && [ -z "$HOSTNAME1" ]
55         then
56         66-env -t boot -r HOSTNAME=!void-live boot@system
57         66-yeller -W %b "No HOSTNAME set, reverting
58  to the default [void-live]." %n
59         fi
60 }
61  
62 set_ttys() {
63         # Same positional args as apply_conf_from_to
64         if  [ -n "${3}" ]
65         then
66                 if [ ${3} -lt 11 ] && [ ${3} -gt 0 ]
67                  then
68                         apply_conf_from_to "${1}" "${2}" "${3}"
69                 else
70                 66-env -t boot -r TTY=!4 boot@system
71                 66-yeller -W %b "${3} TTYS is not valid as a tty number,
72 reverting to the default [4]." %n
73                 exit 1
74                 fi
75         else 
76                 66-env -t boot -r TTY=!4 boot@system
77                 66-yeller -F %r "TTY number not set, reverting
78  to the default [4]." %n
79         fi
80 }
81
82
83 . /etc/rc.conf
84
85 set_hostname "$HOSTNAME"
86 apply_conf_from_to TIMEZONE TZ "$TIMEZONE"
87 apply_conf_from_to HARDWARECLOCK HARDWARECLOCK "$HARDWARECLOCK"
88 apply_conf_from_to KEYMAP KEYMAP "$KEYMAP"
89 apply_conf_from_to FONT_MAP FONT_MAP "$FONT_MAP"
90 apply_conf_from_to FONT FONT "$FONT"
91 apply_conf_from_to FONT_UNIMAP FONT_UNIMAP "$FONT_UNIMAP"
92 set_ttys TTYS TTY "$TTYS"