#!/bin/sh # vim: set noexpandtab die() { printf '%s\n' "$*" >&2; exit 1; } do_help() { cat <<-END Manage kernel modules links Usage: ${0} is one of: copy: copy modules of the current kernel to /run/modules link: link the copied kernel modules into /usr/lib/modules gc: remove dangling links in /usr/lib/modules clean: remove everything from akulm, that it looks like a usual ArchLinux system help: Show this help END } do_copy() { rsync -r \ "/usr/lib/modules/$(uname -r)/" \ "/run/modules/$(uname -r)/" } do_clean() { rm -rf /run/modules/* do_gc_links } do_gc() { do_gc_links && do_gc_modules } do_gc_modules() { find /run/modules \ -mindepth 1 \ -maxdepth 1 \ -not -name "$(uname -r)" \ -exec rm -rf '{}' ';' } do_gc_links() { find /usr/lib/modules \ -mindepth 1 \ -maxdepth 1 \ -xtype l \ -exec rm '{}' ';' } do_link() { [ -e "/usr/lib/modules/$(uname -r)" ] \ || ln -sT "/run/modules/$(uname -r)" "/usr/lib/modules/$(uname -r)" } case "${1}" in copy) do_copy;; gc) do_gc;; link) do_link;; clean) do_clean;; hook-pre) do_copy && do_gc;; hook-post) do_link;; help) do_help;; *) die "Invalid command: '${1}'. Valid commands: copy gc link clean help";; esac