#!/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";



# SET UP BASIC SETTINGS
abo_mkabobasics "basic";



# HOSTNAME
abo_mkfile.empty "/etc/hostname";
echo "srv-ldbu-base01">>$VAR_PATH;



# HOST FILE
abo_mkfile "/etc/hosts" "orig";
echo "127.0.0.1          localhost">>$VAR_PATH;
echo "127.0.0.1          srv-ldbu-base01.abbeoo.net               srv-ldbu-base01">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "::1                ip6-localhost                            ip6-loopback">>$VAR_PATH;
echo "fe00::0            ip6-localnet">>$VAR_PATH;
echo "ff00::0            ip6-mcastprefix">>$VAR_PATH;
echo "ff02::1            ip6-allnodes">>$VAR_PATH;
echo "ff02::2            ip6-allrouters">>$VAR_PATH;



# RESOLVE FILE
abo_mkfile "/etc/resolv.conf";
echo "domain abbeoo.net">>$VAR_PATH;
echo "search *">>$VAR_PATH;
echo "nameserver 185.78.120.10">>$VAR_PATH;
echo "nameserver 185.78.120.20">>$VAR_PATH;
echo "nameserver 185.16.172.98">>$VAR_PATH;



# APTITUDE SOURCE LIST
abo_mkfile "/etc/apt/sources.list" "orig";
echo "deb http://ftp.ch.debian.org/debian/ stretch main">>$VAR_PATH;
echo "deb-src http://ftp.ch.debian.org/debian/ stretch main">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "deb http://security.debian.org/debian-security stretch/updates main">>$VAR_PATH;
echo "deb-src http://security.debian.org/debian-security stretch/updates main">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "deb http://ftp.ch.debian.org/debian/ stretch-updates main">>$VAR_PATH;
echo "deb-src http://ftp.ch.debian.org/debian/ stretch-updates main">>$VAR_PATH;



# APTITUDE UPDATE SYSTEM
abo_system.aptitude "ssh ntp" "exim";



# CONFIG SSH
abo_mkfile "/etc/ssh/sshd_config" "orig";
echo "Port                              2222">>$VAR_PATH;
echo "#ListenAddress                    ::">>$VAR_PATH;
echo "#ListenAddress                    0.0.0.0">>$VAR_PATH;
echo "Protocol                          2">>$VAR_PATH;
echo "HostKey                           /etc/ssh/ssh_host_rsa_key">>$VAR_PATH;
echo "HostKey                           /etc/ssh/ssh_host_dsa_key">>$VAR_PATH;
echo "UsePrivilegeSeparation            yes">>$VAR_PATH;
echo "KeyRegenerationInterval           3600">>$VAR_PATH;
echo "ServerKeyBits                     768">>$VAR_PATH;
echo "SyslogFacility                    AUTH">>$VAR_PATH;
echo "LogLevel                          INFO">>$VAR_PATH;
echo "LoginGraceTime                    120">>$VAR_PATH;
echo "PermitRootLogin                   yes">>$VAR_PATH;
echo "StrictModes                       yes">>$VAR_PATH;
echo "RSAAuthentication                 yes">>$VAR_PATH;
echo "PubkeyAuthentication              yes">>$VAR_PATH;
echo "#AuthorizedKeysFile               %h/.ssh/authorized_keys">>$VAR_PATH;
echo "IgnoreRhosts                      yes">>$VAR_PATH;
echo "RhostsRSAAuthentication           no">>$VAR_PATH;
echo "HostbasedAuthentication           no">>$VAR_PATH;
echo "#IgnoreUserKnownHosts             yes">>$VAR_PATH;
echo "PermitEmptyPasswords              no">>$VAR_PATH;
echo "ChallengeResponseAuthentication   no">>$VAR_PATH;
echo "#PasswordAuthentication           yes">>$VAR_PATH;
echo "#KerberosAuthentication           no">>$VAR_PATH;
echo "#KerberosGetAFSToken              no">>$VAR_PATH;
echo "#KerberosOrLocalPasswd            yes">>$VAR_PATH;
echo "#KerberosTicketCleanup            yes">>$VAR_PATH;
echo "#GSSAPIAuthentication             no">>$VAR_PATH;
echo "#GSSAPICleanupCredentials         yes">>$VAR_PATH;
echo "X11Forwarding                     yes">>$VAR_PATH;
echo "X11DisplayOffset                  10">>$VAR_PATH;
echo "PrintMotd                         no">>$VAR_PATH;
echo "PrintLastLog                      yes">>$VAR_PATH;
echo "TCPKeepAlive                      yes">>$VAR_PATH;
echo "#UseLogin                         no">>$VAR_PATH;
echo "#MaxStartups                      10:30:60">>$VAR_PATH;
echo "#Banner                           /etc/issue.net">>$VAR_PATH;
echo "AcceptEnv                         LANG LC_*">>$VAR_PATH;
echo "Subsystem sftp                    /usr/lib/openssh/sftp-server">>$VAR_PATH;
echo "UsePAM                            yes">>$VAR_PATH;



abo_mkfile "/etc/default/ssh";
echo "SSHD_OPTS=">>$VAR_PATH;



# CONFIG NTP
abo_mkfile "/etc/ntp.conf" "orig";
echo "driftfile /var/lib/ntp/ntp.drift">>$VAR_PATH;
echo "server time.abbeoo.net">>$VAR_PATH;
echo "restrict 127.0.0.1">>$VAR_PATH;
echo "restrict ::1">>$VAR_PATH;
echo "#broadcast 192.168.123.255">>$VAR_PATH;
echo "#broadcastclient">>$VAR_PATH;
/etc/init.d/ntp restart;


# SET STANDARD MODULES ON BOOT
abo_mkfile "/etc/modules" "orig";
echo "loop">>$VAR_PATH;
echo "8021q">>$VAR_PATH;
echo "bonding">>$VAR_PATH;

# SET STANDARD LOCALE
abo_mkfile "/etc/default/locale" "orig";
echo "LANG=\"en_US\"">>$VAR_PATH;



# SET STANDARD KEYBOARD
abo_mkfile "/etc/default/keyboard" "orig";
echo "XKBMODEL=\"pc105\"">>$VAR_PATH;
echo "XKBLAYOUT=\"ch\"">>$VAR_PATH;
echo "XKBVARIANT=\"de\"">>$VAR_PATH;
echo "XKBOPTIONS=\"\"">>$VAR_PATH;
echo "BACKSPACE=\"guess\"">>$VAR_PATH;


# SET STANDARD NETWORK PARAMETERS
abo_mkfile "/etc/sysctl.conf" "orig";
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;



# SET STANDARD BACKUP DEFINITION
abo_mkfile.bash "/etc/abbeoo/abo.system.backup.sh";
echo "BACKUP_TEST() {">>$VAR_PATH;
echo "VAR1=\$1">>$VAR_PATH;
echo "VAR2=\$2">>$VAR_PATH;
echo "}">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "cd /usr/src">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "exit 0;">>$VAR_PATH;



# SET STANDARD CRON
abo_mkfile "/etc/crontab" "orig";
echo "SHELL=/bin/sh">>$VAR_PATH;
echo "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/etc/abbeoo">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "#m        h       dom     mon     dow     user    command">>$VAR_PATH;
echo "30        *       *       *       *       root    cd / && run-parts --report /etc/cron.hourly">>$VAR_PATH;
echo "0         4       *       *       *       root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )">>$VAR_PATH;
echo "0         5       *       *       7       root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )">>$VAR_PATH;
echo "0         6       1       *       *       root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )">>$VAR_PATH;
echo "0         22      *       *       *       root    cd /etc/abbeoo && /etc/abbeoo/abo.system.update.sh > /tmp/abo.system.update.log 2>&1">>$VAR_PATH;
echo "5         0       *       *       *       root    cd /etc/abbeoo && /etc/abbeoo/abo.system.backup.sh > /tmp/abo.system.backup.log 2>&1">>$VAR_PATH;
/etc/init.d/cron restart;



abo_mkfile "/etc/default/cron";
echo "READ_ENV=\"yes\"">>$VAR_PATH;



# SETUP USER
PASS=$(perl -e 'print crypt($ARGV[0], "password")' "abbeoo9999");

egrep -w "^abbeoo" /etc/passwd >/dev/null;
if [ $? -eq 0 ]; then
  echo -e "\nabbeoo exists!\n";
else
  useradd -p $PASS -s /bin/bash -m -d /var/local/abbeoo -b /var/local/abbeoo -k /var/local/abbeoo abbeoo;
fi
cp /etc/skel/.* /var/local/abbeoo;



# GIVE USER RIGHTS
abo_mkfile "/etc/sudoers" "orig";
echo "Defaults  env_reset">>$VAR_PATH;
echo "Defaults  mail_badpass">>$VAR_PATH;
echo "Defaults  secure_path=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/abbeoo\"">>$VAR_PATH;
echo "root      ALL=(ALL:ALL) ALL">>$VAR_PATH;
echo "abbeoo    ALL=(ALL:ALL) NOPASSWD: /sbin/lvdisplay,/sbin/lvcreate,/sbin/lvremove">>$VAR_PATH;
echo "%sudo     ALL=(ALL:ALL) ALL">>$VAR_PATH;




# MAKE LIFE EASIER FOR XEN USER
abo_mkfile.append "/var/local/abbeoo/.bashrc";
echo "alias lvdisplay='sudo lvdisplay'">>$VAR_PATH;
echo "alias lvcreate='sudo lvcreate'">>$VAR_PATH;
echo "alias lvremove='sudo lvremove'">>$VAR_PATH;



abo_mkfile "/etc/rc.local" "orig";
echo "#!/bin/sh -e">$VAR_PATH;
echo "">>$VAR_PATH;
echo "swapon -a">>$VAR_PATH;
echo "">>$VAR_PATH;
echo "exit 0">>$VAR_PATH;
chmod +x /etc/rc.local;


abo_writelog "end abo.inst.basic.sh";



exit 0;
