2008-05-03 17:03:02 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
#Framework, welches ein komplettes Linux System aus den Sourcen erstellt
|
|
|
|
|
#dieses Framework wird im CVS Repository
|
|
|
|
|
#:pserver:cvs.compuextreme.de:/Data/cvs zur Verf<72>gung gestellt
|
|
|
|
|
#
|
|
|
|
|
#Lage dieser Datei im Archiv: $Source: /export/Data/cvs/Viitor_sysvinit/etc/init.d/functions,v $
|
|
|
|
|
#
|
|
|
|
|
#(c) 2003 Harald Kueller, Germany
|
|
|
|
|
#This program is free software; you can redistribute it and/or
|
|
|
|
|
#modify ist 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; if not write to the Free Software Foundation,
|
|
|
|
|
#Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
#
|
|
|
|
|
#InitScript zum Start des Daemons:
|
|
|
|
|
#Funktionen f<>r die init scripten
|
|
|
|
|
#Dieses Script basiert auf der Vorlage des Linuxfromscratch Projetes
|
|
|
|
|
#
|
|
|
|
|
#Letzte <20>nderung von: $Author: kueller $
|
|
|
|
|
#Datum der letzten <20>nderung: $Date: 2004/03/03 12:48:07 $
|
|
|
|
|
#Version der Datei: $Revision: 1.12 $
|
|
|
|
|
#
|
|
|
|
|
#$Log: functions,v $
|
|
|
|
|
#Revision 1.12 2004/03/03 12:48:07 kueller
|
|
|
|
|
#Header auf neuen Viitor GPL Header umgestellt
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.11 2002/09/30 20:32:22 kueller
|
|
|
|
|
#Korrektur der Funktion getmasks - bei nichtvorhandener /etc/netmasks
|
|
|
|
|
#bricht die Funktion mit einem [] Fehler ab. Variable FOUND wurde
|
|
|
|
|
#in diesem Fall nicht gesetzt. Fehler behoben
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.10 2002/09/23 20:22:09 hkueller
|
|
|
|
|
#Anpassung der Funktionen an BASH - dazu musste jedes typeset kommando
|
|
|
|
|
#entfernt werden, da bash keine zahlenumrechnung kann. Durch Neue Funktion
|
|
|
|
|
#GetShortMask problem mit short mask angabe bei ip kommando ohne verwendung
|
|
|
|
|
#von umrechnungsfunktionen gel<65>st.
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.9 2002/09/11 18:16:05 hkueller
|
|
|
|
|
#Korrekturen bei der netzmask erkennung unter zsh
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.8 2002/08/09 07:00:00 hkueller
|
|
|
|
|
#getmask vereinfacht und beschleunigt
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.6 2002/05/05 14:40:08 hkueller
|
|
|
|
|
#mit neuem Release wandert basename von /usr/bin nach /bin. functions
|
|
|
|
|
#entsprechend angepasst
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.5 2002/02/05 02:59:04 hkueller
|
|
|
|
|
#functions: getbroadcast() hinzugefuegt - gibt broadcast eines Netzes
|
|
|
|
|
# zurueck - Aufruf: getbroadcast <IP> <NETMASK>
|
|
|
|
|
# getmask erweitert - keine mask in /etc/netmasks ->
|
|
|
|
|
# defaultmask (Class A/B/C)
|
|
|
|
|
#networks: Ueberfaelliger eintrag fuer PTP entfernt
|
|
|
|
|
# Eintraege zur Konfiguration mit ifconfig hinzugefuegt - aber
|
|
|
|
|
# auskommentiert.
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.4 2001/11/18 21:25:52 kueller
|
|
|
|
|
#Korrektur der Aufr<66>umfunktion (sed Regulare Expression) f<>r /etc/netmasks
|
|
|
|
|
#(getmask funktion)
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.3 2001/11/17 23:41:35 kueller
|
|
|
|
|
#Network Setup erweitert. Netmasks werden jetzt aus /etc/netmasks erkannt.
|
|
|
|
|
#Konfiguration der Netmask in /etc/sysconfig/hostname.<if> nicht mehr
|
|
|
|
|
#notwendig!
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.2 2001/11/17 22:20:33 kueller
|
|
|
|
|
#Funktionen dectohex und dectobin zur Umrechnung von dezimalen IP Adressen in
|
|
|
|
|
#Bin<69>re bzw. Dezimale Darstellung hinzugef<65>gt.
|
|
|
|
|
#Achtung: Diese Funktione funktionieren nur in Verbindung mit der zsh oder
|
|
|
|
|
#eine ksh - nicht mit sh oder bash!!!!
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.1.1.1 2001/09/23 00:02:08 kueller
|
|
|
|
|
#Neustart wg. Datenverlust
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.2 2001/08/25 10:14:28 kueller
|
|
|
|
|
#
|
|
|
|
|
#Optische Retusche der READY und FAILED Meldungen
|
|
|
|
|
#
|
|
|
|
|
#Revision 1.1.1.1 2001/08/08 10:02:32 kueller
|
|
|
|
|
#sysvinit addons
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if [ "$COLUMNS" ]; then
|
|
|
|
|
(( COL = $COLUMNS - 10 ))
|
|
|
|
|
else
|
|
|
|
|
COL=70
|
|
|
|
|
fi
|
|
|
|
|
SET_COL="/bin/echo -en \\033[${COL}G"
|
|
|
|
|
NORMAL="/bin/echo -en \\033[0;39m"
|
|
|
|
|
SUCCESS="/bin/echo -en \\033[1;42m"
|
|
|
|
|
FAILURE="/bin/echo -en \\033[1;41m"
|
|
|
|
|
|
|
|
|
|
evaluate_retval()
|
|
|
|
|
{
|
|
|
|
|
if [ $? = 0 ]
|
|
|
|
|
then
|
|
|
|
|
print_status success
|
|
|
|
|
else
|
|
|
|
|
print_status failure
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print_status()
|
|
|
|
|
{
|
|
|
|
|
if [ $# = 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Usage: print_status {success|failure}"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
|
success)
|
|
|
|
|
$SET_COL
|
|
|
|
|
$SUCCESS
|
|
|
|
|
echo -n " READY "
|
|
|
|
|
$NORMAL
|
|
|
|
|
echo ""
|
|
|
|
|
;;
|
|
|
|
|
failure)
|
|
|
|
|
$SET_COL
|
|
|
|
|
$FAILURE
|
|
|
|
|
echo -n " FAILED "
|
|
|
|
|
$NORMAL
|
|
|
|
|
echo ""
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadproc()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if [ $# = 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Usage: loadproc {program}"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
base=`/bin/basename $1`
|
|
|
|
|
|
2010-04-23 08:16:54 +00:00
|
|
|
|
pidlist=`/bin/pidof -x $base|sed -e "s/$$//"|sed -e "s/$PPID//"`
|
2008-05-03 17:03:02 +00:00
|
|
|
|
|
|
|
|
|
pid=""
|
|
|
|
|
|
|
|
|
|
for apid in $pidlist
|
|
|
|
|
do
|
|
|
|
|
if [ -d /proc/$apid ]
|
|
|
|
|
then
|
|
|
|
|
pid="$pid $apid"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ ! -n "$pid" ]
|
|
|
|
|
then
|
|
|
|
|
$*
|
|
|
|
|
evaluate_retval
|
|
|
|
|
else
|
|
|
|
|
print_status failure
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
killproc()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if [ $# = 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Usage: killproc {program} [signal]"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
base=`/bin/basename $1`
|
|
|
|
|
|
|
|
|
|
if [ "$2" != "" ]
|
|
|
|
|
then
|
|
|
|
|
killlevel=$2
|
|
|
|
|
else
|
|
|
|
|
nolevel=1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
pidlist=`/bin/pidof -o $$ -o $PPID -o %PPID -x $base`
|
|
|
|
|
|
|
|
|
|
pid=""
|
|
|
|
|
|
|
|
|
|
for apid in $pidlist
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
if [ -d /proc/$apid ]
|
|
|
|
|
then
|
|
|
|
|
pid="$pid $apid"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ -n "$pid" ]
|
|
|
|
|
then
|
|
|
|
|
if [ "$nolevel" = 1 ]
|
|
|
|
|
then
|
|
|
|
|
/bin/kill -TERM $pid
|
|
|
|
|
if ps h $pid >/dev/null 2>&1
|
|
|
|
|
then
|
|
|
|
|
/bin/kill -KILL $pid
|
|
|
|
|
fi
|
|
|
|
|
/bin/ps h $pid >/dev/null 2>&1
|
|
|
|
|
if [ $? = 0 ]
|
|
|
|
|
then
|
|
|
|
|
print_status failure
|
|
|
|
|
else
|
|
|
|
|
/bin/rm -f /var/run/$base.pid
|
|
|
|
|
print_status success
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
/bin/kill $killlevel $pid
|
|
|
|
|
/bin/ps h $pid >/dev/null 2>&1
|
|
|
|
|
if [ $? = 0 ]
|
|
|
|
|
then
|
|
|
|
|
print_status failure
|
|
|
|
|
else
|
|
|
|
|
/bin/rm -f /var/run/$base.pid
|
|
|
|
|
print_status success
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
print_status failure
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reloadproc()
|
|
|
|
|
{
|
|
|
|
|
if [ $# = 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Usage: reloadproc {program} [signal]"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
base=`/bin/basename $1`
|
|
|
|
|
|
|
|
|
|
if [ -n "$2" ]
|
|
|
|
|
then
|
|
|
|
|
killlevel=-$2
|
|
|
|
|
else
|
|
|
|
|
nolevel=1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
pidlist=`/bin/pidof -o $$ -o $PPID -o %PPID -x $base`
|
|
|
|
|
|
|
|
|
|
pid=""
|
|
|
|
|
|
|
|
|
|
for apid in $pidlist
|
|
|
|
|
do
|
|
|
|
|
if [ -d /proc/$apid ]
|
|
|
|
|
then
|
|
|
|
|
pid="$pid $apid"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ -n "$pid" ]
|
|
|
|
|
then
|
|
|
|
|
if [ "$nolevel" = 1 ]
|
|
|
|
|
then
|
|
|
|
|
/bin/kill -SIGHUP $pid
|
|
|
|
|
evaluate_retval
|
|
|
|
|
else
|
|
|
|
|
/bin/kill -$killlevel $pid
|
|
|
|
|
evaluate_retval
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
print_status failure
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statusproc()
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
if [ $# = 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Usage: status {program}"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
pid=`/bin/pidof -o $$ -o $PPID -o %PPID -x $1`
|
|
|
|
|
if [ -n "$pid" ]
|
|
|
|
|
then
|
|
|
|
|
echo "$1 running with Process ID $pid"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -f /var/run/$1.pid ]
|
|
|
|
|
then
|
|
|
|
|
pid=`/usr/bin/head -1 /var/run/$1.pid`
|
|
|
|
|
if [ -n "$pid" ]
|
|
|
|
|
then
|
|
|
|
|
echo "$1 not running but /var/run/$1.pid exists"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "$i is not running"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getbroadcast() {
|
|
|
|
|
IP=$1
|
|
|
|
|
MASK=$2
|
|
|
|
|
for i in 1 2 3 4; do
|
|
|
|
|
IP[$i]=`echo $IP|awk -F. '{print $'$i'}'`
|
|
|
|
|
MASK[$i]=`echo $MASK|awk -F. '{print $'$i'}'`
|
|
|
|
|
(( BCAST[$i] = ${IP[$i]} | (( ${MASK[$i]} ^ 255 )) ))
|
|
|
|
|
done
|
|
|
|
|
echo ${BCAST[1]}.${BCAST[2]}.${BCAST[3]}.${BCAST[4]}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getnetaddr() {
|
|
|
|
|
IP=$1
|
|
|
|
|
MASK=$2
|
|
|
|
|
for i in 1 2 3 4; do
|
|
|
|
|
IPS=`echo $IP|awk -F. '{print $'$i'}'`
|
|
|
|
|
MASKS=`echo $MASK|awk -F. '{print $'$i'}'`
|
|
|
|
|
(( BCASTS = $IPS & $MASKS ))
|
|
|
|
|
if [ "$i" = "4" ]; then
|
|
|
|
|
printf "$BCASTS"
|
|
|
|
|
else
|
|
|
|
|
printf "$BCASTS."
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
echo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getmask() {
|
|
|
|
|
IP=$1
|
|
|
|
|
FOUND=0
|
|
|
|
|
if [ -f /etc/netmasks ]; then
|
|
|
|
|
sed -e "/^#/d" /etc/netmasks |\
|
|
|
|
|
sed -e "/^ *$/d" >/tmp/if
|
|
|
|
|
while read NETADDR NETMASK; do
|
|
|
|
|
NETIP=`getnetaddr $IP $NETMASK`
|
|
|
|
|
if [ "$NETADDR" = "$NETIP" ]; then
|
|
|
|
|
echo $NETMASK
|
|
|
|
|
FOUND=1
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done </tmp/if
|
|
|
|
|
rm /tmp/if
|
|
|
|
|
fi
|
|
|
|
|
if [ "$FOUND" -eq "0" ]; then
|
|
|
|
|
Byte=`echo $IP|awk -F . '{ print $1 }'`
|
|
|
|
|
if [ "$Byte" -le 127 ] && [ "$Byte" -ge 1 ]; then
|
|
|
|
|
echo "255.0.0.0"
|
|
|
|
|
elif [ "$Byte" -le 191 ] && [ "$Byte" -ge 128 ]; then
|
|
|
|
|
echo "255.255.0.0"
|
|
|
|
|
elif [ "$Byte" -le 223 ] && [ "$Byte" -ge 192 ]; then
|
|
|
|
|
echo "255.255.255.0"
|
|
|
|
|
else
|
|
|
|
|
echo "255.255.255.255"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetShortMask () {
|
|
|
|
|
IP=$1
|
|
|
|
|
NumIP=0
|
|
|
|
|
for i in 1 2 3 4; do
|
|
|
|
|
Byte=`echo $IP|awk -F . '{ print $'$i' }'`
|
|
|
|
|
if (( "$Byte" & 128 )); then
|
|
|
|
|
(( NumIP = $NumIP + 1 ))
|
|
|
|
|
fi
|
|
|
|
|
if (( "$Byte" & 64 )); then
|
|
|
|
|
(( NumIP = $NumIP + 1 ))
|
|
|
|
|
fi
|
|
|
|
|
if (( "$Byte" & 32 )); then
|
|
|
|
|
(( NumIP = $NumIP + 1 ))
|
|
|
|
|
fi
|
|
|
|
|
if (( "$Byte" & 16 )); then
|
|
|
|
|
(( NumIP = $NumIP + 1 ))
|
|
|
|
|
fi
|
|
|
|
|
if (( "$Byte" & 8 )); then
|
|
|
|
|
(( NumIP = $NumIP + 1 ))
|
|
|
|
|
fi
|
|
|
|
|
if (( "$Byte" & 4 )); then
|
|
|
|
|
(( NumIP = $NumIP + 1 ))
|
|
|
|
|
fi
|
|
|
|
|
if (( "$Byte" & 2 )); then
|
|
|
|
|
(( NumIP = $NumIP + 1 ))
|
|
|
|
|
fi
|
|
|
|
|
if (( "$Byte" & 1 )); then
|
|
|
|
|
(( NumIP = $NumIP + 1 ))
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
echo $NumIP
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initautomount() {
|
|
|
|
|
MOUNTSOURCE=$1
|
|
|
|
|
AUTOMOUNTSOURCE=$2
|
|
|
|
|
source /etc/sysconfig/autofstime
|
|
|
|
|
sed -e '/^#/d' |\
|
|
|
|
|
sed -e '/^ *$/d' >/tmp/autofs
|
|
|
|
|
exec 3</tmp/autofs
|
|
|
|
|
while read <&3 MOUNTPOINT FILE; do
|
|
|
|
|
echo -n "starting automount for $MOUNTPOINT ($MOUNTSOURCE)"
|
|
|
|
|
automount -t $TIMEOUT $MOUNTPOINT $AUTOMOUNTSOURCE,sun $FILE
|
|
|
|
|
evaluate_retval
|
|
|
|
|
done
|
|
|
|
|
exec 3>&-
|
|
|
|
|
rm /tmp/autofs
|
|
|
|
|
}
|
|
|
|
|
# End /etc/init.d/functions
|