source: server/bin/setsmbpass @ 65baf16

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 65baf16 was 9555dd1, checked in by ramon <ramongomez@…>, 12 years ago

#565 #576: Crear el acceso correcto a Rsync para imágenes diferenciales.

git-svn-id: https://opengnsys.es/svn/branches/version1.0@3520 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 2.6 KB
Line 
1#!/bin/bash
2# setsmbpass: cambia la contraseña del usuario del cliente para acceder a los
3#       servicios Samba.
4# Nota: se modifica el Initrd del cliente y se cambia la clave en el servidor.
5# Nota: no se modifica el usuario de acceso (usuario "opengnsys").
6# Uso:  setsmbpass
7# Autor: Ramon Gomez - Univ. Sevilla, julio 2011
8
9
10# Variables.
11PROG=$(basename $0)
12OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
13SAMBAUSER="opengnsys"                           # Usuario por defecto.
14TFTPDIR=$OPENGNSYS/tftpboot
15CLIENTINITRD=$TFTPDIR/ogclient/oginitrd.img
16TMPDIR=/tmp/ogclient$$
17
18# Control básico de errores.
19if [ $# != 0 ]; then
20        echo "$PROG: Error de ejecución" >&2
21        echo "Formato: $PROG"
22        exit 1
23fi
24if [ "$USER" != "root" ]; then
25        echo "$PROG: Error: solo ejecutable por root" >&2
26        exit 1
27fi
28
29# Crear clave para usuario de acceso a los recursos.
30if [ -r $CLIENTINITRD ]; then
31        stty -echo 2>/dev/null
32        echo -n "Clave del usuario Samba: "
33        read SAMBAPASS
34        # Solo se deben aceptar números y letras para la clave de acceso.
35        if [ -n "${SAMBAPASS//[a-zA-Z0-9]/}" ]; then
36                echo
37                echo "$PROG: Error: la clave solo debe contener caracteres alfanuméricos" >&2
38                stty echo 2>/dev/null
39                exit 2
40        fi
41        echo
42        echo -n "Confirmar clave: "
43        read SAMBAPASS2
44        echo
45        stty echo 2>/dev/null
46        if [ "$SAMBAPASS" != "$SAMBAPASS2" ]; then
47                echo "$PROG: Error: las claves no coinciden" >&2
48                exit 2
49        fi
50        # Editar la parte de acceso del cliente:
51        #    descomprimir Initrd, sustituir clave y recomprimir Initrd).
52        mkdir -p $TMPDIR
53        cd $TMPDIR
54        gzip -dc $CLIENTINITRD | cpio -im
55        if [ -f scripts/ogfunctions ]; then
56                sed -i "s/OPTIONS=\(.*\)user=\w*\(.*\)pass=\w*\(.*\)/OPTIONS=\1user=$SAMBAUSER\2pass=$SAMBAPASS\3/" scripts/ogfunctions
57                # TEMPORAL: solución ticket 554, actualizar cliente en caché (ogLive r3257).
58                sed -i "s/busybox reboot/reboot/" scripts/ogfunctions
59                # FIN CÓDIGO TEMPORAL.
60                # Ticket 565, preparar acceso Rsync cliente.
61                echo "$SAMBAPASS" > scripts/passrsync
62                chown root.root scripts/passrsync
63                chmod 400 scripts/passrsync
64                # Generar Initrd del cliente.
65                find . | cpio -H newc -oa | gzip -9c > $CLIENTINITRD
66                # Ticket 565, preparar acceso Rsync servidor.
67                echo "$SAMBAUSER:$SAMBAPASS" > /etc/rsyncd.secrets
68                chown root.root /etc/rsyncd.secrets
69                chmod 600 /etc/rsyncd.secrets
70        else
71                echo "$PROG: Aviso: no se ha modificado la clave del cliente."
72        fi
73        rm -fr $TMPDIR
74        md5sum $CLIENTINITRD | cut -f1 -d" " > $CLIENTINITRD.sum
75        cp -a $CLIENTINITRD $TFTPDIR
76        cp -a $CLIENTINITRD.sum $TFTPDIR
77else
78        SAMBAPASS="og"                  # Clave por defecto.
79        echo "$PROG: Aviso: no se ha modificado la clave del cliente."
80fi
81echo -ne "$SAMBAPASS\n$SAMBAPASS\n" | smbpasswd -a -s $SAMBAUSER
82
Note: See TracBrowser for help on using the repository browser.