Guest User

Untitled

a guest
Jan 20th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. #!/bin/bash
  2. set -e
  3.  
  4. ###
  5. # Script to set root password and networking config on first boot.
  6. #
  7. # Make your modifications and turn this on by running:
  8. # /etc/init.d/firstrun enable
  9. ###
  10.  
  11.  
  12. ##
  13. # Configure this stuff with your own defaults, these get used in prompts
  14. ##
  15.  
  16. DEF_DOM="oddbox.org"
  17. DEF_IP="10.42.0."
  18. DEF_NM="255.255.0.0"
  19. DEF_GW="10.42.0.1"
  20. DEF_DNS1="198.237.137.20"
  21. DEF_DNS2="198.237.137.21"
  22. DEF_ADMIN="root@$DEF_DOM"
  23. DEF_RELAY="mail.$DEF_DOM"
  24.  
  25.  
  26.  
  27. if [ "$1" == "enable" ]; then
  28. update-rc.d firstrun start 38 S .
  29. echo "Enabled firstrun script."
  30. fi
  31.  
  32. if [ "$1" != "start" ] ; then
  33. exit
  34. fi
  35.  
  36. sleep 3 ; clear
  37.  
  38. echo
  39. echo "Doing initial local config of passwords and networking."
  40. echo "To re-use, read and edit /etc/init.d/firstrun, then run"
  41. echo "/etc/init.d/firstrun enable"
  42. echo
  43.  
  44.  
  45. # only prompt in interactive mode
  46. if ! grep -q "noninteractive" /proc/cmdline ; then
  47. stty sane
  48.  
  49. echo "Please specify a root password:"
  50. while ! passwd ; do : ; done
  51.  
  52. if [ -f /usr/bin/vncpasswd ]; then
  53. echo "Please specify a VNC password:"
  54. while ! vncpasswd /etc/vncpass ; do : ; done
  55. fi
  56.  
  57. # hostname:
  58. read -p "Hostname (w/o domain): " hn
  59. echo "$hn" >/etc/hostname
  60. hostname $hn
  61.  
  62. dpkg -s nullmailer &>/dev/null
  63. if [ "$?" == "0" ]; then
  64. read -ei "$DEF_ADMIN" -p "Admin Email Address: " adminaddr
  65. read -ei "$DEF_RELAY" -p "Mail Server: " relayhost
  66. fi
  67.  
  68. read -e -p "Press enter for DHCP or N for static IP configuration [Y/n] " usedhcp
  69.  
  70. case "$usedhcp" in
  71. [Nn])
  72. read -ei "$DEF_DOM" -p "Domain name: " dn
  73. read -ei "$DEF_IP" -p "Primary IP address: " ipaddr
  74. read -ei "$DEF_NM" -p "Subnet Mask: " nm
  75. read -ei "$DEF_GW" -p "Gateway: " gw
  76. read -ei "$DEF_DNS1" -p "First DNS server: " dns1
  77. read -ei "$DEF_DNS2" -p "Second DNS server: " dns2
  78.  
  79. echo "Adding /etc/hosts entry for $ipaddr $hn.$dn"
  80. echo "$ipaddr $hn.$dn $hn" >> /etc/hosts
  81.  
  82. echo "Configuring /etc/resolv.conf with DNS servers $dns1 and $dns2 and search of $dn"
  83. cat /dev/null > /etc/resolv.conf
  84. echo "search $dn" >> /etc/resolv.conf
  85. echo "nameserver $dns1" >> /etc/resolv.conf
  86. echo "nameserver $dns2" >> /etc/resolv.conf
  87.  
  88. echo "Reconfiguring interface eth0 via ifupdown..."
  89.  
  90. of="/etc/network/interfaces"
  91. cat /dev/null > $of
  92. echo "auto lo" >> $of
  93. echo "iface lo inet loopback" >> $of
  94. echo "" >> $of
  95. echo "auto eth0" >> $of
  96. echo "iface eth0 inet static" >> $of
  97. echo " address $ipaddr" >> $of
  98. echo " netmask $nm" >> $of
  99. echo " gateway $gw" >> $of
  100. ;;
  101. [Yy]*)
  102. echo "Setting eth0 as DHCP in /etc/network/interfaces..."
  103.  
  104. rm -f /var/lib/dhcp3/*leases
  105. of="/etc/network/interfaces"
  106. cat /dev/null > $of
  107. echo "auto lo" >> $of
  108. echo "iface lo inet loopback" >> $of
  109. echo "" >> $of
  110. echo "auto eth0" >> $of
  111. echo "iface eth0 inet dhcp" >> $of
  112. ;;
  113. esac
  114. fi
  115.  
  116. hn=`hostname`
  117. dn=$DEF_DOM
  118.  
  119. echo "Re-generating unique host keys for your SSH server..."
  120. find /etc/ssh -name "ssh_host_*_key*" -exec rm -f {} \;
  121. DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical dpkg-reconfigure openssh-server
  122.  
  123. dpkg -s puppet &>/dev/null && (
  124. echo "Re-generating unique keys for puppet configuration management..."
  125. find /var/lib/puppet/ssl -type f -exec rm {} \;
  126. DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical dpkg-reconfigure puppet
  127. echo "Puppet setup complete. Contact puppetmaster admin to approve keys."
  128. )
  129.  
  130. dpkg -s postfix &>/dev/null && (
  131. echo "Reconfiguring postfix mailer"
  132. rm -f /etc/mailname /etc/postfix/main.cf
  133. echo "postfix postfix/mailname string $hn.$dn" | debconf-set-selections
  134. DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical dpkg-reconfigure postfix
  135. )
  136.  
  137. dpkg -s nullmailer &>/dev/null && (
  138. echo "Reconfiguring nullmailer..."
  139. rm -f /etc/mailname /etc/nullmailer/*
  140. echo "nullmailer shared/mailname string $hn.$dn" | debconf-set-selections
  141. echo "nullmailer nullmailer/adminaddr string $adminaddr" | debconf-set-selections
  142. echo "nullmailer nullmailer/relayhost string $relayhost" | debconf-set-selections
  143. DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical dpkg-reconfigure nullmailer
  144. )
  145.  
  146. update-rc.d -f firstrun remove &>/dev/null
  147. echo "done with first-run config."
Add Comment
Please, Sign In to add comment