jq was in fact not available in base arch iso

This commit is contained in:
2026-01-15 15:30:58 +01:00
parent 5e30040898
commit d0f046b43c
2 changed files with 49 additions and 22 deletions

View File

@@ -15,7 +15,7 @@ After writing the [iso](https://archlinux.org/download/) file to a bootable medi
Some helper:
```bash
loadkeys be-latin1 #load the belgian keyboard keys
curl -fLO https://git.jika.li/Jika/system-spec/archive/master.tar.gz
```
## Ansible replication

View File

@@ -16,7 +16,10 @@ CFG_IN="user_config_base.json"
CFG_OUT="user_config.json"
MIN_GIB=80
die() { echo "Error: $*" >&2; exit 1; }
die() {
echo "Error: $*" >&2
exit 1
}
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <disk-device>"
@@ -33,36 +36,60 @@ DISK="$1"
# Minimum size check (bytes)
SIZE_BYTES="$(lsblk -dn -o SIZE -b "$DISK")"
(( SIZE_BYTES >= MIN_GIB * 1024 * 1024 * 1024 )) || die "'$DISK' is smaller than ${MIN_GIB}GiB."
((SIZE_BYTES >= MIN_GIB * 1024 * 1024 * 1024)) || die "'$DISK' is smaller than ${MIN_GIB}GiB."
read -r BOOT_SIZE_UNIT BOOT_SIZE_VALUE ROOT_START_BYTES ROOT_SIZE_BYTES < <(
python3 - "$DISK" "$SIZE_BYTES" "$CFG_IN" "$CFG_OUT" <<'PY'
import json, sys
disk = sys.argv[1]
size_bytes = int(sys.argv[2])
cfg_in = sys.argv[3]
cfg_out = sys.argv[4]
with open(cfg_in, "r", encoding="utf-8") as f:
cfg = json.load(f)
# Sanity: ensure expected JSON structure exists
jq -e '
.disk_config.device_modifications
| type == "array" and length >= 1
and (. [0].partitions | type == "array" and length >= 2)
and (. [0].partitions[1].start.value | type == "number")
and (. [0].partitions[1].size.value | type == "number")
' "$CFG_IN" >/dev/null || die "Unexpected JSON structure in $CFG_IN (cannot locate partitions[1].start/size)."
try:
dm0 = cfg["disk_config"]["device_modifications"][0]
parts = dm0["partitions"]
if not (isinstance(parts, list) and len(parts) >= 2):
raise TypeError("partitions not length >= 2")
p0 = parts[0]
p1 = parts[1]
root_start = p1["start"]["value"]
if isinstance(root_start, float) and root_start.is_integer():
root_start = int(root_start)
if not isinstance(root_start, int):
raise TypeError(f"start.value not int: {root_start!r}")
except Exception as e:
raise SystemExit(f"Unexpected JSON structure in {cfg_in}: {e}")
# Compute "root = remaining space" in bytes based on the configured root partition start offset
ROOT_START_BYTES="$(jq -r '.disk_config.device_modifications[0].partitions[1].start.value' "$CFG_IN")"
[[ "$ROOT_START_BYTES" =~ ^[0-9]+$ ]] || die "Root start offset is not a number: $ROOT_START_BYTES"
ROOT_SIZE_BYTES=$(( SIZE_BYTES - ROOT_START_BYTES ))
(( ROOT_SIZE_BYTES > 0 )) || die "Computed root size is not positive. Disk may be smaller than the configured start offset."
root_size = size_bytes - root_start
if root_size <= 0:
raise SystemExit("Computed root size is not positive.")
# Patch:
# - set target disk
# - set root partition size to fill to end of disk (bytes)
jq --arg d "$DISK" --argjson root_size "$ROOT_SIZE_BYTES" '
.disk_config.device_modifications[0].device = $d
| .disk_config.device_modifications[0].partitions[1].size.unit = "B"
| .disk_config.device_modifications[0].partitions[1].size.value = $root_size
' "$CFG_IN" > "$CFG_OUT"
dm0["device"] = disk
p1["size"]["unit"] = "B"
p1["size"]["value"] = int(root_size)
with open(cfg_out, "w", encoding="utf-8") as f:
json.dump(cfg, f, indent=4)
f.write("\n")
# Report
BOOT_SIZE_UNIT="$(jq -r '.disk_config.device_modifications[0].partitions[0].size.unit' "$CFG_OUT")"
BOOT_SIZE_VALUE="$(jq -r '.disk_config.device_modifications[0].partitions[0].size.value' "$CFG_OUT")"
boot = p0["size"]
print(boot["unit"], boot["value"], p1["start"]["value"], p1["size"]["value"])
PY
)
echo "Prepared archinstall config: $CFG_OUT"
echo " Disk : $DISK"