#!/bin/bash
### BEGIN INIT INFO
# Provides:          networking
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Activate network interfaces
### END INIT INFO

case "$1" in
    start)
        echo "Starting networking..."
        ip link set lo up
        ip addr add 127.0.0.1/8 dev lo
        if [ -f /etc/network/interfaces ]; then
            # Aktiviere eth0 Interface
            ip link set eth0 up
            # Parse interfaces file für IP-Konfiguration
            if grep -q "inet static" /etc/network/interfaces; then
                ADDRESS=$(grep "address" /etc/network/interfaces | awk '{print $2}')
                GATEWAY=$(grep "gateway" /etc/network/interfaces | awk '{print $2}')
                if [ ! -z "$ADDRESS" ]; then
                    ip addr add $ADDRESS dev eth0
                fi
                if [ ! -z "$GATEWAY" ]; then
                    ip route add default via $GATEWAY
                fi
            fi
        fi
        ;;
    stop)
        echo "Stopping networking..."
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac
exit 0
