// Run in the diskless guest with both X11 bitmap font packages installed. module main import os const font_dir = '/usr/share/fonts/X11/misc' fn rebuild(expect_cursor bool) ! { hook := '/usr/share/libalpm/hooks/60-update-x11-misc-fonts.hook' commands := os.read_lines(hook)!.filter(it.starts_with('Exec = ')) if commands.len != 1 { return error('expected one Exec action in ${hook}') } result := os.exec(commands[0].all_after('Exec = ').split(' ')) if result.exit_code != 0 { return error('font index hook exited ${result.exit_code}: ${result.output}') } lines := os.read_lines(os.join_path(font_dir, 'fonts.dir'))! if lines.len < 2 || lines[0].int() != lines.len - 1 || lines.any(it.starts_with('cursor.pcf.gz ')) != expect_cursor || !lines.any(it.to_lower().starts_with('6x13.pcf.gz -misc-fixed-')) { return error('font index has an incorrect count or bitmap font entries') } } fn check() ! { rebuild(true)! cursor := os.join_path(font_dir, 'cursor.pcf.gz') directory := os.join_path(font_dir, '.vinix-test-${os.getpid()}') os.mkdir(directory)! defer { os.rmdir(directory) or { eprintln(err) } } temporary := os.join_path(directory, 'cursor.pcf.gz') os.rename(cursor, temporary)! rebuild(false) or { os.rename(temporary, cursor)! return err } os.rename(temporary, cursor)! rebuild(true)! } fn main() { check() or { eprintln(err) exit(1) } println('Vinix font index hook passed for installed, removed and restored bitmap fonts.') }