Guten Tag Liebe BSDForen User,
ich habe ein Problem mit einem Shellscript, welches ich aus
Übungszwecken und der Vereinfachung willen geschrieben habe:
Beim Ausführen kommt folgende Fehler meldung:
Nun frage ich mich, wo liegt mein Fehler? Ich würde das ungerne in Bash schreiben,
will Shell lernen.
Mit freundlichen Grüßen,
Daroo
ich habe ein Problem mit einem Shellscript, welches ich aus
Übungszwecken und der Vereinfachung willen geschrieben habe:
PHP:
#!/bin/sh
#System Installer by
###############################################
###############################################
### ##### ###### ##### ###### ###### ###
### ## ## ## ## ## ## ## ## ## ## ###
### ## ## ###### ## ## ## ## ## ## ###
### ## ## ## ## ##### ## ## ## ## ###
### ##### ## ## ## ## ###### ###### ###
### ## ###
###############################################
###############################################
##-------------------------------------------##
##Variablen
RELEASE=$(uname -r)
FETCHSERVER="http://example.com/$RELEASE"
SSYS="/usr/src/sys/conf"
TESTFILE="test.tar.gz"
SRCFILE="ssys.tar.gz"
SRCDIR="/usr/src/"
K1="IPFW"
K2="PAE"
K3="PF"
K4="Daroonator"
FWRULES="firewall.rules"
PFRULES="pf.conf"
RC="/etc/rc.conf"
CURDIR="./"
MYSQLUSR="mysql.tar.gz"
MYSQL="/var/db/mysql"
PORTSUPDATE=0
PORTS="/usr/ports"
SQUID="squid.conf"
##Connection Test
while [ "$SERVERCON" != "end" ]
do
if [ "$CONNUM" == 2 ]; then
FETCHSERVER=http://example2.com/$RELEASE
fetch $FETCHSERVER/$TESTFILE
clear
if test ! -f $TESTFILE
then
echo -e "\033[31m \n Server nicht erreichbar!\033[0m"
sleep 3
clear
exit
else
clear
rm $TESTFILE
SERVERCON=end
fi
else
fetch $FETCHSERVER/$TESTFILE
clear
if test ! -f "$TESTFILE"
then
CONNUM = 'expr $CONNUM + 1'
else
clear
rm $TESTFILE
SERVERCON=end
fi
fi
done
if [ $SERVERCON == "end" ]; then
##Funktionen
#IPFW
if [ $1 == 1 ]; then
echo -e "\033[31mÜberprüfe Sources...\033[0m"
if test ! -d $SSYS
then
echo -e "\033[31mDownload Sources...\033[0m"
fetch $FETCHSERVER/$SRCFILE
tar zxf $SRCFILE -C $SRCDIR
echo -e "\033[31mSources erfolgreich installiert!\033[0m"
rehash
fi
echo -e "\033[31mInstalliere IP-Firewall...\033[0m"
make buildkernel KERNCONF=$K1
make installkernel KERNCONF=$K1
echo -e "\033[31mIP-Firewall-Installation abgeschlossen!\033[0m"
fetch $FETCHSERVER/$FWRULES
mv $PFRULES /etc/$FWRULES
echo 'firewall_enable="YES"' >> $RC
echo 'firewall_script="/etc/firewall.rules"' >> $RC
sleep 10
clear
sh install.sh F
##PAE
elif [ $1 == 2 ]; then
echo -e "\033[31mÜberprüfe Sources...\033[0m"
if test ! -d $SSYS
then
echo -e "\033[31mDownload Sources...\033[0m"
fetch $FETCHSERVER/$SRCFILE
tar zxf $SRCFILE -C $SRCDIR
echo -e "\033[31mSources erfolgreich installiert!\033[0m"
rehash
fi
echo -e "\033[31mInstalliere PAE...\033[0m"
make buildkernel KERNCONF=$K2
make installkernel KERNCONF=$K2
echo -e "\033[31mPAE-Installation abgeschlossen!\033[0m"
sleep 10
clear
sh install.sh F
##PF
elif [ $1 == 3 ]; then
echo -e "\033[31mÜberprüfe Sources...\033[0m"
if test ! -d $SSYS
then
echo -e "\033[31mDownload Sources...\033[0m"
fetch $FETCHSERVER/$SRCFILE
tar zxf $SRCFILE -C $SRCDIR
echo -e "\033[31mSources erfolgreich installiert!\033[0m"
rehash
fi
echo -e "\033[31mInstalliere Paketfilter...\033[0m"
make buildkernel KERNCONF=$K3
make installkernel KERNCONF=$K3
echo -e "\033[31mPaketfilter-Installation abgeschlossen!\033[0m"
fetch $FETCHSERVER/$PFRULES
mv $PFRULES /etc/$PFRULES
echo 'pf_enable="YES"' >> $RC
echo 'pf_rules="/etc/pf.conf"' >> $RC
sleep 10
clear
sh install.sh F
##Daroonator
elif [ $1 == 4 ]; then
echo -e "\033[31mÜberprüfe Sources...\033[0m"
if test ! -d $SSYS
then
echo -e "\033[31mDownload Sources...\033[0m"
fetch $FETCHSERVER/$SRCFILE
tar zxf $SRCFILE -C $SRCDIR
echo -e "\033[31mSources erfolgreich installiert!\033[0m"
rehash
fi
echo -e "\033[31mInstalliere Daroonator-Kernel...\033[0m"
make buildkernel KERNCONF=$K4
make installkernel KERNCONF=$K4
echo -e "\033[31mDaroonator-Installation abgeschlossen!\033[0m"
fetch $FETCHSERVER/$PFRULES
mv $PFRULES /etc/$PFRULES
echo 'pf_enable="YES"' >> $RC
echo 'pf_rules="/etc/pf.conf"' >> $RC
fetch $FETCHSERVER/$FWRULES
mv $PFRULES /etc/$FWRULES
echo 'firewall_enable="YES"' >> $RC
echo 'firewall_script="/etc/firewall.rules"' >> $RC
sleep 10
clear
sh install.sh F
##TestFunktion
elif [ $1 == 5 ]; then
echo "Funktion zur Zeit nicht bereit!"
sleep 10
clear
sh install.sh F
##MySQL
elif [ $1 == 6 ]; then
echo -e "\033[31mÜberprüfe Ports...\033[0m"
if test ! -d "$PORTS"
then
echo -e "\033[31mInstalliere Ports...\033[0m"
portsnap fetch extract
fi
if [ $PORTSUPDATE != 1 ]; then
echo -e "\033[31mUpdate Ports...\033[0m"
portsnap fetch update
PORTSUPDATE=1
fi
echo -e "\033[31mInstalliere MySQL 5.1...\033[0m"
cd $PORTS/databases/mysql51-server
make install WITH_XCHARSET=all
make clean
fetch $FETCHSERVER/$MYSQLUSR
tar zxf $MYSQLUSER -C $MYSQL/mysql
chown -R $MYSQL
chgrp -R $MYSQL
read PASSWORD
/usr/local/bin/mysqladmin -u root password $PASSWORD
cd $CURDIR
rehash
echo -e "\033[31mMySQL 5.1-Installation abgeschlossen\033[0m"
sleep 10
clear
sh install.sh F
##Screen
elif [ $1 == 7 ]; then
echo -e "\033[31mÜberprüfe Ports...\033[0m"
if test ! -d "$PORTS"
then
echo -e "\033[31mInstalliere Ports...\033[0m"
portsnap fetch extract
fi
if [ $PORTSUPDATE != 1 ]; then
echo -e "\033[31mUpdate Ports...\033[0m"
portsnap fetch update
PORTSUPDATE=1
fi
echo -e "\033[31mInstalliere Screen...\033[0m"
cd $PORTS/sysutils/screen
make -DBTACH install
make clean
rehash
cd $CURDIR
echo -e "\033[31mScreen-Installation abgeschlossen!\033[0m"
sleep 10
clear
sh install.sh F
##Squid
elif [ $1 == 8 ]; then
echo -e "\033[31mÜberprüfe Ports...\033[0m"
if test ! -d "$PORTS"
then
echo -e "\033[31mInstalliere Ports...\033[0m"
portsnap fetch extract
fi
if [ $PORTSUPDATE != 1 ];then
echo -e "\033[31mUpdate Ports...\033[0m"
portsnap fetch update
PORTSUPDATE=1
fi
echo -e "\033[31mInstalliere Squid...\033[0m"
cd $PORTS/www/squid
make -DBATCH install
make clean
/usr/local/sbin/squid -z
cd /usr/local/etc/
rm squid.conf
fetch $fetchserver/$SQUID
echo 'squid_enable="YES"' >> $RC
rehash
cd $CURDIR
echo -e "\033[31mSquid Installation abgeschlossen!\033[0m"
sleep 10
clear
sh install.sh F
##Sudo
elif [ $1 == 9 ]; then
echo -e "\033[31mÜberprüfe Ports...\033[0m"
if test ! -d "$PORTS"
then
echo -e "\033[31mInstalliere Ports...\033[0m"
portsnap fetch extract
fi
if [ $PORTSUPDATE != 1 ]; then
echo -e "\033[31mUpdate Ports...\033[0m"
portsnap fetch update
PORTSUPDATE=1
fi
echo -e "\033[31mInstalliere Sudo...\033[0m"
cd $PORTS/security/sudo
make -DBATCH install
make clean
rehash
cd $CURDIR
echo -e "\033[31mSudo-Installation abgeschlossen!\033[0m"
sleep 10
clear
sh install.sh F
##Python
elif [ $1 == 10 ]; then
echo -e "\033[31mÜberprüfe Ports...\033[0m"
if test ! -d "$PORTS"
then
echo -e "\033[31mInstalliere Ports...\033[0m"
portsnap fetch extract
fi
if [ $PORTSUPDATE != 1 ]; then
echo -e "\033[31mUpdate Ports...\033[0m"
portsnap fetch update
PORTSUPDATE=1
fi
echo -e "\033[31mInstalliere Python...\033[0m"
cd $PORTS/lang/python
make -DBATCH install
make clean
rehash
cd $CURDIR
echo -e "\033[31mPython-Installation abgeschlossen!\033[0m"
sleep 10
clear
sh install.sh F
##Perl
elif [ $1 == 11 ]; then
echo -e "\033[31mÜberprüfe Ports...\033[0m"
if test ! -d "$PORTS"
then
echo -e "\033[31mInstalliere Ports...\033[0m"
portsnap fetch extract
fi
if [ $PORTSUPDATE != 1 ];then
echo -e "\033[31mUpdate Ports...\033[0m"
portsnap fetch update
PORTSUPDATE=1
fi
echo -e "\033[31mInstalliere Perl 5.8...\033[0m"
cd $PORTS/lang/perl5.8
make -DBATCH install
make clean
rehash
cd $CURDIR
echo -e "\033[31mPerl5.8-Installation abgeschlossen!\033[0m"
sleep 10
clear
sh install.sh F
##Flood
elif [ $1 == 12 ]; then
echo -e "\033[31mDownloade UDP-Flood Script...\033[0m"
fetch $FETCHSERVER/$FLOOD
echo -e "\033[31mBitte gebe die IP ein!\033[0m"
read ip
perl $FLOOD $IP
rm $FLOOD
sleep 3
clear
sh install.sh F
##Quit
elif [ $1 == [Qq] ]; then
exit
##Nach beenden
elif [ $1 == "F" ]; then
echo -e "\033[31mInstallation (f)ortsetzen oder (b)eenden?[y/n]\033[0m"
read choice
if [ $choice == [Ff] ]; then
clear
sh install.sh
elif [ $choice == [Bb] ]; then
sleep 1
clear
exit
else
echo -e "\033[31mUngültige Eingabe!\033[0m"
clear
sh install.sh F
fi
##Hauptmenu
else
if [ $RELEASE == "7.4-RELEASE" ] || [ $RELEASE == "8.1-RELEASE" ]; then
echo -e "\033[31mWillkommen beim Systeminstaller von Daroo\033[0m"
echo -e "\033[31mBitte wähle eine Option:\033[0m"
echo -e "\033[31m Kernel Installation \n
1*) IP-Firewall
2*) PAE
3*) Packetfilter
4*) IPFW+PAE+PF
5*) Testpunkt \n
6*) MySQL 5.1 Installation \n
7*) Screen \n
8*) Squid \n
9*) Sudo \n
10*) Python \n
11*) Perl \n
12*) Flood Script \n
13*) Ende\033[0m"
read chs
sleep 1
if [ $chs -ge 14 ]; then
echo -e "\033[31mUngültige Eingabe!\033[0m"
sleep 2
clear
sh install.sh
else
clear
sleep 1
sh install.sh $chs
fi
else
echo -e "\033[31mDas Release $RELEASE ist nicht unterstützt.\033[0m"
fi
fi
fi
Beim Ausführen kommt folgende Fehler meldung:
Code:
2P22# sh install.sh
install.sh: 93: Syntax error: "elif" unexpected (expecting "then")
2P22#
Nun frage ich mich, wo liegt mein Fehler? Ich würde das ungerne in Bash schreiben,
will Shell lernen.
Mit freundlichen Grüßen,
Daroo