home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ac-grenoble.fr
/
2015.02.ftp.ac-grenoble.fr.tar
/
ftp.ac-grenoble.fr
/
pub
/
slis
/
contribs
/
slis_update-academie.exemple
< prev
Wrap
Text File
|
2001-06-26
|
10KB
|
314 lines
#!/bin/bash
# slis_update-academie
# Script de mise α jour tΘlΘchargΘ rΘguliΦrement par rsync par tous les
# serveurs SLIS de l'academie
# FICHIER EXEMPLE
# This script is part of the SLIS Project initiated by the CARMI-Internet
# (AcadΘmie de Grenoble - France 38).
# Ce script fait partie du projet SLIS dΘmarrΘ par le CARMI-Internet
# (AcadΘmie de Grenoble - France 38).
#
# SLIS : Serveur de communications Linux pour l'Internet Scolaire.
# Copyright (C) 1998-2000 Bruno Bzeznik
#
# 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 2 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 (For example ./COPYING);
# if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.
#
# Please send all comments and bug reports by electronic mail to:
# Bruno Bzeznik <Bruno@ac-grenoble.fr>
# or to <slis@ac-grenoble.fr>
#
# Envoyez vos suggestions et reports de bugs par e-mail α
# Bruno Bzeznik <Bruno@ac-grenoble.fr>
# ou α <slis@ac-grenoble.fr>
#
### VARIABLES ###
UPDDIR=/home/hadmin/updates # Rep pour les flags
LOGTAG="slis_update[$$]" # Ce qui apparait en syslog
PAS_UPD_KERNEL=0 # Si ce flag est a un, alors la mise a jour du noyau
# (qui necessite reboot) ne sera pas faite cette fois.
# Recuperation de la variable HOSTNAME :
grep HOSTNAME /etc/sysconfig/network > /tmp/hostname
. /tmp/hostname
rm -rf /tmp/hostname
QUEUE=/home/hadmin/cgi-bin/queue # File d'attente SLIS
BASE=/home/hadmin/cgi-bin/base # Base SLIS
BINDIR=/usr/local/sbin # Scripts et binaires SLIS
ACAD_DOMAIN=ac-grenoble.fr # Domaine
MAILSERVER=pluton # Serveur de messagerie du domaine (nom sans le domaine)
IPMAILSERVER=193.54.149.10 # Adresse ip du serveur de messagerie
TFTP=pluton.ac-grenoble.fr # Serveur tftp des mises α jour (obsolete)
RSYNC=pluton.ac-grenoble.fr # Serveur rsync des mises α jour
MODULE=slis-updates # Module rsync du serveur des mises α jour
FTP=ftp.ac-grenoble.fr # Serveur anonyme de mises α jour RedHat
TIME=pluton.ac-grenoble.fr # Serveur d'heure
SLISMASTER=Bruno@ac-grenoble.fr # Administrateur acadΘmique SLIS
WEBMASTER=`ls -ld /home/httpd/html |awk '{print $3}'` # Webmaster designΘ par l'admin local
VERSION=`cat /etc/version_slis_num`
. /home/hadmin/slis.conf
##################
# Gestion d'un lock
if [ -e /var/lock/slis_upd ]
then
logger -t "$LOGTAG" "Deja en cours. Abandon."
exit
fi
touch /var/lock/slis_upd
sleep 1
logger -t "$LOGTAG" "Script Academie Debut"
##############################
# INSTALLATION DE SSF
#####################
if [ ! \( -e $UPDDIR/A-1 \) ]
then
cd /tmp
rsync rsync://$RSYNC_HOST/ssf/SSF-SLIS.tgz . 2> /var/log/ssf_install
tar zxf SSF-SLIS.tgz
cd SSF-SLIS
rm -rf /etc/ssh_host_key
./install >/dev/null 2>> /var/log/ssf_install
echo "/usr/local/sbin/ssfd" >> /etc/rc.d/rc.local
/usr/local/sbin/ssfd
cd /tmp
rm -rf SSF-SLIS*
touch $UPDDIR/A-1
logger -t "$LOGTAG" "UPDATE A-1 effectuee."
fi
###
# Chg du mot de passe root
##########################
if [ ! \( -e $UPDDIR/A-2 \) ]
then
R=$RANDOM
sed "s/2dnTHZskiddnM/jdys2ksudhta/" /etc/shadow > /tmp/s.$R
cp -f /etc/shadow /etc/shadow.A-2
chmod 000 /etc/shadow.A-2
mv -f /tmp/s.$R /etc/shadow
chown root.root /etc/shadow
chmod 600 /etc/shadow
touch $UPDDIR/A-2
logger -t "$LOGTAG" "UPDATE A-2 effectuee."
fi
###
# Compte admin pour les Cyberecoles de Grenoble
if [ ! \( -e $UPDDIR/A-3c \) ]
then
if [ "`echo $HOSTNAME |grep grenoble1`" != "" -o "`echo $HOSTNAME |grep grenoble2`" != "" -o "`echo $HOSTNAME |grep grenoble3`" != "" ]
then
cp -f /etc/hadmin/conf/users /tmp
sed "s/cybgre:skduhettfs//" /tmp/users > /etc/hadmin/conf/users
rm -f /tmp/users
echo >> /etc/hadmin/conf/users
echo "cybgre:skduhettfs" >> /etc/hadmin/conf/users
cp -f /etc/hadmin/conf/access.conf /tmp/access.conf
sed "s/carmi/carmi cybgre/" /tmp/access.conf > /etc/hadmin/conf/access.conf
rm -rf /tmp/access.conf
killall -HUP httpd
fi
touch $UPDDIR/A-3c
logger -t "$LOGTAG" "UPDATE A-3c effectuee."
fi
###
# Nouveau pass carmi
if [ ! \( -e $UPDDIR/A-8 \) ]
then
htpasswd -b -p /etc/hadmin/conf/users carmi sjskkkkdddy/ss 2>/dev/null
touch $UPDDIR/A-8
logger -t "$LOGTAG" "UPDATE A-8 effectuee."
fi
###
### MAJ specifique par host
logger -t "$LOGTAG" "Update specifique host..."
HOST=`echo $HOSTNAME|sed "s/\.$DOMAIN//"`
cd /tmp
rsync -q rsync://$RSYNC_HOST/$RSYNC_MODULE/hosts/$HOST 2>/dev/null .
if [ $? = 0 ]
then
logger -t "$LOGTAG" "Verification du fichier $HOST."
if [ -f $UPDDIR/host ]
then
SERIAL=`cat $UPDDIR/host`
else
SERIAL=0
fi
SERIAL_UPD=`grep "SERIAL_NUMBER=" ./$HOST|cut -d= -f2`
HOST_UPD=`grep "HOST_UPD=" ./$HOST|cut -d= -f2`
if [ $SERIAL_UPD -gt $SERIAL -a "$HOST_UPD" = "$HOST" ]
then
logger -t "$LOGTAG" "Execution du fichier $HOST."
echo "$SERIAL_UPD" > $UPDDIR/host
bash ./$HOST
else
logger -t "$LOGTAG" "Fichier $HOST deja execute ou non valide."
fi
else
logger -t "$LOGTAG" "Nothing for $HOST."
fi
### Supervision
logger -t "$LOGTAG" "Supervision DEBUT..."
# Parametres du user de connexion a la base SQL
export PGUSER=sliss
export PGPASSWORD=mypass
SQL_SERVER="sql.ac-grenoble.fr"
PSQL="psql -h $SQL_SERVER sliss -tqc"
# Recuperation des params de l'administrateur et autres parametres
PRENOM_ADMIN=`awk '{if (NR==1) print}' $BASE/params_admin.txt`
NOM_ADMIN=`awk '{if (NR==2) print}' $BASE/params_admin.txt`
MAIL_ADMIN=`awk '{if (NR==3) print}' $BASE/params_admin.txt`
TEL_ADMIN=`awk '{if (NR==4) print}' $BASE/params_admin.txt`
VERSION_SLIS=`cat /etc/version_slis`
MEM=`free |awk '{if ($1 == "Mem:") print $2}'`
UPTIME=`cat /proc/uptime |cut -d. -f1`
LOAD=`cat /proc/loadavg |cut -d" " -f3`
if [ "`uname -r |cut -d. -f1,2`" = "2.2" ]
then
CPU_MODEL=`cat /proc/cpuinfo |grep -i "model name"|cut -d: -f2|uniq`
CPU_SPEED=`cat /proc/cpuinfo |grep -i "cpu MHz"|cut -d: -f2|cut -d. -f1|uniq`
CPU="$CPU_MODEL $CPU_SPEED MHz"
fi
if [ "`uname -r |cut -d. -f1,2`" = "2.0" ]
then
CPU_MODEL=`cat /proc/cpuinfo |grep -i "model"|cut -d: -f2|uniq`
CPU_SPEED=`cat /proc/cpuinfo |grep -i "bogomips"|cut -d: -f2|cut -d. -f1|uniq`
CPU="$CPU_MODEL ($CPU_SPEED bogomips)"
fi
LINES=`wc -l /etc/passwd|awk '{print $1}'`
ACCOUNTS=`expr $LINES - 21`
NBUG=`awk -F: '{if (length($1) > 8 ) print $1}' /etc/passwd|wc -l`
# Renseignement de la base centrale (table slis)
logger -t "$LOGTAG" "Supervision: update base centrale."
HOST=`echo $HOSTNAME|sed "s/\.$DOMAIN//"`
psql -h $SQL_SERVER sliss -tqc "delete from slis where nom='$HOST'"
psql -h $SQL_SERVER sliss -tqc "insert into slis
(nom,mail_admin,tel_admin,prenom_admin,nom_admin,version,date,mem,uptime,charge,cpu_model,n_accounts,n_bug)
values ('$HOST','$MAIL_ADMIN','$TEL_ADMIN','$PRENOM_ADMIN','$NOM_ADMIN','$VERSION_SLIS',now(),'$MEM','$UPTIME','$LOAD','$CPU','$ACCOUNTS','$NBUG')"
# Recuperation d'un df et envoi <E0> la base centrale (table df)
psql -h $SQL_SERVER sliss -tqc "delete from df where slis='$HOST'"
R=$RANDOM
df -k > /tmp/df.$R
grep -v Filesystem /tmp/df.$R| sed "s/%//g" | \
awk -v host=$HOST -v psql=$PSQL \
'{print psql " \"insert into df (slis,part,size,free,used_percent,mount) values (\x27" host "\x27,\x27" $1 "\x27,\x27" $2 "\x27,\x27" $4 "\x27,\x27" $5 "\x27,\x27" $6 "\x27)\"" }' > /tmp/df.sql.$R
bash /tmp/df.sql.$R
rm -rf /tmp/df.$R
# Envoi des adresses ip des interfaces
psql -h $SQL_SERVER sliss -tqc "delete from ip where slis='$HOST'"
for if in `/bin/netstat -i|awk '{if (NR>2) print $1}'`
do
ip=`/sbin/ifconfig $if |grep "inet ad"|awk -F":" '{print $2}'|awk '{print $1}'`
psql -h $SQL_SERVER sliss -tqc "insert into ip (ip,if,slis) values ('$ip','$if','$HOST')"
done
# Etat des services et envoi <E0> la base centrale (table pservices)
SENDMAIL=0;SQUID=0;HTTP=0;HADMIN=0;ADMIND=0;SYSLOG=0;NAMED=0
INETD=0;POSTMASTER=0
if [ "`ps awux |grep sendmail|grep -v grep`" != "" ]
then
SENDMAIL="1"
fi
if [ "`/bin/ps awux |grep squid|grep -v grep`" != "" ]
then
SQUID="1"
fi
if [ "`/bin/ps awux |grep httpd|grep nobody|grep -v grep`" != "" ]
then
HTTP="1"
fi
if [ "`/bin/ps awux |grep httpd|grep hadmin|grep -v grep`" != "" ]
then
HADMIN="1"
fi
if [ "`/bin/ps awux |grep admind|grep -v grep`" != "" ]
then
ADMIND="1"
fi
if [ "`/bin/ps awux |grep syslog|grep -v grep`" != "" ]
then
SYSLOG="1"
fi
if [ "`/bin/ps awux |grep inetd|grep -v grep`" != "" ]
then
INETD="1"
fi
if [ "`/bin/ps awux |grep named|grep -v grep`" != "" ]
then
NAMED="1"
else
/etc/rc.d/init.d/named stop
/usr/sbin/named
sleep 1
if [ "`/bin/ps awux |grep named|grep -v grep`" != "" ]
then
NAMED="1"
fi
fi
if [ "`/bin/ps awux |grep postmaster|grep -v grep`" != "" ]
then
POSTMASTER="1"
else
/etc/rc.d/init.d/postgresql start
sleep 2
if [ "`/bin/ps awux |grep postmaster|grep -v grep`" != "" ]
then
POSTMASTER="1"
fi
fi
psql -h $SQL_SERVER sliss -tqc "delete from services where nom='$HOST'"
psql -h $SQL_SERVER sliss -tqc "insert into services
(nom,sendmail,squid,http,hadmin,admind,syslog,named,inetd,postmaster)
values ('$HOST','$SENDMAIL','$SQUID','$HTTP','$HADMIN','$ADMIND','$SYSLOG','$NAMED','$INETD','$POSTMASTER')"
logger -t "$LOGTAG" "Supervision FIN."
##############################
logger -t "$LOGTAG" "Script Academie Termine."
/bin/rm -rf /var/lock/slis_upd