#!/bin/sh
#    reseteo_anual_de_usuarios.sh es un script que trabaja con las cuentas
#    de usuarios SAMBA que inician con la letra U, vaciando el profile de
#    esos usuarios e inicializando sus contraseñas a 12345. El script es
#    muy elemental y puede generalizarse.
#    
#    Escrito por Nicolás Pereyra Molinas <pereyra@gmail.com> en febrero 2009
#    bajo los términos de la licencia GPL
#
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#

FECHA=$(date +%Y%m%d-%H%M%S)
AL=file-$FECHA.log
NUEVOPASS=12345
echo Este script sirve para resetear las cuentas de SAMBA | tee -a $AL
echo Fecha de ejecucion: $(date)
#Borrado de datos
echo "Esta es la primera parte del script" | tee -a $AL
echo
echo "Desea todos borrar los datos de los usuarios? (S/N)" | tee -a $AL
read PREG
if [[ "$PREG" = "S" || "$PREG" = "s" ]]; then
	echo
	echo
	echo
	echo "ULTIMA OPORTUNIDAD!!!!"  | tee -a $AL
	echo "Desea realmente borrar TODOS LOS DATOS de los usuarios? (S/N)"  | tee -a $AL 
	read PREG
	if [[ "$PREG" = "S" || "$PREG" = "s" ]]; then
		echo
		echo
		echo Borrando efectivamente los datos  | tee -a $AL
		echo
		echo
		DIR=/var/opt/shares/profiles
		rm -Rvf $DIR/U*  | tee -a $AL
	fi
else
	echo
	echo
	echo Abandonando tarea de borrado | tee -a $AL
	echo
	echo
fi

#Reseteo de passwords

echo "Esta es la SEGUNDA parte del script" | tee -a $AL
echo
echo "Desea resetear todos los passwords de los usuarios? (S/N)" | tee -a $AL
read PREG
if [[ "$PREG" = "S" || "$PREG" = "s" ]]; then
	echo
	echo
	echo
	echo "ULTIMA OPORTUNIDAD!!!!"  | tee -a $AL
	echo "Desea realmente resetear TODOS LOS PASSWORDS de los usuarios? (S/N)"  | tee -a $AL 
	read PREG
	if [[ "$PREG" = "S" || "$PREG" = "s" ]]; then
		echo
		echo
		echo Reseteando efectivamente los passwords  | tee -a $AL
		echo
		echo
		for USUARIO in $(slapcat|grep U|grep uid\:|cut -d" " -f2|sort); do
			echo "reseteando password de $USUARIO a $NUEVOPASS" | tee -a $AL	
			echo -e "$NUEVOPASS\n$NUEVOPASS"|smbpasswd -s $USUARIO | tee -a $AL
			sleep 0.5
		done
	fi
else
	echo
	echo
	echo Abandonando tarea de reseteo de passwords | tee -a $AL
	echo
	echo
fi

echo "Fin: $(date)"| tee -a $AL


