freebsd_installer.sh

  1. #!/bin/sh
  2. ################################################################################
  3. # Copyright (c) 2016, Manuel Strauch (manuel.strauch@outlook.com)
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are met:
  8. #
  9. #  -Redistributions of source code must retain the above copyright notice,
  10. #   this list of conditions and the following disclaimer.
  11. #  -Redistributions in binary form must reproduce the above copyright notice,
  12. #   this list of conditions and the following disclaimer in the documentation
  13. #   and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  19. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. # POSSIBILITY OF SUCH DAMAGE.
  26. ################################################################################
  27.  
  28. ### Config
  29. scriptversion="3.1.0"
  30. freebsdversion="11.0"
  31. freebsdtype="RELEASE"
  32. zfs_needed_mem="4"
  33. sourcedir="/usb/FreeBSD_install"
  34. destinationdir="/mnt/install"
  35. installdir="/mnt"
  36. prg_gpart="/sbin/gpart"
  37. prg_zfs="/sbin/zfs"
  38. prg_zpool="/sbin/zpool"
  39. freebsdurl="http://ftp2.de.freebsd.org/pub/FreeBSD/releases"
  40.  
  41.  
  42. ### Program (DONT TOUCH)
  43. DONE="\033[80C\033[11D\033[1;34m -= OK =-\033[m"
  44. GREEN="\033[1;32m"
  45. RED="\033[1;31m"
  46. NORMAL="\033[m"
  47. DOWNLOADDONE="\033[2A\033[80C\033[11D\033[1;34m -= OK =-\033[1B\033[m"
  48. amd64pkg="base.txz doc.txz kernel.txz lib32.txz"
  49. jaili386="base.txz doc.txz"
  50. jailamd64="base.txz doc.txz lib32.txz"
  51. mfsportspkg=" ../../ports.txz"
  52. mfssrcpkg=" ../../src.txz"
  53. portspkg=" ports.txz"
  54. srcpkg=" src.txz"
  55.  
  56. realmem="`dmesg | grep "real memory" | sed -e 's/[^ ].* = \([0-9].*\) ([^ ].*$/\1/'`"
  57. realmem_format="`expr ${realmem} / 1024 / 1024 / 1024`"
  58. installmode="normal"
  59. masterjail="no"
  60. arch="`uname -m`"
  61. mfs="no"
  62. tmpfs="no"
  63. zfs="no"
  64. ports="no"
  65. src="no"
  66.  
  67. ################################################################################
  68. ################################################################################
  69. find_options() {
  70.   shift
  71.   for i in ${@}; do
  72.     option="`echo "${i}" | cut -f1 -d':'`"
  73.     case "${option}" in
  74.       --installmode | -i)
  75.         t="`echo "${i}" | cut -f2 -d':'`"
  76.         if [ "${t}" = "db-or-mail" ] || [ "${t}" = "alix" ]; then
  77.           installmode="${t}"
  78.         fi
  79.       ;;
  80.       --masterjail | -mj)
  81.         t="`echo "${i}" | cut -f2 -d':'`"
  82.         if [ "${t}" = "jroot" ]; then
  83.           masterjail="jroot"
  84.         fi
  85.         if [ "${t}" = "normal" ]; then
  86.           masterjail="normal"
  87.         fi
  88.       ;;
  89.       --tmpfs | -t)
  90.         t="`echo "${i}" | cut -f2 -d':'`"
  91.         if [ "${t}" = "yes" ] || [ "${t}" = "-t" ]; then
  92.           tmpfs="yes"
  93.         fi
  94.       ;;
  95.       --zfs | -z)
  96.         t="`echo "${i}" | cut -f2 -d':'`"
  97.         if [ "${t}" = "yes" ] || [ "${t}" = "-z" ]; then
  98.           if [ ${realmem_format} -lt ${zfs_needed_mem} ]; then
  99.             zfs_info="zfs use min. ${zfs_needed_mem}GB RAM, i will use ufs2!"
  100.             zfs="no"
  101.           else
  102.             zfs="yes"
  103.             kldload opensolaris
  104.             kldload zfs
  105.           fi
  106.         fi
  107.       ;;
  108.       --ports | -p)
  109.         t="`echo "${i}" | cut -f2 -d':'`"
  110.         if [ "${t}" = "yes" ] || [ "${t}" = "-p" ]; then
  111.           ports="yes"
  112.           if [ -e /etc/hsi-version ]; then
  113.             amd64pkg="${amd64pkg} ${mfsportspkg}"
  114.           else
  115.             amd64pkg="${amd64pkg} ${portspkg}"
  116.           fi
  117.         fi
  118.       ;;
  119.       --source | -s)
  120.         t="`echo "${i}" | cut -f2 -d':'`"
  121.         if [ "${t}" = "yes" ] || [ "${t}" = "-s" ]; then
  122.           src="yes"
  123.           if [ -e /etc/hsi-version ]; then
  124.             amd64pkg="${amd64pkg} ${mfssrcpkg}"
  125.           else
  126.             amd64pkg="${amd64pkg} ${srcpkg}"
  127.           fi
  128.         fi
  129.       ;;
  130.       *)
  131.         echo "syntax error!!"
  132.         echo "option { "${i}" } was not supported!"
  133.         exit 1
  134.       ;;
  135.     esac
  136.   done
  137. }
  138.  
  139. ################################################################################
  140. ################################################################################
  141. find_mfsbsd() {
  142.   ### only when special mfsbsd was booted
  143.   if [ -e /etc/hsi-version ]; then
  144.     mfs="yes"
  145.     mount -t cd9660 /dev/cd0 /cdrom
  146.     sourcedir="/cdrom"
  147.   fi
  148. }
  149.  
  150. ################################################################################
  151. ################################################################################
  152. check_options() {
  153.   if [ "${zfs}" = "yes" ]; then
  154.     arch="amd64"
  155.   fi
  156.   clear
  157.   echo "starting installer version ${scriptversion} for FreeBSD ${freebsdversion}-${freebsdtype}"
  158.   echo " --> installing FreeBSD on ${1} with the following options:"
  159.   echo -e "\033[6C\033[m installmode = ${GREEN}${installmode}${NORMAL}"
  160.   echo -e "\033[6C\033[m masterjail\033[1C = ${GREEN}${masterjail}${NORMAL}"
  161.   echo -e "\033[6C\033[m arch\033[7C = ${GREEN}${arch}${NORMAL}"
  162.   echo -e "\033[6C\033[m tmpfs\033[6C = ${GREEN}${tmpfs}${NORMAL}"
  163.   echo -e "\033[6C\033[m MFS\033[8C = ${GREEN}${mfs}${NORMAL}"
  164.   echo -e "\033[6C\033[m Source\033[5C = ${GREEN}${src}${NORMAL}"
  165.   echo -e "\033[6C\033[m Ports\033[6C = ${GREEN}${ports}${NORMAL}"
  166.   echo -e "\033[6C\033[m ZFS\033[8C = ${GREEN}${zfs}${NORMAL}"
  167.   echo -e "\033[20C\033[m ${RED}${zfs_info}${NORMAL}"
  168.   echo
  169.   echo -n "Press (y) to start the installation: "
  170.   read startinstall
  171.   if [ "${startinstall}" != "y" ]; then
  172.     exit 0
  173.   fi
  174. }
  175.  
  176. ################################################################################
  177. ################################################################################
  178. create_ufs_partitions() {
  179.   echo -n "  --> destroy all partitions on ${1}"
  180.   ${prg_gpart} destroy -F ${1} >/dev/null 2>&1
  181.   echo -e "${DONE}"
  182.   echo -n "  --> create GPT on ${1}"
  183.   ${prg_gpart} create -s gpt ${1} >/dev/null 2>&1
  184.   echo -e "${DONE}"
  185.   echo -n "  --> create boot partition on ${1}"
  186.   ${prg_gpart} add -s 128k -t freebsd-boot -l boot -i 1 ${1} >/dev/null 2>&1
  187.   echo -e "${DONE}"
  188.   echo -n "   --> insert bootcode on ${1}"
  189.   ${prg_gpart} bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ${1} >/dev/null 2>&1
  190.   echo -e "${DONE}"
  191.   if [ "${installmode}" = "alix" ]; then
  192.     echo -n "  --> create root partition on ${1}"
  193.     ${prg_gpart} add -t freebsd-ufs -l root -i 2 ${1} >/dev/null 2>&1
  194.     echo -e "${DONE}"
  195.     echo -n "  --> UFS format all partitions "
  196.     newfs -O2 "/dev/${1}p2" >/dev/null 2>&1  
  197.     echo -e "${DONE}"
  198.     echo -n "  --> mount all partitions "
  199.     if [ ! -d "${installdir}" ]; then
  200.       mkdir "${installdir}"
  201.     fi
  202.     mount "/dev/${1}p2" "${installdir}"
  203.     mkdir "${destinationdir}"
  204.     echo -e "${DONE}"
  205.   else
  206.     z=2
  207.     echo -n "  --> create 2GB swap partition on ${1}"
  208.     ${prg_gpart} add -s 2G -t freebsd-swap -i ${z} ${1} >/dev/null 2>&1
  209.     echo -e "${DONE}"
  210.     z=`expr ${z} + 1`
  211.     echo -n "  --> create 1GB root partition on ${1}"
  212.     ${prg_gpart} add -s 1G -t freebsd-ufs -l root -i ${z} ${1} >/dev/null 2>&1
  213.     echo -e "${DONE}"
  214.     if [ "${tmpfs}" = "no"  ]; then
  215.       z=`expr ${z} + 1`
  216.       echo -n "  --> create 1GB tmp partition on ${1}"
  217.       ${prg_gpart} add -s 1G -t freebsd-ufs -l tmp -i ${z} ${1} >/dev/null 2>&1
  218.       echo -e "${DONE}"
  219.     fi
  220.     z=`expr ${z} + 1`
  221.     if [ ${installmode} = "db-or-mail" ]; then
  222.       echo -n "  --> create 15GB var partition on ${1}"
  223.       ${prg_gpart} add -s 15G -t freebsd-ufs -l var -i ${z} ${1} >/dev/null 2>&1
  224.       echo -e "${DONE}"
  225.     else
  226.       echo -n "  --> create 2GB var partition on ${1}"
  227.       ${prg_gpart} add -s 2G -t freebsd-ufs -l var -i ${z} ${1} >/dev/null 2>&1
  228.       echo -e "${DONE}"
  229.     fi
  230.     z=`expr ${z} + 1`
  231.     echo -n "  --> create usr partition on ${1}"
  232.     ${prg_gpart} add -t freebsd-ufs -l usr -i ${z} ${1} >/dev/null 2>&1
  233.     echo -e "${DONE}"
  234.     echo -n "  --> UFS format all partitions "
  235.     if [ ${tmpfs} = "yes" ]; then
  236.       partitions="${1}p3 ${1}p4 ${1}p5"
  237.     else
  238.       partitions="${1}p3 ${1}p4 ${1}p5 ${1}p6"
  239.     fi
  240.     for i in ${partitions}; do
  241.       if [ "${i}" = "${1}p3" ]; then
  242.         newfs -O2 "/dev/${1}p3" >/dev/null 2>&1  
  243.       else
  244.         newfs -O2 -U "/dev/${i}" >/dev/null 2>&1  
  245.       fi
  246.     done
  247.     echo -e "${DONE}"
  248.     echo -n "  --> mount all partitions "
  249.     if [ ! -d "${installdir}" ]; then
  250.       mkdir "${installdir}"
  251.     fi
  252.     mount "/dev/${1}p3" "${installdir}"
  253.     mkdir "${destinationdir}"
  254.     mkdir "${installdir}/tmp" "${installdir}/var" "${installdir}/usr"
  255.     if [ ${tmpfs} = "no" ]; then
  256.       mount "/dev/${1}p4" "${installdir}/tmp"
  257.       mount "/dev/${1}p5" "${installdir}/var"
  258.       mount "/dev/${1}p6" "${installdir}/usr"
  259.     else
  260.       mount "/dev/${1}p4" "${installdir}/var"
  261.       mount "/dev/${1}p5" "${installdir}/usr"
  262.     fi
  263.     echo -e "${DONE}"
  264.   fi
  265. }
  266.  
  267. ################################################################################
  268. ################################################################################
  269. create_zfs_partitions() {
  270.   echo -n "  --> destroy all partitions on ${1}"
  271.   ${prg_gpart} destroy -F ${1} >/dev/null 2>&1
  272.   echo -e "${DONE}"
  273.   echo -n "  --> create GPT on ${1}"
  274.   ${prg_gpart} create -s gpt ${1} >/dev/null 2>&1
  275.   echo -e "${DONE}"
  276.   echo -n "  --> create boot partition on ${1}"
  277.   ${prg_gpart} add -s 128k -t freebsd-boot -l boot -i 1 ${1} >/dev/null 2>&1
  278.   echo -e "${DONE}"
  279.   echo -n "   --> insert bootcode on ${1}"
  280.   ${prg_gpart} bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${1} >/dev/null 2>&1
  281.   echo -e "${DONE}"
  282.   echo -n "  --> create 2GB swap partition on ${1}"
  283.   ${prg_gpart} add -s 2G -t freebsd-swap -i 2 ${1} >/dev/null 2>&1
  284.   echo -e "${DONE}"
  285.   echo -n "  --> create tank partition on ${1}"
  286.   ${prg_gpart} add -t freebsd-zfs -l root -i 3 ${1} >/dev/null 2>&1
  287.   echo -e "${DONE}"
  288.   echo -n "  --> create tank on ${1}p3"
  289.   ${prg_zpool} create -f -O checksum=fletcher4 -O atime=off -O canmount=off -O mountpoint=${installdir} tank ${1}p3
  290.   ${prg_zfs} create -o mountpoint=legacy -o setuid=on tank/root
  291.   if [ ! -d "${installdir}" ]; then
  292.     mkdir "${installdir}"
  293.   fi
  294.   mount -t zfs tank/root "${installdir}"
  295.   ${prg_zfs} create -o canmount=off tank/usr
  296.   ${prg_zfs} create tank/usr/home
  297.   ${prg_zfs} create -o compress=lzjb -o exec=off tank/usr/obj
  298.   ${prg_zfs} create -o compress=gzip tank/usr/ports
  299.   ${prg_zfs} create -o compress=off -o exec=off tank/usr/ports/distfiles
  300.   ${prg_zfs} create -o compress=off -o exec=off tank/usr/ports/packages
  301.   ${prg_zfs} create -o compress=gzip -o exec=off tank/usr/src
  302.   ${prg_zfs} create -o exec=off -o canmount=off tank/var
  303.   ${prg_zfs} create -o compress=lzjb tank/var/audit
  304.   ${prg_zfs} create -o compress=lzjb tank/var/crash
  305.   ${prg_zfs} create tank/var/db
  306.   ${prg_zfs} create -o compress=lzjb -o exec=on tank/var/db/pkg
  307.   ${prg_zfs} create tank/var/empty
  308.   ${prg_zfs} create -o compress=gzip tank/var/log
  309.   ${prg_zfs} create -o compress=gzip tank/var/mail
  310.   ${prg_zfs} create tank/var/run
  311.   mkdir "${destinationdir}"
  312.   mkdir "${installdir}/tmp"
  313.   echo -e "${DONE}"
  314. }
  315.  
  316. ################################################################################
  317. ################################################################################
  318. download_needed_files() {
  319.   echo " --> install FreeBSD ${freebsdversion}-${freebsdtype} ${arch}"
  320.       pkg="${amd64pkg}"
  321.       if [ -d "${sourcedir}/${freebsdversion}/${arch}" ]; then
  322.         echo  "  --> found local install files"
  323.         for i in ${pkg}; do
  324.           echo -n "  --> copy file ${i} to ${destinationdir}"
  325.           cp "${sourcedir}/${freebsdversion}/${arch}/${i}" "${destinationdir}"
  326.           echo -e "${DONE}"
  327.         done
  328.       else
  329.         echo "  --> download install files"
  330.         for i in ${pkg}; do
  331.           echo -n "   --> download file ${i} to ${destinationdir}"
  332.           cd "${destinationdir}"
  333.           fetch "${freebsdurl}/${arch}/${freebsdversion}-${freebsdtype}/${i}"
  334.           echo -e "${DOWNLOADDONE}"
  335.         done
  336.       fi
  337. }
  338.  
  339. ################################################################################
  340. ################################################################################
  341. install_freebsd() {
  342.   cd "${installdir}"
  343.   for i in `ls -1 ${destinationdir}/*.txz`; do
  344.     echo -n "   --> install file ${i} to ${installdir}"
  345.     tar -xzpf "${i}"
  346.     echo -e "${DONE}"
  347.   done
  348.   if [ ! -d usr/ports ]; then
  349.     mkdir usr/ports
  350.   fi
  351.   if [ ! -d usr/src ]; then
  352.     mkdir usr/src
  353.   fi
  354. }
  355.  
  356. ################################################################################
  357. ################################################################################
  358. configure_ufs_freebsd() {
  359.   echo -n " --> create ${installdir}/etc/fstab"
  360.   if [ ${installmode} = "alix" ]; then
  361.     if [ ${tmpfs} = "yes" ]; then
  362.       echo "/dev/${1}p2 /       ufs     rw      1       1
  363. tmpfs   /tmp    tmpfs   rw,mode=777     0       0
  364. " > "${installdir}/etc/fstab"
  365.     else
  366.       echo "/dev/${1}p2 /       ufs     rw      1       1 " > "${installdir}/etc/fstab"
  367.     fi
  368.   else
  369.     if [ ${tmpfs} = "yes" ]; then
  370.       echo "/dev/${1}p2 none    swap    sw      0       0
  371. /dev/${1}p3     /       ufs     rw      1       1
  372. tmpfs   /tmp    tmpfs   rw,mode=777     0       0
  373. /dev/${1}p4     /var    ufs     rw      2       2
  374. /dev/${1}p5     /usr    ufs     rw      2       2
  375. " > "${installdir}/etc/fstab"
  376.     else
  377.       echo "/dev/${1}p2 none    swap    sw      0       0
  378. /dev/${1}p3     /       ufs     rw      1       1
  379. /dev/${1}p4     /tmp    ufs     rw      2       2
  380. /dev/${1}p5     /var    ufs     rw      2       2
  381. /dev/${1}p6     /usr    ufs     rw      2       2
  382. " > "${installdir}/etc/fstab"
  383.     fi
  384.   fi
  385.   echo "fdesc   /dev/fd fdescfs rw      0       0" >> "${installdir}/etc/fstab"
  386.   echo -e "${DONE}"
  387.   echo -n " --> create ${installdir}/etc/rc.conf"
  388.   all_interfaces="`ifconfig | egrep "^[a-z][a-z]?[a-z]?[a-z][0-9]" | cut -f1 -d':'`"
  389.   echo 'hostname="beastie.freebsd.local"' > "${installdir}/etc/rc.conf"
  390.   for i in ${all_interfaces}; do
  391.     if [ "${i}" != "lo0" ] ; then
  392.       echo "ifconfig_${i}=\"DHCP\"" >> "${installdir}/etc/rc.conf"
  393.     fi
  394.   done
  395.   echo '
  396. keymap="de"
  397. keyrate="fast"
  398. scrnmap="NO"
  399.  
  400. #### Services
  401. sshd_enable="YES"
  402. sendmail_enable="NONE"
  403. sendmail_outbound_enable="NO"
  404. sendmail_submit_enable="NO"
  405. sendmail_msp_queue_enable="NO"
  406. vm_enable="YES"
  407. vm_dir="/home/bhyve"
  408.  
  409. ' >> "${installdir}/etc/rc.conf"
  410.   echo -e "${DONE}"
  411.   echo -n " --> create ${installdir}/etc/sysctl.conf"
  412.   echo 'kern.coredump=0
  413.  
  414. ### Hyper-V WLAN
  415. net.link.ether.inet.max_age=60
  416. ### bhyve
  417. net.link.tap.up_on_open=1
  418.  
  419. ' >> "${installdir}/etc/sysctl.conf"
  420.   echo -e "${DONE}"
  421.   echo -n " --> create ${installdir}/boot/loader.conf"
  422.   echo 'loader_color="YES"
  423. loader_logo="beastie"
  424. vmm_load="YES"
  425. nmdm_load="YES"
  426. if_bridge_load="YES"
  427. if_tap_load="YES"
  428.  
  429. ' > "${installdir}/boot/loader.conf"
  430.   echo -e "${DONE}"
  431.  
  432. }
  433.  
  434. configure_zfs_freebsd() {
  435.   echo -n " --> create ${installdir}/etc/fstab"
  436.   if [ ${tmpfs} = "yes" ]; then
  437.     echo "/dev/${1}p2   none    swap    sw      0       0
  438. tmpfs   /tmp    tmpfs   rw,mode=777     0       0
  439. " > "${installdir}/etc/fstab"
  440.   else
  441.       echo "/dev/${1}p2 none    swap    sw      0       0
  442. " > "${installdir}/etc/fstab"
  443.   fi
  444.   echo "fdesc   /dev/fd fdescfs rw      0       0" >> "${installdir}/etc/fstab"
  445.   echo -e "${DONE}"
  446.   echo -n " --> create ${installdir}/etc/rc.conf"
  447.   all_interfaces="`ifconfig | egrep "^[a-z][a-z]?[a-z]?[a-z][0-9]" | cut -f1 -d':'`"
  448.   echo 'hostname="beastie.freebsd.local"' > "${installdir}/etc/rc.conf"
  449.   for i in ${all_interfaces}; do
  450.     if [ "${i}" != "lo0" ] ; then
  451.       echo "ifconfig_${i}=\"DHCP\"" >> "${installdir}/etc/rc.conf"
  452.     fi
  453.   done
  454.   echo '
  455. keymap="de"
  456. keyrate="fast"
  457. scrnmap="NO"
  458.  
  459. #### Services
  460. zfs_enable="YES"
  461. sshd_enable="YES"
  462. sendmail_enable="NONE"
  463. sendmail_outbound_enable="NO"
  464. sendmail_submit_enable="NO"
  465. sendmail_msp_queue_enable="NO"
  466. vm_enable="YES"
  467. vm_dir="/home/bhyve"
  468.  
  469.  
  470. ' >> "${installdir}/etc/rc.conf"
  471.   echo -e "${DONE}"
  472.   echo -n " --> create ${installdir}/etc/sysctl.conf"
  473.   echo 'kern.coredump=0
  474.  
  475. ### Hyper-V WLAN
  476. net.link.ether.inet.max_age=60
  477. ### bhyve
  478. net.link.tap.up_on_open=1
  479.  
  480. ' >> "${installdir}/etc/sysctl.conf"
  481.   echo -e "${DONE}"
  482.  
  483.   echo -n " --> create ${installdir}/boot/loader.conf"
  484.   echo 'loader_color="YES"
  485. loader_logo="beastie"
  486. zfs_load="YES"
  487. vfs.root.mountfrom="zfs:tank/root"
  488. vm.kmem_size="512M"
  489. vm.kmem_size_max="512M"
  490. vfs.zfs.arc_max="40M"
  491. vfs.zfs.vdev.cache.size="5M"
  492. vmm_load="YES"
  493. nmdm_load="YES"
  494. if_bridge_load="YES"
  495. if_tap_load="YES"
  496.  
  497. ' > "${installdir}/boot/loader.conf"
  498.   echo -e "${DONE}"
  499. }
  500.  
  501. ################################################################################
  502. ################################################################################
  503. configure_freebsd_part2() {
  504.   echo -n " --> create resolv.conf"
  505.   cp /etc/resolv.conf "${installdir}/etc/resolv.conf"
  506.   mkdir "${installdir}/usr/local/etc" >/dev/null 2>&1
  507.   mkdir "${installdir}/usr/local/etc/rc.d" >/dev/null 2>&1
  508.   ln -s /opt/bin/install_default_pkg.sh "${installdir}/usr/local/etc/rc.d/Z99_install_default_pkg.sh"
  509.   echo -e "${DONE}"
  510.  
  511.   echo -n " --> setting up timezone to Europe/Berlin"
  512.   cp "${installdir}/usr/share/zoneinfo/Europe/Berlin" \
  513.      "${installdir}/etc/localtime"
  514.   echo -e "${DONE}"
  515.  
  516.   echo -n " --> configure syslog daemon"
  517.   cp ${sourcedir}/syslog.conf "${installdir}/etc/syslog.conf"
  518.   echo -e "${DONE}"
  519.  
  520. }
  521.  
  522. ################################################################################
  523. ################################################################################
  524. install_opt() {
  525.   echo -n " --> install /opt"
  526.   cd ${installdir}
  527.   if [ "${mfs}" = "no" ]; then
  528.     fetch http://www.anukis.de/download/opt.tgz >/dev/null 2>&1
  529.   else
  530.     cp ${sourcedir}/opt.tgz .
  531.   fi
  532.   tar -xzf opt.tgz
  533.   chown -R root:wheel opt/
  534.   rm opt.tgz
  535.   echo -e "${DONE}"
  536.  
  537. }
  538.  
  539. ################################################################################
  540. ################################################################################
  541. install_jail_normal() {
  542.   if [ "${masterjail}" = "normal" ]; then
  543.     echo " --> install masterjail ${installdir}/usr/jails/sample"
  544.     mkdir "${installdir}/usr/jails" "${installdir}/usr/jails/sample"
  545.       pkg="${jailamd64}"
  546.     cd "${installdir}/usr/jails/sample"
  547.     for i in ${pkg}; do
  548.       echo -n "  --> install file ${i} to ${installdir}/usr/jails/sample"
  549.       tar -xzpf "${destinationdir}/${i}"
  550.       echo -e "${DONE}"
  551.     done
  552.     echo -n "  --> setting up timezone and default configs"
  553.     touch etc/fstab
  554.     cp "${installdir}/usr/share/zoneinfo/Europe/Berlin" \
  555.        "${installdir}/usr/jails/sample/etc/localtime"
  556.     cp "${installdir}/etc/hosts" \
  557.        "${installdir}/usr/jails/sample/etc/hosts"
  558.     cp "${installdir}/etc/resolv.conf" \
  559.        "${installdir}/usr/jails/sample/etc/resolv.conf"
  560.  
  561.     mkdir usr/home usr/ports usr/src 2>/dev/null
  562.     ln -s usr/home home
  563.     echo "
  564. ### JAILS
  565. /usr/ports      /usr/jails/sample/usr/ports             nullfs  ro      0       0
  566. /usr/src        /usr/jails/sample/usr/src               nullfs  ro      0       0
  567. " >>"${installdir}/usr/jails/fstab.sample"
  568.     echo -e "${DONE}"
  569.   fi
  570. }
  571.  
  572. ################################################################################
  573. ################################################################################
  574. install_jail_jroot() {
  575.   if [ "${masterjail}" = "jroot" ]; then
  576.     echo " --> install masterjail ${installdir}/usr/jails/jroot"
  577.     mkdir "${installdir}/usr/jails" "${installdir}/usr/jails/jroot" "${installdir}/usr/jails/skel"
  578.     pkg="${jailamd64}"
  579.     cd "${installdir}/usr/jails/jroot"
  580.     for i in ${pkg}; do
  581.       echo -n "  --> install file ${i} to ${installdir}/usr/jails/jroot"
  582.       tar -xzpf "${destinationdir}/${i}"
  583.       echo -e "${DONE}"
  584.     done
  585.     echo -n " --> create ${installdir}/usr/jails/skel"
  586.     cd "${installdir}/usr/"
  587.     mkdir jails/jroot/usr/ports >/dev/null 2>&1
  588.     mkdir jails/jroot/usr/src >/dev/null 2>&1
  589.     cd jails/skel
  590.     mkdir home usr-X11R6 distfiles portbuild packages
  591.     cd ../jroot
  592.  
  593.     mkdir s
  594.     mv etc ../skel
  595.     mv usr/local ../skel/usr-local
  596.     mv tmp ../skel
  597.     mv var ../skel
  598.     mv root ../skel
  599.  
  600.     ln -s s/etc etc
  601.     ln -s s/home home
  602.     ln -s s/root root
  603.     ln -s ../s/usr-local usr/local
  604.     ln -s ../s/usr-X11R6 usr/X11R6
  605.     ln -s ../../s/distfiles usr/ports/distfiles
  606.     ln -s s/tmp tmp
  607.     ln -s s/var var
  608.      
  609.     cd ../skel
  610.     echo "WRKDIRPREFIX?=/s/portbuild" >>etc/make.conf
  611.     echo "DISTDIR=/s/distfiles" >>etc/make.conf
  612.     echo "PACKAGES=/tmp" >>etc/make.conf
  613.     touch etc/fstab
  614.     cp "${installdir}/usr/share/zoneinfo/Europe/Berlin" \
  615.        "${installdir}/usr/jails/skel/etc/localtime"
  616.     cp "${installdir}/etc/hosts" \
  617.        "${installdir}/usr/jails/skel/etc/hosts"
  618.     cp "${installdir}/etc/resolv.conf" \
  619.        "${installdir}/usr/jails/skel/etc/resolv.conf"
  620.     echo -e "${DONE}"
  621.     echo -n " --> install sample jail"
  622.     cd ..
  623.     mkdir sample
  624.     cp -Rp skel sample_skel
  625.     echo "
  626. ### JAILS
  627. /usr/jails/jroot           /usr/jails/sample            nullfs  ro      0       0
  628. /usr/jails/sample_skel     /usr/jails/sample/s          nullfs  rw      0       0
  629. /usr/ports                 /usr/jails/sample/usr/ports  nullfs  rw      0       0
  630. /usr/src                   /usr/jails/sample/usr/src    nullfs  rw      0       0
  631. " >"${installdir}/usr/jails/fstab.sample"
  632.     echo -e "${DONE}"
  633.   fi
  634. }
  635.  
  636. ################################################################################
  637. ################################################################################
  638. configure_jail() {
  639.   if [ "${masterjail}" != "no" ]; then
  640.     echo " --> configure sample jail"
  641.     if [ "${masterjail}" = "normal" ]; then
  642.       jailpath="${installdir}/usr/jails/sample"
  643.     else
  644.       jailpath="${installdir}/usr/jails/sample_skel"
  645.     fi
  646.  
  647. ## create Jail make.conf
  648. echo -n "  --> create ${jailpath}/etc/make.conf"
  649. (
  650. cat <<__EOF__
  651. WRKDIRPREFIX?=/tmp
  652. DISTDIR=/home/distfiles
  653. PACKAGES=/tmp
  654.  
  655.  
  656. DOC_LANG=de_DE.ISO8859-1
  657. # -----------------------------------------------------------------------------
  658.  
  659. # Fetching from de sites preferred
  660. MASTER_SORT_REGEX?=://[^/]*\.de[/.]
  661. # -----------------------------------------------------------------------------
  662.  
  663. KERNCONF=GENERIC
  664.  
  665. # wget statt fetch zum downloaden der ports benutzen. falls existiert
  666. .if exists(/usr/local/bin/wget)
  667. DISABLE_SIZE=   yes
  668. FETCH_CMD=      /usr/local/bin/wget --continue --passive-ftp -t 2 -T 15
  669. .endif
  670.  
  671. # --- common ----------------------------------------------------------------
  672. # Default build flags.
  673. #CPUTYPE?=              pentium-m
  674. CFLAGS=-O2 -pipe
  675. # -----------------------------------------------------------------------------
  676.  
  677. # --- common for all ports --------------------------------------------------
  678. BATCH=YES
  679. WITHOUT_DEBUG=yes
  680. # -----------------------------------------------------------------------------
  681. WITH_PKGNG=yes
  682. __EOF__
  683. ) > "${jailpath}/etc/make.conf"
  684. echo -e "${DONE}"
  685.  
  686. ## create Jail rc.conf
  687. echo -n "  --> create ${jailpath}/etc/rc.conf"
  688. (
  689. cat <<__EOF__
  690. syslogd_flags="-s -s"
  691. newsyslog_enable="NO"
  692. syslogd_enable="NO"
  693.  
  694. sendmail_enable="NONE"
  695. sendmail_outbound_enable="NO"
  696. sendmail_submit_enable="NO"
  697. sendmail_msp_queue_enable="NO"
  698. __EOF__
  699. ) > "${jailpath}/etc/rc.conf"
  700. echo -e "${DONE}"
  701.  
  702. ## create Jail hosts
  703. echo -n "  --> create ${jailpath}/etc/hosts"
  704. (
  705. cat <<__EOF__
  706. 192.168.20.1      sample    sample.freebsd.local
  707. __EOF__
  708. ) > "${jailpath}/etc/hosts"
  709.  
  710. echo -e "${DONE}"
  711. fi
  712. }
  713.  
  714. ################################################################################
  715. ################################################################################
  716. dismount_mfsbsd() {
  717.   if [ ${mfs} = "yes" ]; then
  718.     umount /cdrom
  719.   fi
  720. }
  721.  
  722. ################################################################################
  723. ################################################################################
  724. finished() {
  725.   if [ ${zfs} = "yes" ]; then
  726.     if [ ! -d ${installdir}/boot/zfs ]; then
  727.       mkdir ${installdir}/boot/zfs
  728.     fi
  729.     cp /boot/zfs/zpool.cache /${installdir}/boot/zfs/
  730.     ${prg_zfs} set mountpoint=/ tank
  731.     ${prg_zpool} set bootfs=tank/root tank
  732.   fi
  733. }
  734.  
  735.  
  736.  
  737. ################################################################################
  738. ################################################################################
  739. case "${1}" in
  740.   ad[0-9]|da[0-9]|ada[0-9]|mirror/gm[0-9])
  741.     if [ ! -e "/dev/${1}" ]; then
  742.       echo "device ${1} not found!"
  743.       exit 1
  744.     fi
  745.  
  746.     find_options "${@}"
  747.     find_mfsbsd
  748.     check_options
  749.     if [ ${zfs} = "yes" ]; then
  750.       create_zfs_partitions "${1}"
  751.     else
  752.       create_ufs_partitions "${1}"
  753.     fi
  754.     download_needed_files
  755.     install_freebsd
  756.     if [ ${zfs} = "yes" ]; then
  757.       configure_zfs_freebsd "${1}"
  758.     else
  759.       configure_ufs_freebsd "${1}"
  760.     fi
  761.     configure_freebsd_part2 "${1}"
  762.     install_opt
  763.     install_jail_normal
  764.     install_jail_jroot
  765.     configure_jail
  766.     dismount_mfsbsd
  767.     finished
  768.     if [ `echo ${1} | wc -m` -gt 5 ]; then
  769.       echo 'geom_mirror_load="YES"' >>/${installdir}/boot/loader.conf
  770.     fi
  771.     echo
  772.     echo " --> Install finished <-- "
  773.     echo " --> Rebooting the System, remove the CD/DVD please!"
  774.   ;;
  775.   --list | -l)
  776.     echo "FreeBSD Installer version ${scriptversion} for FreeBSD ${freebsdversion}-${freebsdtype}"
  777.     echo "============================================="
  778.     echo "possible FreeBSD install devices are:"
  779.     ls -1 /dev/da[0-9] /dev/ada[0-9] /dev/mirror/gm[0-9] 2>/dev/null | sed -e 's/\/dev\///g' -e 's/^/- /g'
  780.   ;;
  781.   --help | -h)
  782. cat <<__USAGE__
  783.  
  784.     FreeBSD Installer version ${scriptversion} for FreeBSD ${freebsdversion}-${freebsdtype}
  785.     =======================================================================
  786.     usage: ${0} { ada[0-9] | mirror/gm[0-9] | -l | -h }
  787.     -----------------------------------------------------------------------
  788.       { -l | --list } list possible install devices
  789.       { -h | --help } this help
  790.     install mode (default is normal)
  791.       normal=/var 2GB | db-or-mail=/var 15GB | alix=/ complete disc
  792.       { -i:normal | db-or-mail | alix }
  793.       { --installmode:normal | db-or-mail | alix }
  794.     -----------------------------------------------------------------------
  795.     optional options:
  796.       { -mj:jroot  | --masterjail:jroot }  one base for ALL jails
  797.       { -mj:normal | --masterjail:normal } one base for ONE jail
  798.       { -t | --tmpfs:yes }  use tmpfs for /tmp
  799.       { -z | --zfs:yes }    use zfs as filesystem
  800.       { -p | --ports:yes }  install ports
  801.       { -s | --source:yes } install source
  802.     -----------------------------------------------------------------------
  803.     example: ${0} ada0 -i:db-or-mail -t -s -mj:normal
  804.     -----------------------------------------------------------------------
  805.  
  806. __USAGE__
  807.   ;;
  808.   *)
  809.     echo "usage: ${0} --help"
  810.     echo "for --help"
  811.   ;;
  812. esac
  813.  
  814. exit 0