#!/usr/bin/env bash #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=1&state_text=STARTING" sleep 20 disks=$(fdisk -l | grep "Disk /dev/sd" | awk '{ print $2" "$5 }' | sed -e s/://g) service networking stop cat > /etc/network/interfaces << EOL #/etc/network/interfaces # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 allow-hotplug eth0 iface eth0 inet static address 172.16.4.20 netmask 255.255.255.0 gateway 172.16.4.1 EOL echo 'nameserver 212.224.71.71' > /etc/resolv.conf service networking start apt-get install ubuntu-archive-keyring debian-archive-keyring -y apt-get update #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=2&state_text=NETWORK_SETUP" gdisk /dev/sda << EOF o Y w Y EOF gdisk /dev/sda << EOF n 1 +64M EF02 n 2 +512M 8200 n 3 8300 w Y EOF fdisk -l #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=3&state_text=DISK_PARTITIONING" mkswap /dev/sda2 mkfs.ext2 /dev/sda1 << EOF y EOF mkfs.ext4 /dev/sda3 << EOF y EOF #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=5&state_text=DISK_FORMATTING" mount /dev/sda3 /mnt #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=6&state_text=DISK_MOUNTED" debootstrap stretch /mnt http://ftp.de.debian.org/debian/ #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=34&state_text=BASE_SYSTEM_INSTALLED" mount --bind /dev /mnt/dev mount -o bind /dev/pts /mnt/dev/pts mount -t sysfs /sys /mnt/sys mount -t proc /proc /mnt/proc setup_server () { apt-get update apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 apt-get update DEBIAN_FRONTEND=noninteractive \ apt-get upgrade -y #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=35&state_text=BASE_SYSTEM_INSTALLED" DEBIAN_FRONTEND=noninteractive \ apt-get install linux-image-amd64 -y #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=36&state_text=BASE_SYSTEM_INSTALLED" apt-get update DEBIAN_FRONTEND=noninteractive \ apt-get upgrade -y DEBIAN_FRONTEND=noninteractive \ apt-get dist-upgrade -y DEBIAN_FRONTEND=noninteractive \ apt-get install grub-pc openssh-server wget ca-certificates acpi acpi-support-base aspell aspell-de aspell-de-alt console-setup console-setup-linux discover discover-data eject ingerman installation-report laptop-detect libio-socket-ip-perl libusb-1.0-0:amd64 task-german task-ssh-server usbutils mdadm iputils-ping sudo git nano dialog parted -y #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=55&state_text=UTILS_INSTALLED" wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=56&state_text=UTILS_INSTALLED" echo 'debconf debconf/frontend select Dialog' | debconf-set-selections apt-get install locales -y export LANGUAGE=de_DE.UTF-8 export LANG=de_DE.UTF-8 export LC_ALL=de_DE.UTF-8 locale-gen "de_DE.UTF-8" localedef -i de_DE -f UTF-8 de_DE.UTF-8 update-locale LANG=de_DE.UTF-8 #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=59&state_text=SYSTEM_UPDATE" update-initramfs -u #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=68&state_text=INITRAMFS" apt-get install htop iftop nload -y apt-get install qemu-guest-agent -y #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=95&state_text=STANDARD_PACKAGES" update-grub grub-install /dev/sda mdadm --detail --scan >>/etc/mdadm/mdadm.conf mdadm --assemble --scan #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=97&state_text=GRUB_INSTALL" cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime passwd << EOF test123 test123 EOF #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=RUNNING&state_percent=98&state_text=PASSWORD" echo 'schmolke' > /etc/hostname echo "45.93.248.160 schmolke schmolke" >> /etc/hosts hostname schmolke echo 'schmolke' > /etc/mailname echo "proc /proc proc defaults 0 0" > /etc/fstab echo "/dev/sda3 / ext4 defaults,noatime,errors=remount-ro 0 1" >> /etc/fstab echo "/dev/sda2 none swap defaults 0 0" >> /etc/fstab cat > /etc/network/interfaces << EOL auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet static address 45.93.248.160 netmask 255.255.255.0 gateway 45.93.248.1 dns-nameservers 212.224.71.71 79.133.62.62 EOL cat > /etc/systemd/resolved.conf << EOL # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Entries in this file show the compile time defaults. # You can change settings by editing this file. # Defaults can be restored by simply deleting this file. # # See resolved.conf(5) for details [Resolve] DNS=8.8.8.8 #FallbackDNS= #Domains= #LLMNR=no #MulticastDNS=no #DNSSEC=no #Cache=yes #DNSStubListener=yes EOL service systemd-resolved restart echo 'nameserver 8.8.8.8' > /etc/resolv.conf apt-get install anacron -y cat > /etc/cron.weekly/fstrim << EOL #!/bin/sh ionice -c 3 fstrim -av EOL chmod +x /etc/cron.weekly/fstrim sed -ie "s/PermitRootLogin without-password/PermitRootLogin yes/g" /etc/ssh/sshd_config sed -ie "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config sed -ie "s/PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config sed -ie "s/#Port 22/Port 22/g" /etc/ssh/sshd_config sed -ie "s/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/g" /etc/ssh/sshd_config sed -ie "s/GRUB_CMDLINE_LINUX=\"\"/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub update-grub update-initramfs -u apt clean #wget -q https://connect.nicapi.eu/api/v1/datacenter/server-actions/status?mac_address=`cat /sys/class/net/eth0/address` --post-data "state=DONE&state_percent=100&state_text=FINISH" rm update* } export -f setup_server echo 200000 > /proc/sys/dev/raid/speed_limit_max chroot /mnt /bin/bash -c "setup_server" echo '' > /mnt/root/.bash_history rm update* rm /mnt/status\?* update-initramfs -u read -p "Press [Enter] key to reboot..." reboot