#!/bin/bash

# SAY HI TO SOUL
if [ ! -f "/etc/abbeoo/abo.global.parameters.sh" ]; then
  exit 0;
fi
source "/etc/abbeoo/abo.global.parameters.sh";


# SETUP APT FOR STRETCH PACKAGE
#
abo_mkfile "/etc/apt/preferences.d/stretch-manual-only";
echo "Package: *">>$VAR_PATH
echo "Pin: release n=jessie-updates">>$VAR_PATH
echo "Pin-Priority: 500">>$VAR_PATH
echo "#">>$VAR_PATH
echo "Package: *">>$VAR_PATH
echo "Pin: release n=jessie">>$VAR_PATH
echo "Pin-Priority: 500">>$VAR_PATH
echo "#">>$VAR_PATH
echo "Package: *">>$VAR_PATH
echo "Pin: release n=stretch-updates">>$VAR_PATH
echo "Pin-Priority: 499">>$VAR_PATH
echo "#">>$VAR_PATH
echo "Package: *">>$VAR_PATH
echo "Pin: release n=stretch">>$VAR_PATH
echo "Pin-Priority: 499">>$VAR_PATH


abo_mkfile "/etc/apt/sources.list.d/debian-stretch.list"
echo "deb http://debian.ethz.ch/debian stretch main non-free">>$VAR_PATH
echo "deb-src http://debian.ethz.ch/debian stretch main non-free">>$VAR_PATH
echo "">>$VAR_PATH
echo "deb http://security.debian.org/ stretch/updates main non-free">>$VAR_PATH
echo "deb-src http://security.debian.org/ stretch/updates main non-free">>$VAR_PATH
echo "">>$VAR_PATH
echo "deb http://debian.ethz.ch/debian stretch-updates main non-free">>$VAR_PATH
echo "deb-src http://debian.ethz.ch/debian stretch-updates main non-free">>$VAR_PATH

abo_system.aptitude "xen-utils-common/stretch xen-utils-4.8/stretch xen-tools xen-hypervisor-4.8-amd64/stretch libncurses5/stretch libncursesw5/stretch libtinfo5/stretch qemu-system-x86";

dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen;

abo_mkfile "/etc/default/grub"
echo "GRUB_DEFAULT=0">>$VAR_PATH
echo "GRUB_TIMEOUT=5">>$VAR_PATH
echo "GRUB_DISTRIBUTOR=Debian">>$VAR_PATH
echo "GRUB_CMDLINE_LINUX_DEFAULT=\"quiet\"">>$VAR_PATH
echo "GRUB_CMDLINE_LINUX=\"panic=30 noswap nosplash - rootdelay=7\"">>$VAR_PATH
echo "GRUB_DISABLE_OS_PROBER=\"true\"">>$VAR_PATH
echo "GRUB_CMDLINE_XEN=\"dom0_mem=1024M\"">>$VAR_PATH

update-grub;



abo_mkdir "/var/local/abbeoo/xen.d" "744" "abbeoo";
abo_mkdir "/var/local/abbeoo/iso" "744" "abbeoo";
abo_mkdir "/var/local/abbeoo/backup" "744" "abbeoo";



abo_mkfile "/var/local/abbeoo/xen.d/host11.cfg";
echo "name                  = 'host11'">>$VAR_PATH;
echo "builder               = 'hvm'">>$VAR_PATH;
echo "#device_model_version = \"qemu-xen-traditional\"">>$VAR_PATH;
echo "maxmem                = 1024">>$VAR_PATH;
echo "memory                = 1024">>$VAR_PATH;
echo "vcpus                 = 2">>$VAR_PATH;
echo "acpi                  = 1">>$VAR_PATH;
echo "apic                  = 1">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "uuid                  = '15eb8054-b763-11e0-96b4-002264c49811'">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "vif                   = [ 'type=ioemu,bridge=br0,mac=00:24:1D:C1:98:11' ]">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "#disk                 = [ 'drbd:drbd_host11,xvda,w','file:/var/local/abbeoo/iso/cdrom.iso,xvdc:cdrom,r' ]">>$VAR_PATH;
echo "disk                  = [ 'drbd:drbd_host11,xvda,w' ]">>$VAR_PATH;
echo "#disk                 = [ 'phy:/dev/vgdata/host11,xvda,w' ]">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "boot                  = 'ndc';">>$VAR_PATH;
echo "usbdevice             = 'tablet'">>$VAR_PATH;
echo "viridian              = 1">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "sdl                   = 0">>$VAR_PATH;
echo "stdvga                = 1">>$VAR_PATH;
echo "serial                = 'pty'">>$VAR_PATH;
echo "#ne2000               = '1'">>$VAR_PATH;
echo "vnc                   = 1">>$VAR_PATH;
echo "vnclisten             = \"0.0.0.0\"">>$VAR_PATH;
echo "vncconsole            = 1">>$VAR_PATH;
echo "vncunused             = 11">>$VAR_PATH;
echo "vncdisplay            = 11">>$VAR_PATH;
echo "monitor               = 1">>$VAR_PATH;
echo "keymap                = \"de-ch\"">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "on_poweroff           = 'destroy'">>$VAR_PATH;
echo "on_reboot             = 'restart'">>$VAR_PATH;
echo "on_crash              = 'destroy'">>$VAR_PATH;
chmod 644 $VAR_PATH;



abo_mkfile "/etc/default/xendomains" "orig"
echo "#XENDOMAINS_SYSRQ=">>$VAR_PATH
echo "#XENDOMAINS_MIGRATE=">>$VAR_PATH
echo "XENDOMAINS_SAVE=/var/lib/xen/save">>$VAR_PATH
echo "XENDOMAINS_RESTORE=true">>$VAR_PATH
echo "XENDOMAINS_AUTO=/etc/xen/auto">>$VAR_PATH
echo "XENDOMAINS_STOP_MAXWAIT=300">>$VAR_PATH



abo_mkfile "/etc/default/xend" "orig"
echo "XENCONSOLED_ARGS=">>$VAR_PATH
echo "XENSTORED_ARGS=">>$VAR_PATH



abo_mkfile "/etc/default/xen" "orig"
echo "TOOLSTACK=">>$VAR_PATH



abo_mkfile "/etc/xen/xend-config.sxp" "orig"
echo "#(logfile /var/log/xen/xend.log)">>$VAR_PATH
echo "#(loglevel DEBUG)">>$VAR_PATH
echo "#(xsm_module_name dummy)">>$VAR_PATH
echo "#(xen-api-server ((unix)))">>$VAR_PATH
echo "(xend-http-server yes)">>$VAR_PATH
echo "#(xend-unix-server no)">>$VAR_PATH
echo "#(xend-tcp-xmlrpc-server no)">>$VAR_PATH
echo "#(xend-unix-xmlrpc-server yes)">>$VAR_PATH
echo "(xend-relocation-server yes)">>$VAR_PATH
echo "(xend-relocation-ssl-server yes)">>$VAR_PATH
echo "#(xend-udev-event-server no)">>$VAR_PATH
echo "#(xend-unix-path /var/lib/xend/xend-socket)">>$VAR_PATH
echo "#(xend-tcp-xmlrpc-server-address 'localhost')">>$VAR_PATH
echo "#(xend-tcp-xmlrpc-server-port 8006)">>$VAR_PATH
echo "#(xend-tcp-xmlrpc-server-ssl-key-file  xmlrpc.key)">>$VAR_PATH
echo "#(xend-tcp-xmlrpc-server-ssl-cert-file xmlrpc.crt)">>$VAR_PATH
echo "(xend-port 8000)">>$VAR_PATH
echo "(xend-relocation-port 8002)">>$VAR_PATH
echo "(xend-relocation-ssl-port 8003)">>$VAR_PATH
echo "#(xend-relocation-server-ssl-key-file   xmlrpc.key)">>$VAR_PATH
echo "#(xend-relocation-server-ssl-cert-file  xmlrpc.crt)">>$VAR_PATH
echo "#(xend-relocation-ssl no)">>$VAR_PATH
echo "(xend-address '')">>$VAR_PATH
echo "#(xend-address localhost)">>$VAR_PATH
echo "(xend-relocation-address '')">>$VAR_PATH
echo "(xend-relocation-hosts-allow '')">>$VAR_PATH
echo "#(console-limit 1024)">>$VAR_PATH
echo "#(network-script network-bridge)">>$VAR_PATH
echo "#(network-script 'network-bridge bridge=<name>')">>$VAR_PATH
echo "(vif-script vif-bridge)">>$VAR_PATH
echo "#(vif-script vif-route)">>$VAR_PATH
echo "#(vif-script vif-nat)">>$VAR_PATH
echo "(dom0-min-mem 256)">>$VAR_PATH
echo "(enable-dom0-ballooning no)">>$VAR_PATH
echo "(total_available_memory 0)">>$VAR_PATH
echo "(dom0-cpus 0)">>$VAR_PATH
echo "#(enable-dump no)">>$VAR_PATH
echo "#(external-migration-tool '')">>$VAR_PATH
echo "#(vnc-listen '127.0.0.1')">>$VAR_PATH
echo "(vncpasswd '')">>$VAR_PATH
echo "#(vnc-tls 1)">>$VAR_PATH
echo "#(vnc-x509-cert-dir vnc)">>$VAR_PATH
echo "(keymap 'de-ch')">>$VAR_PATH
echo "#(resource-label-change-script '')">>$VAR_PATH
echo "#(qemu-dm-logrotate-count 10)">>$VAR_PATH
echo "#(xend-domains-path /var/lib/xend/domains)">>$VAR_PATH
echo "#(device-create-timeout 100)">>$VAR_PATH
echo "#(device-destroy-timeout 100)">>$VAR_PATH
echo "#(pci-passthrough-strict-check yes)">>$VAR_PATH
echo "#(pscsi-device-mask ('*'))">>$VAR_PATH



abo_mkfile "/etc/xen/xl.conf" "orig"
echo "#autoballoon=\"auto\"">>$VAR_PATH
echo "#lockfile=\"/var/lock/xl\"">>$VAR_PATH
echo "output_format=\"json\"">>$VAR_PATH
echo "#blkdev_start=\"xvda\"">>$VAR_PATH
echo "#run_hotplug_scripts=1">>$VAR_PATH
echo "#vif.default.backend=\"0\"">>$VAR_PATH
echo "#vif.default.gatewaydev=\"eth0\"">>$VAR_PATH
echo "#vif.default.script=\"vif-bridge\"">>$VAR_PATH
echo "#vif.default.bridge=\"xenbr0\"">>$VAR_PATH
echo "#claim_mode=1">>$VAR_PATH




# SET STANDARD NETWORK PARAMETERS
abo_mkfile "/etc/sysctl.conf"
echo "#kernel.domainname = abbeoo.net">>$VAR_PATH;
echo "#kernel.printk = 3 4 1 3">>$VAR_PATH;
echo "#net.ipv4.conf.default.rp_filter=1">>$VAR_PATH;
echo "#net.ipv4.conf.all.rp_filter=1">>$VAR_PATH;
echo "#net.ipv4.tcp_syncookies=1">>$VAR_PATH;
echo "#net.ipv4.ip_forward=1">>$VAR_PATH;
echo "#net.ipv6.conf.all.forwarding=1">>$VAR_PATH;
echo "#net.ipv4.conf.all.accept_redirects = 0">>$VAR_PATH;
echo "#net.ipv6.conf.all.accept_redirects = 0">>$VAR_PATH;
echo "#net.ipv4.conf.all.send_redirects = 0">>$VAR_PATH;
echo "#net.ipv4.conf.all.accept_source_route = 0">>$VAR_PATH;
echo "#net.ipv6.conf.all.accept_source_route = 0">>$VAR_PATH;
echo "#net.ipv4.conf.all.log_martians = 1">>$VAR_PATH;
echo "net.bridge.bridge-nf-call-ip6tables = 0">>$VAR_PATH;
echo "net.bridge.bridge-nf-call-iptables = 0">>$VAR_PATH;
echo "net.bridge.bridge-nf-call-arptables = 0">>$VAR_PATH;



exit 0;
