Guest User

Untitled

a guest
Mar 2nd, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.77 KB | None | 0 0
  1. # NanoBSD configuration file that modifies functions in the
  2. # /usr/src/tools/tools/nanobsd/nanobsd.sh script to extract
  3. # a FreeBSD system from installation media rather than compiling
  4. # from source.
  5. #
  6. # Copyright (c) 2013 Ross McKelvie
  7. # All rights reserved.
  8. #
  9. # Redistribution and use in source and binary forms, with or without
  10. # modification, are permitted provided that the following conditions
  11. # are met:
  12. # 1. Redistributions of source code must retain the above copyright
  13. #    notice, this list of conditions and the following disclaimer.
  14. # 2. Redistributions in binary form must reproduce the above copyright
  15. #    notice, this list of conditions and the following disclaimer in the
  16. #    documentation and/or other materials provided with the distribution.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  19. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  22. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. # SUCH DAMAGE.
  29. #
  30.  
  31. PROJECT_DIR=/home/user/projects/nanobsd
  32.  
  33. # Standard NanoBSD configuration options go here
  34. NANO_NAME=binary_build
  35. NANO_LABEL="keg"
  36.  
  37. NANO_OBJ="${PROJECT_DIR}/output"
  38. NANO_IMAGES=2
  39. NANO_INIT_IMG2=0
  40.  
  41. # Size of the /etc ramdisk in 512 bytes sectors
  42. NANO_RAM_ETCSIZE=51200
  43.  
  44. # Size of the /tmp+/var ramdisk in 512 bytes sectors
  45. NANO_RAM_TMPVARSIZE=204800
  46.  
  47. ## Custom NanoBSD configuration options for binary install
  48. # INSTALLFILESDIR The directory where the installation tarballs
  49. #                 are located. This is where you downloaded the
  50. #                 tarballs or the freebsd-dist directory on your
  51. #                 installation media, without a trailing slash.
  52. INSTALLFILESDIR="${PROJECT_DIR}/dists"
  53.  
  54. # WORLD_TXZ the list of tarballs that will be expanded from the
  55. #           installation media; edit this to install additional
  56. #           packages:
  57. #           - base.txz  Base system including man pages (REQUIRED)
  58. #           - doc.txz   Documentation, including FreeBSD handbook
  59. #           - games.txz "Useful and semi-frivolous programs"    
  60. #           - lib32.txz 32-bit libraries for 64-bit x86 systems
  61. #           - ports.txz Ports tree
  62. #           - src.txz   System source code
  63. WORLD_TXZ="base.txz"
  64.  
  65. # KERNEL_TXZ the list of kernel tarballs that will be expanded from
  66. #            the installation media. For vanilla FreeBSD installation
  67. #            media this will most likely just be the GENERIC kernel.
  68. KERNEL_TXZ="kernel.txz"
  69.  
  70. # DO_FETCH_UPDATES Set to true to use freebsd-update to fetch updates
  71. #                  to be applied to NanoBSD. Note this assumes that
  72. #                  you are running a RELEASE version of FreeBSD and the
  73. #                  the version on your build machine matches the version
  74. #                  you are using for NanoBSD.
  75. #                  Control freebsd-update through /etc/freebsd-update.conf
  76. DO_FETCH_UPDATES=false  ## disable for now. no updates yet
  77.  
  78.  
  79. # DO_INSTALL_UPDATES Set to true to use freebsd-update to install updates
  80. #                    to NanoBSD. Note this assumes that
  81. #                    you are running a RELEASE version of FreeBSD and the
  82. #                    the version on your build machine matches the version
  83. #                    you are using for NanoBSD.
  84. #                    Control freebsd-update through /etc/freebsd-update.conf
  85. DO_INSTALL_UPDATES=false  ## disable for now. no updates yet
  86.  
  87.  
  88. # List of packages to install
  89. PACKAGELIST='
  90.  bash
  91.  ca_root_nss
  92.  curl
  93.  git
  94.  htop
  95.  lsof
  96.  iperf
  97.  netatalk3
  98.  ngrep
  99.  openssl
  100.  pkg
  101.  python27
  102.  rsync
  103.  samba36
  104.  smartmontools
  105.  ssmtp
  106.  sudo
  107.  tmux
  108.  vim-lite
  109.  zfs-stats
  110. '
  111.  
  112. ##########################################################
  113. #
  114. # Custom functions follow. Note these overwrite the
  115. # functions in the nanobsd.sh script, so if you want to
  116. # build your own kernel, you need to comment out the
  117. # build_kernel and install_kernel functions contained in
  118. # this configuration file.
  119. #
  120. # Functions overwritten (and their new purposes) are:
  121. # build_world - Dummy function that does nothing
  122. # build_kernel - Dummy function that does nothing
  123. # install_world - Extracts world from installation tarball(s)
  124. # install_kernel - Extracts kernel(s) from installation tarball(s)
  125. # install_etc - Creates an empty /etc/make.conf
  126. #
  127. ##########################################################
  128.  
  129.  
  130. ##########################################################
  131. # Replace build_world with a dummy version
  132.  
  133. build_world ( ) (
  134.    pprint 2 "Instead of buildworld, a built world will be extracted from installation media"
  135.    pprint 3 "Log: ${MAKEOBJDIRPREFIX}/.bw"
  136.    echo "Custom configuration file used. buildworld not processed; a built world will be extracted from installation media." > ${MAKEOBJDIRPREFIX}/_.bw 2>&1  
  137. )
  138.  
  139. ##########################################################
  140. # Replace build_world with a dummy version
  141.  
  142. build_kernel ( ) (
  143.    pprint 2 "Instead of building kernel, a built kernel will be extracted from installation media"
  144.    pprint 3  "Log: ${MAKEOBJDIRPREFIX}/.bk"
  145.    echo "Custom configuration file used. buildkernel not processed; a built kernel will be extracted from installation media." > ${MAKEOBJDIRPREFIX}/_.bk 2>&1  
  146. )
  147.  
  148. ##########################################################
  149. # install_world Function to replace standard nanobsd.sh
  150. #               world installation with expansion of tarballs
  151. #               from installation media.
  152.  
  153. install_world ( ) (
  154.    pprint 2 "Install world by expanding installation tarball(s)"
  155.    pprint 3 "Log: ${NANO_OBJ}/_.iw"
  156.  
  157.    # Check the directory holding the tarballs exists
  158.    if [ ! -d "${INSTALLFILESDIR}" ]; then
  159.       echo "Error: Directory for installation tarballs ${INSTALLFILESDIR} does not exist"
  160.       exit 1  
  161.     fi
  162.  
  163.    # Check tarballs exist
  164.    for tarball in ${WORLD_TXZ}; do
  165.       if [ ! -f "${INSTALLFILESDIR}/${tarball}" ]; then
  166.          echo "Error: Installation tarball $1 does not exist in $INSTALLATIONFILESDIR."
  167.       exit 1
  168.       fi
  169.    done
  170.  
  171.    # Install the tarballs
  172.    for tarball in ${WORLD_TXZ}; do
  173.       pprint 3 "Unpacking ${INSTALLFILESDIR}/${tarball}"
  174.       xzdec "${INSTALLFILESDIR}/${tarball}" | tar --unlink -xpJf - -C ${NANO_WORLDDIR} > ${NANO_OBJ}/_.iw 2>&1
  175.    done
  176. )
  177.  
  178. ##########################################################
  179. # install_kernel Function to replace standard nanobsd.sh
  180. #                kernel installation with expansion of tarball(s)
  181. #                from installation media.
  182.  
  183. install_kernel ( ) (
  184.    pprint 2 "Install kernel(s) by expanding installation tarballs"
  185.    pprint 3 "Log: ${NANO_OBJ}/_.ik"
  186.  
  187.    # Check the directory holding the tarballs exists
  188.    if [ ! -d "${INSTALLFILESDIR}" ]; then
  189.       echo "Error: Directory for installation tarballs ${INSTALLFILESDIR} does not exist"
  190.       exit 1  
  191.     fi
  192.  
  193.    # Check tarballs exist
  194.    for tarball in ${KERNEL_TXZ}; do
  195.       if [ ! -f "${INSTALLFILESDIR}/${tarball}" ]; then
  196.          echo "Error: Installation tarball $1 does not exist in $INSTALLATIONFILESDIR."
  197.       exit 1
  198.       fi
  199.    done
  200.  
  201.    # Install the tarballs
  202.    for tarball in ${KERNEL_TXZ}; do
  203.       pprint 3 "Unpacking ${INSTALLFILESDIR}/${tarball}"
  204.       xzdec "${INSTALLFILESDIR}/${tarball}" | tar --unlink -xpJf - -C ${NANO_WORLDDIR} > ${NANO_OBJ}/_.ik 2>&1
  205.    done
  206. )
  207.  
  208. ##########################################################
  209. # install_etc Function to replace standard nanobsd.sh
  210. #             etc installation with minimal version.
  211.  
  212. install_etc () (
  213.    pprint 2 "Install /etc"
  214.    pprint 3 "Log: ${NANO_OBJ}/_.etc"
  215.  
  216.    # make.conf doesn't get created by default, but some
  217.    # ports need it so they can spam it.
  218.    cp /dev/null "${NANO_WORLDDIR}/etc/make.conf"
  219. )
  220.  
  221. ##########################################################
  222. # cust_fetch_updates Use freebsd-update to fetch security
  223. #                    updates for the release.
  224.  
  225. cust_fetch_updates ( ) (
  226.    if $DO_FETCH_UPDATES; then
  227.       freebsd-update -b ${NANO_WORLDDIR} fetch
  228.    fi
  229. )
  230.  
  231. ##########################################################
  232. # cust_install_updates Use freebsd-update to install
  233. #                      security updates for the release.
  234.  
  235. cust_install_updates ( ) (
  236.    if $DO_INSTALL_UPDATES ; then
  237.       freebsd-update -b ${NANO_WORLDDIR} install
  238.    fi
  239. )
  240.  
  241. zfs_tunables() (
  242.     cat ${PROJECT_DIR}/configs/loader.conf >> ${NANO_WORLDDIR}/boot/loader.conf
  243.     #cp ${PROJECT_DIR}/configs/sysctl.conf ${NANO_WORLDDIR}/etc/sysctl.conf
  244. )
  245.  
  246. install_packages () (
  247.     cp /etc/resolv.conf ${NANO_WORLDDIR}/etc/
  248.     env SSL_NO_VERIFY_HOSTNAME="true" \
  249.         SSL_NO_VERIFY_PEER="true" \
  250.         pkg -c ${NANO_WORLDDIR} install -y ${PACKAGELIST}
  251.     env SSL_NO_VERIFY_HOSTNAME="true" \
  252.         SSL_NO_VERIFY_PEER="true" \
  253.         pkg -c ${NANO_WORLDDIR} clean -a -y
  254.     rm -f ${NANO_WORLDDIR}/var/db/pkg/repo-*.sqlite
  255.     rm -f ${NANO_WORLDDIR}/etc/resolv.conf
  256. )
  257.  
  258. htop_fix_fstab() {
  259.     cd ${NANO_WORLDDIR}
  260.     mkdir -p compat/linux/proc
  261.     echo "linproc /compat/linux/proc linprocfs rw,late 0 0" >> etc/fstab
  262. }
  263.  
  264. #FlashDevice generic 4G
  265. UsbDevice Generic 4000
  266. customize_cmd cust_fetch_updates
  267. customize_cmd cust_install_updates
  268. customize_cmd cust_install_files
  269. customize_cmd cust_allow_ssh_root
  270. customize_cmd install_packages
  271. customize_cmd zfs_tunables
  272. customize_cmd htop_fix_fstab
Advertisement
Add Comment
Please, Sign In to add comment