|
|
- #! /bin/bash
- #
- # virtpanel
- #
- # chkconfig: 2345 10 90
- # description: Configures VPS networking, resolvers, hostname and root password.
- #
- ### BEGIN INIT INFO
- # Provides: virtpanel
- # Short-Description: Configures VPS networking, resolvers, hostname and root password.
- # Description: Configures VPS networking, resolvers, hostname and root password.
- # Should-Start: $network
- # Required-Start:
- # Required-Stop:
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- ### END INIT INFO
- if [ "$1" != "start" ];then
- exit;
- fi
- mkdir -p /mnt/floppy
- modprobe floppy &> /dev/null
- umount /mnt/floppy &> /dev/null
- mount -t vfat /dev/fd0 /mnt/floppy
- # IPv4 Addresses
- ip link set dev eth0 up
- i=0;
- cat /mnt/floppy/ips.txt | while read ip; do
- i=$((i+1))
- if [[ "$i" == "1" ]]; then
- echo Main IP: $ip
- ip addr add $ip dev eth0
- gateway=`cat /mnt/floppy/gateway.txt`
- ip route add $gateway dev eth0
- ip route add default via $gateway dev eth0
- else
- echo Additional IP: $ip
- #ifconfig eth0:$((i-2)) $ip
- #route add -host $ip dev eth0:$((i-2))
- ip addr add $ip dev eth0
- fi
- done
- # IPv6 Addresses
- ipv6=`cat /mnt/floppy/ipv6.txt`
- ipv6cidr=`cat /mnt/floppy/ipv6_cidr.txt`
- ipv6gw=`cat /mnt/floppy/ipv6_gateway.txt`
- if [[ "$ipv6" != "" ]]; then
- echo IPv6: ${ipv6}/${ipv6cidr} Gateway: ${ipv6gw}
- ip -6 addr add ${ipv6}/${ipv6cidr} dev eth0
- ip -6 route add ${ipv6gw} dev eth0
- ip -6 route add default via ${ipv6gw} dev eth0
- fi
- # Name Servers
- echo -n "" > /etc/resolv.conf
- cat /mnt/floppy/dns.txt | while read dns; do
- echo "nameserver $dns" >> /etc/resolv.conf
- done
- # Hostname
- hostname=`cat /mnt/floppy/hostname.txt`
- hostname $hostname
- echo "$hostname" > /etc/hostname
- # Root password
- if [ -f "/mnt/floppy/password.txt" ]; then
- echo "root:`cat /mnt/floppy/password.txt`" | chpasswd
- rm -f /mnt/floppy/password.txt
- fi
- # Create SSH keys if required
- if [ ! -f "/etc/ssh/ssh_host_rsa_key" ]; then
- cat /etc/os-release 2> /dev/null | grep -E "(Debian|Ubuntu)" >/dev/null 2>&1 && dpkg-reconfigure openssh-server
- fi
- # Prevent the display from blanking
- setterm -blank 0
- setterm -powersave off
- umount /mnt/floppy
复制代码 |
|