Skip to content

Commit 592f15c

Browse files
committed
dracut/autoinstaller: Replace inscrutable awk with inscrutable jq
1 parent 5c3f949 commit 592f15c

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

dracut/autoinstaller/autoinstall.cfg

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# ===
55
# Disk Configuration
66
# ===
7+
# disk_expr: jq expression to select the disk from the output of `lsblk --json`
8+
# default: .blockdevices[0].name
9+
#disk_expr=".blockdevices[0].name"
10+
711
# disk: the disk to install to
812
# default: the first disk that isn't the installer
913
#disk=/dev/hda
@@ -46,6 +50,12 @@
4650
# default: en_US.UTF-8
4751
#libclocale=en.US.UTF-8
4852

53+
# hostname_expr: Expression to derive the hostname from the output of
54+
# `ip --json -r a`. The default finds all interfaces that are up and
55+
# possess a global address, and then picks the first one.
56+
# hostname_expr: [.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]
57+
#hostname_expr='[.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]'
58+
4959
# hostname: static hostname for the system
5060
# default: derived from DNS
5161
#hostname=VoidLinux

dracut/autoinstaller/install.sh

+5-14
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,6 @@ VAI_configure_hostname() {
128128
echo "${hostname}" > "${target}/etc/hostname"
129129
}
130130

131-
VAI_configure_rc_conf() {
132-
# Set the value of various tokens
133-
sed -i "s:Europe/Madrid:${timezone}:" "${target}/etc/rc.conf"
134-
sed -i "s:\"es\":\"${keymap}\":" "${target}/etc/rc.conf"
135-
136-
# Activate various tokens
137-
sed -i "s:#HARDWARECLOCK:HARDWARECLOCK:" "${target}/etc/rc.conf"
138-
sed -i "s:#TIMEZONE:TIMEZONE:" "${target}/etc/rc.conf"
139-
sed -i "s:#KEYMAP:KEYMAP:" "${target}/etc/rc.conf"
140-
}
141-
142131
VAI_add_user() {
143132
chroot "${target}" useradd -m -s /bin/bash -U -G wheel,users,audio,video,cdrom,input "${username}"
144133
if [ -z "${password}" ] ; then
@@ -154,7 +143,7 @@ VAI_configure_grub() {
154143
echo "hostonly=yes" > "${target}/etc/dracut.conf.d/hostonly.conf"
155144

156145
# Choose the newest kernel
157-
kernel_version="$(chroot "${target}" xbps-query linux | awk -F "[-_]" '/pkgver/ {print $2}')"
146+
kernel_version="$(xbps-uhelper -r ${target} version linux | sed 's/_.*//')"
158147

159148
# Install grub
160149
chroot "${target}" grub-install "${disk}"
@@ -220,8 +209,10 @@ VAI_end_action() {
220209

221210
VAI_configure_autoinstall() {
222211
# -------------------------- Setup defaults ---------------------------
223-
disk="$(lsblk -ipo NAME,TYPE,MOUNTPOINT | awk '{if ($2=="disk") {disks[$1]=0; last=$1} if ($3=="/") {disks[last]++}} END {for (a in disks) {if(disks[a] == 0){print a; break}}}')"
224-
hostname="$(ip -4 -o -r a | awk -F'[ ./]' '{x=$7} END {print x}')"
212+
disk_expr=".blockdevices[0].name"
213+
disk="$(lsblk --json | jq -r "$disk_expr")"
214+
hostname_expr='[.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]'
215+
hostname="$(ip --json -r a | jq -r "$hostname_expr")"
225216
target="/mnt"
226217
timezone="America/Chicago"
227218
keymap="us"

dracut/autoinstaller/module-setup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ depends() {
1111
}
1212

1313
install() {
14-
inst /usr/bin/awk
1514
inst /usr/bin/chmod
1615
inst /usr/bin/chroot
1716
inst /usr/bin/clear
@@ -21,6 +20,7 @@ install() {
2120
inst /usr/bin/dhclient-script
2221
inst /usr/bin/halt
2322
inst /usr/bin/install
23+
inst /usr/bin/jq
2424
inst /usr/bin/lsblk
2525
inst /usr/bin/mkdir
2626
inst /usr/bin/mkfs.ext4

mknet.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ else
170170
info_msg "Selecting u-boot bootloader"
171171
bootloader_pkg=uboot-mkimage
172172
fi
173-
run_cmd_target "xbps-install $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -Sy ${KERNELPKG-linux} dracut binutils dracut-network dialog ${INITRAMFS_COMPRESSION-xz} ${bootloader_pkg}"
173+
run_cmd_target "xbps-install $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -Sy ${KERNELPKG-linux} dracut binutils dracut-network dialog jq ${INITRAMFS_COMPRESSION-xz} ${bootloader_pkg}"
174174
run_cmd_chroot "$ROOTFS" "xbps-reconfigure -a"
175175

176176
# Dracut needs to know the kernel version that will be using this

0 commit comments

Comments
 (0)