Forráskód Böngészése

dracut/autoinstaller: Replace inscrutable awk with inscrutable jq

Michael Aldridge 3 hónapja
szülő
commit
9d681c609d

+ 10 - 0
dracut/autoinstaller/autoinstall.cfg

@@ -4,6 +4,10 @@
 # ===
 # Disk Configuration
 # ===
+# disk_expr: jq expression to select the disk from the output of `lsblk --json`
+# default: .blockdevices[0].name
+#disk_expr=".blockdevices[0].name"
+
 # disk: the disk to install to
 # default: the first disk that isn't the installer
 #disk=/dev/hda
@@ -46,6 +50,12 @@
 # default: en_US.UTF-8
 #libclocale=en.US.UTF-8
 
+# hostname_expr: Expression to derive the hostname from the output of
+# `ip --json -r a`.  The default finds all interfaces that are up and
+# possess a global address, and then picks the first one.
+# hostname_expr: [.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]
+#hostname_expr='[.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]'
+
 # hostname: static hostname for the system
 # default: derived from DNS
 #hostname=VoidLinux

+ 5 - 3
dracut/autoinstaller/install.sh

@@ -154,7 +154,7 @@ VAI_configure_grub() {
     echo "hostonly=yes" > "${target}/etc/dracut.conf.d/hostonly.conf"
 
     # Choose the newest kernel
-    kernel_version="$(chroot "${target}" xbps-query linux | awk -F "[-_]" '/pkgver/ {print $2}')"
+    kernel_version="$(xbps-uhelper -r ${target} version linux | sed 's/_.*//')"
 
     # Install grub
     chroot "${target}" grub-install "${disk}"
@@ -220,8 +220,10 @@ VAI_end_action() {
 
 VAI_configure_autoinstall() {
     # -------------------------- Setup defaults ---------------------------
-    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}}}')"
-    hostname="$(ip -4 -o -r a | awk -F'[ ./]' '{x=$7} END {print x}')"
+    disk_expr=".blockdevices[0].name"
+    disk="/dev/$(lsblk --json | jq -r "$disk_expr")"
+    hostname_expr='[.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]'
+    hostname="$(ip --json -r a | jq -r "$hostname_expr")"
     target="/mnt"
     timezone="America/Chicago"
     keymap="us"

+ 1 - 1
dracut/autoinstaller/module-setup.sh

@@ -11,7 +11,6 @@ depends() {
 }
 
 install() {
-    inst /usr/bin/awk
     inst /usr/bin/chmod
     inst /usr/bin/chroot
     inst /usr/bin/clear
@@ -21,6 +20,7 @@ install() {
     inst /usr/bin/dhclient-script
     inst /usr/bin/halt
     inst /usr/bin/install
+    inst /usr/bin/jq
     inst /usr/bin/lsblk
     inst /usr/bin/mkdir
     inst /usr/bin/mkfs.ext4

+ 1 - 1
mklive.sh

@@ -31,7 +31,7 @@ umask 022
 REQUIRED_PKGS=(base-files libgcc dash coreutils sed tar gawk squashfs-tools xorriso)
 TARGET_PKGS=(base-files)
 INITRAMFS_PKGS=(binutils xz device-mapper dhclient dracut-network openresolv)
-PACKAGE_LIST=()
+PACKAGE_LIST=(jq)
 IGNORE_PKGS=()
 PLATFORMS=()
 readonly PROGNAME="$(basename "$0")"

+ 1 - 1
mknet.sh

@@ -170,7 +170,7 @@ else
     info_msg "Selecting u-boot bootloader"
     bootloader_pkg=uboot-mkimage
 fi
-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}"
+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}"
 run_cmd_chroot "$ROOTFS" "xbps-reconfigure -a"
 
 # Dracut needs to know the kernel version that will be using this