source: server/bin/installmodule

qndtest
Last change on this file was ded9f40, checked in by Irina Gómez <irinagomez@…>, 2 years ago

#1066 #997: Fix variable name in commit . (cherry-pick a3aa3e3).

  • Property mode set to 100755
File size: 2.6 KB
Line 
1#!/bin/bash
2# isntallmodule - instalar módulo de kernel en Initrd de cliente ogLive.
3# Uso:  installmodule tarfile
4# Nota: tarfile es un fichero tar.gz con el fichero .ko del módulo y un fichero "module.conf"
5#       para configuración de instalación (debe incluir nombre, fichero y camino del módulo).
6# Autor: Ramón M. Gómez
7# Fecha: 2015-12-03
8
9
10# Variables.
11PROG=$(basename $0)
12OPENGNSYS=/opt/opengnsys
13INITRD=$OPENGNSYS/tftpboot/ogclient/oginitrd.img
14TARFILE=$(realpath $1 2>/dev/null)
15tmpmod=/tmp/module$$
16tmpinit=/tmp/initrd$$
17
18# Comprobar errores.
19if [ $# -ne 1 ]; then
20        echo "$PROG: Incorrect operand. Format: $PROG moduletarfile" >&2
21        exit 1
22fi
23if [ "$USER" != "root" ]; then
24        echo "$PROG: Need to be root." >&2
25        exit 1
26fi
27
28# Mostrar ayuda.
29if [ "$1" == "help" ]; then
30        cat << EOT
31
32$PROG: installs kernel module into ogLive image (initrd).
33
34Format: $PROG moduletarfile
35
36moduletarfile must be a tar.gz archive with 2 files:
37 - *.ko: compiled module
38 - module.conf: configuration file
39
40Configuration file format:
41        module=ModuleName
42        file=ModuleFile
43        path=ModulePath
44
45ModuleName must be a single word.
46ModuleFile must be a kernel compiled module file (*.ko).
47ModulePath must be the kernel target directory, started by "kernel/".
48
49EOT
50        exit 0
51fi
52
53# Comprobar acceso al fichero de módulos.
54if [ ! -r "$TARFILE" ]; then
55        echo "$PROG: Cannot access module file." >&2
56        exit 1
57fi
58
59pushd /tmp >/dev/null
60
61# Borrar al salir del programa.
62trap "popd 2>/dev/null; rm -fr $tmpmod $tmpinit" 0 1 2 3 6 9 15
63
64# Descompresión de módulos para el ogLive actual.
65mkdir -p $tmpmod
66cd $tmpmod
67tar xvzf $TARFILE >/dev/null || exit
68
69# Fichero de configuración.
70source module.conf || exit
71[ -z "$module" ] && echo "Module not detected." && exit 1
72
73# Descomprimir Initrd.
74mkdir -p $tmpinit
75cd $tmpinit
76COMPRESS=$(file -b "$INITRD" | awk '{print tolower($1);}')
77$COMPRESS -dc "$INITRD" | cpio -im 2>/dev/null
78
79# Versión del Kernel del Initrd.
80KERNEL=$(ls -d lib/modules/[0-9]* | head -1)
81[ -z "$KERNEL" ] && echo "Kernel not detected." && exit 1
82# Avisar si el Kernel del módulo es distinto del del Initred.
83echo "$(basename $KERNEL) $(modinfo -F vermagic $tmpmod/$file | cut -f1 -d' ')" | awk '$1!=$2 {print "WARNING: installing module for Kernel",$1,"on Kernel",$2}'
84
85# Copiar módulo y reconstruir dependencias.
86echo "Installing module: $module"
87cp -a $tmpmod/$file $KERNEL/$path
88depmod -b . -a $(basename $KERNEL)
89
90# Recomponer el Initrd.
91find . | cpio -H newc -oa | gzip -9c >$INITRD
92md5sum $INITRD | cut -f1 -d" " > $INITRD.sum
93cp -a $INITRD $INITRD.sum $OPENGNSYS/tftpboot
94
95# Limpiar.
96popd >/dev/null
97rm -fr $tmpmod $tmpinit
98
Note: See TracBrowser for help on using the repository browser.