source: server/bin/installmodule

lgromero-new-oglive
Last change on this file was c28eefa, checked in by Natalia Serrano <natalia.serrano@…>, 19 months ago

Log to syslog in a number of shell scripts

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