Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 118.88 KB | None | 0 0
  1. #!/bin/bash
  2. AVDC_STEP=
  3.  
  4. #Check if root, if else let the user login as root.
  5. if [[ $EUID -ne 0 ]] ; then
  6.     sudo su root
  7. fi
  8.  
  9. #Check if this has already been executed
  10. if [[ 130 -gt $AVDC_STEP ]] || [ -z ${AVDC_STEP+x} ] ; then
  11. #Copy this script to a location. To sustain reboots until the script has finished running.
  12. mkdir -p /etc/avorix/
  13. cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" || exit
  14. cp "$0" /etc/avorix/avdc_install.sh
  15. chmod +x /etc/avorix/avdc_install.sh
  16. #touch /etc/avorix/avdc_install_variables.sh
  17. #echo '#!/bin/bash' >> /etc/avorix/avdc_install_variables.sh
  18. #chmod +x /etc/avorix/avdc_install_variables.sh
  19. fi
  20.  
  21. ###########################################################
  22. #                Avorix Domain Controller                 #
  23. ###########################################################
  24. #
  25. # This is currently in development!
  26. # I recommend to execute this script per command in
  27. # a CLEAN RASPBIAN installation!
  28. #
  29. # The Avorix Domain Controller uses SAMBA, NTP, DHCPD to
  30. # mimic Microsoft Active Directory Domain Services
  31. # (MS ADDS) on Raspberry Pi's running Raspbian while
  32. # keeping it's configuration on a USB-memory device.
  33. #
  34. # This allows us to manage computers, users, shares,
  35. # and policies using the RSAT-tools.
  36. #
  37. # This script was built upon best practices and experiences.
  38. # ~ Rik Heijmann
  39.  
  40. ###########################################################
  41. #                     Development notes!                  #
  42. ###########################################################
  43. #
  44. # 1. Don't use multiple tabs! Just 1 to seperate the first
  45. #    if/else statements. Or it will trigger output similar
  46. #    to the "ls"-command and skip the next characters.
  47. #    Note that "cat"-commands to write text are not
  48. #    affected by this problem.
  49. #
  50.  
  51. ###########################################################
  52. #                       Versions                          #
  53. ###########################################################
  54. DC_SCRIPT_VERSION="1.0-RC9"
  55. DC_RELEASE_DATE="25-12-2017"
  56. # Major update: Can break your current installation.
  57. # Minor update: Will not break your current installation.
  58. #
  59. # 1.0: First release.
  60.  
  61.  
  62. ###########################################################
  63. #                         To Do                           #
  64. ###########################################################
  65. # - Make this script work with CentOS and Ubuntu.
  66. # - Integrate a GUI for configuration.
  67. # - Automaticly detect removable storage.
  68. # - Find a way to make AUDITD to work.
  69. # - Make the SELinux rules portable.
  70. # - Integrate Nitrobit Update Server for distributing Windows Updates.
  71. # - PXE: Set the permissions on the "users"-share automaticly.
  72.  
  73. ###########################################################
  74. #                       Summary                           #
  75. ###########################################################
  76. # 1. The configuration fase.
  77. # 1.1. Settings.
  78. # 1.2. System Specific Variables.
  79. # 1.2.1. System Specific Variables for Raspbian.
  80. # 1.2.2. System Specific Variables for CentOS.
  81. # 1.3. Check the configuration.
  82. # 1.4. Show a summary of the settings.
  83.  
  84. # 2. The fase of compatibility.
  85. # 2.1. Test the internet connection.
  86. # 2.2. Update the complete system.
  87. # 2.3. (Optional) Configure USBmount.
  88. # 2.4. Build the Location-Of-Important-Files directorystructure.
  89.  
  90. # 3. The fase of installation
  91. # 3.1. (Optional) Install & Temporarely disable SELinux.
  92. # 3.2. Install the main components.
  93. # 3.3. Configure the timezone.
  94. # 3.4. Configure the hosts file.
  95. # 3.5. Change the hostname.
  96. # 3.6. Configure a static IP-address.
  97. #! As of the above all the other steps are being treated as if is no internet connection
  98. # 3.7. Configure the NTP-server.
  99. # 3.8. Configure the Domain Controller.
  100.  
  101. # 4. The fase of adaption
  102. # 4.1. (Optional) Configure SSH.
  103. # 4.2. (Optional) Configure the DHCP-server.
  104. # 4.3. (Optional) Configure the PXE-server.
  105. # 4.4. (Optional) Configure SELinux.
  106. # 4.5. (Optional) Configure automatic security updates.
  107. # 4.6. (Optional) Test & Enable the Firewall.
  108. # 4.7. Configure log in/out messages and EULA.
  109.  
  110. # 5. The fase of finishing up.
  111. # 5.1. Log the current installation.
  112. # 5.2. Display a summary of the installation.
  113.  
  114.  
  115. ###########################################################
  116. #                                                         #
  117. # 1.             The configuration fase                   #
  118. #                                                         #
  119. ###########################################################
  120.  
  121. ###########################################################
  122. # 1.1.                 Settings                           #
  123. ###########################################################
  124. # All these settings are important!
  125. # Make sure that everything is setup correctly.
  126.  
  127. #Operating system:
  128. OS=RASPBIAN
  129. #1: RASPBIAN: Raspbian: Debian Stretch
  130. #Not working yet ! 2: CENTOS7: CentOS 7
  131.  
  132. #Script settings: Set to 1 to enable.
  133. SKIP_BEGINNING_SUMMARY=1 #Set this to 1 to fully automate the script.
  134. SKIP_END_SUMMARY=1 #Set this to 1 to fully automate the script.
  135. SKIP_INSTALLATION_CHECK=1 #Set this to 1 to disable checking if the packages are correctly installed.
  136. SKIP_SERVICES_CHECK=1 #Set this to 1 to disable checking if the services work.
  137. BRANDING=1 #RECOMMENDED! Configures log-in/out messages with an EULA. Might need some of your own customization as it probably does not represent the complete environment and law of the server.
  138.  
  139. #Storage Settings
  140. CENTRALIZED_STORAGE=0 #Enable this to save al configuration files in 1 place.
  141.     LOCATION_OF_IMPORTANT_FILES=/media/usb1 #Will only work if PORTABLE_CONFIGURATION is set to 0.
  142.     #Portable Config is not working yet!
  143.     PORTABLE_CONFIGURATION=0 #Store the configuration and the databases files on a removable drive. Will include scripts to automaticly detect the removable drive.
  144.     BACKUP_LOIP=0 #Set this to 1 to automaticly backup the users and groups.
  145.     BACKUP_LOIP_TIMING="0 2 * * *" #Enter here using the CRON-format at which time a backup should be made.
  146.     # Quick CRON tutorial:
  147.     # Every day at 2AM: 0 2 * * *
  148.     # Every first day of the month at 2AM: 0 2 1 * *
  149.     BACKUP_LOIP_DESTINATION="$LOCATION_OF_IMPORTANT_FILES/Backup/"
  150.  
  151. #Network Settings
  152. IP_ADDRESS=192.168.192.40
  153. SUBNETMASKBITS=24
  154. GATEWAY=192.168.192.168
  155. DNSSERVER1=127.0.0.1
  156. DNSSERVER2=192.168.192.168
  157.  
  158. #Time Settings
  159. REGION=Europe
  160. TIMEZONE=Amsterdam
  161. NTPSERVER1=0.pool.ntp.org
  162. NTPSERVER2=1.pool.ntp.org
  163. NTPSERVER3=2.pool.ntp.org
  164.  
  165. #Domain Controller Settings
  166. #Not Working yet! JOIN_A_DOMAIN=0 #Set this to 1 to join a domain. Leave it to 0 to create a domain. Installing replication for DHCP, PXE, the GPO's and other functions will be done using a different script, that is still in development.
  167.  
  168. #Before you begin, please take a look at: https://wiki.samba.org/index.php/Active_Directory_Naming_FAQ
  169. FQDN=D.local #This is your domain name.
  170. #EXTENSION=.local
  171. NBIOS=D
  172. #This is the second level domain name capitalized.
  173. DCNAME=DC
  174. BACKUP_DC=1 #Set this to 1 to automaticly backup the users and groups.
  175.     BACKUP_DC_TIMING="0 2 * * *" #Enter here using the CRON-format at which time a backup should be made.
  176.     # Quick CRON tutorial:
  177.     # Every day at 2AM: 0 2 * * *
  178.     # Every first day of the month at 2AM: 0 2 1 * *
  179.     BACKUP_DC_DESTINATION="$LOCATION_OF_IMPORTANT_FILES/SAMBA/Backup/"
  180.  
  181. #Note please only use Alpha-Numeric passwords. Special characters will cause problems.
  182. ADMINPWD='P4ssw0rd' #This is the password of the Active Directory "Administrator"-account.
  183.  
  184. #Security Functions: Set to 1 to enable.
  185. FIREWALL=1 #RECOMMENDED! Enables the built-in firewall and adds support for the selected functions.
  186. ANTIVIRUS=1 #RECOMMENDED! Installs ClamAV antivirus to scan through your shares.
  187. SELINUX=1 #RECOMMENDED! Enables SELINUX (Will first start permissive and collect data. The next day that data will be used to create a policy)
  188. AUTOMATIC_SECURITY_UPDATES=1 #RECOMMENDED! Will daily check for security updates.
  189.  
  190. #Additional Modules: Set to 1 to enable.
  191. WEBMIN=0
  192.     WEBMIN_VERSION=1.840
  193. DHCP_SERVER=0 #Enable this only if you know that this is needed.
  194.     DHCP_SUBNET=192.168.192.0
  195.     DHCP_SUBNETMASK=255.255.255.0
  196.     DHCP_BROADCASTADDRESS=192.168.192.255
  197.     DHCP_GATEWAY=$GATEWAY
  198.     DHCP_DNSSERVER1=$IP_ADDRESS #By using $IP_ADDRESS the DHCP server will instruct new clients to use the DNS-server of this Domain controller.
  199.     DHCP_DNSSERVER2=$DNSSERVER2 #By using $DNSSERVER2 the DHCP server will instruct new clients to use the second preferred DNS-server of this Domain controller. Which in most cases is the router or the DNS-server provided by the internet provider..
  200.     DHCP_NETBIOSSERVER=$IP_ADDRESS
  201.     DHCP_NTPSERVER1=$IP_ADDRESS
  202.     DHCP_NTPSERVER2=0.pool.ntp.org
  203.     DHCP_MAX_LEASE_TIME=1800
  204.     DHCP_FIRST_IP_ADDRESS=192.168.192.10
  205.     DHCP_LAST_IP_ADDRESS=192.168.192.200
  206.  
  207.     PXE_SERVER=0 #Requires DHCP! #Enable PXE to deliver minimal network environments such as WinPE to computers.
  208.     PXE_TFTP_ROOT=$LOCATION_OF_IMPORTANT_FILES/Data/TFTP/Root #This location is for the WinPE .WIM-file.
  209.     PXE_HTTP_ROOT=$LOCATION_OF_IMPORTANT_FILES/Data/Apache/Root #This location is for the Windows Installer.
  210.  
  211. SSH_SERVER=1 #Enable this to add a user and allow it to be used to mange the server remotely.
  212.     SSH_PORT=22
  213.     SSH_USER=Administrator #Future users have to be added to the "ssh"-group to use "ssh".
  214.     SSH_USER_PASSWORD='P4ssw0rd'
  215.     SSH_USER_SUDO=1 #Set to 1 to give this user permission to run administrator commands using "sudo".
  216.     SSH_PORTKNOCKING=1 #Enable this to only provide the SSH service when a sequence of numbers is knocked.
  217.     SSH_PORTKNOCKING_OPEN_SEQ1=7999 #Sequence number 1 for opening the openssh Portknock.
  218.     SSH_PORTKNOCKING_OPEN_SEQ2=8181
  219.     SSH_PORTKNOCKING_OPEN_SEQ3=1821
  220.     SSH_PORTKNOCKING_CLOSE_SEQ1=7997 #Sequence number 1 for closing the openssh Portknock.
  221.     SSH_PORTKNOCKING_CLOSE_SEQ2=8121
  222.     SSH_PORTKNOCKING_CLOSE_SEQ3=5821
  223.  
  224.     SSH_FAIL2BAN=1 #Requires FIREWALL! Enable this to block an IP-address when a configurable amount of failed attempts has been reached.
  225.     SSH_FAIL2BAN_MAXRETRY=3 #How many attempts can be made to access the server from a single IP before a ban is imposed.
  226.     SSH_FAIL2BAN_FINDTIME=900 #The length of time between login attempts before a ban is set. For example, if Fail2Ban is set to ban an IP after three failed log-in attempts, those three attempts must occur within the set findtime limit. The findtime value should be a set number of seconds.
  227.     SSH_FAIL2BAN_BANTIME=900 #The length of time in seconds that the IP Address will be banned for. In my example I used ‘900’ seconds which would be 15 minutes. If you want to ban an IP Address permanently then you will set the bantime to ‘-1’.
  228.  
  229.     SSH_2FA=1 #Enable this to login usign Two-Factor-Authentication using Google-Authenticator. After installation run 'google-authenticator' as the user which will be using 2FA. During prompts choose 'y'. Afterwards restart SSH.
  230.     SSH_2FA_FORCE=0 #Enable this option to force users to use 2FA, if disabled only the users that have installed 2FA will have to use 2FA.
  231.  
  232.  
  233. ###########################################################
  234. # 1.2.         System  Specific Variables                 #
  235. ###########################################################
  236. # These different sets of variables ensure compatibility over multiple Linux-distributions.
  237. # Please do not change these!
  238. # If you would like to add compatibility for a different Linux-distribution (or even a different Unix-distribution)
  239. # then copy the template and fill it in with the correct parameters of the target dsitrbution.
  240.  
  241. if [ "$OS" == "RASPBIAN" ] ; then
  242. # For Raspbian Stretch
  243. #Patches
  244. REORDER_AVAHI_DNS=1 #Avahi interupts the domain name translation if the FQDN ends with .local. This fixes the problem by prioritizing the default DNS over Avahi.
  245.  
  246. # Tools
  247. PM_UPDATE='apt update'
  248. PM_UPGRADE='apt upgrade -y'
  249. PM_SYSUPGRADE='apt dist-upgrade -y'
  250. PM_INSTALL='apt install'
  251. PM_INSTALL_ENDING_VARIABLES='-y'
  252.  
  253. # Packages:
  254. PACKAGE_SAMBA='samba'
  255. PACKAGE_NTP='ntp'
  256. PACKAGE_FIREWALLD='firewalld'
  257. PACKAGE_SELINUX='selinux-basics'
  258. PACKAGE_SELINUX_POLICY_DEFAULT='selinux-policy-default'
  259. PACKAGE_DHCPD='isc-dhcp-server'
  260. PACKAGE_CLAMAV='clamav'
  261. PACKAGE_CLAMAV_FRESHCLAM='clamav-freshclam'
  262. PACKAGE_OPENSSHD='openssh-server'
  263. PACKAGE_TFTPD='tftpd-hpa'
  264. PACKAGE_APACHE='apache2'
  265. PACKAGE_USBMOUNT='usbmount'
  266. PACKAGE_KNOCKD='knockd'
  267. PACKAGE_FAIL2BAN='fail2ban'
  268. PACKAGE_LIBPAM_GOOGLE_AUTHENTICATOR='libpam-google-authenticator'
  269.  
  270. #Daemons
  271. DAEMON_SSH='ssh'
  272. DAEMON_FIREWALLD='firewalld'
  273. DAEMON_TFTPD='tftpd-hpa'
  274. DAEMON_APACHE='apache2'
  275. DAEMON_DHCPCD='dhcpcd'
  276. DAEMON_KNOCKD='knockd'
  277. DAEMON_FAIL2BAN='fail2ban'
  278. DAEMON_NTP='ntp'
  279. DAEMON_SMBD='smbd'
  280. DAEMON_NMBD='nmbd'
  281. DAEMON_SAMBA_AD_DC='samba-ad-dc'
  282. DAEMON_DHCPD='isc-dhcp-server'
  283.  
  284. # Paths to folders:
  285. OR_PATH_FOLDER_CRON_DAILY='/etc/cron.daily'
  286. OR_PATH_FOLDER_CRON_HOURLY='/etc/cron.hourly'
  287. OR_PATH_FOLDER_APACHE_SITES_ENABLED='/etc/apache2/sites-enabled'
  288. OR_PATH_FOLDER_SSH_KEYS='/etc/ssh'
  289. OR_PATH_FOLDER_SAMBA_VAR_LIB='/var/lib/samba'
  290. OR_PATH_FOLDER_SAMBA_SETUP='/usr/share/samba/setup'
  291. OR_PATH_FOLDER_SAMBA_CACHE='/var/cache/samba'
  292. OR_PATH_FOLDER_SAMBA_LOG='/var/log/samba'
  293. OR_PATH_FOLDER_SELINUX_POLICY='/etc/selinux/avorix_rules'
  294.  
  295. # Paths to files:
  296. OR_PATH_FILE_AUDIT_LOG='/var/log/audit/audit.log'
  297. OR_PATH_FILE_SELINUX_CONF='/etc/selinux/conf'
  298. OR_PATH_FILE_SELINUX_CONF_REPLACER='/etc/selinux/config.replacer'
  299. OR_PATH_FILE_DHCPD_CONF='/etc/dhcp/dhcpd.conf'
  300. OR_PATH_FILE_DHCPCD_CONF='/etc/dhcpcd.conf'
  301. OR_PATH_FILE_KRB5_CONF_EXAMPLE='/var/lib/samba/private/krb5.conf'
  302. OR_PATH_FILE_KRB5_CONF='/etc/krb5.conf'
  303. OR_PATH_FILE_SAMBA_CONF='/etc/samba/smb.conf'
  304. OR_PATH_FILE_NTP_CONF='/etc/ntp.conf'
  305. OR_PATH_FILE_NTP_DRIFT='/var/lib/ntp/ntp.drift'
  306. OR_PATH_FILE_NTP_LOG='/var/log/ntp'
  307. OR_PATH_FILE_NTP_SOCKET='/usr/local/samba/var/lib/ntp_signd/'
  308. OR_PATH_FILE_SSH_CONF='/etc/ssh/sshd_config'
  309. OR_PATH_FILE_SUDO_CONF='/etc/sudoers'
  310. OR_PATH_FILE_HOSTNAME_CONF='/etc/hostname'
  311. OR_PATH_FILE_HOSTS_CONF='/etc/hosts'
  312. OR_PATH_FILE_TFTPD_CONF='/etc/default/tftpd-hpa'
  313. OR_PATH_FILE_USBMOUNT_CONF='/etc/usbmount/usbmount.conf'
  314. OR_PATH_FILE_KNOCKD_DEFAULT='/etc/default/knockd'
  315. OR_PATH_FILE_KNOCKD_CONF='/etc/knockd.conf'
  316. OR_PATH_FILE_FAIL2BAN_JAIL='/etc/fail2ban/jail.local'
  317. OR_PATH_FILE_PAMD_SSHD='/etc/pam.d/sshd'
  318. OR_PATH_FILE_ISSUE='/etc/issue'
  319. OR_PATH_FILE_ISSUENET='/etc/issue.net'
  320. OR_PATH_FILE_MOTD='/etc/motd'
  321.  
  322. elif [ "$OS" == "CENTOS7" ] ; then
  323. # Has not been finished!
  324. # For CentOS 7
  325. # Tools
  326. PM_UPDATE='yum check-update' #This is actually not neccesary as most yum commands will run this automaticly.
  327. PM_UPGRADE='yum update -y'
  328. PM_SYSUPGRADE='yum upgrade -y' #Correct
  329. PM_INSTALL='yum install' #Correct
  330. PM_INSTALL_ENDING_VARIABLES='-y' #Correct
  331.  
  332. # Packages:
  333. PACKAGE_SAMBA='samba samba-dc'
  334. PACKAGE_NTP='ntp'
  335. PACKAGE_FIREWALLD='firewalld'
  336. PACKAGE_SELINUX='' #Not required, it is allready within Centos 7
  337. PACKAGE_SELINUX_POLICY_DEFAULT=''
  338. PACKAGE_DHCPD='dhcp'
  339. PACKAGE_CLAMAV='epel-release && yum install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd -y'
  340. PACKAGE_CLAMAV_FRESHCLAM=''
  341. PACKAGE_OPENSSHD='openssh'
  342. PACKAGE_TFTPD='tftp-server' #!Might be different from the debian variety.
  343. PACKAGE_APACHE='httpd'
  344. PACKAGE_USBMOUNT='' #!Not for CentOS!
  345. PACKAGE_KNOCKD='knock' #!Requires EPEL, not verified.
  346. PACKAGE_FAIL2BAN='fail2ban' #Requires EPEL
  347. PACKAGE_LIBPAM_GOOGLE_AUTHENTICATOR='google-authenticator'
  348.  
  349. #Daemons
  350. DAEMON_SSH=''
  351. DAEMON_FIREWALLD=''
  352. DAEMON_TFTPD=''
  353. DAEMON_APACHE=''
  354. DAEMON_DHCPCD=''
  355. DAEMON_KNOCKD=''
  356. DAEMON_FAIL2BAN=''
  357. DAEMON_NTP=''
  358. DAEMON_SMBD=''
  359. DAEMON_NMBD=''
  360. DAEMON_SAMBA_AD_DC=''
  361. DAEMON_DHCPD=''
  362.  
  363. # Paths to folders:
  364. PATH_FOLDER_CRON_DAILY='/etc/cron.daily'
  365. PATH_FOLDER_CRON_HOURLY='/etc/cron.hourly'
  366. PATH_FOLDER_APACHE_SITES_ENABLED=''
  367. PATH_FOLDER_SSH_KEYS=''
  368.  
  369. # Paths to files:
  370. PATH_FILE_AUDIT_LOG=''
  371. PATH_FILE_SELINUX_CONF=''
  372. PATH_FILE_SELINUX_CONF_REPLACER=''
  373. PATH_FILE_DHCPD_CONF=''
  374. PATH_FILE_DHCPCD_CONF=''
  375. PATH_FILE_KRB5_CONF_EXAMPLE=''
  376. PATH_FILE_KRB5_CONF=''
  377. PATH_FILE_SAMBA_CONF=''
  378. PATH_FILE_NTP_CONF=''
  379. PATH_FILE_SSH_CONF=''
  380. PATH_FILE_SUDO_CONF=''
  381. PATH_FILE_HOSTNAME_CONF=''
  382. PATH_FILE_HOSTS_CONF=''
  383. PATH_FILE_TFTPD_CONF=''
  384. PATH_FILE_USBMOUNT_CONF=''
  385. PATH_FILE_KNOCKD_DEFAULT=''
  386. PATH_FILE_KNOCKD_CONF=''
  387. PATH_FILE_FAIL2BAN_JAIL=''
  388. PATH_FILE_PAMD_SSHD=''
  389.  
  390. else
  391.    setterm -term linux -back red -fore white
  392.     echo "###########################################################"
  393.     echo "# Warning: The inputted operating system is currently     #"
  394.     echo "#          unsupported, please check script settings!     #"
  395.     echo "###########################################################"
  396.     echo "# Suported operating systems:"
  397.     echo "#          - Raspbian Stretch (RASPBIAN)"
  398.     echo "###########################################################"
  399.     read -r fackEnterKey
  400.     setterm -default
  401.     exit
  402. fi
  403.  
  404. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  405. # Paths to folders:
  406. PATH_FOLDER_CRON_DAILY="$LOCATION_OF_IMPORTANT_FILES/Configuration/Cron/Daily"
  407. PATH_FOLDER_CRON_HOURLY="$LOCATION_OF_IMPORTANT_FILES/Configuration/Cron/Hourly"
  408. PATH_FOLDER_APACHE_SITES_ENABLED="$LOCATION_OF_IMPORTANT_FILES/Apache/Sites-Enabled"
  409. PATH_FOLDER_SSH_KEYS="$LOCATION_OF_IMPORTANT_FILES/Configuration/SSH/Configuration/Keys"
  410. PATH_FOLDER_SAMBA_VAR_LIB="$LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA_VAR_LIB"
  411. PATH_FOLDER_SAMBA_SETUP="$LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA/Setup"
  412. PATH_FOLDER_SAMBA_CACHE="$LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA/Cache"
  413. PATH_FOLDER_SAMBA_LOG="$LOCATION_OF_IMPORTANT_FILES/Logs/Samba"
  414. PATH_FOLDER_SELINUX_POLICY="$LOCATION_OF_IMPORTANT_FILES/Configuration/SELinux/Policy"
  415.  
  416. # Paths to files:
  417. PATH_FILE_AUDIT_LOG="$LOCATION_OF_IMPORTANT_FILES/Logs/AuditD/audit.log"
  418. PATH_FILE_SELINUX_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/SELinux/conf"
  419. PATH_FILE_SELINUX_CONF_REPLACER="$LOCATION_OF_IMPORTANT_FILES/Configuration/SELinux/conf-replacer"
  420. PATH_FILE_DHCPD_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/DHCPD/dhcpd.conf"
  421. PATH_FILE_DHCPCD_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/DHCPCD/dhcpcd.conf"
  422. #PATH_FILE_KRB5_CONF_EXAMPLE="$LOCATION_OF_IMPORTANT_FILES"
  423. PATH_FILE_KRB5_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/KRB5/krb5.conf"
  424. PATH_FILE_SAMBA_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA/smb.conf"
  425. PATH_FILE_NTP_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/NTP/ntp.conf"
  426. PATH_FILE_NTP_DRIFT="$LOCATION_OF_IMPORTANT_FILES/Configuration/NTP/ntp.drift"
  427. PATH_FILE_NTP_LOG="$LOCATION_OF_IMPORTANT_FILES/Logs/NTP/ntp.log"
  428. PATH_FILE_NTP_SOCKET="$LOCATION_OF_IMPORTANT_FILES/Configuration/NTP/ntp_signd"
  429. PATH_FILE_SSH_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/SSH/sshd_config"
  430. PATH_FILE_SUDO_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/General/sudoers"
  431. PATH_FILE_HOSTNAME_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/General/hostname"
  432. PATH_FILE_HOSTS_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/General/hosts"
  433. PATH_FILE_TFTPD_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/TFTPD/tftpd-hpa"
  434. PATH_FILE_USBMOUNT_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/USBMount/usbmount.conf"
  435. PATH_FILE_KNOCKD_DEFAULT="$LOCATION_OF_IMPORTANT_FILES/Configuration/KnockD/knockd.default.conf"
  436. PATH_FILE_KNOCKD_CONF="$LOCATION_OF_IMPORTANT_FILES/Configuration/KnockD/knockd.conf"
  437. PATH_FILE_FAIL2BAN_JAIL="$LOCATION_OF_IMPORTANT_FILES/Configuration/Fail2Ban/jail.local"
  438. PATH_FILE_PAMD_SSHD="$LOCATION_OF_IMPORTANT_FILES/Configuration/PAMD/sshd"
  439. PATH_FILE_ISSUE="$LOCATION_OF_IMPORTANT_FILES/Configuration/General/issue"
  440. PATH_FILE_ISSUENET="$LOCATION_OF_IMPORTANT_FILES/Configuration/General/issue.net"
  441. PATH_FILE_MOTD="$LOCATION_OF_IMPORTANT_FILES/Configuration/General/motd"
  442.  
  443. else
  444. # Paths to folders:
  445. PATH_FOLDER_CRON_DAILY="$OR_PATH_FOLDER_CRON_DAILY"
  446. PATH_FOLDER_CRON_HOURLY="$OR_PATH_FOLDER_CRON_HOURLY"
  447. PATH_FOLDER_APACHE_SITES_ENABLED="$OR_PATH_FOLDER_APACHE_SITES_ENABLED"
  448. PATH_FOLDER_SSH_KEYS="$OR_PATH_FOLDER_SSH_KEYS"
  449. PATH_FOLDER_SAMBA_VAR_LIB="$OR_PATH_FOLDER_SAMBA_VAR_LIB"
  450. PATH_FOLDER_SAMBA_SETUP="$OR_PATH_FOLDER_SAMBA_SETUP"
  451. PATH_FOLDER_SAMBA_CACHE="$OR_PATH_FOLDER_SAMBA_CACHE"
  452. PATH_FOLDER_SAMBA_LOG="$OR_PATH_FOLDER_SAMBA_LOG"
  453. PATH_FOLDER_SELINUX_POLICY="$OR_PATH_FOLDER_SELINUX_POLICY"
  454.  
  455. # Paths to files:
  456. PATH_FILE_AUDIT_LOG="$OR_PATH_FILE_AUDIT_LOG"
  457. PATH_FILE_SELINUX_CONF="$OR_PATH_FILE_SELINUX_CONF"
  458. PATH_FILE_SELINUX_CONF_REPLACER="$OR_PATH_FILE_SELINUX_CONF_REPLACER"
  459. PATH_FILE_DHCPD_CONF="$OR_PATH_FILE_DHCPD_CONF"
  460. PATH_FILE_DHCPCD_CONF="$OR_PATH_FILE_DHCPCD_CONF"
  461. #PATH_FILE_KRB5_CONF_EXAMPLE="$OR_PATH_FILE_KRB5_CONF_EXAMPLE"
  462. PATH_FILE_KRB5_CONF="$OR_PATH_FILE_KRB5_CONF"
  463. PATH_FILE_SAMBA_CONF="$OR_PATH_FILE_SAMBA_CONF"
  464. PATH_FILE_NTP_CONF="$OR_PATH_FILE_NTP_CONF"
  465. PATH_FILE_NTP_DRIFT="$OR_PATH_FILE_NTP_DRIFT"
  466. PATH_FILE_NTP_LOG="$OR_PATH_FILE_NTP_LOG"
  467. PATH_FILE_NTP_SOCKET="$OR_PATH_FILE_NTP_SOCKET"
  468. PATH_FILE_SSH_CONF="$OR_PATH_FILE_SSH_CONF"
  469. PATH_FILE_SUDO_CONF="$OR_PATH_FILE_SUDO_CONF"
  470. PATH_FILE_HOSTNAME_CONF="$OR_PATH_FILE_HOSTNAME_CONF"
  471. PATH_FILE_HOSTS_CONF="$OR_PATH_FILE_HOSTS_CONF"
  472. PATH_FILE_TFTPD_CONF="$OR_PATH_FILE_TFTPD_CONF"
  473. PATH_FILE_USBMOUNT_CONF="$OR_PATH_FILE_USBMOUNT_CONF"
  474. PATH_FILE_KNOCKD_DEFAULT="$OR_PATH_FILE_KNOCKD_DEFAULT"
  475. PATH_FILE_KNOCKD_CONF="$OR_PATH_FILE_KNOCKD_CONF"
  476. PATH_FILE_FAIL2BAN_JAIL="$OR_PATH_FILE_FAIL2BAN_JAIL"
  477. PATH_FILE_PAMD_SSHD="$OR_PATH_FILE_PAMD_SSHD"
  478. PATH_FILE_ISSUE="$OR_PATH_FILE_ISSUE"
  479. PATH_FILE_ISSUENET="$OR_PATH_FILE_ISSUENET"
  480. PATH_FILE_MOTD="$OR_PATH_FILE_MOTD"
  481. fi
  482.  
  483. ###########################################################
  484. # 1.3.               Check the configuration              #
  485. ###########################################################
  486.  
  487. if [ "$CENTRALIZED_STORAGE" -eq "0" ] ; then
  488. LOCATION_OF_IMPORTANT_FILES=/etc/avorix
  489. fi
  490.  
  491. # Not Needed anymore! This was written when step where being stored in seperate files. #To provide step control. Check if the AVDC_STEP variabel exists, and if delete it.
  492. #clear_exported_avdc_step(){
  493. #   sed -i '/AVDC_STEP/d' /etc/avorix/avdc_install_variables.sh
  494. #}
  495.  
  496. #Create a few functions to enable the script to pause the installation and wait for the user to confirm the further going of the installation.
  497. pause(){
  498.     read -r fackEnterKey
  499. }
  500.  
  501. pause_with_msg(){
  502.     read -r -p "Press [Enter] to continue..." fackEnterKey
  503. }
  504.  
  505. #Since the PXE-module requires the DHCP-modules, check if both the DHCP- & PXE-modules have been enabled and if not warn the user that if the user wants to use PXE they have to enable the DHCP-module.
  506. if [ "$DHCP_SERVER" -eq "1" ] && [ "$PXE_SERVER" -eq "1" ] ; then
  507.     PXE_SERVER=2
  508. elif [ "$PXE_SERVER" -eq "1" ] ; then
  509.     PXE_SERVER=0
  510.     setterm -term linux -back red -fore white
  511.     echo "###########################################################"
  512.     echo "# Warning: To use PXE enable the DHCP Server              #"
  513.     echo "#          in the settings section of this script!        #"
  514.     echo "###########################################################"
  515.     pause_with_msg
  516.     setterm -default
  517.     exit
  518. fi
  519.  
  520. if [ "$SSH_FAIL2BAN" -eq "1" ] && [ "$FIREWALL" -eq "1" ] ; then
  521.     SSH_FAIL2BAN=2
  522. elif [ "$PXE_SERVER" -eq "1" ] ; then
  523.     SSH_FAIL2BAN=0
  524.     setterm -term linux -back red -fore white
  525.     echo "###########################################################"
  526.     echo "# Warning: To use FAIL2BAN enable the FIREWALL            #"
  527.     echo "#          in the settings section of this script!        #"
  528.     echo "###########################################################"
  529.     pause_with_msg
  530.     setterm -default
  531.     exit
  532. fi
  533.  
  534. #Check if this step has already been executed.
  535. if [[ 130 -gt $AVDC_STEP ]] || [ -z ${AVDC_STEP+x} ] ; then
  536.  
  537. #Copy this script to a static location
  538. #mkdir -p $LOCATION_OF_IMPORTANT_FILES/Tools/
  539. #CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  540. #cp "$(readlink -f $0" "$LOCATION_OF_IMPORTANT_FILES/Tools/avdc_install.sh"
  541.  
  542. #Check if the command afterwards has allready been added.
  543. #sed -i '/avdc_install_variables.sh/d' /root/.bashrc
  544. #Run this script, to add the permanently stored variables, whenever the root user logs in.
  545. #echo '/etc/avorix/avdc_install_variables.sh' >> /root/.bashrc
  546.  
  547. #Check if the command afterwards has allready been added.
  548. sed -i '/avdc_install.sh/d' /root/.bashrc
  549. #Run the script whenever the root user logs in.
  550. echo '/etc/avorix/avdc_install.sh' >> /root/.bashrc
  551.  
  552. AVDC_STEP=140; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=140/' /etc/avorix/avdc_install.sh
  553. fi
  554.  
  555.  
  556. ###########################################################
  557. # 1.4.        Show a summary of the settings              #
  558. ###########################################################
  559. if [[ $AVDC_STEP -eq 140 ]] ; then
  560.  
  561. clear
  562. if [ "$SKIP_BEGINNING_SUMMARY" -eq "0" ] ; then
  563.     echo "###########################################################";
  564.     echo "#       A quick summary of the installed settings         #";
  565.     echo "###########################################################";
  566.     echo "# You can change these settings"
  567.     echo "# by opening this script in a texteditor"
  568.     echo "# and change the variables that start from line 110."
  569.     echo ""
  570.     echo "This script will $(if [ "$JOIN_A_DOMAIN" -eq "0" ] ; then echo "create a standalone domaincontroller!" ; fi);$(if [ "$JOIN_A_DOMAIN" -eq "1" ] ; then echo "join a domain!" ; fi)"
  571.     echo "";
  572.     echo "Will be installed: $(if [ "$DHCP_SERVER" -eq "1" ] ; then echo "DHCP" ; fi);$(if [ "$PXE_SERVER" -eq "2" ] ; then echo "(with PXE)" ; fi)$(if [ "$SSH_SERVER" -eq "1" ]; then echo "SSH" ; fi);$(if [ "$SSH_2FA" -eq "1" ] || [ "$SSH_PORTKNOCKING" -eq "1" ] || [ "$SSH_FAIL2BAN" -eq "2" ]; then echo " (with $(if [ "$SSH_2FA" -eq "1" ] ; then echo "2-Factor-Authentication"; fi)$(if [ "$SSH_PORTKNOCKING" -eq "1" ] ; then echo "Portknocking"; fi)$(if [ "$SSH_FAIL2BAN" -eq "2" ] ; then echo "Fail2Ban"; fi)" ; fi)"
  573.     echo "";
  574.     echo "Will be configured: $(if [ "$AUTOMATIC_SECURITY_UPDATES" -eq "1" ]; then echo "Automatic_Security_Updates"; else echo ""; fi) $(if [ "$FIREWALL" -eq "1" ]; then echo "Firewall"; else echo ""; fi) $(if [ "$SELINUX" -eq "1" ]; then echo "SELinux"; else echo ""; fi)"
  575.  
  576.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  577.     pause_with_msg;
  578.     echo "";
  579.     echo "Storage Settings:";
  580.     echo "1. Files will be stored in: $LOCATION_OF_IMPORTANT_FILES";
  581. #   echo "2. Files will be stored on removable USB storage: $(if [ "$PORTABLE_CONFIGURATION" -eq "1" ]; then echo "Yes"; else echo "No"; fi)";
  582.     fi
  583.  
  584.     pause_with_msg;
  585.     echo "";
  586.     echo "Network settings:";
  587.     echo "1. IP address: $IP_ADDRESS";
  588.     echo "2. Subnetmaskbits: $SUBNETMASKBITS";
  589.     echo "3. Gateway: $GATEWAY";
  590.     echo "4. Preferred DNS-server: $DNSSERVER1";
  591.     echo "5. Alternate DNS-server: $DNSSERVER2";
  592.  
  593.     pause_with_msg;
  594.     echo "";
  595.     echo "Domain Controller Settings:";
  596.     echo "1. Fully Qualified Domain Name: $FQDN";
  597.     echo "2. NetBIOS name: $NBIOS";
  598.     echo "3. Name of the Domain Controller: $DCNAME";
  599.     echo "4. Administrator User: Administrator (can not be changed)";
  600.     echo "5. Administrator Password: $(if [ "$ADMINPWD" = 'P455w0RD' ]; then echo 'P455w0RD'; else echo "Hidden! "; fi)";
  601.  
  602.     pause_with_msg;
  603.     echo "";
  604.     echo "Time settings:";
  605.     echo "1. Region: $REGION";
  606.     echo "2. Timezone: $TIMEZONE";
  607.     echo "3. NTP-Server 1: $NTPSERVER1";
  608.     echo "4. NTP-Server 2: $NTPSERVER2";
  609.     echo "5. NTP-Server 3: $NTPSERVER3";
  610.  
  611.     if [ "$DHCP_SERVER" -eq "1" ] ; then
  612.     pause_with_msg;
  613.     echo "";
  614.     echo "DHCP Settings:";
  615.     echo "1. Subnet: $DHCP_SUBNET";
  616.     echo "2. Subnetmask: $DHCP_SUBNETMASK";
  617.     echo "3. Broadcastaddress: $DHCP_BROADCASTADDRESS";
  618.     echo "4. Gateway: $DHCP_GATEWAY";
  619.     echo "5. Preferred DNS-Server: $DHCP_DNSSERVER1";
  620.     echo "6. Alternate DNS-Server: $DHCP_DNSSERVER2";
  621.  
  622.     pause_with_msg;
  623.     echo "7. NetBIOS-Server: $DHCP_NETBIOSSERVER";
  624.     echo "8. NTP-Server 1: $DHCP_NTPSERVER1";
  625.     echo "9. NTP-Server 2: $DHCP_NTPSERVER2";
  626.     echo "10. Max Lease Time: $DHCP_MAX_LEASE_TIME";
  627.     echo "11. First IP Address: $DHCP_FIRST_IP_ADDRESS";
  628.     echo "12. Last IP Address: $DHCP_LAST_IP_ADDRESS";
  629.  
  630.     if [ "$PXE_SERVER" -eq "2" ] ; then
  631.     pause_with_msg
  632.     echo "";
  633.     echo "PXE Settings:";
  634.     echo "1. HTTP Folder: $PXE_HTTP_ROOT (This location is for the Windows Installer files)";
  635.     echo "2. TFTP Folder: $PXE_TFTP_ROOT (This location is for the Windows PE .WIM-file.)";
  636.     fi
  637.     fi
  638.  
  639.     if [ "$SSH_SERVER" -eq "1" ] ; then
  640.     pause_with_msg;
  641.     echo "";
  642.     echo "SSH Settings:";
  643.     echo "SSH Port: $SSH_PORT";
  644.     echo "SSH User: $SSH_USER";
  645.     echo "SSH Password: $(if [ "$SSH_USER_PASSWORD" = 'P455w0RD' ]; then echo 'P455w0RD'; else echo "Hidden! "; fi)";
  646.     echo "SSH User has Admin rights: $(if [ "$SSH_USER_SUDO" -eq "1" ]; then echo "Yes"; else echo "No"; fi)";
  647.  
  648.     if [ "$SSH_2FA" -eq "1" ] ; then
  649.     pause_with_msg
  650.     echo "";
  651.     echo "Two-Factor-Authentication: $(if [ "$SSH_2FA" -eq "1" ]; then echo "Yes"; else echo "No"; fi)";
  652.     fi
  653.  
  654.     if [ "$SSH_PORTKNOCKING" -eq "1" ] ; then
  655.     pause_with_msg
  656.     echo ""
  657.     echo "Portknocking: Yes";
  658.     echo "Portknocking Opening sequence: $SSH_PORTKNOCKING_OPEN_SEQ1, $SSH_PORTKNOCKING_OPEN_SEQ2, $SSH_PORTKNOCKING_OPEN_SEQ3";
  659.     echo "Portknocking Closing sequence: $SSH_PORTKNOCKING_CLOSE_SEQ1, $SSH_PORTKNOCKING_CLOSE_SEQ2, $SSH_PORTKNOCKING_CLOSE_SEQ3";
  660.     fi
  661.  
  662.     if [ "$SSH_FAIL2BAN" -eq "2" ] ; then
  663.     pause_with_msg
  664.     echo ""
  665.     echo "Fail2Ban: Yes";
  666.     echo "Fail2Ban Bantime: $SSH_FAIL2BAN_BANTIME";
  667.     echo "Fail2Ban Time between login attempts: $SSH_FAIL2BAN_FINDTIME";
  668.     echo "Fail2Ban Max login retries: $SSH_FAIL2BAN_MAXRETRY";
  669.     fi
  670.     fi
  671.     pause_with_msg
  672.     clear
  673.  
  674.     setterm -term linux -back black -fore green
  675.     echo "###########################################################"
  676.     echo "#                 Confirm these settings                  #"
  677.     echo "###########################################################"
  678.     echo "Are these settings correct?"
  679.     echo ""
  680.     echo "Note: You can bypass this in the future by setting"
  681.     echo "'SKIP_BEGINNING_SUMMARY' to 1"
  682.     echo ""
  683.     pause_with_msg
  684.     setterm -default
  685.     clear
  686. fi
  687.  
  688. AVDC_STEP=220; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=220/' /etc/avorix/avdc_install.sh
  689. fi
  690.  
  691.  
  692. ###########################################################
  693. #                                                         #
  694. # 2.            The fase of compatibility                 #
  695. #                                                         #
  696. ###########################################################
  697.  
  698. ###########################################################
  699. # 2.1.         Test the internet connection               #
  700. ###########################################################
  701.  
  702. #Should run everytime till the script has executed step
  703. if [[ 370 -gt $AVDC_STEP ]] ; then
  704.  
  705. echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
  706.  
  707. if [ $? -eq 0 ]; then
  708.     echo "Your device is connected to the internet."
  709. else
  710.     setterm -term linux -back red -fore white
  711.     echo "###########################################################"
  712.     echo "# Warning: This script requires an internet connection!   #"
  713.     echo "###########################################################"
  714.     pause
  715.     setterm -default
  716.     exit
  717. fi
  718.  
  719. fi
  720.  
  721.  
  722. ###########################################################
  723. # 2.2.          Update the complete system                #
  724. ###########################################################
  725. if [[ $AVDC_STEP -eq 220 ]] ; then
  726.  
  727. $PM_UPDATE
  728. $PM_UPGRADE
  729. $PM_SYSUPGRADE
  730. $PM_UPGRADE # Just to make sure that every system installs the newest packages without limitations of the OS-version.
  731.  
  732. AVDC_STEP=230; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=230/' /etc/avorix/avdc_install.sh
  733. reboot
  734. fi
  735.  
  736. ###########################################################
  737. # 2.3.           (Optional) Configure USBmount            #
  738. ###########################################################
  739. if [[ $AVDC_STEP -eq 230 ]] ; then
  740.  
  741. if [ "$PORTABLE_CONFIGURATION" -eq "1" ] ; then
  742.     "$PM_INSTALL" "$PACKAGE_USBMOUNT" "$PM_INSTALL_ENDING_VARIABLES"
  743.  
  744.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  745.     if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_USBMOUNT 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  746.     USBMOUNT_INSTALLATION_STATUS=1
  747.     echo "The '$PACKAGE_USBMOUNT'-package is succesfully installed!"
  748.     else
  749.     USBMOUNT_INSTALLATION_STATUS=0
  750.     setterm -term linux -back red -fore white
  751.     echo "###########################################################"
  752.     echo "# Error: Installation stopped!                            #"
  753.     echo "###########################################################"
  754.     echo "Reason:"
  755.     echo " - The '$PACKAGE_USBMOUNT'-package could not be installed."
  756.     echo ""
  757.     echo "Solution:"
  758.     echo " - Make sure that:"
  759.     echo "  - You have a stable internet connection!"
  760.     echo "  - Install it manually."
  761.     echo "  - Skip this part."
  762.     echo "###########################################################"
  763.     pause_with_msg
  764.     setterm -default
  765.     exit
  766.     fi
  767.     fi
  768.  
  769.     #USBMount: Configuring.
  770.     mv "$PATH_FILE_USBMOUNT_CONF" "$PATH_FILE_USBMOUNT_CONF.original"
  771.     touch "$PATH_FILE_USBMOUNT_CONF"
  772.  
  773. cat <<EOT >> "$PATH_FILE_USBMOUNT_CONF"
  774. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  775. # Generated on $(date)
  776. #
  777.  
  778. ENABLED=1
  779. MOUNTPOINTS="/media/usb1 /media/usb2 /media/usb3
  780.             /media/usb4 /media/usb5 /media/usb6 /media/usb7 /media/usb8"
  781.  
  782. FILESYSTEMS="vfat ext2 ext3 ext4 hfsplus"
  783. MOUNTOPTIONS="sync,noexec,nodev,noatime,nodiratime"
  784. FS_MOUNTOPTIONS=""
  785. VERBOSE=no
  786. EOT
  787.  
  788.     clear
  789.  
  790.     #Inform the user to insert their USB-device.
  791.     setterm -term linux -back red -fore white
  792.     read -r -p "Insert your removable drive and press [Enter] to continue..." fackEnterKey
  793.     setterm -default
  794.  
  795.     #USBMount: Make sure that the removable drive is mounted else copy the files to a temporary folder.
  796.     #It would be better if we listed the drives using mountusb.
  797.     if [ "$PORTABLE_CONFIGURATION" -eq "1" ] ; then
  798.     if mount | grep /media/usb1 > /dev/null || mount | grep /media/usb2 > /dev/null || mount | grep /media/usb3 > /dev/null || mount | grep /media/usb4 > /dev/null || mount | grep /media/usb5 > /dev/null || mount | grep /media/usb6 > /dev/null || mount | grep /media/usb7 > /dev/null || mount | grep /media/usb8 > /dev/null ; then
  799.     LOCATION_OF_IMPORTANT_FILES=/media/usb1
  800.     setterm -term linux -back green -fore white
  801.     echo "###########################################################"
  802.     echo "#           Your USB-device has been found!               #"
  803.     echo "###########################################################"
  804.     setterm -default
  805.     else
  806.     setterm -term linux -back red -fore white
  807.     echo "###########################################################"
  808.     echo "# Error: Installation stopped!                            #"
  809.     echo "###########################################################"
  810.     echo "Reason:"
  811.     echo " - Your USB-storage device could not be mounted."
  812.     echo ""
  813.     echo "Solution:"
  814.     echo " - Prepare your USB-storage device:"
  815.     echo "  - Find your USB-device by executing the command: lsblk"
  816.     echo "  - Format your device by executing: mkfs.ext4 /dev/Your_Device"
  817.     echo "    As an example: mkfs.ext4 /dev/sda"
  818.     echo "###########################################################"
  819.     pause_with_msg
  820.     setterm -default
  821.     exit
  822.     fi
  823.     fi
  824. fi
  825.  
  826. AVDC_STEP=240; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=240/' /etc/avorix/avdc_install.sh
  827. fi
  828.  
  829.  
  830. ###########################################################
  831. # 2.4.       Build the LOIF directory structure           #
  832. ###########################################################
  833. if [[ $AVDC_STEP -eq 240 ]] ; then
  834.  
  835. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  836. #Creating folders for the $LOCATION_OF_IMPORTANT_FILES
  837. mkdir -p "$LOCATION_OF_IMPORTANT_FILES/Configuration" "$LOCATION_OF_IMPORTANT_FILES/Logs" "$LOCATION_OF_IMPORTANT_FILES/Data" "$LOCATION_OF_IMPORTANT_FILES/Configuration/Cron" "$LOCATION_OF_IMPORTANT_FILES/Configuration/Cron/Daily" "$LOCATION_OF_IMPORTANT_FILES/Configuration/Cron/Hourly"  "$LOCATION_OF_IMPORTANT_FILES/Data/SAMBA" "$LOCATION_OF_IMPORTANT_FILES/Logs" "$LOCATION_OF_IMPORTANT_FILES/Logs/General" "$LOCATION_OF_IMPORTANT_FILES/Logs/SAMBA" "$LOCATION_OF_IMPORTANT_FILES/Logs/NTP" "$LOCATION_OF_IMPORTANT_FILES/Logs/AuditD" "$LOCATION_OF_IMPORTANT_FILES/Configuration/KRB5" "$LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA" "$LOCATION_OF_IMPORTANT_FILES/Configuration/General" "$LOCATION_OF_IMPORTANT_FILES/Configuration/NTP" "$LOCATION_OF_IMPORTANT_FILES/Data/SAMBA/Cache"  "$LOCATION_OF_IMPORTANT_FILES/Data/NTP" "$LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA_VAR_LIB" "$LOCATION_OF_IMPORTANT_FILES/Data/SAMBA/Shares/Users"
  838.  
  839. #Linking folder to folders on the USB, as we want to capture all these files!
  840. ln -sdf "$PATH_FOLDER_SAMBA_VAR_LIB" "$OR_PATH_FOLDER_SAMBA_VAR_LIB"
  841. ln -sdf "$PATH_FOLDER_SAMBA_SETUP" "$OR_PATH_FOLDER_SAMBA_SETUP"
  842. ln -sdf "$PATH_FOLDER_SAMBA_CACHE" "$OR_PATH_FOLDER_SAMBA_CACHE"
  843. ln -sdf "$PATH_FOLDER_SAMBA_LOG" "$OR_PATH_FOLDER_SAMBA_LOG"
  844.  
  845. if [ "$SELINUX" -eq "0" ]; then
  846.     mkdir -p "$LOCATION_OF_IMPORTANT_FILES/Configuration/SELinux/Rules" "$LOCATION_OF_IMPORTANT_FILES/Configuration/SELinux/Policy"
  847. fi
  848.  
  849. if [ "$DHCP_SERVER" -eq "1" ]; then
  850.     mkdir -p "$LOCATION_OF_IMPORTANT_FILES/Configuration/DHCP"
  851.     #PXE has to be 2, unlike the others.
  852.     if [ "$PXE_SERVER" -eq "2" ]; then
  853.     mkdir -p "$LOCATION_OF_IMPORTANT_FILES/Configuration/PXE" "$LOCATION_OF_IMPORTANT_FILES/Configuration/Apache/Sites-Enabled" "$LOCATION_OF_IMPORTANT_FILES/Data/TFTP/Root" "$LOCATION_OF_IMPORTANT_FILES/Data/Apache/Root" "$LOCATION_OF_IMPORTANT_FILES/PXE/Logs"
  854.     fi
  855. else
  856.  
  857. mkdir PATH_FOLDER_SELINUX_POLICY
  858. fi
  859.  
  860. if [ "$SSH_SERVER" -eq "1" ]; then
  861.     mkdir -p "$LOCATION_OF_IMPORTANT_FILES/Configuration/SSH/Keys"
  862.     if [ "$SSH_PORTKNOCKING" -eq "1" ] ; then
  863.     mkdir -p "$LOCATION_OF_IMPORTANT_FILES/Logs/KnockD/" "$LOCATION_OF_IMPORTANT_FILES/Configuration/KNOCKD/default"
  864.     fi
  865.     if [ "$SSH_FAIL2BAN" -eq "2" ] ; then
  866.     mkdir -p "$LOCATION_OF_IMPORTANT_FILES/Logs/Fail2Ban/" "$LOCATION_OF_IMPORTANT_FILES/Configuration/Fail2Ban"
  867.     fi
  868. fi
  869.  
  870. fi
  871.  
  872. AVDC_STEP=310; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=310/' /etc/avorix/avdc_install.sh
  873. fi
  874.  
  875. ###########################################################
  876. #                                                         #
  877. # 3.            The fase of installation                  #
  878. #                                                         #
  879. ###########################################################
  880.  
  881. ###########################################################
  882. # 3.1. (Optional) Install & Temporarely disable SELinux   #
  883. ###########################################################
  884. if [[ $AVDC_STEP -eq 310 ]] ; then
  885.  
  886. #Temporary disable SELinux, will be enabled the next day with exclusions for DNS, SAMBA, DHCP and DHCP.
  887. if [ "$SELINUX" -eq "1" ]; then
  888.     "$PM_INSTALL" "$PACKAGE_SELINUX" "$PACKAGE_SELINUX_POLICY_DEFAULT" "$PM_INSTALL_ENDING_VARIABLES"
  889.  
  890.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  891.     if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_SELINUX 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  892.     SELINUXBASICS_INSTALLATION_STATUS=1
  893.     echo "The '$PACKAGE_SELINUX'-package is succesfully installed!"
  894.     else
  895.     SELINUXBASICS_INSTALLATION_STATUS=0
  896.     setterm -term linux -back red -fore white
  897.     echo "###########################################################"
  898.     echo "# Error: Installation stopped!                            #"
  899.     echo "###########################################################"
  900.     echo "Reason:"
  901.     echo " - The '$PACKAGE_SELINUX'-package could not be installed."
  902.     echo ""
  903.     echo "Solution:"
  904.     echo " - Make sure that:"
  905.     echo "  - You have a stable internet connection!"
  906.     echo "  - Install it manually."
  907.     echo "  - Skip this part."
  908.     echo "###########################################################"
  909.     pause_with_msg
  910.     setterm -default
  911.     exit
  912.     fi
  913.     fi
  914.  
  915.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  916.     if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_SELINUX_POLICY_DEFAULT 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  917.     SELINUXPOLICYDEFAULT_INSTALLATION_STATUS=1
  918.     echo "The '$PACKAGE_SELINUX_POLICY_DEFAULT'-package is succesfully installed!"
  919.     else
  920.     SELINUXPOLICYDEFAULT_INSTALLATION_STATUS=0
  921.     setterm -term linux -back red -fore white
  922.     echo "###########################################################"
  923.     echo "# Error: Installation stopped!                            #"
  924.     echo "###########################################################"
  925.     echo "Reason:"
  926.     echo " - The '$PACKAGE_SELINUX_POLICY_DEFAULT'-package could not be installed."
  927.     echo ""
  928.     echo "Solution:"
  929.     echo " - Make sure that:"
  930.     echo "  - You have a stable internet connection!"
  931.     echo "  - Install it manually."
  932.     echo "  - Skip this part."
  933.     echo "###########################################################"
  934.     pause_with_msg
  935.     setterm -default
  936.     exit
  937.     fi
  938.     fi
  939.  
  940.     selinux-activate
  941.  
  942.     #If SELinux is enabled go to step 3.15.
  943.     AVDC_STEP=315; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=315/' /etc/avorix/avdc_install.sh
  944.     reboot
  945.     fi
  946.  
  947.     #If SELinux is not enabled go to step 3.15.
  948.     AVDC_STEP=315; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=315/' /etc/avorix/avdc_install.sh
  949. fi
  950.  
  951. if [[ $AVDC_STEP -eq 315 ]] ; then
  952.  
  953.     if [ "$SELINUX" -eq "1" ]; then
  954.  
  955.     cp "$PATH_FOLDER_SELINUX_POLICY" "$PATH_FOLDER_SELINUX_POLICY.bak"
  956.     mv "$PATH_FILE_SELINUX_CONF" "$PATH_FILE_SELINUX_CONF.original"
  957.     touch "$PATH_FILE_SELINUX_CONF"
  958.  
  959. cat <<EOT >> "$PATH_FILE_SELINUX_CONF"
  960. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  961. # Generated on $(date)
  962. #
  963.  
  964. # This file controls the state of SELinux on the system.
  965. # SELINUX= can take one of these three values:
  966. #       enforcing - SELinux security policy is enforced.
  967. #       permissive - SELinux prints warnings instead of enforcing.
  968. #       disabled - SELinux is fully disabled.
  969. SELINUX=permissive
  970. # SELINUXTYPE= type of policy in use. Possible values are:
  971. #       targeted - Only targeted network daemons are protected.
  972. #       strict - Full SELinux protection.
  973. SELINUXTYPE=strict
  974.  
  975. # SETLOCALDEFS= Check local definition changes
  976. SETLOCALDEFS=0
  977. EOT
  978.  
  979.     fi
  980.     AVDC_STEP=320; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=320/' /etc/avorix/avdc_install.sh
  981. fi
  982.  
  983.  
  984. ###########################################################
  985. # 3.2.             Install the main components            #
  986. ###########################################################
  987. if [[ $AVDC_STEP -eq 320 ]] ; then
  988.  
  989. if [ "$DHCP_SERVER" -eq "1" ]; then
  990.    "$PM_INSTALL" "$PACKAGE_DHCPD" "$PM_INSTALL_ENDING_VARIABLES"
  991.  
  992.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  993.     if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_DHCPD 2>/dev/null >/dev/null)" -eq "1" ] ; then
  994.     ISCDHCPSERVER_INSTALLATION_STATUS=1
  995.     echo "The '$PACKAGE_DHCPD'-package is succesfully installed!"
  996.     else
  997.     ISCDHCPSERVER_INSTALLATION_STATUS=0
  998.     setterm -term linux -back red -fore white
  999.     echo "###########################################################"
  1000.     echo "# Error: Installation stopped!                            #"
  1001.     echo "###########################################################"
  1002.     echo "Reason:"
  1003.     echo " - The '$PACKAGE_DHCPD'-package could not be installed."
  1004.     echo ""
  1005.     echo "Solution:"
  1006.     echo " - Make sure that:"
  1007.     echo "  - You have a stable internet connection!"
  1008.     echo "  - Install it manually."
  1009.     echo "  - Skip this part."
  1010.     echo "###########################################################"
  1011.     pause_with_msg
  1012.     setterm -default
  1013.     exit
  1014.     fi
  1015.     fi
  1016. fi
  1017.  
  1018. if [ "$ANTIVIRUS" -eq "1" ]; then
  1019.     "$PM_INSTALL" "$PACKAGE_CLAMAV" "$PACKAGE_CLAMAV_FRESHCLAM" "$PM_INSTALL_ENDING_VARIABLES"
  1020.     touch "$PATH_FOLDER_CRON_HOURLY/ClamAV"
  1021.  
  1022. #Variables are not properly being pasted.
  1023. cat <<'EOT' >> "$PATH_FOLDER_CRON_HOURLY/ClamAV"
  1024. #!/bin/bash
  1025. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  1026. # Generated on $(date)
  1027. #
  1028.  
  1029. # Email subject
  1030. SUBJECT="VIRUS DETECTED ON `hostname`!!!"
  1031. # Email To ?
  1032. EMAIL="root@localhost"
  1033. # Log location
  1034. LOG=/var/log/clamav/scan.log
  1035.  
  1036. check_scan () {
  1037.  
  1038.     # Check the last set of results. If there are any "Infected" counts that aren't zero, we have a problem.
  1039.     if [ `tail -n 12 ${LOG}  | grep Infected | grep -v 0 | wc -l` != 0 ]
  1040.     then
  1041.         EMAILMESSAGE=`mktemp /tmp/virus-alert.XXXXX`
  1042.         echo "To: ${EMAIL}" >>  ${EMAILMESSAGE}
  1043. EOT
  1044.  
  1045. #We want it to translate these parts
  1046. cat <<EOT >> "$PATH_FOLDER_CRON_HOURLY/ClamAV"
  1047.         echo "From: antivirus@$DCNAME.$FQDN" >> \
  1048. EOT
  1049.  
  1050. cat <<'EOT' >> "$PATH_FOLDER_CRON_HOURLY/ClamAV"
  1051. ${EMAILMESSAGE}
  1052.         echo "Subject: ${SUBJECT}" >>  ${EMAILMESSAGE}
  1053.         echo "Importance: High" >> ${EMAILMESSAGE}
  1054.         echo "X-Priority: 1" >> ${EMAILMESSAGE}
  1055.         echo "`tail -n 50 ${LOG}`" >> ${EMAILMESSAGE}
  1056.         sendmail -t < ${EMAILMESSAGE}
  1057.     fi
  1058.  
  1059. }
  1060.  
  1061. find / -not -wholename '/sys/*' -and -not -wholename '/proc/*' -mmin -61 -type f -print0 | xargs -0 -r clamscan --exclude-dir=/proc/ --exclude-dir=/sys/ --quiet --infected --log=${LOG}
  1062. check_scan
  1063.  
  1064. find / -not -wholename '/sys/*' -and -not -wholename '/proc/*' -cmin -61 -type f -print0 | xargs -0 -r clamscan --exclude-dir=/proc/ --exclude-dir=/sys/ --quiet --infected --log=${LOG}
  1065. check_scan
  1066. EOT
  1067.  
  1068.     chmod +x "$PATH_FOLDER_CRON_HOURLY/ClamAV"
  1069.  
  1070.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  1071.     if [ "$(dpkg-query -W -f='${Status}' "$PACKAGE_CLAMAV" 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  1072.     CLAMAV_INSTALLATION_STATUS=1
  1073.     echo "The '$PACKAGE_CLAMAV'-package is succesfully installed!"
  1074.     else
  1075.     CLAMAV_INSTALLATION_STATUS=0
  1076.     setterm -term linux -back red -fore white
  1077.     echo "###########################################################"
  1078.     echo "# Error: Installation stopped!                            #"
  1079.     echo "###########################################################"
  1080.     echo "Reason:"
  1081.     echo " - The '$PACKAGE_CLAMAV'-package could not be installed."
  1082.     echo ""
  1083.     echo "Solution:"
  1084.     echo " - Make sure that:"
  1085.     echo "  - You have a stable internet connection!"
  1086.     echo "  - Install it manually."
  1087.     echo "  - Skip this part."
  1088.     echo "###########################################################"
  1089.     pause_with_msg
  1090.     setterm -default
  1091.     exit
  1092.     fi
  1093.     fi
  1094.  
  1095.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  1096.     if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_CLAMAV_FRESHCLAM 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  1097.     CLAMAVFRESHCLAM_INSTALLATION_STATUS=1
  1098.     echo "The '$PACKAGE_CLAMAV_FRESHCLAM'-package is succesfully installed!"
  1099.     else
  1100.     CLAMAVFRESHCLAM_INSTALLATION_STATUS=0
  1101.     setterm -term linux -back red -fore white
  1102.     echo "###########################################################"
  1103.     echo "# Error: Installation stopped!                            #"
  1104.     echo "###########################################################"
  1105.     echo "Reason:"
  1106.     echo " - The '$PACKAGE_CLAMAV_FRESHCLAM'-package could not be installed."
  1107.     echo ""
  1108.     echo "Solution:"
  1109.     echo " - Make sure that:"
  1110.     echo "  - You have a stable internet connection!"
  1111.     echo "  - Install it manually."
  1112.     echo "  - Skip this part."
  1113.     echo "###########################################################"
  1114.     pause_with_msg
  1115.     setterm -default
  1116.     exit
  1117.     fi
  1118.     fi
  1119. fi
  1120.  
  1121. if [ "$FIREWALL" -eq "1" ]; then
  1122.     "$PM_INSTALL" "$PACKAGE_FIREWALLD" "$PM_INSTALL_ENDING_VARIABLES"
  1123.  
  1124.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  1125.     if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_FIREWALLD 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  1126.     FIREWALLD_INSTALLATION_STATUS=1
  1127.     echo "The '$PACKAGE_FIREWALLD'-package is succesfully installed!"
  1128.     else
  1129.     FIREWALLD_INSTALLATION_STATUS=0
  1130.     setterm -term linux -back red -fore white
  1131.     echo "###########################################################"
  1132.     echo "# Error: Installation stopped!                            #"
  1133.     echo "###########################################################"
  1134.     echo "Reason:"
  1135.     echo " - The '$PACKAGE_FIREWALLD'-package could not be installed."
  1136.     echo ""
  1137.     echo "Solution:"
  1138.     echo " - Make sure that:"
  1139.     echo "  - You have a stable internet connection!"
  1140.     echo "  - Install it manually."
  1141.     echo "  - Skip this part."
  1142.     echo "###########################################################"
  1143.     pause_with_msg
  1144.     setterm -default
  1145.     exit
  1146.     fi
  1147.     fi
  1148.  
  1149.     systemctl start $DAEMON_FIREWALLD
  1150. fi
  1151.  
  1152. if [ "$SSH_SERVER" -eq "1" ] ; then
  1153.     "$PM_INSTALL" "$PACKAGE_OPENSSHD" "$PM_INSTALL_ENDING_VARIABLES"
  1154.  
  1155.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  1156.     if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_OPENSSHD 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  1157.     OPENSSHSERVER_INSTALLATION_STATUS=1
  1158.     eche "The '$PACKAGE_OPENSSHD'-package is succesfully installed!"
  1159.     else
  1160.     OPENSSHSERVER_INSTALLATION_STATUS=0
  1161.     setterm -term linux -back red -fore white
  1162.     echo "###########################################################"
  1163.     echo "# Error: Installation stopped!                            #"
  1164.     echo "###########################################################"
  1165.     echo "Reason:"
  1166.     echo " - The '$PACKAGE_OPENSSHD'-package could not be installed."
  1167.     echo ""
  1168.     echo "Solution:"
  1169.     echo " - Make sure that:"
  1170.     echo "  - You have a stable internet connection!"
  1171.     echo "  - Install it manually."
  1172.     echo "  - Skip this part."
  1173.     echo "###########################################################"
  1174.     pause_with_msg
  1175.     setterm -default
  1176.     exit
  1177.     fi
  1178.     fi
  1179.  
  1180.     if [ "$SSH_PORTKNOCKING" -eq "1" ] ; then
  1181.     "$PM_INSTALL" "$PACKAGE_KNOCKD" "$PM_INSTALL_ENDING_VARIABLES"
  1182.     fi
  1183.     if [ "$SSH_FAIL2BAN" -eq "2" ] ; then
  1184.     "$PM_INSTALL" "$PACKAGE_FAIL2BAN" "$PM_INSTALL_ENDING_VARIABLES"
  1185.     fi
  1186.     if [ "$SSH_2FA" -eq "1" ] ; then
  1187.     "$PM_INSTALL" "$PACKAGE_LIBPAM_GOOGLE_AUTHENTICATOR" "$PM_INSTALL_ENDING_VARIABLES"
  1188.     fi
  1189. fi
  1190.  
  1191. if [ "$PXE_SERVER" -eq "2" ]; then
  1192.     "$PM_INSTALL" "$PACKAGE_TFTPD" "$PACKAGE_APACHE" "$PM_INSTALL_ENDING_VARIABLES"
  1193.  
  1194.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  1195.     if [ "$(dpkg-query -W -f='${Status}' '$PACKAGE_TFTPD' 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  1196.     TFTPDHPA_INSTALLATION_STATUS=0
  1197.     echo "The '$PACKAGE_TFTPD'-package is succesfully installed!"
  1198.     else
  1199.     TFTPDHPA_INSTALLATION_STATUS=1
  1200.     setterm -term linux -back red -fore white
  1201.     echo "###########################################################"
  1202.     echo "# Error: Installation stopped!                            #"
  1203.     echo "###########################################################"
  1204.     echo "Reason:"
  1205.     echo " - The '$PACKAGE_TFTPD'-package could not be installed."
  1206.     echo ""
  1207.     echo "Solution:"
  1208.     echo " - Make sure that:"
  1209.     echo "  - You have a stable internet connection!"
  1210.     echo "  - Install it manually."
  1211.     echo "  - Skip this part."
  1212.     echo "###########################################################"
  1213.     pause_with_msg
  1214.     setterm -default
  1215.     exit
  1216.     fi
  1217.     fi
  1218.  
  1219.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  1220.     if [ "$(dpkg-query -W -f='${Status}' "$PACKAGE_APACHE" 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  1221.     TFTPDHPA_INSTALLATION_STATUS=0
  1222.     echo "The '$PACKAGE_APACHE'-package is succesfully installed!"
  1223.     else
  1224.     TFTPDHPA_INSTALLATION_STATUS=1
  1225.     setterm -term linux -back red -fore white
  1226.     echo "###########################################################"
  1227.     echo "# Error: Installation stopped!                            #"
  1228.     echo "###########################################################"
  1229.     echo "Reason:"
  1230.     echo " - The '$PACKAGE_APACHE'-package could not be installed."
  1231.     echo ""
  1232.     echo "Solution:"
  1233.     echo " - Make sure that:"
  1234.     echo "  - You have a stable internet connection!"
  1235.     echo "  - Install it manually."
  1236.     echo "  - Skip this part."
  1237.     echo "###########################################################"
  1238.     pause_with_msg
  1239.     setterm -default
  1240.     exit
  1241.     fi
  1242.     fi
  1243. fi
  1244.  
  1245. "$PM_INSTALL" "$PACKAGE_SAMBA" "$PACKAGE_NTP" "$PM_INSTALL_ENDING_VARIABLES"
  1246.  
  1247. if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  1248. if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_SAMBA 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  1249.     SAMBA_INSTALLATION_STATUS=1
  1250.     echo "The '$PACKAGE_SAMBA'-package is succesfully installed!"
  1251. else
  1252.     SAMBA_INSTALLATION_STATUS=0
  1253.     setterm -term linux -back red -fore white
  1254.     echo "###########################################################"
  1255.     echo "# Error: Installation stopped!                            #"
  1256.     echo "###########################################################"
  1257.     echo "Reason:"
  1258.     echo " - The '$PACKAGE_SAMBA'-package could not be installed."
  1259.     echo ""
  1260.     echo "Solution:"
  1261.     echo " - Make sure that:"
  1262.     echo "  - You have a stable internet connection!"
  1263.     echo "  - Install it manually."
  1264.     echo "  - Skip this part."
  1265.     echo "###########################################################"
  1266.     pause_with_msg
  1267.     setterm -default
  1268.     exit
  1269. fi
  1270. fi
  1271.  
  1272. if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  1273. if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_NTP 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  1274.     NTP_INSTALLATION_STATUS=1
  1275.     echo "The '$PACKAGE_NTP'-package is succesfully installed!"
  1276. else
  1277.     NTP_INSTALLATION_STATUS=0
  1278.     setterm -term linux -back red -fore white
  1279.     echo "###########################################################"
  1280.     echo "# Error: Installation stopped!                            #"
  1281.     echo "###########################################################"
  1282.     echo "Reason:"
  1283.     echo " - The '$PACKAGE_NTP'-package could not be installed."
  1284.     echo ""
  1285.     echo "Solution:"
  1286.     echo " - Make sure that:"
  1287.     echo "  - You have a stable internet connection!"
  1288.     echo "  - Install it manually."
  1289.     echo "  - Skip this part."
  1290.     echo "###########################################################"
  1291.     pause_with_msg
  1292.     setterm -default
  1293.     exit
  1294. fi
  1295. fi
  1296.  
  1297. #Won't have: Convert this to support other OS.
  1298. if [ "$WEBMIN" -eq "1" ] ; then
  1299.     apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python
  1300.     cd /root || exit
  1301.     wget "http://prdownloads.sourceforge.net/webadmin/webmin_$(WEBMIN_VERSION)_all.deb"
  1302.     dpkg --install "webmin_$(WEBMIN_VERSION)_all.deb"
  1303.     rm "webmin_$(WEBMIN_VERSION)_all.deb"
  1304.     wget "http://www.webmin.com/jcameron-key.asc"
  1305.     apt-key add jcameron-key.asc
  1306.     sh -c "echo 'deb http://download.webmin.com/download/repository sarge contrib' >> /etc/apt/sources.list"
  1307. fi
  1308.  
  1309. AVDC_STEP=330; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=330/' /etc/avorix/avdc_install.sh
  1310. fi
  1311.  
  1312.  
  1313. ###########################################################
  1314. # 3.3.                Configure the timezone              #
  1315. ###########################################################
  1316. if [[ $AVDC_STEP -eq 330 ]] ; then
  1317.  
  1318. timedatectl set-timezone $REGION/$TIMEZONE
  1319. timedatectl
  1320.  
  1321. AVDC_STEP=340; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=340/' /etc/avorix/avdc_install.sh
  1322. fi
  1323.  
  1324. ###########################################################
  1325. # 3.4.            Configure the hosts file                #
  1326. ###########################################################
  1327. if [[ $AVDC_STEP -eq 340 ]] ; then
  1328.  
  1329. mv "$PATH_FILE_HOSTS_CONF" "$PATH_FILE_HOSTS_CONF.original"
  1330.  
  1331. touch "$PATH_FILE_HOSTS_CONF"
  1332.  
  1333. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1334. ln -sf "$PATH_FILE_HOSTS_CONF" "$OR_PATH_FILE_HOSTS_CONF"
  1335. fi
  1336.  
  1337. cat <<EOT >> "$PATH_FILE_HOSTS_CONF"
  1338. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  1339. # Generated on $(date)
  1340. #
  1341.  
  1342. #Localhost
  1343. 127.0.0.1     localhost localhost $DCNAME.$FQDN $DCNAME
  1344. ::1           localhost ip6-localhost ip6-loopback ip6-$DCNAME.$FQDN ip6-$DCNAME
  1345.  
  1346. #Might not be needed.
  1347. ff02::1       ip6-allnodes
  1348. ff02::2       ip6-allrouters
  1349. EOT
  1350.  
  1351. AVDC_STEP=350; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=350/' /etc/avorix/avdc_install.sh
  1352. fi
  1353.  
  1354.  
  1355. ###########################################################
  1356. # 3.5.                 Change the hostname                #
  1357. ###########################################################
  1358. if [[ $AVDC_STEP -eq 350 ]] ; then
  1359.  
  1360. #Change the hostname and backup the original.
  1361. mv "$PATH_FILE_HOSTNAME_CONF" "$PATH_FILE_HOSTNAME_CONF.original"
  1362.  
  1363. touch "$PATH_FILE_HOSTNAME_CONF"
  1364.  
  1365. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1366. ln -sf "$PATH_FILE_HOSTNAME_CONF" "$OR_PATH_FILE_HOSTNAME_CONF"
  1367. fi
  1368.  
  1369. cat <<EOT >> "$PATH_FILE_HOSTNAME_CONF"
  1370. $DCNAME.$FQDN
  1371. EOT
  1372.  
  1373. #Make the hostname for the current session active.
  1374. hostname $DCNAME.$FQDN
  1375.  
  1376. AVDC_STEP=360; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=360/' /etc/avorix/avdc_install.sh
  1377. fi
  1378.  
  1379.  
  1380. ###########################################################
  1381. # 3.6.         Configure a static IP-address              #
  1382. ###########################################################
  1383. if [[ $AVDC_STEP -eq 360 ]] ; then
  1384.  
  1385. #Change the IP-address to static.
  1386. #First create a backup.
  1387. mv "$PATH_FILE_DHCPCD_CONF" "$PATH_FILE_DHCPCD_CONF.original"
  1388. #Create an empty file.
  1389.  
  1390. touch "$PATH_FILE_DHCPCD_CONF"
  1391. #Link that file to the file that wil be used by DHCPCD.
  1392. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1393. ln -sf "$PATH_FILE_DHCPCD_CONF" "$OR_PATH_FILE_DHCPCD_CONF"
  1394. fi
  1395.  
  1396. cat <<EOT >> "$PATH_FILE_DHCPCD_CONF"
  1397. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION.
  1398. # Generated on $(date)
  1399. #
  1400.  
  1401. # See dhcpcd.conf(5) for details.
  1402.  
  1403. # Allow users of this group to interact with dhcpcd via the control socket.
  1404. #controlgroup wheel
  1405.  
  1406. # Inform the DHCP server of our hostname for DDNS.
  1407. hostname
  1408.  
  1409. # Use the hardware address of the interface for the Client ID.
  1410. clientid
  1411. # or
  1412. # Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
  1413. #duid
  1414.  
  1415. # Persist interface configuration when dhcpcd exits.
  1416. persistent
  1417.  
  1418. # Rapid commit support.
  1419. # Safe to enable by default because it requires the equivalent option set
  1420. # on the server to actually work.
  1421. option rapid_commit
  1422.  
  1423. # A list of options to request from the DHCP server.
  1424. option domain_name_servers, domain_name, domain_search, host_name
  1425. option classless_static_routes
  1426. # Most distributions have NTP support.
  1427. option ntp_servers
  1428. # Respect the network MTU.
  1429. # Some interface drivers reset when changing the MTU so disabled by default.
  1430. #option interface_mtu
  1431.  
  1432. # A ServerID is required by RFC2131.
  1433. require dhcp_server_identifier
  1434.  
  1435. # Generate Stable Private IPv6 Addresses instead of hardware based ones
  1436. slaac private
  1437.  
  1438. # A hook script is provided to lookup the hostname if not set by the DHCP
  1439. # server, but it should not be run by default.
  1440. nohook lookup-hostname
  1441.  
  1442. interface eth0
  1443. static ip_address=$IP_ADDRESS/$SUBNETMASKBITS
  1444. static routers=$GATEWAY
  1445. static domain_name_servers=$DNSSERVER1, $DNSSERVER2
  1446. EOT
  1447.  
  1448. #After this step the user could lose internet connectivity.
  1449. ifconfig eth0 $IP_ADDRESS/$SUBNETMASKBITS
  1450. systemctl stop $DAEMON_DHCPCD
  1451. sleep 5s
  1452. systemctl start $DAEMON_DHCPCD
  1453. systemctl daemon-reload
  1454.  
  1455. #Check if the DHCPCD configuration passes DHCPCD's test.
  1456. if [ $(systemctl is-active $DAEMON_DHCPCD) = "active" ] ; then
  1457.     DHCPCD_SERVICE_STATUS=1
  1458.     systemctl enable $DAEMON_DHCPCD
  1459. else
  1460.     DHCPCD_SERVICE_STATUS=0
  1461.     setterm -term linux -back red -fore white
  1462.     echo "###########################################################"
  1463.     echo "# Error: Installation stopped!                            #"
  1464.     echo "###########################################################"
  1465.     echo "Reason:"
  1466.     echo " - Your Network (DHCPCD) settings are incorrect."
  1467.     echo ""
  1468.     echo "Solution:"
  1469.     echo " - Make sure that the settings abide to:"
  1470.     echo "  - Not containing any illegal characters!"
  1471.     echo "  - Correct IP-addresses."
  1472.     echo "  - Correct Subnetmaskbits: Calculate one at: http://jodies.de/ipcalc"
  1473.     echo "  - Check: systemctl $DAEMON_DHCPCD status -l, for more details."
  1474.     echo "###########################################################"
  1475.     pause_with_msg
  1476.     setterm -default
  1477.     exit
  1478. fi
  1479.  
  1480. AVDC_STEP=370; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=370/' /etc/avorix/avdc_install.sh
  1481. fi
  1482.  
  1483.  
  1484. ###########################################################
  1485. # 3.7.          Configure the NTP-server                  #
  1486. ###########################################################
  1487. if [[ $AVDC_STEP -eq 370 ]] ; then
  1488.  
  1489. #If function FIREWALL is enabled then allow NTP to send and recieve over the network.
  1490. if [ "$FIREWALL" -eq "1" ]; then
  1491.     firewall-cmd --permanent --zone=public --add-port=123/udp
  1492. fi
  1493.  
  1494. mv "$PATH_FILE_NTP_CONF" "$PATH_FILE_NTP_CONF.original"
  1495.  
  1496. touch "$PATH_FILE_NTP_CONF"
  1497.  
  1498. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1499. ln -sf "$PATH_FILE_NTP_CONF" "$OR_PATH_FILE_NTP_CONF"
  1500. fi
  1501.  
  1502. cat <<EOT >> "$PATH_FILE_NTP_CONF"
  1503. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  1504. # Generated on $(date)
  1505. #
  1506.  
  1507. # Local clock. Note that is not the "localhost" address!
  1508. server 127.127.1.0
  1509. fudge  127.127.1.0 stratum 10
  1510.  
  1511. # Where to retrieve the time from
  1512. server $NTPSERVER1     iburst prefer
  1513. server $NTPSERVER2     iburst prefer
  1514. server $NTPSERVER3     iburst prefer
  1515. EOT
  1516.  
  1517. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1518. cat <<'EOT' >> "$PATH_FILE_NTP_CONF"
  1519.  
  1520. driftfile       $PATH_FILE_NTP_DRIFT
  1521. logfile         $PATH_FILE_NTP_LOG
  1522. ntpsigndsocket  $PATH_FILE_NTP_SOCKET
  1523. EOT
  1524.  
  1525. else
  1526. cat <<EOT >> "$PATH_FILE_NTP_CONF"
  1527.  
  1528. driftfile       $PATH_FILE_NTP_DRIFT
  1529. logfile         $PATH_FILE_NTP_LOG
  1530. ntpsigndsocket  $PATH_FILE_NTP_SOCKET
  1531. EOT
  1532.  
  1533. fi
  1534.  
  1535. cat <<EOT >> "$PATH_FILE_NTP_CONF"
  1536.  
  1537. # Access control
  1538. # Default restriction: Allow clients only to query the time
  1539. restrict default kod nomodify notrap nopeer mssntp
  1540.  
  1541. # No restrictions for "localhost"
  1542. restrict 127.0.0.1
  1543.  
  1544. # Enable the time sources to only provide time to this host
  1545. restrict $NTPSERVER1   mask 255.255.255.255    nomodify notrap nopeer noquery
  1546. restrict $NTPSERVER2   mask 255.255.255.255    nomodify notrap nopeer noquery
  1547. restrict $NTPSERVER3   mask 255.255.255.255    nomodify notrap nopeer noquery
  1548. EOT
  1549.  
  1550. systemctl stop $DAEMON_NTP
  1551. sleep 5s
  1552. systemctl start $DAEMON_NTP
  1553.  
  1554. #Check if the NTP configuration passes NTP's test.
  1555. if [ "$SKIP_SERVICES_CHECK" -eq "0" ] ; then
  1556. if [ "$(systemctl is-active $DAEMON_NTP)" = "active" ] ; then
  1557.     NTP_SERVICE_STATUS=1
  1558.     systemctl enable $DAEMON_NTP
  1559. else
  1560.     NTP_SERVICE_STATUS=0
  1561.     setterm -term linux -back red -fore white
  1562.     echo "###########################################################"
  1563.     echo "# Error: Installation stopped!                            #"
  1564.     echo "###########################################################"
  1565.     echo "Reason:"
  1566.     echo " - Your Time (NTP) settings are incorrect."
  1567.     echo ""
  1568.     echo "Solution:"
  1569.     echo " - Make sure that the settings abide to:"
  1570.     echo "  - Not containing any illegal characters!"
  1571.     echo "  - Containing a correct Timezone/Region:"
  1572.     echo "    Display all Timezones using: ls /usr/share/zoneinfo"
  1573.     echo "    Display all Regions within a timezone using:"
  1574.     echo "     ls /usr/share/zoneinfo/Your_timezone/"
  1575.     echo ""
  1576.     echo "  - Check: systemctl $DAEMON_NTP status -l, for more details."
  1577.     echo "###########################################################"
  1578.     pause_with_msg
  1579.     setterm -default
  1580.     exit
  1581. fi
  1582. fi
  1583.  
  1584. AVDC_STEP=380; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=380/' /etc/avorix/avdc_install.sh
  1585. fi
  1586.  
  1587.  
  1588. ###########################################################
  1589. # 3.8.       Configure the Domain Controller              #
  1590. ###########################################################
  1591. if [[ $AVDC_STEP -eq 380 ]] ; then
  1592.  
  1593. if [ "$FIREWALL" -eq "1" ] ; then
  1594.     #SAMBA: DNS
  1595.     firewall-cmd --permanent --zone=public --add-port=53/tcp
  1596.     firewall-cmd --permanent --zone=public --add-port=53/udp
  1597.  
  1598.     #SAMBA: Kerberos
  1599.     firewall-cmd --permanent --zone=public --add-port=88/tcp
  1600.     firewall-cmd --permanent --zone=public --add-port=88/udp
  1601.  
  1602.     #SAMBA: End Point Mapper (DCE\RPC Locator Service)
  1603.     firewall-cmd --permanent --zone=public --add-port=135/tcp
  1604.  
  1605.     #SAMBA: NetBIOS Name Service
  1606.     firewall-cmd --permanent --zone=public --add-port=137/udp
  1607.  
  1608.     #SAMBA: NetBIOS Datagram
  1609.     firewall-cmd --permanent --zone=public --add-port=138/udp
  1610.  
  1611.     #SAMBA: NetBIOS Session
  1612.     firewall-cmd --permanent --zone=public --add-port=139/udp
  1613.  
  1614.     #SAMBA: LDAP
  1615.     firewall-cmd --permanent --zone=public --add-port=389/tcp
  1616.     firewall-cmd --permanent --zone=public --add-port=389/udp
  1617.     #firewall-cmd --permanent --zone=public --add-port=636/tcp #For TLS-encryption
  1618.  
  1619.     #SAMBA: SMB over TCP
  1620.     firewall-cmd --permanent --zone=public --add-port=445/tcp
  1621.  
  1622.     #SAMBA: Kerberos kpasswd
  1623.     firewall-cmd --permanent --zone=public --add-port=464/tcp
  1624.     firewall-cmd --permanent --zone=public --add-port=464/udp
  1625.  
  1626.     #SAMBA: Global Catalog
  1627.     firewall-cmd --permanent --zone=public --add-port=3268/tcp
  1628.     #firewall-cmd --permanent --zone=public --add-port=3269/tcp #For TLS-encryption
  1629.  
  1630.     #SAMBA: Dynamic RPC Ports
  1631.     firewall-cmd --permanent --add-port=1024-5000/tcp
  1632.     firewall-cmd --permanent --add-port=1024-5000/udp
  1633. fi
  1634.  
  1635. #Linking the configs to the USB and creating the DC.
  1636. mv "$PATH_FILE_SAMBA_CONF" "$PATH_FILE_SAMBA_CONF.original"
  1637.  
  1638. if [ "$JOIN_A_DOMAIN" -eq "1" ] ; then
  1639.  
  1640.     mv "$PATH_FILE_SAMBA_CONF" "$PATH_FILE_SAMBA_CONF.before_provision"
  1641.  
  1642.     samba-tool domain join $FQDN DC -U "$NBIOS\administrator" --dns-backend=SAMBA_INTERNAL
  1643.  
  1644.     cp "$PATH_FILE_KRB5_CONF_EXAMPLE" "$PATH_FILE_KRB5_CONF"
  1645.  
  1646.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1647.     ln -sf "$PATH_FILE_SAMBA_CONF" "$OR_PATH_FILE_SAMBA_CONF"
  1648.     ln -sf "$PATH_FILE_KRB5_CONF" "$OR_PATH_FILE_KRB5_CONF"
  1649.     fi
  1650.  
  1651. cat <<EOT >> "$PATH_FILE_KRB5_CONF"
  1652.  
  1653. [libdefaults]
  1654.     dns_lookup_realm = false
  1655.     dns_lookup_kdc = true
  1656.     default_realm = $FQDN
  1657.  
  1658. EOT
  1659.  
  1660. else
  1661.  
  1662.     mv "$PATH_FILE_SAMBA_CONF" "$PATH_FILE_SAMBA_CONF.before_provision"
  1663.  
  1664.     samba-tool domain provision --server-role=dc --use-rfc2307 --dns-backend=SAMBA_INTERNAL --realm=$FQDN --domain=$NBIOS --host-name=$DCNAME --adminpass="$ADMINPWD" --host-ip=$IP_ADDRESS
  1665.  
  1666.     cp "$PATH_FILE_KRB5_CONF_EXAMPLE" "$PATH_FILE_KRB5_CONF"
  1667.  
  1668.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1669.     ln -sf "$PATH_FILE_SAMBA_CONF" "$OR_PATH_FILE_SAMBA_CONF"
  1670.     ln -sf "$PATH_FILE_KRB5_CONF" "$OR_PATH_FILE_KRB5_CONF"
  1671.     fi
  1672.  
  1673. cat <<'EOT' >> "$PATH_FILE_SAMBA_CONF"
  1674.  
  1675. [users]
  1676.        path = $LOCATION_OF_IMPORTANT_FILES/SAMBA/Shares/Users
  1677.  
  1678.        read only = no
  1679. EOT
  1680.  
  1681. fi
  1682.  
  1683. if [ "$PXE_SERVER" -eq "2" ] ; then
  1684. cat <<EOT >> "$PATH_FILE_SAMBA_CONF"
  1685.  
  1686. [wininstall]
  1687.     comment = Windows Installers
  1688. EOT
  1689. fi
  1690.  
  1691. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1692. cat <<'EOT' >> "$PATH_FILE_SAMBA_CONF"
  1693.     path = $PATH_FOLDER_SAMBA_SETUP
  1694. EOT
  1695.  
  1696. else
  1697. cat <<EOT >> "$PATH_FILE_SAMBA_CONF"
  1698.     path = $PATH_FOLDER_SAMBA_SETUP
  1699. EOT
  1700.  
  1701. fi
  1702.  
  1703. cat <<EOT >> "$PATH_FILE_SAMBA_CONF"
  1704.     guest ok = yes
  1705.     writable = no
  1706.     browsable = yes
  1707. EOT
  1708.  
  1709. fi
  1710.  
  1711. #Not neccesary. All these daemons are combined in later versions in 1 specialized daemon for Samba Active Directory.
  1712. #systemctl stop $DAEMON_SMBD
  1713. #sleep 5s
  1714. #systemctl start $DAEMON_SMBD
  1715. #sleep 1s
  1716. #systemctl stop $DAEMON_NMBD
  1717. #sleep 5s
  1718. #systemctl start $DAEMON_NMBD
  1719. #sleep 1s
  1720.  
  1721. if [ "$REORDER_AVAHI_DNS" -eq "1" ] ; then
  1722.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1723.     sed -i -e 's#TFTP_DIRECTORY="/srv/tftp"#TFTP_DIRECTORY="$PXE_TFTP_ROOT"#g' "$PATH_FILE_AVAHI_CONF"
  1724.     else
  1725.     sed -i -e "s#TFTP_DIRECTORY="/srv/tftp"#TFTP_DIRECTORY="$PXE_TFTP_ROOT"#g" "$PATH_FILE_AVAHI_CONF"
  1726.  
  1727. fi
  1728.  
  1729. systemctl unmask "$DAEMON_SAMBA_AD_DC"
  1730. systemctl start "$DAEMON_SAMBA_AD_DC"
  1731.  
  1732. #Check if the SAMBA configuration passes SAMBA's test.
  1733. if [ "$SKIP_SERVICES_CHECK" -eq "0" ] ; then
  1734. if [ "$(systemctl is-active $DAEMON_NMBD)" = "active" ] ; then
  1735.     SAMBA_SERVICE_STATUS=1
  1736. #   systemctl enable $DAEMON_SMBD
  1737. #   systemctl enable $DAEMON_NMBD
  1738.     systemctl enable "$DAEMON_SAMBA_AD_DC"
  1739. else
  1740.     SAMBA_SERVICE_STATUS=0
  1741.     setterm -term linux -back red -fore white
  1742.     echo "###########################################################"
  1743.     echo "# Error: Installation stopped!                            #"
  1744.     echo "###########################################################"
  1745.     echo "Reason:"
  1746.     echo " - Your SAMBA settings are incorrect."
  1747.     echo ""
  1748.     echo "Solution:"
  1749.     echo " - Make sure that the settings abide to:"
  1750.     echo "  - Not containing any illegal characters!"
  1751.     echo "  - Containing a correct FQDN, NetBiosname and DCName."
  1752. #   echo "  - Check: systemctl $DAEMON_SMBD status -l, for more details."
  1753. #   echo "  - Check: systemctl $DAEMON_NMBD status -l, for more details."
  1754.     echo "  - Check: systemctl $DAEMON_SAMBA_AD_DC status -l, for more details."
  1755.     echo "###########################################################"
  1756.     pause_with_msg
  1757.     setterm -default
  1758.     exit
  1759. fi
  1760. fi
  1761. AVDC_STEP=410; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=410/' /etc/avorix/avdc_install.sh
  1762. fi
  1763.  
  1764.  
  1765. ###########################################################
  1766. #                                                         #
  1767. # 4.                The fase of adaption                  #
  1768. #                                                         #
  1769. ###########################################################
  1770.  
  1771. ###########################################################
  1772. # 4.1. (Optional)          Configure SSH                  #
  1773. ###########################################################
  1774. if [[ $AVDC_STEP -eq 410 ]] ; then
  1775.  
  1776. #SSH allows us to remotely open a terminal shell.
  1777. #Within a terminal shell we are able to completely modify the system.
  1778. #But if you are only in to modifying Active Directory just install the RSAT-tools, you won't need SSH.
  1779.  
  1780. if [ "$SSH_SERVER" -eq "1" ] ; then
  1781.     #If the SSH user needs SSH access, create the SSH group and the SSH user.
  1782.     if [ "$SSH_USER_SUDO" -eq "1" ] ; then
  1783.     groupadd ssh
  1784.     echo '%ssh  ALL=(ALL:ALL) ALL' >> "$PATH_FILE_SUDO_CONF"
  1785.     useradd $SSH_USER -p "$SSH_USER_PASSWORD" -d "/home/$SSH_USER" -g ssh -g sudo -m
  1786.     else
  1787.     groupadd ssh
  1788.     mkdir /home/$SSH_USER
  1789.     useradd $SSH_USER -p "$SSH_USER_PASSWORD" -d "/home/$SSH_USER" -g ssh -m
  1790.     fi
  1791.  
  1792.     if [ "$FIREWALL" -eq "1" ] ; then
  1793.     if [ "$SSH_PORTKNOCKING" -eq "1" ] ; then
  1794.     #cp "$PATH_FILE_KNOCKD_CONF" "$LOCATION_OF_IMPORTANT_FILES/KNOCKD/Configuration"
  1795.  
  1796.     mv "$PATH_FILE_KNOCKD_CONF" "$PATH_FILE_KNOCKD_CONF.original"
  1797.     mv "$PATH_FILE_KNOCKD_DEFAULT" "$PATH_FILE_KNOCKD_DEFAULT.original"
  1798.  
  1799.     touch "$PATH_FILE_KNOCKD_CONF"
  1800.     touch "$PATH_FILE_KNOCKD_DEFAULT"
  1801.  
  1802.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1803.     ln -sf "$PATH_FILE_KNOCKD_CONF" "$OR_PATH_FILE_KNOCKD_CONF"
  1804.     ln -sf "$PATH_FILE_KNOCKD_DEFAULT" "$OR_PATH_FILE_KNOCKD_DEFAULT"
  1805.     fi
  1806.  
  1807. cat <<EOT >> "$PATH_FILE_KNOCKD_CONF"
  1808.  
  1809. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  1810. # Generated on $(date)
  1811. #
  1812.  
  1813. [options]
  1814. EOT
  1815.  
  1816.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1817. cat <<'EOT' >> "$PATH_FILE_KNOCKD_CONF"
  1818.     logfile = $PATH_FILE_KNOCKD_LOG
  1819. EOT
  1820.  
  1821.     else
  1822. cat <<EOT >> "$PATH_FILE_KNOCKD_CONF"
  1823.     logfile = $PATH_FILE_KNOCKD_LOG
  1824. EOT
  1825.  
  1826.     fi
  1827.  
  1828. cat <<EOT >> "$PATH_FILE_KNOCKD_CONF"
  1829.  
  1830. [openSSH]
  1831.     sequence    = $SSH_PORTKNOCKING_OPEN_SEQ1,$SSH_PORTKNOCKING_OPEN_SEQ2,$SSH_PORTKNOCKING_OPEN_SEQ3
  1832.     seq_timeout = 10
  1833.     command     = /usr/sbin/firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="%IP%" port protocol="tcp" port="$SSH_PORT" accept'
  1834.     tcpflags    = syn
  1835.  
  1836. [closeSSH]
  1837.     sequence    = $SSH_PORTKNOCKING_CLOSE_SEQ1,$SSH_PORTKNOCKING_CLOSE_SEQ1,$SSH_PORTKNOCKING_CLOSE_SEQ1
  1838.     seq_timeout = 10
  1839.     command     = /usr/sbin/firewall-cmd --permanent --zone=public --remove-rich-rule='rule family="ipv4" source address="%IP%" port protocol="tcp" port="$SSH_PORT" accept'
  1840.     tcpflags    = syn
  1841. EOT
  1842.  
  1843.     sed -i -e 's/START_KNOCKD=0/START_KNOCKD=1/g' "$PATH_FILE_KNOCKD_CONF"
  1844.  
  1845.     systemctl start $DAEMON_KNOCKD
  1846.     systemctl enable $DAEMON_KNOCKD
  1847.     firewall-cmd --permanent --zone=public --add-port=$SSH_PORT/tcp
  1848.     fi
  1849.  
  1850.     if [ "$SSH_FAIL2BAN" -eq "2" ] ; then
  1851.     mv "$PATH_FILE_FAIL2BAN_JAIL" "$PATH_FILE_FAIL2BAN_JAIL.original"
  1852.     touch "$PATH_FILE_FAIL2BAN_JAIL"
  1853.  
  1854.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1855.     ln -sf "$PATH_FILE_FAIL2BAN_JAIL" "$OR_PATH_FILE_FAIL2BAN_JAIL"
  1856.     fi
  1857.  
  1858. cat <<EOT >> "$PATH_FILE_FAIL2BAN_JAIL"
  1859.  
  1860. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  1861. # Generated on $(date)
  1862. #
  1863.  
  1864. [ssh]
  1865.  
  1866. enabled = true
  1867. port = $SSH_PORT
  1868. filter = sshd
  1869. EOT
  1870.  
  1871.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1872. cat <<'EOT' >> "$PATH_FILE_FAIL2BAN_JAIL"
  1873. logpath = $LOCATION_OF_IMPORTANT_FILES/FAIL2BAN/Logs/auth.log
  1874. EOT
  1875.  
  1876.     else
  1877. cat <<EOT >> "$PATH_FILE_FAIL2BAN_JAIL"
  1878. logpath = $LOCATION_OF_IMPORTANT_FILES/FAIL2BAN/Logs/auth.log
  1879. EOT
  1880.  
  1881.     fi
  1882. cat <<EOT >> "$PATH_FILE_FAIL2BAN_JAIL"
  1883.  
  1884. bantime = $SSH_FAIL2BAN_BANTIME
  1885. banaction = iptables-allports
  1886. findtime = $SSH_FAIL2BAN_FINDTIME
  1887. maxretry = $SSH_FAIL2BAN_MAXRETRY
  1888. EOT
  1889.  
  1890.     systemctl start $DAEMON_FAIL2BAN
  1891.     systemctl enable $DAEMON_FAIL2BAN
  1892.     fi
  1893.  
  1894.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1895.     mv "$OR_PATH_FOLDER_SSH_KEYS/ssh_host_*" "$PATH_FOLDER_SSH_KEYS/"
  1896.     fi
  1897.  
  1898.     mv "$PATH_FILE_SSH_CONF" "$PATH_FILE_SSH_CONF.original"
  1899.     touch "$PATH_FILE_SSH_CONF"
  1900.  
  1901.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1902.     ln -sf "$PATH_FILE_SSH_CONF" "$OR_PATH_FILE_SSH_CONF"
  1903.     fi
  1904.  
  1905. cat <<EOT >> "$PATH_FILE_SSH_CONF"
  1906. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  1907. # Generated on $(date)
  1908. #
  1909.  
  1910. # See the sshd_config(5) manpage for details
  1911.  
  1912. # What ports, IPs and protocols we listen for
  1913. Port $SSH_PORT
  1914. # Use these options to restrict which interfaces/protocols sshd will bind to
  1915. #ListenAddress ::
  1916. #ListenAddress 0.0.0.0
  1917. Protocol 2
  1918. # HostKeys for protocol version 2
  1919. EOT
  1920.  
  1921.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  1922. cat <<'EOT' >> "$PATH_FILE_SSH_CONF"
  1923. HostKey $PATH_FOLDER_SSH_KEYS/ssh_host_rsa_key
  1924. HostKey $PATH_FOLDER_SSH_KEYS/ssh_host_dsa_key
  1925. HostKey $PATH_FOLDER_SSH_KEYS/ssh_host_ecdsa_key
  1926. HostKey $PATH_FOLDER_SSH_KEYS/ssh_host_ed25519_key
  1927. EOT
  1928.  
  1929.     else
  1930. cat <<EOT >> "$PATH_FILE_SSH_CONF"
  1931. HostKey $PATH_FOLDER_SSH_KEYS/ssh_host_rsa_key
  1932. HostKey $PATH_FOLDER_SSH_KEYS/ssh_host_dsa_key
  1933. HostKey $PATH_FOLDER_SSH_KEYS/ssh_host_ecdsa_key
  1934. HostKey $PATH_FOLDER_SSH_KEYS/ssh_host_ed25519_key
  1935. EOT
  1936.  
  1937.     fi
  1938.  
  1939. cat <<EOT >> "$PATH_FILE_SSH_CONF"
  1940. #Privilege Separation is turned on for security
  1941. UsePrivilegeSeparation yes
  1942.  
  1943. # Lifetime and size of ephemeral version 1 server key
  1944. KeyRegenerationInterval 3600
  1945. ServerKeyBits 1024
  1946.  
  1947. # Logging
  1948. SyslogFacility AUTH
  1949. LogLevel INFO
  1950.  
  1951. # Authentication:
  1952. LoginGraceTime 120
  1953. PermitRootLogin yes
  1954. StrictModes yes
  1955.  
  1956. RSAAuthentication yes
  1957. PubkeyAuthentication yes
  1958. #AuthorizedKeysFile     %h/.ssh/authorized_keys
  1959.  
  1960. # Don't read the user's ~/.rhosts and ~/.shosts files
  1961. IgnoreRhosts yes
  1962. # For this to work you will also need host keys in /etc/ssh_known_hosts
  1963. RhostsRSAAuthentication no
  1964. # similar for protocol version 2
  1965. HostbasedAuthentication no
  1966. # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
  1967. #IgnoreUserKnownHosts yes
  1968.  
  1969. # To enable empty passwords, change to yes (NOT RECOMMENDED)
  1970. PermitEmptyPasswords no
  1971.  
  1972. # Change to yes to enable challenge-response passwords (beware issues with
  1973. # some PAM modules and threads)
  1974. EOT
  1975.  
  1976.  
  1977.     if [ "$SSH_2FA" -eq "1" ] ; then
  1978.     if [ "$SSH_2FA_FORCE" -eq "1" ] ; then
  1979.     sed -i '1s/^/auth   required   pam_google_authenticator.so\n/' "$PATH_FILE_PAMD_SSHD"
  1980.     else
  1981.     sed -i '1s/^/auth   required   pam_google_authenticator.so   nullok\n/' "$PATH_FILE_PAMD_SSHD"
  1982.     fi
  1983.  
  1984. cat <<EOT >> "$PATH_FILE_SSH_CONF"
  1985. ChallengeResponseAuthentication yes
  1986. EOT
  1987.  
  1988. cat <<EOT >> "/etc/avorix/avdc_generate_2fa.sh"
  1989. pause_with_msg(){
  1990.     read -r -p "Press [Enter] to continue..." fackEnterKey
  1991. }
  1992.  
  1993. google-authenticator -t --qr-mode=utf8
  1994. google-authenticator --emergency-codes=5 > $LOCATION_OF_IMPORTANT_FILES/Google_Authenticator_Emergency_Codes_$USER.txt
  1995. pause_with_msg
  1996. EOT
  1997.  
  1998. chmod +x /etc/avorix/avdc_generate_2fa.sh
  1999. sed -i '//etc/avorix/avdc_generate_2fa.sh/d' "/$SSH_USER/.bashrc"
  2000.  
  2001.     else
  2002. cat <<EOT >> "$PATH_FILE_SSH_CONF"
  2003. ChallengeResponseAuthentication no
  2004. EOT
  2005.  
  2006.     fi
  2007.  
  2008. cat <<EOT >> "$PATH_FILE_SSH_CONF"
  2009.  
  2010. # Change to no to disable tunnelled clear text passwords
  2011. PasswordAuthentication yes
  2012.  
  2013. # Kerberos options
  2014. #KerberosAuthentication no
  2015. #KerberosGetAFSToken no
  2016. #KerberosOrLocalPasswd yes
  2017. #KerberosTicketCleanup yes
  2018.  
  2019. # GSSAPI options
  2020. #GSSAPIAuthentication no
  2021. #GSSAPICleanupCredentials yes
  2022.  
  2023. X11Forwarding yes
  2024. X11DisplayOffset 10
  2025. PrintMotd no
  2026. PrintLastLog yes
  2027. TCPKeepAlive yes
  2028. #UseLogin no
  2029.  
  2030. #MaxStartups 10:30:60
  2031.  
  2032. EOT
  2033.  
  2034.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2035. cat <<'EOT' >> "$PATH_FILE_SSH_CONF"
  2036. Banner $PATH_FILE_ISSUENET
  2037. EOT
  2038.  
  2039.     else
  2040. cat <<EOT >> "$PATH_FILE_SSH_CONF"
  2041. Banner $PATH_FILE_ISSUENET
  2042. EOT
  2043.  
  2044.     fi
  2045.  
  2046. cat <<EOT >> "$PATH_FILE_SSH_CONF"
  2047. # Allow client to pass locale environment variables
  2048. AcceptEnv LANG LC_*
  2049.  
  2050. Subsystem sftp /usr/lib/openssh/sftp-server
  2051.  
  2052. # Set this to 'yes' to enable PAM authentication, account processing,
  2053. # and session processing. If this is enabled, PAM authentication will
  2054. # be allowed through the ChallengeResponseAuthentication and
  2055. # PasswordAuthentication.  Depending on your PAM configuration,
  2056. # PAM authentication via ChallengeResponseAuthentication may bypass
  2057. # the setting of "PermitRootLogin without-password".
  2058. # If you just want the PAM account and session checks to run without
  2059. # PAM authentication, then enable this but set PasswordAuthentication
  2060. # and ChallengeResponseAuthentication to 'no'.
  2061. UsePAM yes
  2062.  
  2063. # Automaticly kick the user after 5 minutes of inactivity.
  2064. # ClientAliveInterval 300
  2065. # ClientAliveCountMax 0
  2066.  
  2067. # Only allow users that are in the SSH-group.
  2068. # AllowGroups ssh
  2069. EOT
  2070.  
  2071. systemctl stop $DAEMON_SSH
  2072. sleep 5s
  2073. systemctl start $DAEMON_SSH
  2074.  
  2075. #Check if the SSH configuration passes SSH's test.
  2076.     if [ "$SKIP_SERVICES_CHECK" -eq "0" ] ; then
  2077.     if [ "$(systemctl is-active $DAEMON_SSH)" = "active" ] ; then
  2078.     SSH_SERVICE_STATUS=1
  2079.     systemctl enable $DAEMON_SSH
  2080.     else
  2081.     SSH_SERVICE_STATUS=0
  2082.     setterm -term linux -back red -fore white
  2083.     echo "###########################################################"
  2084.     echo "# Error: Installation stopped!                            #"
  2085.     echo "###########################################################"
  2086.     echo "Reason:"
  2087.     echo " - Your SSH settings are incorrect."
  2088.     echo ""
  2089.     echo "Solution:"
  2090.     echo " - Make sure that the settings abide to:"
  2091.     echo "  - Not containing any illegal characters!"
  2092.     echo "  - Containing a correct portnumber."
  2093.     echo "  - Check: systemctl $DAEMON_SSH status -l, for more details."
  2094.     echo "###########################################################"
  2095.     pause_with_msg
  2096.     setterm -default
  2097.     exit
  2098.     fi
  2099.     fi
  2100. fi
  2101. fi
  2102. AVDC_STEP=420; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=420/' /etc/avorix/avdc_install.sh
  2103. fi
  2104.  
  2105.  
  2106. ###########################################################
  2107. # 4.2.     (Optional) Configure the DHCP server           #
  2108. ###########################################################
  2109. if [[ $AVDC_STEP -eq 420 ]] ; then
  2110.  
  2111. #In some situations and environments you do not want to have an additional DHCP-server.
  2112. #As there can only be 1 DHCP-server in a network. Having multiple will cause network failure.
  2113. #But to make the Domain Controller reachable you will need to let the DHCP-server instruct the devices on the network
  2114. #to use the DNS, NTP and the NetBIOS server of the Domain Controller.
  2115. if [ "$DHCP_SERVER" -eq "1" ] && [ "$FIREWALL" -eq "1" ] ; then
  2116.     firewall-cmd --permanent --zone=public --add-port=67/udp
  2117. fi
  2118.  
  2119. if [ "$DHCP_SERVER" -eq "1" ] ; then
  2120.     mv "$PATH_FILE_DHCPD_CONF" "$PATH_FILE_DHCPD_CONF.original"
  2121.     touch "$PATH_FILE_DHCPD_CONF"
  2122.  
  2123.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2124.     ln -sf "$PATH_FILE_DHCPD_CONF" "$OR_PATH_FILE_DHCPD_CONF"
  2125.     fi
  2126.  
  2127. cat <<EOT >> "$PATH_FILE_DHCPD_CONF"
  2128. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  2129. # Generated on $(date)
  2130.  
  2131. EOT
  2132.  
  2133.     if [ "$PXE_SERVER" -eq "2" ] ; then
  2134. cat <<EOT >> "$PATH_FILE_DHCPD_CONF"
  2135.   option space ipxe;
  2136.   option ipxe-encap-opts code 175 = encapsulate ipxe;
  2137.   option ipxe.priority code 1 = signed integer 8;
  2138.   option ipxe.keep-san code 8 = unsigned integer 8;
  2139.   option ipxe.skip-san-boot code 9 = unsigned integer 8;
  2140.   option ipxe.syslogs code 85 = string;
  2141.   option ipxe.cert code 91 = string;
  2142.   option ipxe.privkey code 92 = string;
  2143.   option ipxe.crosscert code 93 = string;
  2144.   option ipxe.no-pxedhcp code 176 = unsigned integer 8;
  2145.   option ipxe.bus-id code 177 = string;
  2146.   option ipxe.bios-drive code 189 = unsigned integer 8;
  2147.   option ipxe.username code 190 = string;
  2148.   option ipxe.password code 191 = string;
  2149.   option ipxe.reverse-username code 192 = string;
  2150.   option ipxe.reverse-password code 193 = string;
  2151.   option ipxe.version code 235 = string;
  2152.   option iscsi-initiator-iqn code 203 = string;
  2153.  
  2154.   # Feature indicators
  2155.   option ipxe.pxeext code 16 = unsigned integer 8;
  2156.   option ipxe.iscsi code 17 = unsigned integer 8;
  2157.   option ipxe.aoe code 18 = unsigned integer 8;
  2158.   option ipxe.http code 19 = unsigned integer 8;
  2159.   option ipxe.https code 20 = unsigned integer 8;
  2160.   option ipxe.tftp code 21 = unsigned integer 8;
  2161.   option ipxe.ftp code 22 = unsigned integer 8;
  2162.   option ipxe.dns code 23 = unsigned integer 8;
  2163.   option ipxe.bzimage code 24 = unsigned integer 8;
  2164.   option ipxe.multiboot code 25 = unsigned integer 8;
  2165.   option ipxe.slam code 26 = unsigned integer 8;
  2166.   option ipxe.srp code 27 = unsigned integer 8;
  2167.   option ipxe.nbi code 32 = unsigned integer 8;
  2168.   option ipxe.pxe code 33 = unsigned integer 8;
  2169.   option ipxe.elf code 34 = unsigned integer 8;
  2170.   option ipxe.comboot code 35 = unsigned integer 8;
  2171.   option ipxe.efi code 36 = unsigned integer 8;
  2172.   option ipxe.fcoe code 37 = unsigned integer 8;
  2173.   option ipxe.vlan code 38 = unsigned integer 8;
  2174.   option ipxe.menu code 39 = unsigned integer 8;
  2175.   option ipxe.sdi code 40 = unsigned integer 8;
  2176.   option ipxe.nfs code 41 = unsigned integer 8;
  2177.   option ipxe.no-pxedhcp 1;
  2178.  
  2179. EOT
  2180.  
  2181. cat <<EOT >> "$PATH_FILE_DHCPD_CONF"
  2182. autorative;
  2183.  
  2184. subnet $DHCP_SUBNET netmask $DHCP_SUBNETMASK {
  2185.   max-lease-time $DHCP_MAX_LEASE_TIME; # 30 minutes
  2186.   range $DHCP_FIRST_IP_ADDRESS $DHCP_LAST_IP_ADDRESS;
  2187.   option subnet-mask $DHCP_SUBNETMASK;
  2188.   option broadcast-address $BROADCASTADDRESS;
  2189.   option time-offset 0;
  2190.   option routers $DHCP_GATEWAY;
  2191.   option domain-name "$FQDN";
  2192.   option domain-name-servers $DHCP_DNSSERVER1, $DHCP_DNSSERVER2;
  2193.   option netbios-name-servers $DHCP_NETBIOSSERVER;
  2194.   option ntp-servers $DHCP_NTPSERVER1, $DHCP_NTPSERVER2;
  2195. EOT
  2196.  
  2197.     #Had to split these up as Cat doesn't like some characters.
  2198. cat <<EOT >> "$PATH_FILE_DHCPD_CONF"
  2199.   next-server $IP_ADDRESS;
  2200. EOT
  2201.  
  2202. cat <<'EOT' >> "$PATH_FILE_DHCPD_CONF"
  2203.   option client-arch code 93 = unsigned integer 16;
  2204.   if option client-arch != 0 {
  2205.      filename "ipxe.efi";
  2206.   } else {
  2207.      filename "undionly.kpxe";
  2208.   }
  2209.  
  2210.   if exists user-class and option user-class = "iPXE" {
  2211. EOT
  2212.  
  2213. cat <<EOT >> "$PATH_FILE_DHCPD_CONF"
  2214.     filename = "http://$IP_ADDRESS/boot.ipxe";
  2215. EOT
  2216.  
  2217. cat <<'EOT' >> "$PATH_FILE_DHCPD_CONF"
  2218.   } else {
  2219.     filename = "undionly.kpxe";
  2220.   }
  2221. EOT
  2222.  
  2223. cat <<EOT >> "$PATH_FILE_DHCPD_CONF"
  2224. }
  2225. EOT
  2226.  
  2227. cat <<'EOT' >> "$PXE_TFTP_ROOT/boot.ipxe"
  2228.   #!ipxe
  2229.  
  2230.   cpuid --ext 29 && set arch amd64 || set arch x86
  2231.   kernel wimboot
  2232.   initrd ${arch}/media/Boot/BCD                     BCD
  2233.   initrd ${arch}/media/Boot/boot.sdi                boot.sdi
  2234.   initrd ${arch}/media/sources/boot.wim             boot.wim
  2235.   boot
  2236. EOT
  2237.  
  2238.     fi
  2239.  
  2240.     systemctl stop $DAEMON_DHCPD
  2241.     sleep 5s
  2242.     systemctl start $DAEMON_DHCPD
  2243.  
  2244. #Check if the ISC-DHCP-Server configuration passes ISC-DHCP-Server's test.
  2245.     if [ "$SKIP_SERVICES_CHECK" -eq "0" ] ; then
  2246.     if [ "$(systemctl is-active $DAEMON_DHCPD)" = "active" ] ; then
  2247.     DHCPD_SERVICE_STATUS=1
  2248.     systemctl enable $DAEMON_DHCPD
  2249.     else
  2250.     DHCPD_SERVICE_STATUS=0
  2251.     setterm -term linux -back red -fore white
  2252.     echo "###########################################################"
  2253.     echo "# Error: Installation stopped!                            #"
  2254.     echo "###########################################################"
  2255.     echo "Reason:"
  2256.     echo " - Your DHCP settings are incorrect."
  2257.     echo ""
  2258.     echo "Solution:"
  2259.     echo " - Make sure that the settings abide to:"
  2260.     echo "  - Not containing any illegal characters!"
  2261.     echo "  - Containing a correct FQDN, NetBiosname and DCName."
  2262.     echo "  - Check: systemctl $DAEMON_DHCPD status -l, for more details."
  2263.     echo "###########################################################"
  2264.     pause_with_msg
  2265.     setterm -default
  2266.     exit
  2267.     fi
  2268.     fi
  2269.     fi
  2270. AVDC_STEP=430; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=430/' "/etc/avorix/avdc_install.sh"
  2271. fi
  2272.  
  2273.  
  2274. ###########################################################
  2275. # 4.3.       (Optional) Configure the PXE-server          #
  2276. ###########################################################
  2277. if [[ $AVDC_STEP -eq 430 ]] ; then
  2278.  
  2279. if [ "$PXE_SERVER" -eq "1" ] ; then
  2280.     if [ "$FIREWALL" -eq "1" ]; then
  2281.     firewall-cmd --permanent --zone=public --add-port=69/udp
  2282.     firewall-cmd --permanent --zone=public --add-port=80/udp
  2283.     fi
  2284.  
  2285.     if [ "$SKIP_INSTALLATION_CHECK" -eq "0" ] ; then
  2286.     if [ "$(dpkg-query -W -f='${Status}' $PACKAGE_TFTPD 2>/dev/null | grep -c "ok installed")" -eq 0 ] ; then
  2287.     SSH_INSTALLATION_STATUS=1
  2288.     echo "The '$PACKAGE_TFTPD'-package is succesfully installed!"
  2289.     else
  2290.     SSH_INSTALLATION_STATUS=0
  2291.     setterm -term linux -back red -fore white
  2292.     echo "###########################################################"
  2293.     echo "# Error: Installation stopped!                            #"
  2294.     echo "###########################################################"
  2295.     echo "Reason:"
  2296.     echo " - The '$PACKAGE_TFTPD'-package could not be installed."
  2297.     echo ""
  2298.     echo "Solution:"
  2299.     echo " - Make sure that:"
  2300.     echo "  - You have a stable internet connection!"
  2301.     echo "  - Install it manually."
  2302.     echo "  - Skip this part."
  2303.     echo "###########################################################"
  2304.     pause_with_msg
  2305.     setterm -default
  2306.     exit
  2307.     fi
  2308.     fi
  2309.  
  2310.     curl http://boot.ipxe.org/undionly.kpxe -o "$PXE_TFTP_ROOT/undionly.kpxe"
  2311.     curl http://boot.ipxe.org/ipxe.efi -o "$PXE_TFTP_ROOT/ipxe.efi"
  2312.     mkdir /avorix_temp/dc -f
  2313.     curl http://git.ipxe.org/releases/wimboot/wimboot-latest.tar.gz /avorix-temp/dc/wimboot-latest.tar.gz
  2314.     tar xvf wimboot-latest.tar.gz -C /avorix-temp/dc/wimboot
  2315.     find /avorix-temp/dc/wimboot -name 'wimboot' -exec cp {} "$PXE_HTTP_ROOT/"  \;
  2316.     rm -Rf /avorix-temp
  2317.  
  2318.     touch "$PXE_TFTP_ROOT/boot.ipxe"
  2319.  
  2320.     systemctl start $DAEMON_TFTPD
  2321.     sleep 5s
  2322.     systemctl stop $DAEMON_TFTPD
  2323.  
  2324.     mv "$PATH_FILE_TFTPD_CONF" "$PATH_FILE_TFTPD_CONF.original"
  2325.     touch "$PATH_FILE_TFTPD_CONF"
  2326.  
  2327.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2328.     ln -sf "$LOCATION_OF_IMPORTANT_FILES/PXE/Configuration/tftpd-hpa.conf" "$PATH_FILE_TFTPD_CONF"
  2329.     fi
  2330.  
  2331. # Uses # as a delimiter.
  2332.     sed -i -e 's#TFTP_DIRECTORY="/srv/tftp"#TFTP_DIRECTORY="$PXE_TFTP_ROOT"#g' "$PATH_FILE_TFTPD_CONF"
  2333.     systemctl start $DAEMON_TFTPD
  2334.     systemctl enable $DAEMON_TFTPD
  2335.  
  2336.     touch "$PATH_FOLDER_APACHE_SITES_ENABLED/Apache_iPXE.conf"
  2337.  
  2338. cat <<EOT >> "$PATH_FOLDER_APACHE_SITES_ENABLED/Apache_iPXE.conf"
  2339. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION.
  2340. # Generated on $(date)
  2341.  
  2342.     <VirtualHost *:80>
  2343.     # The ServerName directive sets the request scheme, hostname and port that
  2344.     # the server uses to identify itself. This is used when creating
  2345.     # redirection URLs. In the context of virtual hosts, the ServerName
  2346.     # specifies what hostname must appear in the request's Host: header to
  2347.     # match this virtual host. For the default virtual host (this file) this
  2348.     # value is not decisive as it is used as a last resort host regardless.
  2349.     # However, you must set it for any further virtual host explicitly.
  2350.     #ServerName www.example.com
  2351.  
  2352.     ServerSignature Off
  2353.     ServerTokens Prod
  2354.     FileETag None
  2355.  
  2356.     <Directory />
  2357.     Options None
  2358.     Order allow,deny
  2359.     Allow from all
  2360.     </Directory>
  2361.  
  2362.     ServerAdmin webmaster@localhost
  2363. EOT
  2364.  
  2365.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2366. cat <<'EOT' >> "$PATH_FOLDER_APACHE_SITES_ENABLED/Apache_iPXE.conf"
  2367.     DocumentRoot $PXE_HTTP_ROOT
  2368. EOT
  2369.  
  2370.     else
  2371. cat <<EOT >> "$PATH_FOLDER_APACHE_SITES_ENABLED/Apache_iPXE.conf"
  2372.     DocumentRoot $PXE_HTTP_ROOT
  2373. EOT
  2374.  
  2375.     fi
  2376.  
  2377.     cat <<EOT >> "$PATH_FOLDER_APACHE_SITES_ENABLED/Apache_iPXE.conf"
  2378.     # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
  2379.     # error, crit, alert, emerg.
  2380.     # It is also possible to configure the loglevel for particular
  2381.     # modules, e.g.
  2382.     #LogLevel info ssl:warn
  2383.  
  2384.     #ErrorLog ${APACHE_LOG_DIR}/error.log
  2385.     #CustomLog ${APACHE_LOG_DIR}/access.log combined
  2386.  
  2387.     # For most configuration files from conf-available/, which are
  2388.     # enabled or disabled at a global level, it is possible to
  2389.     # include a line for only one particular virtual host. For example the
  2390.     # following line enables the CGI configuration for this host only
  2391.     # after it has been globally disabled with "a2disconf".
  2392.     #Include conf-available/serve-cgi-bin.conf
  2393.     </VirtualHost>
  2394.     # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  2395. EOT
  2396.  
  2397.     systemctl start $DAEMON_APACHE
  2398.     systemctl enable $DAEMON_APACHE
  2399. fi
  2400.  
  2401. AVDC_STEP=440; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=440/' "/etc/avorix/avdc_install.sh"
  2402. fi
  2403.  
  2404.  
  2405. ###########################################################
  2406. # 4.4.          (Optional) Configure SELinux              #
  2407. ###########################################################
  2408. if [[ $AVDC_STEP -eq 440 ]] ; then
  2409. #SELinux is a security module for the Linux kernel.
  2410. #It allows us to create security policy for each process.
  2411. #The policies include: Allowing files to be accessed, Allowing services to be run.
  2412.  
  2413. if [ "$SELINUX" -eq "1" ] ; then
  2414.     #Creates a script that wil check the next day which permissions NTP, SAMBA and DHCP need.
  2415.     touch "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2416.  
  2417. cat <<EOT >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2418. #!/bin/bash
  2419. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  2420. # Generated on $(date)
  2421. #
  2422.  
  2423. EOT
  2424.  
  2425. if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2426. cat <<'EOT' >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2427. grep samba "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/samba"
  2428. grep smbd "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/smbd"
  2429. grep nmbd "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/nmbd"
  2430. grep samba-ad-dc "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/samba-ad-dc"
  2431. grep ntp "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/ntp"
  2432. EOT
  2433.  
  2434. else
  2435. cat <<EOT >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2436. grep samba "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/samba"
  2437. grep smbd "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/smbd"
  2438. grep nmbd "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/nmbd"
  2439. grep samba-ad-dc "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/samba-ad-dc"
  2440. grep ntp "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/ntp"
  2441. EOT
  2442.  
  2443. fi
  2444.  
  2445.     if [ "$DHCP_SERVER" -eq "1" ] ; then
  2446.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2447. cat <<'EOT' >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2448. grep dhcp "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/dhcp"
  2449. EOT
  2450.  
  2451.     else
  2452. cat <<EOT >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2453. grep dhcp "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/dhcp"
  2454. EOT
  2455.  
  2456.     fi
  2457.     if [ "$PXE_SERVER" -eq "1" ] ; then
  2458.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2459. cat <<'EOT' >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2460. grep tftpd "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/tftpd"
  2461. semodule -i "$PATH_FOLDER_SELINUX_POLICY/tftpd"
  2462. EOT
  2463.  
  2464.     else
  2465. cat <<EOT >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2466. grep tftpd "$PATH_FILE_AUDIT_LOG" | audit2allow -M "$PATH_FOLDER_SELINUX_POLICY/tftpd"
  2467. semodule -i "$PATH_FOLDER_SELINUX_POLICY/tftpd"
  2468. EOT
  2469.  
  2470.     fi
  2471.     fi
  2472.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2473. cat <<'EOT' >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2474. semodule -i "$PATH_FOLDER_SELINUX_POLICY/dhcp"
  2475. EOT
  2476.  
  2477.     else
  2478. cat <<EOT >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2479. semodule -i "$PATH_FOLDER_SELINUX_POLICY/dhcp"
  2480. EOT
  2481.  
  2482.     fi
  2483.     fi
  2484.  
  2485.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2486. cat <<'EOT' >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2487. semodule -i "$PATH_FOLDER_SELINUX_POLICY/samba"
  2488. semodule -i "$PATH_FOLDER_SELINUX_POLICY/smbd"
  2489. semodule -i "$PATH_FOLDER_SELINUX_POLICY/nmbd"
  2490. semodule -i "$PATH_FOLDER_SELINUX_POLICY/samba-ad-dc"
  2491. semodule -i "$PATH_FOLDER_SELINUX_POLICY/ntp"
  2492.  
  2493. mv -Rf "$PATH_FILE_SELINUX_CONF_REPLACER" "$PATH_FILE_SELINUX_CONF"
  2494. rm -Rf "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2495. EOT
  2496.  
  2497.     else
  2498. cat <<EOT >> "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2499. semodule -i "$PATH_FOLDER_SELINUX_POLICY/samba"
  2500. semodule -i "$PATH_FOLDER_SELINUX_POLICY/smbd"
  2501. semodule -i "$PATH_FOLDER_SELINUX_POLICY/nmbd"
  2502. semodule -i "$PATH_FOLDER_SELINUX_POLICY/samba-ad-dc"
  2503. semodule -i "$PATH_FOLDER_SELINUX_POLICY/ntp"
  2504.  
  2505. mv -Rf "$PATH_FILE_SELINUX_CONF_REPLACER" "$PATH_FILE_SELINUX_CONF"
  2506. rm -Rf "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2507. EOT
  2508.  
  2509.     fi
  2510.  
  2511.     chmod +x "$PATH_FOLDER_CRON_DAILY/Configure-SELinux"
  2512.  
  2513.     #This file will be replaced with the original /etc/selinux/config once the above script is ran.
  2514.     touch "$PATH_FILE_SELINUX_CONF_REPLACER"
  2515.  
  2516. cat <<EOT >> "$PATH_FILE_SELINUX_CONF_REPLACER"
  2517. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  2518. # Generated on $(date)
  2519. #
  2520.  
  2521. # This file controls the state of SELinux on the system.
  2522. # SELINUX= can take one of these three values:
  2523. #       enforcing - SELinux security policy is enforced.
  2524. #       permissive - SELinux prints warnings instead of enforcing.
  2525. #       disabled - SELinux is fully disabled.
  2526. SELINUX=enforced
  2527. # SELINUXTYPE= type of policy in use. Possible values are:
  2528. #       targeted - Only targeted network daemons are protected.
  2529. #       strict - Full SELinux protection.
  2530. SELINUXTYPE=strict
  2531.  
  2532. # SETLOCALDEFS= Check local definition changes
  2533. SETLOCALDEFS=0
  2534. EOT
  2535.  
  2536. fi
  2537.  
  2538. AVDC_STEP=450; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=450/' "/etc/avorix/avdc_install.sh"
  2539. fi
  2540.  
  2541. ###########################################################
  2542. # 4.5.  (Optional) Configure automatic security updates   #
  2543. ###########################################################
  2544. if [[ $AVDC_STEP -eq 450 ]] ; then
  2545.  
  2546. if [ "$AUTOMATIC_SECURITY_UPDATES" -eq "1" ]; then
  2547.     #Check daily for updates and install the security updates.
  2548.  
  2549. if [ "$CENTRALIZED_STORAGE" -eq "1" ]; then
  2550. cat <<'EOT' >> "$PATH_FOLDER_CRON_DAILY/Install-Security-Updates"
  2551. #!/bin/bash
  2552. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  2553. # Generated on $(date)
  2554. #
  2555.  
  2556. echo "**************" >> "$LOCATION_OF_IMPORTANT_FILES/Logs/General/Security-Updates.log"
  2557. date >> "$LOCATION_OF_IMPORTANT_FILES/Logs/General/Security-Updates.log"
  2558. aptitude update >> "$LOCATION_OF_IMPORTANT_FILES/Logs/General/Security-Updates.log"
  2559. aptitude safe-upgrade -o Aptitude::Delete-Unused=false --assume-yes --target-release `lsb_release -cs`-security >> "$LOCATION_OF_IMPORTANT_FILES/General/Logs/Security-Updates.log"
  2560. echo "Security updates (if any) installed"
  2561. EOT
  2562.  
  2563.  
  2564.     else
  2565. cat <<EOT >> "$PATH_FOLDER_CRON_DAILY/Install-Security-Updates"
  2566. #!/bin/bash
  2567. # Generated by the Avorix Domain Controller install script $DC_SCRIPT_VERSION
  2568. # Generated on $(date)
  2569. #
  2570.  
  2571. echo "**************" >> "$LOCATION_OF_IMPORTANT_FILES/Logs/General/Security-Updates.log"
  2572. date >> "$LOCATION_OF_IMPORTANT_FILES/Logs/General/Security-Updates.log"
  2573. aptitude update >> "$LOCATION_OF_IMPORTANT_FILES/Logs/General/Security-Updates.log"
  2574. aptitude safe-upgrade -o Aptitude::Delete-Unused=false --assume-yes --target-release `lsb_release -cs`-security >> "$LOCATION_OF_IMPORTANT_FILES/Logs/General/Security-Updates.log"
  2575. echo "Security updates (if any) installed"
  2576. EOT
  2577.  
  2578.     fi
  2579.     chmod +x "$PATH_FOLDER_CRON_DAILY/Install-Security-Updates"
  2580. fi
  2581.  
  2582. AVDC_STEP=460; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=460/' "/etc/avorix/avdc_install.sh"
  2583. fi
  2584.  
  2585. ###########################################################
  2586. # 4.6.      (Optional) Test & Enable the Firewall         #
  2587. ###########################################################
  2588. if [[ $AVDC_STEP -eq 460 ]] ; then
  2589.  
  2590. if [ "$FIREWALL" -eq "1" ]; then
  2591.     systemctl stop $DAEMON_FIREWALLD
  2592.     sleep 5s
  2593.     systemctl start $DAEMON_FIREWALLD
  2594.  
  2595.     if [ "$SKIP_SERVICES_CHECK" -eq "0" ] ; then
  2596.     if [ "$(systemctl is-active $DAEMON_FIREWALLD)" = "active" ] ; then
  2597.     FIREWALL_SERVICE_STATUS=1
  2598.     systemctl enable $DAEMON_FIREWALLD
  2599.     else
  2600.     FIREWALL_SERVICE_STATUS=0
  2601.     setterm -term linux -back red -fore white
  2602.     echo "###########################################################"
  2603.     echo "# Error: Installation stopped!                            #"
  2604.     echo "###########################################################"
  2605.     echo "Reason:"
  2606.     echo " - Your port settings are incorrect."
  2607.     echo ""
  2608.     echo "Solution:"
  2609.     echo " - Make sure that the port numbers abide to:"
  2610.     echo "  - Not containing any illegal characters!"
  2611.     echo "  - Containing a port number between 1 - 65535."
  2612.     echo "  - Containing a port number that is not reserved."
  2613.     echo "  - Check: systemctl $DAEMON_FIREWALLD status -l, for more details."
  2614.     echo "###########################################################"
  2615.     pause_with_msg
  2616.     setterm -default
  2617.     exit
  2618.     fi
  2619.     fi
  2620. fi
  2621.  
  2622. AVDC_STEP=470; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=470/' "/etc/avorix/avdc_install.sh"
  2623. fi
  2624.  
  2625.  
  2626. ###########################################################
  2627. # 4.7.               Configure a the backups              #
  2628. ###########################################################
  2629. if [[ $AVDC_STEP -eq 470 ]] ; then
  2630.  
  2631. if [ "$BACKUP_DC" -eq "1" ] ; then
  2632. #Won't fix: Needs updating for other systems.
  2633.     crontab -l | { cat; echo "$BACKUP_DC_TIMING" /usr/sbin/samba_backup /usr/local/samba $BACKUP_DC_DESTINATION; } | crontab -
  2634. fi
  2635.  
  2636. if [ "$BACKUP_LOIP" -eq "1" ] && [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2637.     crontab -l | { cat; echo "$BACKUP_LOIP_TIMING tar cjf $LOCATION_OF_IMPORTANT_FILES/* $BACKUP_LOIP_DESTINATION/loip_$(date +%d%m%y).tar.bz2 --exclude $BACKUP_LOIP_DESTINATION/*"; } | crontab -
  2638. fi
  2639.  
  2640. AVDC_STEP=480; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=480/' "/etc/avorix/avdc_install.sh"
  2641.  
  2642. fi
  2643.  
  2644.  
  2645. ###########################################################
  2646. # 4.8.        Configure log in/out messages and EULA      #
  2647. ###########################################################
  2648. if [[ $AVDC_STEP -eq 480 ]] ; then
  2649.  
  2650. if [ "$BRANDING" -eq "1" ] ; then
  2651.     #Will be displayed after a SSH user had logged in.
  2652.  
  2653.     mv "$PATH_FILE_ISSUE" "$PATH_FILE_ISSUE.original"
  2654.     touch "$PATH_FILE_ISSUE"
  2655.  
  2656.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2657.     ln -sf "$PATH_FILE_ISSUE" "$OR_PATH_FILE_ISSUE"
  2658.     fi
  2659.  
  2660. cat <<EOT >> "$PATH_FILE_ISSUE"
  2661.                            _      _____   _____   __   ___
  2662.        /\                 (_)    |  __ \ / ____| /_ | / _ \
  2663.       /  \__   _____  _ __ ___  _| |  | | |       | || | | |
  2664.      / /\ \ \ / / _ \| '__| \ \/ / |  | | |       | || | | |
  2665.    / ____ \ V / (_) | |  | |>  <| |__| | |____   | || |_| |
  2666.   /_/    \_\_/ \___/|_|  |_/_/\_\_____/ \_____|  |_(_)___/
  2667.  
  2668.     For more: Github.com/RHeijmann/Avorix-Domain-Controller
  2669.  
  2670.  
  2671. _____________________________________________________________
  2672. |
  2673. | ####          Version: $DC_SCRIPT_VERSION
  2674. | ####      Released at: $DC_RELEASE_DATE
  2675. |_____________________________________________________________
  2676. _____________________________________________________________
  2677. |
  2678. | ####           Domain: $FQDN
  2679. | ####      Server name: $NBIOS
  2680. |_____________________________________________________________
  2681. _____________________________________________________________
  2682. |
  2683. |  Current date: %d , %t
  2684. |_____________________________________________________________
  2685. _____________________________________________________________
  2686. |#############################################################
  2687. | This private computer system is only for the use
  2688. | of authorized users. If you are not authorized by its owners
  2689. | you must log out immediately.
  2690. |#############################################################
  2691. |_____________________________________________________________
  2692. EOT
  2693.  
  2694.  
  2695.     #Will be displayed after a login using the interface.
  2696.     mv "$PATH_FILE_MOTD" "$PATH_FILE_MOTD.original"
  2697.     touch "$PATH_FILE_MOTD"
  2698.  
  2699.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2700.     ln -sf "$PATH_FILE_MOTD" "$OR_PATH_FILE_MOTD"
  2701.     fi
  2702.  
  2703. cat <<EOT >> "$PATH_FILE_MOTD"
  2704.                           _      _____   _____   __   ___
  2705.       /\                 (_)    |  __ \ / ____| /_ | / _ \
  2706.      /  \__   _____  _ __ ___  _| |  | | |       | || | | |
  2707.     / /\ \ \ / / _ \| '__| \ \/ / |  | | |       | || | | |
  2708.     / ____ \ V / (_) | |  | |>  <| |__| | |____   | || |_| |
  2709.    /_/    \_\_/ \___/|_|  |_/_/\_\_____/ \_____|  |_(_)___/
  2710.  
  2711.     For more: Github.com/RHeijmann/Avorix-Domain-Controller
  2712.  
  2713.  
  2714.  _____________________________________________________________
  2715. |
  2716. | ####          Version: $DC_SCRIPT_VERSION
  2717. | ####      Released at: $DC_RELEASE_DATE
  2718. |_____________________________________________________________
  2719.  _____________________________________________________________
  2720. |
  2721. | ####           Domain: $FQDN
  2722. | ####      Server name: $NBIOS
  2723. |_____________________________________________________________
  2724.  _____________________________________________________________
  2725. |
  2726. |  Current date: %d , %t
  2727. |_____________________________________________________________
  2728.  _____________________________________________________________
  2729. |#############################################################
  2730. | This private computer system is only for the use
  2731. | of authorized users. If you are not authorized by its owners
  2732. | you must log out immediately.
  2733. |#############################################################
  2734. |_____________________________________________________________
  2735. EOT
  2736.  
  2737.     #Will be displayed after a SSH-authenticator has entered its loginname but still has to enter its password.
  2738.     mv "$PATH_FILE_ISSUENET" "$PATH_FILE_ISSUENET.original"
  2739.     touch "$PATH_FILE_ISSUENET"
  2740.  
  2741.     if [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  2742.     ln -sf "$PATH_FILE_ISSUENET" "$OR_PATH_FILE_ISSUENET"
  2743.     fi
  2744.  
  2745. cat <<EOT >> "$PATH_FILE_ISSUENET"
  2746.                            _      _____   _____   __   ___
  2747.        /\                 (_)    |  __ \ / ____| /_ | / _ \
  2748.       /  \__   _____  _ __ ___  _| |  | | |       | || | | |
  2749.      / /\ \ \ / / _ \| '__| \ \/ / |  | | |       | || | | |
  2750.    / ____ \ V / (_) | |  | |>  <| |__| | |____   | || |_| |
  2751.   /_/    \_\_/ \___/|_|  |_/_/\_\_____/ \_____|  |_(_)___/
  2752.  
  2753.    For more: Github.com/RHeijmann/Avorix-Domain-Controller
  2754. _____________________________________________________________
  2755. |                                                             |
  2756. |                           -EULA-                            |
  2757. |_____________________________________________________________|
  2758. _____________________________________________________________
  2759. |                            -EN-                             |
  2760. |_____________________________________________________________|
  2761. |                                                             |
  2762. |                                                             |
  2763. |     This private computer system is for the use             |
  2764. |     of authorized users only. Individuals using             |
  2765. |     this computer system without authority,                 |
  2766. |     or in excess of their authority,                        |
  2767. |     are subject to having all of their activities           |
  2768. |     on this system monitored and recorded                   |
  2769. |     by system personnel.                                    |
  2770. |                                                             |
  2771. |     Authority can be obtained only with a written           |
  2772. |     authorization of the owners or administrators           |
  2773. |     of this system.                                         |
  2774. |     Owning a login name does not give authority to          |
  2775. |     use this system.                                        |
  2776. |     The use of potential exploits in order                  |
  2777. |     to gain access to this system does not provide          |
  2778. |     authorization to the use of this system.                |
  2779. |                                                             |
  2780. |     In the course of monitoring individuals                 |
  2781. |     improperly using this system, or in the                 |
  2782. |     course of system maintenance, the activities            |
  2783. |     of authorized users may also be monitored.              |
  2784. |                                                             |
  2785. |     Anyone using this system expressly consents             |
  2786. |     to such monitoring and is advised that if               |
  2787. |     such monitoring reveals possible evidence               |
  2788. |     of criminal activity, system personnel                  |
  2789. |     may provide the evidence of such                        |
  2790. |     monitoring to law enforcement officials.                |
  2791. |                                                             |
  2792. |_____________________________________________________________|
  2793.  
  2794.  
  2795.  
  2796.  
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.  
  2803.  
  2804.  
  2805.  
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.                           _      _____   _____   __   ___
  2826.       /\                 (_)    |  __ \ / ____| /_ | / _ \
  2827.      /  \__   _____  _ __ ___  _| |  | | |       | || | | |
  2828.     / /\ \ \ / / _ \| '__| \ \/ / |  | | |       | || | | |
  2829.     / ____ \ V / (_) | |  | |>  <| |__| | |____   | || |_| |
  2830.    /_/    \_\_/ \___/|_|  |_/_/\_\_____/ \_____|  |_(_)___/
  2831.  
  2832.     For more: Github.com/RHeijmann/Avorix-Domain-Controller
  2833.  _____________________________________________________________
  2834. |                                                             |
  2835. | ####      BEFORE YOU AUTHENTICATE READ OUR EULA!       #### |
  2836. | ###                                                     ### |
  2837. | ####         Scroll upwards to read our EULA.          #### |
  2838. |_____________________________________________________________|
  2839.  
  2840. EOT
  2841.  
  2842. fi
  2843.  
  2844. AVDC_STEP=510; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=510/' "/etc/avorix/avdc_install.sh"
  2845. fi
  2846.  
  2847.  
  2848. ###########################################################
  2849. #                                                         #
  2850. # 5.           The fase of finishing up                   #
  2851. #                                                         #
  2852. ###########################################################
  2853.  
  2854. ###########################################################
  2855. # 5.1.          Log the current installation              #
  2856. ###########################################################
  2857. if [[ $AVDC_STEP -eq 510 ]] ; then
  2858.  
  2859. cat <<EOT >> "$LOCATION_OF_IMPORTANT_FILES/info.avdc"
  2860. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
  2861. #!!!!!!!!!!!!!!! Do not Remove This File !!!!!!!!!!!!!!!!!#
  2862. #!!!!! By deleting this file, the developers will not !!!!#
  2863. #!!!!!!!!!!!!!! be able to provide support! !!!!!!!!!!!!!!#
  2864. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
  2865.  
  2866. ###########################################################
  2867. # 1.                      General                         #
  2868. ###########################################################
  2869. 1. Script version: $DC_SCRIPT_VERSION ($DC_RELEASE_DATE)
  2870. 2. Installation date: $(date)
  2871. 3. Operating System: $(cat /etc/*-release)
  2872. 4. Location of the important files: $LOCATION_OF_IMPORTANT_FILES
  2873. 5. Timezone and Region: $TIMEZONE / $REGION
  2874. 6. Correct Network settings: $(if [ "$DHCPCD_STATUS" -eq "1" ]; then echo "Yes"; else echo "No"; fi)
  2875.  
  2876.  
  2877. ###########################################################
  2878. # 2.                      Modules                         #
  2879. ###########################################################
  2880. 1. DHCP: $(if [ "$DHCP_SERVER" -eq "1" ]; then echo "Yes"; else echo "No"; fi)
  2881.     - With: $(if [ "$PXE_SERVER" -eq "2" ]; then echo "PXE"; fi)
  2882. 2. SSH: $(if [ "$SSH_SERVER" -eq "1" ]; then echo "Yes"; else echo "No"; fi)
  2883.     - With: $(if [ "$SSH_PORTKNOCKING" -eq "1" ]; then echo "Portknocking,"; fi) $(if [ "$SSH_FAIL2BAN" -eq "2" ]; then echo "Fail2Ban,"; fi) $(if [ "$SSH_2FA" -eq "1" ]; then echo "2-Factor-Authentication"; fi)
  2884.  
  2885.  
  2886. ###########################################################
  2887. # 3.                Security Functions                    #
  2888. ###########################################################
  2889. 1. Automatic Security Updates: $(if [ "$AUTOMATIC_SECURITY_UPDATES" -eq "1" ]; then echo "Yes"; else echo "No"; fi)
  2890. 2. Firewall: $(if [ "$FIREWALL" -eq "1" ]; then echo "Yes"; else echo "No"; fi)
  2891. 3. SELinux: $(if [ "$SELINUX" -eq "1" ]; then echo "Yes"; else echo "No"; fi)
  2892.  
  2893.  
  2894. ###########################################################
  2895. # 4.                  Network Settings                    #
  2896. ###########################################################
  2897. 1. IP-Address: $IP_ADDRESS
  2898. 2. Subnetmaskbits: $SUBNETMASKBITS
  2899. 3. Gateway: $GATEWAY
  2900.  
  2901.  
  2902. ###########################################################
  2903. # 3.                 Installed packages                   #
  2904. ###########################################################
  2905.  
  2906. #############
  2907. ### SAMBA ###
  2908. #############
  2909.  
  2910. Installed correctly: $(if [ "$SAMBA_STATUS" -eq "1" ]; then echo "Yes"; else echo "No"; fi)
  2911.  
  2912. ### Installation Settings ###
  2913. 1. Fully Qualified Domain Name: $FQDN
  2914. 2. NetBIOS name: $NBIOS
  2915. 3. Name of the Domain Controller: $DCNAME
  2916.  
  2917. ### Packages ###
  2918.  
  2919. SAMBA:
  2920.     $(dpkg -p PACKAGE_SAMBA)
  2921.  
  2922.  
  2923. #############
  2924. ###  NTP  ###
  2925. #############
  2926.  
  2927. Installed correctly: $(if [ "$NTP_STATUS" -eq "1" ]; then echo "Yes"; else echo "No"; fi)
  2928.  
  2929. ### Installation Settings ###
  2930. 1. First External NTP-Server: $NTPSERVER1
  2931. 2. Second External NTP-Server: $NTPSERVER2
  2932. 3. Third External NTP-Server: $NTPSERVER3
  2933.  
  2934. ### Packages ###
  2935. NTP:
  2936.     $(dpkg -p ntp)
  2937.  
  2938.  
  2939. #########################
  2940. ### Security Functions ##
  2941. #########################
  2942.  
  2943. $(if [ "$FIREWALL" -eq "1" ] ; then
  2944.     echo "##############"
  2945.     echo "###Firewall###"
  2946.     echo "##############"
  2947.     echo "";
  2948.     echo "Installed correctly: $(if [ "$FIREWALL_STATUS" -eq "1" ]; then echo "Yes"; else echo "No"; fi)"
  2949.     echo "";
  2950.     echo "### Packages ###"
  2951.     echo "FirewallD:"
  2952.     echo "  $(dpkg -p $PACKAGE_FIREWALLD)"
  2953. fi)
  2954.  
  2955. $(if [ "$SELINUX" -eq "1" ] ; then
  2956.     echo "##############"
  2957.     echo "###SELinux ###"
  2958.     echo "##############"
  2959.     echo "";
  2960.     echo "### Packages ###"
  2961.     echo "SELinux-Basics"
  2962.     echo "  $(dpkg -p $PACKAGE_SELINUX)"
  2963.     echo "";
  2964.     echo "SELinux-Policy-Default"
  2965.     echo "  $(dpkg -p $PACKAGE_SELINUX_POLICY_DEFAULT)"
  2966. fi)
  2967.  
  2968. #########################
  2969. ######## Modules ########
  2970. #########################
  2971.  
  2972. $(if [ "$DHCP_SERVER" -eq "1" ] ; then
  2973.     echo "##############"
  2974.     echo "###  DHCP  ###"
  2975.     echo "##############"
  2976.     echo ""
  2977.     echo "Installed correctly: $(if [ "$DHCPD_STATUS" -eq "1" ]; then echo "Yes"; else echo "No"; fi)"
  2978.     echo ""
  2979.     echo "### Installation Settings ###"
  2980.     echo "DHCP Subnet ID: $DHCP_SUBNET"
  2981.     echo "DHCP Subnetmask: $DHCP_SUBNETMASK"
  2982.     echo "DHCP Broadcastaddress: $DHCP_BROADCASTADDRESS"
  2983.     echo "DHCP Gateway: $DHCP_GATEWAY"
  2984.     echo "DHCP First DNS-Server: $DHCP_DNSSERVER1"
  2985.     echo "DHCP Second DNS-Server: $DHCP_DNSSERVER2"
  2986.     echo "DHCP NetBIOS-Server: $DHCP_NETBIOSSERVER"
  2987.     echo "DHCP First NTP-Server: $DHCP_NTPSERVER1"
  2988.     echo "DHCP Second NTP-Server: $DHCP_NTPSERVER2"
  2989.     echo "DHCP Maximum Lease Time: $DHCP_MAX_LEASE_TIME"
  2990.     echo "DHCP First IP-adres: $DHCP_FIRST_IP_ADDRESS"
  2991.     echo "DHCP Last IP-adres: $DHCP_LAST_IP_ADDRESS"
  2992.     echo ""
  2993.     echo "### Packages ###"
  2994.     echo "ISC-DHCP-Server"
  2995.     dpkg -p $PACKAGE_DHCPD
  2996. fi)
  2997.  
  2998. $(if [ "$PXE_SERVER" -eq "2" ] ; then
  2999.     echo "##############"
  3000.     echo "###  PXE   ###"
  3001.     echo "##############"
  3002.     echo "";
  3003.     echo "Installed correctly: $(if [ "$PXE_STATUS" -eq "1" ]; then echo "Yes"; else echo "No"; fi)"
  3004.     echo ""
  3005.     echo "### Installation Settings ###"
  3006.     echo "HTTP Folder: $PXE_HTTP"
  3007.     echo "TFTP Folder: $PXE_TFTP"
  3008.     echo ""
  3009.     echo "### Packages ###"
  3010.     echo "TFTPd:"
  3011.     echo "  $(dpkg -p $PACKAGE_TFTPD)"
  3012.     echo ""
  3013.     echo "Apache:"
  3014.     echo "  $(dpkg -p $PACKAGE_APACHE)"
  3015. fi)
  3016.  
  3017. EOT
  3018.  
  3019. AVDC_STEP=520; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=520/' "/etc/avorix/avdc_install.sh"
  3020. fi
  3021.  
  3022.  
  3023. ###########################################################
  3024. # 5.2.       Display a summary of the installatioon       #
  3025. ###########################################################
  3026. if [[ $AVDC_STEP -eq 520 ]] ; then
  3027.  
  3028. if [ "$SKIP_END_SUMMARY" -eq "0" ] ; then
  3029.     if [ "$DHCP_SERVER" -eq "0" ] ; then
  3030.     clear
  3031.     echo "To connect a computer follow these steps:"
  3032.     echo "1. Search and open as admin 'control.exe'"
  3033.     echo "   on a Windows client PC that is on the same network."
  3034.     pause_with_msg
  3035.     echo "2. Within this control panel click on 'Network and internet'."
  3036.     pause
  3037.     echo "3. Click on 'Networkcenter'."
  3038.     pause
  3039.     echo "4. Click on the blue text next to 'Connections:'."
  3040.     pause
  3041.     echo "5. Click on in the opened popup on the 'Properties'-button."
  3042.     pause
  3043.     echo "6. Click on the text 'Internet Protocol version 4 (TCP/IPv4)'."
  3044.     pause
  3045.     echo "7. Click on the 'Properties'-button.."
  3046.     pause
  3047.     echo "8. Click on the text 'Use the following IP address:'."
  3048.     pause
  3049.     echo "9. Use the following data to fill this form:'."
  3050.     echo "  - IP address: $IP_ADDRESS"
  3051.     echo "  - Subnet mask: $SUBNETMASK"
  3052.     echo "  - Default gateway: $GATEWAY"
  3053.     pause
  3054.     echo "10. Click on the text 'Use the following DNS server addresses:'"
  3055.     pause
  3056.     echo "11. Use the following data to fill the next part of the form:"
  3057.     echo "  - Preferred DNS server: $DNSSERVER1"
  3058.     echo "  - Preferred DNS server: $DNSSERVER2"
  3059.     pause
  3060.     echo " If you followed these steps correctly you are now able to"
  3061.     echo " connect to this server and if you have entered a correct"
  3062.     echo " gateway address you are now able to reach the Internet."
  3063.     fi
  3064.  
  3065.     echo ""
  3066.     echo "To connect a computer follow these steps:"
  3067.     echo "1. Search and open as admin 'SystemPropertiesComputerName.exe'"
  3068.     pause_with_msg
  3069.     echo "   on a Windows client PC that is on the same network."
  3070.     pause
  3071.     echo "2. Select 'Domain'."
  3072.     pause
  3073.     echo "3. Enter '$FQDN' as your domain name."
  3074.     pause
  3075.     echo "4. Click on 'OK'."
  3076.     pause
  3077.     echo "5. Log in using these credentials:"
  3078.     echo "  - Username: $NBIOS\\Administrator"
  3079.  
  3080.     if [ "$ADMINPWD" = 'P455w0RD' ] ; then
  3081.     echo '  - Password: P455w0RD (Make sure to change this!).'
  3082.     else
  3083.     echo "  - Password: Your password!"
  3084.     fi
  3085.  
  3086.     pause_with_msg
  3087.     setterm -term linux -back black -fore green
  3088.     echo "###########################################################"
  3089.     echo " Congratulations! If you followed these steps correctly"
  3090.     echo " you now have correctly configured this domain controller! "
  3091.     echo " The next step is configuring users, computers and policies!"
  3092.     echo ""
  3093.     echo " We recommend this video tutorial: https://youtu.be/lFwek_OuYZ8"
  3094.     echo " Although the video is mainly foccused on Windows Server,"
  3095.     echo " ours does exactly the same thing."
  3096.     echo " But to manage ours follow this tutorial on the client:"
  3097.     echo " https://youtu.be/eBdEoczETDY"
  3098.     echo "###########################################################"
  3099.     pause_with_msg
  3100.     setterm -default
  3101. fi
  3102.  
  3103. AVDC_STEP=530; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=530/' /etc/avorix/avdc_install.sh
  3104. fi
  3105.  
  3106. ###########################################################
  3107. # 5.3.              Generate the modulesfile              #
  3108. ###########################################################
  3109. if [[ $AVDC_STEP -eq 530 ]] ; then
  3110.  
  3111. cat <<'EOT' >> "$LOCATION_OF_IMPORTANT_FILES/modules.avdc"
  3112. $(if [ "$SSH_SERVER" -eq "1" ]; then echo "SSH_SERVER" ; fi)
  3113. $(if [ "$SSH_PORTKNOCKING" -eq "1" ]; then echo "SSH_PORTKNOCKING" ; fi)
  3114.     - Test if there is knockd and its depends.
  3115. $(if [ "$SSH_FAIL2BAN" -eq "2" ]; then echo "SSH_FAIL2BAN" ; fi)
  3116.     - Test if there is fail2ban and its depends.
  3117. $(if [ "$DHCP_SERVER" -eq "1" ]; then echo "DHCP_SERVER" ; fi)
  3118.     - Test if there is ISC-DHCP-Server.
  3119. $(if [ "$PXE_SERVER" -eq "1" ]; then echo "PXE_SERVER" ; fi)
  3120.     - Test if there is Apache.
  3121. EOT
  3122.  
  3123. AVDC_STEP=540; sed -i '2s/AVDC_STEP=.*/AVDC_STEP=540/' "/etc/avorix/avdc_install.sh"
  3124. fi
  3125.  
  3126.  
  3127. ###########################################################
  3128. # 5.4.             Generate the locationscript            #
  3129. ###########################################################
  3130. if [[ $AVDC_STEP -eq 540 ]] ; then
  3131.  
  3132. # 1. Disable all services if this function is enabled.
  3133.  
  3134. if [ "$PORTABLE_CONFIGURATION" -eq "1" ] && [ "$CENTRALIZED_STORAGE" -eq "1" ] ; then
  3135.     systemctl disable $DAEMON_DHCPCD
  3136.     systemctl disable $DAEMON_NTP
  3137.     systemctl disable $DAEMON_SMBD
  3138.     systemctl disable $DAEMON_NMBD
  3139.     systemctl disable $DAEMON_SAMBA_AD_DC
  3140.     systemctl disable $DAEMON_KNOCKD
  3141.     systemctl disable $DAEMON_FAIL2BAN
  3142.     systemctl disable $DAEMON_SSH
  3143.     systemctl disable $DAEMON_DHCPD
  3144.     systemctl disable $DAEMON_TFTPD
  3145.     # systemctl disable $DAEMON_FIREWALLD
  3146.  
  3147. #Script starts here.
  3148. # 2. Check if the last LOIF still works.
  3149. cat <<'EOT' >> "/etc/avorix/avdc_locationscript.sh"
  3150.     read -r $LAST_LOIF < "/etc/avorix/avdc_loip"
  3151.  
  3152.     if ! [ -f $LAST_LOIF ]; then
  3153.     LOCATION_OF_IMPORTANT_FILES="$(find . -type f -iname 'info.avdc' -print -quit)"
  3154.     if [ "$LOCATION_OF_IMPORTANT_FILES" == "" ] ; then
  3155.     echo "The last device could not be found. Recreating "
  3156.     X + 1;
  3157.     Y + 2;
  3158.     sleep 60
  3159.     fi
  3160. else
  3161.  
  3162. LAST_LOIF=LOCATION_OF_IMPORTANT_FILES
  3163. mkdir /etc/avorix
  3164. touch /etc/avorix/loip.avdc
  3165. sed -i '1s/^/$LOCATION_OF_IMPORTANT_FILES\n/' /etc/avorix/avdc_loip
  3166. LOCATION_OF_IMPORTANT_FILES=${LOCATION_OF_IMPORTANT_FILES%"info.avdc"}; #Remove suffix
  3167.  
  3168. fi
  3169.  
  3170. #4. Test using the info.avdc-file if this is the right system.
  3171. #   - If not, display an error.
  3172.  
  3173. #if grep -xq "1. Script version: $DC_SCRIPT_VERSION ($DC_RELEASE_DATE)" $LOCATION_OF_IMPORTANT_FILES/info.avdc ; then
  3174. #   SSH_FAIL2BAN=2
  3175. #else
  3176. #   SSH_FAIL2BAN=0
  3177. #fi
  3178.  
  3179. #5. Test using the modules.avdc-file if this system has the correct dependencies (PXE, SSH...)
  3180. #   - If not, display error ask and the user to fix this by automaticly installing the dependencies for them.
  3181.  
  3182.  
  3183. if grep -xq "SSH_SERVER" $LOCATION_OF_IMPORTANT_FILES/modules.avdc ; then
  3184.     SSH_SERVER=1
  3185. else
  3186.     SSH_SERVER=0
  3187. fi
  3188.  
  3189. if grep -xq "SSH_PORTKNOCKING" $LOCATION_OF_IMPORTANT_FILES/modules.avdc ; then
  3190.     SSH_PORTKNOCKING=1
  3191. else
  3192.     SSH_PORTKNOCKING=0
  3193. fi
  3194.  
  3195. if grep -xq "SSH_FAIL2BAN" $LOCATION_OF_IMPORTANT_FILES/modules.avdc ; then
  3196.     SSH_FAIL2BAN=2
  3197. else
  3198.     SSH_FAIL2BAN=0
  3199. fi
  3200.  
  3201. if grep -xq "DHCP_SERVER" $LOCATION_OF_IMPORTANT_FILES/modules.avdc ; then
  3202.     DHCP_SERVER=1
  3203. else
  3204.     DHCP_SERVER=0
  3205. fi
  3206.  
  3207.  
  3208. if grep -xq "PXE_SERVER" $LOCATION_OF_IMPORTANT_FILES/modules.avdc ; then
  3209.     PXE_SERVER=1
  3210. else
  3211.     PXE_SERVER=0
  3212. fi
  3213. fi
  3214.  
  3215. if [ "$BRANDING" -eq "1" ] ; then
  3216.     ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/General/issue $PATH_FILE_ISSUE
  3217.     ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/General/motd $PATH_FILE_MOTD
  3218.     ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/General/issue.net $PATH_FILE_ISSUENET
  3219. fi
  3220.  
  3221.  
  3222. # 6. Link the files.
  3223. # - If an error occurs warn the user.
  3224. systemctl start $DAEMON_DHCPD
  3225. ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/DHCPCD/dhcpcd.conf $PATH_FILE_DHCPCD_CONF
  3226. ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/General/hosts $PATH_FILE_HOSTS_CONF
  3227. ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/General/hostname $PATH_FILE_HOSTNAME_CONF
  3228. ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/NTP/ntp.conf $PATH_FILE_NTP_CONF
  3229. ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/KRB5/krb5.conf $PATH_FILE_KRB5_CONF
  3230. ln -sdf $LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA_VAR_LIB $PATH_FOLDER_SAMBA_VAR_LIB
  3231. ln -sdf $LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA/Setup $PATH_FOLDER_SAMBA_SETUP
  3232. ln -sdf $LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA/Cache $PATH_FOLDER_SAMBA_CACHE
  3233. ln -sdf $LOCATION_OF_IMPORTANT_FILES/Logs/Samba $PATH_FOLDER_SAMBA_LOG
  3234. ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/SAMBA/smb.conf $PATH_FILE_SAMBA_CONF
  3235.  
  3236. systemctl start $DAEMON_NTP
  3237. systemctl start $DAEMON_SAMBA_AD_DC
  3238.  
  3239. if [ "$SSH_SERVER" -eq "1" ] ; then
  3240. ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/SSH/sshd_config $PATH_FILE_SSH_CONF
  3241.  
  3242.     if [ "$SSH_PORTKNOCKING" -eq "1" ] ; then
  3243.     ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/KnockD/knockd.conf $PATH_FILE_KNOCKD_CONF
  3244.     ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/KnockD/knockd.default.conf $PATH_FILE_KNOCKD_DEFAULT
  3245.     systemctl start $DAEMON_KNOCKD
  3246.     fi
  3247.  
  3248.     if [ "$SSH_FAIL2BAN" -eq "2" ] ; then
  3249.     ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/Fail2Ban/jail.local $PATH_FILE_FAIL2BAN_JAIL
  3250.     systemctl start $DAEMON_FAIL2BAN
  3251.     fi
  3252.  
  3253.     systemctl start $DAEMON_SSH
  3254. fi
  3255.  
  3256. if [ "$DHCP_SERVER" -eq "1" ] ; then
  3257.     ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/DHCPD/dhcpd.conf $PATH_FILE_DHCPD_CONF
  3258.  
  3259.     if [ "$PXE_SERVER" -eq "1" ] ; then
  3260.     ln -sdf $LOCATION_OF_IMPORTANT_FILES/Apache/Sites-Enabled $PATH_FOLDER_APACHE_SITES_ENABLED/Apache_iPXE.conf
  3261.     ln -sf $LOCATION_OF_IMPORTANT_FILES/Configuration/TFTPD/tftpd-hpa $PATH_FILE_TFTPD_CONF
  3262.     systemctl start $DAEMON_TFTPD
  3263.     fi
  3264. fi
  3265. EOT
  3266.  
  3267. chmod 744 "/etc/avorix/avdc_locationscript.sh"
  3268.  
  3269. touch "/lib/systemd/system/AVDC_LocationScript.service"
  3270. cat <<'EOT' >> "/lib/systemd/system/AVDC_LocationScript.service"
  3271. [Unit]
  3272. Description=Avorix DC LocationScript Service
  3273. After=multi-user.target
  3274.  
  3275. [Service]
  3276. Type=idle
  3277. ExecStart=/etc/avorix/avdc_locationscript.sh
  3278.  
  3279. [Install]
  3280. WantedBy=multi-user.target
  3281. EOT
  3282.  
  3283. chmod 644 "/lib/systemd/system/AVDC_LocationScript.service"
  3284. systemctl daemon-reload
  3285. systemctl enable "AVDC_LocationScript.service"
  3286.  
  3287. fi
  3288.  
  3289.  
  3290. clear_exported_avdc_step
  3291.  
  3292. #NOT Tested!
  3293. sed -i '/avdc_install.sh/d' "/root/.bashrc"
  3294. sed -i '/avdc_install_variables.sh/d' "/root/.bashrc"
  3295. reboot
  3296. fi
  3297.  
  3298. #NOTES:
  3299.  
  3300. #Useful Windows commands:
  3301. #Activate Windows using: slmgr -ipk $PRODUCT_KEY, followed by: slmgr -ato
  3302. #Join Active Directory domain: netdom.exe join %computername% /domain:%FQDN /UserD:$NBIOS\Administrator /Password:$ADMINPWD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement