diff --git a/rootfs overrides/usr/bin/modprobe.js b/rootfs overrides/usr/bin/modprobe.js index 7d0244b..f135689 100644 --- a/rootfs overrides/usr/bin/modprobe.js +++ b/rootfs overrides/usr/bin/modprobe.js @@ -1,3 +1,44 @@ -const { modprobe } = require('/chibrax/kernel.js') -if(process.argv[3])modprobe(process.argv[3]) -else console.log("missing argument") \ No newline at end of file +//@ts-check +const { finit_module, uname } = require('../../chibrax/kernel.js') +const fs = require('fs') +const path = require('path') + +const name = uname() +const modulePath = path.join('/lib/modules', name, 'kernel') + + +if(process.argv[3]) { + let filename = process.argv[3] + if(!filename.endsWith('.ko')) { + filename += '.ko' + } + const kernModule = findmodule(modulePath, filename) + if(kernModule) { + finit_module(kernModule) + } else { + console.log('module not found') + } +} +else console.log("missing argument") + +/** + * @param { string } modulesPath + * @param { string } moduleName + * @returns {string | null } + */ +function findmodule(modulesPath, moduleName) { + if (fs.existsSync(path.join(modulesPath, moduleName))) { + return path.join(modulesPath, moduleName) + } + const subfiles = fs.readdirSync(modulesPath, { withFileTypes: true }) + + for (const file of subfiles) { + if(file.isDirectory()) { + const foundModule = findmodule(path.join(modulesPath, file.name), moduleName) + if(foundModule) { + return foundModule + } + } + } + return null +}