| 1 | // Run in the diskless guest with both X11 bitmap font packages installed. |
| 2 | module main |
| 3 | |
| 4 | import os |
| 5 | |
| 6 | const font_dir = '/usr/share/fonts/X11/misc' |
| 7 | |
| 8 | fn rebuild(expect_cursor bool) ! { |
| 9 | hook := '/usr/share/libalpm/hooks/60-update-x11-misc-fonts.hook' |
| 10 | commands := os.read_lines(hook)!.filter(it.starts_with('Exec = ')) |
| 11 | if commands.len != 1 { |
| 12 | return error('expected one Exec action in ${hook}') |
| 13 | } |
| 14 | result := os.exec(commands[0].all_after('Exec = ').split(' ')) |
| 15 | if result.exit_code != 0 { |
| 16 | return error('font index hook exited ${result.exit_code}: ${result.output}') |
| 17 | } |
| 18 | lines := os.read_lines(os.join_path(font_dir, 'fonts.dir'))! |
| 19 | if lines.len < 2 || lines[0].int() != lines.len - 1 |
| 20 | || lines.any(it.starts_with('cursor.pcf.gz ')) != expect_cursor |
| 21 | || !lines.any(it.to_lower().starts_with('6x13.pcf.gz -misc-fixed-')) { |
| 22 | return error('font index has an incorrect count or bitmap font entries') |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | fn check() ! { |
| 27 | rebuild(true)! |
| 28 | cursor := os.join_path(font_dir, 'cursor.pcf.gz') |
| 29 | directory := os.join_path(font_dir, '.vinix-test-${os.getpid()}') |
| 30 | os.mkdir(directory)! |
| 31 | defer { |
| 32 | os.rmdir(directory) or { eprintln(err) } |
| 33 | } |
| 34 | temporary := os.join_path(directory, 'cursor.pcf.gz') |
| 35 | os.rename(cursor, temporary)! |
| 36 | rebuild(false) or { |
| 37 | os.rename(temporary, cursor)! |
| 38 | return err |
| 39 | } |
| 40 | os.rename(temporary, cursor)! |
| 41 | rebuild(true)! |
| 42 | } |
| 43 | |
| 44 | fn main() { |
| 45 | check() or { |
| 46 | eprintln(err) |
| 47 | exit(1) |
| 48 | } |
| 49 | println('Vinix font index hook passed for installed, removed and restored bitmap fonts.') |
| 50 | } |
| 51 | |