pkvlm-create
changeset 20 ee16d147a06c
parent 18 65301be81959
child 21 e26b3773ae0e
equal deleted inserted replaced
19:b50c8571a067 20:ee16d147a06c
   267 INSTALL_ISO="iso-out/${INSTALL_NAME}.iso"
   267 INSTALL_ISO="iso-out/${INSTALL_NAME}.iso"
   268 
   268 
   269 
   269 
   270 ### Preseed setup
   270 ### Preseed setup
   271 ## preseed.cfg templating
   271 ## preseed.cfg templating
   272 PRESEED_SOURCE_DIR="preseed"
   272 PRESEED_DIR="preseed"
   273 
   273 
   274 # Preseed output file in install tree
   274 # Preseed output file in install tree
   275 PRESEED_NAME="preseed.cfg"
   275 PRESEED_NAME="preseed.cfg"
   276 
   276 
   277 # Mount path of preseed target in installer
   277 # Mount path of preseed target in installer
   280 # Prefix for target files in install tree
   280 # Prefix for target files in install tree
   281 # XXX: not implemented
   281 # XXX: not implemented
   282 #PRESEED_TARGET_PREFIX=""
   282 #PRESEED_TARGET_PREFIX=""
   283 
   283 
   284 # Main preseed source template
   284 # Main preseed source template
   285 PRESEED_TEMPLATE="${PRESEED_SOURCE_DIR}/${PRESEED_NAME}"
   285 PRESEED_TEMPLATE="${PRESEED_DIR}/${PRESEED_NAME}"
   286 
   286 
   287 # Target path for preseed in install tree
   287 # Target path for preseed in install tree
   288 PRESEED_FILE="${INSTALL_TREE}/${PRESEED_NAME}"
   288 PRESEED_FILE="${INSTALL_TREE}/${PRESEED_NAME}"
   289 
   289 
   290 # Checksum of target preseed.cfg
   290 # Checksum of target preseed.cfg
   319 }
   319 }
   320 
   320 
   321 
   321 
   322 ## preseed-files
   322 ## preseed-files
   323 # template source
   323 # template source
   324 CONF_FILES_SOURCE='preseed/files'
   324 PRESEED_FILES_SOURCES=( 'preseed/files' )
   325 
   325 
   326 # template output into install tree
   326 # template output into install tree
   327 CONF_FILES_TARGET_NAME='preseed-files'
   327 PRESEED_FILES_TARGET_NAME='preseed-files'
   328 CONF_FILES_TARGET="${INSTALL_TREE}/${CONF_FILES_TARGET_NAME}"
   328 PRESEED_FILES_TARGET="${INSTALL_TREE}/${PRESEED_FILES_TARGET_NAME}"
   329 
   329 
   330 # paths within installer runtime
   330 # paths within installer runtime
   331 CONF_FILES_CP_SRC="${PRESEED_MOUNT}/${CONF_FILES_TARGET_NAME}"
   331 PRESEED_FILES_INSTALLER_SOURCE="${PRESEED_MOUNT}/${PRESEED_FILES_TARGET_NAME}"
   332 CONF_FILES_CP_DST='/target'
   332 PRESEED_FILES_INSTALLER_TARGET='/target'
       
   333 
       
   334 # Add a tree of configuration files to template into the installer
       
   335 function preseed_conf_files () {
       
   336     PRESEED_FILES_SOURCES=( "${PRESEED_FILES_SOURCES[@]:-}" "$@" )
       
   337 }
   333 
   338 
   334 # Add a file to install in preseed, without templating
   339 # Add a file to install in preseed, without templating
   335 # preseed_file <src> <dst>/
   340 # preseed_file <src> <dst>/
   336 #   if dst is a dir, it must end in /
   341 #   if dst is a dir, it must end in /
   337 function preseed_file () {
   342 function preseed_file () {
   338     local src=$1
   343     local src=$1
   339     local dst=$2
   344     local dst=$2
   340     local dir=$(dirname $dst)
   345     local dir=$(dirname $dst)
   341     local tgt=${CONF_FILES_TARGET}
   346     local tgt=${PRESEED_FILES_TARGET}
   342 
   347 
   343     local tgt_dir="$tgt/$dir"
   348     local tgt_dir="$tgt/$dir"
   344 
   349 
   345     if [ ! -d "$tgt_dir" ]; then
   350     if [ ! -d "$tgt_dir" ]; then
   346         cmd mkdir -p "$tgt_dir"
   351         cmd mkdir -p "$tgt_dir"
   354 PUPPET=
   359 PUPPET=
   355 
   360 
   356 if [ $opt_puppet ]; then
   361 if [ $opt_puppet ]; then
   357     log_info "Puppetizing preseed"
   362     log_info "Puppetizing preseed"
   358     PUPPET=yes
   363     PUPPET=yes
   359 
   364     
   360     # install package
   365     PUPPET_PRESEED_DIR="${PRESEED_DIR}/puppet"
       
   366 
       
   367     ## Packages
   361     preseed_packages puppet
   368     preseed_packages puppet
   362 
   369 
   363     ## Vars for preseed-files
   370     ## Vars for preseed-files
   364     # hostname for puppetmaster (server)
   371     # hostname for puppetmaster (server)
   365     PUPPET_MASTER="${opt_puppet_master}"
   372     PUPPET_MASTER="${opt_puppet_master}"
   366 
   373 
   367     # path ssl data (ssldir)
   374     # path ssl data (ssldir)
   368     PUPPET_SSLDIR=/etc/puppet/ssl
   375     PUPPET_SSLDIR=/etc/puppet/ssl
       
   376    
       
   377     ## Preseed files 
       
   378     # add to list of conf files to copy
       
   379     preseed_conf_files "${PUPPET_PRESEED_DIR}/files"
       
   380 
   369 fi
   381 fi
   370 
   382 
   371 # Invoked during image-customizing process
   383 # Invoked during image-customizing process
   372 function puppet_config () {
   384 function puppet_config () {
   373     ## Preseed ssl certs?
   385     ## Preseed ssl certs?
   374     PUPPET_SOURCE_SSLDIR="${PRESEED_SOURCE_DIR}/puppet/ssl"
   386     PUPPET_SOURCE_SSLDIR="${PUPPET_PRESEED_DIR}/ssl"
   375 
   387 
   376     # copy file to preseed if exists
   388     # copy file to preseed if exists
   377     function puppet_preseed_ssl_file () {
   389     function puppet_preseed_ssl_file () {
   378         local name=$1
   390         local name=$1
   379 
   391 
   424 ## Preseed / config files
   436 ## Preseed / config files
   425 
   437 
   426 
   438 
   427 
   439 
   428 # copy at end of install
   440 # copy at end of install
   429 preseed_late_commands "cp -rd -- ${CONF_FILES_CP_SRC}/* ${CONF_FILES_CP_DST}"
   441 preseed_late_commands "cp -rd -- ${PRESEED_FILES_INSTALLER_SOURCE}/* ${PRESEED_FILES_INSTALLER_TARGET}"
   430 
   442 
   431 # Additional files to copy
   443 # Additional files to copy
   432 PRESEED_INCLUDE_FILES=( $(for preseed in ${PRESEED_INCLUDES[@]}; do echo "${PRESEED_SOURCE_DIR}/${preseed}"; done) )
   444 PRESEED_INCLUDE_FILES=( $(for preseed in ${PRESEED_INCLUDES[@]}; do echo "${PRESEED_DIR}/${preseed}"; done) )
   433 #PRESEED_INCLUDE_FILES=("preseed/passwords.cfg" "preseed/host.cfg")
   445 #PRESEED_INCLUDE_FILES=("preseed/passwords.cfg" "preseed/host.cfg")
   434 
   446 
   435 # preseed.cfg 'includes' line
   447 # preseed.cfg 'includes' line
   436 PRESEED_INCLUDE=${PRESEED_INCLUDES[@]}
   448 PRESEED_INCLUDE=${PRESEED_INCLUDES[@]}
   437 
   449 
   439 PRESEED_LATE_COMMAND=$(for cmd in "${PRESEED_LATE_COMMANDS[@]}" "${PRESEED_LATE_COMMANDS_END[@]:-}"; do if [ "$cmd" ]; then echo -n "$cmd;" $'\\\n    '; fi; done; echo true)
   451 PRESEED_LATE_COMMAND=$(for cmd in "${PRESEED_LATE_COMMANDS[@]}" "${PRESEED_LATE_COMMANDS_END[@]:-}"; do if [ "$cmd" ]; then echo -n "$cmd;" $'\\\n    '; fi; done; echo true)
   440 
   452 
   441 
   453 
   442 ## Isolinux
   454 ## Isolinux
   443 # Source for install tree isolinux file
   455 # Source for install tree isolinux file
   444 PRESEED_ISOLINUX="${PRESEED_SOURCE_DIR}/isolinux.cfg"
   456 PRESEED_ISOLINUX="${PRESEED_DIR}/isolinux.cfg"
   445 
   457 
   446 # Automagics for serial boot :)
   458 # Automagics for serial boot :)
   447 #      virt-install assumes we have an X $DISPLAY if given --vnc
   459 #      virt-install assumes we have an X $DISPLAY if given --vnc
   448 #      but we also want to enable the serial console...
   460 #      but we also want to enable the serial console...
   449 #      d-i automagically configures the serial boot/login console, but only if the installer is run under serial...
   461 #      d-i automagically configures the serial boot/login console, but only if the installer is run under serial...
   558 
   570 
   559 
   571 
   560 
   572 
   561 
   573 
   562 ### Prepare install
   574 ### Prepare install
       
   575 log_info "Extract installer..."
       
   576 
   563 ## Extract .iso
   577 ## Extract .iso
   564 if [ -f ${INSTALLER_FLAG} ]; then
   578 if [ -f ${INSTALLER_FLAG} ]; then
   565     log_info "Installer already unpacked: ${INSTALLER_TREE}"
   579     log_info "Installer already unpacked: ${INSTALLER_TREE}"
   566 
   580 
   567 else
   581 else
   578 log_info "Installer extracted: $INSTALL_TREE"
   592 log_info "Installer extracted: $INSTALL_TREE"
   579 
   593 
   580 
   594 
   581 
   595 
   582 ### Customize preseed
   596 ### Customize preseed
       
   597 log_info "Generate preseed..."
       
   598 
   583 ## preseed.cfg
   599 ## preseed.cfg
   584 cmd expand_template ${PRESEED_TEMPLATE} ${PRESEED_FILE}
   600 cmd expand_template ${PRESEED_TEMPLATE} ${PRESEED_FILE}
   585 
   601 
   586 # md5sum
   602 # md5sum
   587 PRESEED_CHECKSUM=$(my_md5sum $PRESEED_FILE)
   603 PRESEED_CHECKSUM=$(my_md5sum $PRESEED_FILE)
   588 
   604 
       
   605 
   589 ## Isolinux
   606 ## Isolinux
   590 cmd expand_template ${PRESEED_ISOLINUX} ${INSTALL_TREE}/isolinux/isolinux.cfg
   607 cmd expand_template ${PRESEED_ISOLINUX} ${INSTALL_TREE}/isolinux/isolinux.cfg
       
   608 
   591 
   609 
   592 ## Includes
   610 ## Includes
   593 for file in ${PRESEED_INCLUDE_FILES[@]}; do
   611 for file in ${PRESEED_INCLUDE_FILES[@]}; do
   594     name=$(basename $file)
   612     name=$(basename $file)
   595 
   613 
   596     cmd expand_template $file ${INSTALL_TREE}/${name}
   614     cmd expand_template $file ${INSTALL_TREE}/${name}
   597 done
   615 done
   598 
   616 
   599 log_info "Preseed generated: $PRESEED_FILE"
   617 log_debug "Preseed generated: $PRESEED_FILE"
       
   618 
   600 
   619 
   601 ## Config preseed-files
   620 ## Config preseed-files
   602 log_info "Copy preseed-files"...
   621 log_info "Copy preseed-files..."
   603 cmd expand_tree ${CONF_FILES_SOURCE} ${CONF_FILES_TARGET}
   622 
       
   623 for tree in "${PRESEED_FILES_SOURCES[@]}"; do
       
   624     log_info "preseed-files: $tree"
       
   625 
       
   626     cmd expand_tree $tree ${PRESEED_FILES_TARGET}
       
   627 done
   604 
   628 
   605 ## Modules
   629 ## Modules
   606 # Puppet
   630 # Puppet
   607 [ $PUPPET ] && puppet_config
   631 [ $PUPPET ] && puppet_config
   608 
   632 
   609 
   633 
   610 
   634 
   611 
   635 
   612 
   636 
   613 ### Create .iso
   637 ### Create .iso
       
   638 log_info "Generate ISO..."
       
   639 
   614 [ -f ${INSTALL_ISO} ] && cmd rm -f ${INSTALL_ISO}
   640 [ -f ${INSTALL_ISO} ] && cmd rm -f ${INSTALL_ISO}
   615 
   641 
   616 # generates a lot of output
   642 # generates a lot of output
   617 cmd ${GENISOIMAGE} -o ${INSTALL_ISO} -quiet ${GENISOIMAGE_OPTS} ${INSTALL_TREE} 
   643 cmd ${GENISOIMAGE} -o ${INSTALL_ISO} -quiet ${GENISOIMAGE_OPTS} ${INSTALL_TREE} 
   618 
   644 
   623 
   649 
   624 
   650 
   625 
   651 
   626 ### Create virtual machine
   652 ### Create virtual machine
   627 if [ $DO_VIRTINSTALL ]; then
   653 if [ $DO_VIRTINSTALL ]; then
       
   654     log_info "Create VM..."
       
   655 
   628     ## Check
   656     ## Check
   629     # VM exists?
   657     # VM exists?
   630     if cmd virsh domid ${GUEST_NAME} > /dev/null 2> /dev/null; then
   658     if cmd virsh domid ${GUEST_NAME} > /dev/null 2> /dev/null; then
   631         die "Virtual machine already exists: ${GUEST_NAME}"
   659         die "Virtual machine already exists: ${GUEST_NAME}"
   632     fi
   660     fi