diff options
Diffstat (limited to 'usr.sbin/pc-sysinstall/backend/functions.sh')
-rwxr-xr-x | usr.sbin/pc-sysinstall/backend/functions.sh | 189 |
1 files changed, 151 insertions, 38 deletions
diff --git a/usr.sbin/pc-sysinstall/backend/functions.sh b/usr.sbin/pc-sysinstall/backend/functions.sh index 847d97e..cb3b698 100755 --- a/usr.sbin/pc-sysinstall/backend/functions.sh +++ b/usr.sbin/pc-sysinstall/backend/functions.sh @@ -284,27 +284,123 @@ get_zpool_name() fi }; +iscompressed() +{ + local FILE + local RES + + FILE="$1" + RES=1 + + if echo "${FILE}" | \ + grep -iE '\.(Z|lzo|lzw|lzma|gz|bz2|xz|zip)$' >/dev/null 2>&1 + then + RES=0 + fi + + return ${RES} +} + +get_compression_type() +{ + local FILE + local SUFFIX + + FILE="$1" + SUFFIX=`echo "${FILE}" | sed -E 's|^(.+)\.(.+)$|\2|'` + + VAL="" + SUFFIX=`echo "${SUFFIX}" | tr A-Z a-z` + case "${SUFFIX}" in + z) VAL="lzw" ;; + lzo) VAL="lzo" ;; + lzw) VAL="lzw" ;; + lzma) VAL="lzma" ;; + gz) VAL="gzip" ;; + bz2) VAL="bzip2" ;; + xz) VAL="xz" ;; + zip) VAL="zip" ;; + esac + + export VAL +} + +decompress_file() +{ + local FILE + local COMPRESSION + + FILE="$1" + COMPRESSION="$2" + + if [ -n "${COMPRESSION}" ] + then + case "${COMPRESSION}" in + lzw) + rc_halt "uncompress ${FILE}" + VAL="${FILE%.Z}" + ;; + + lzo) + rc_halt "lzop -d ${FILE}" + VAL="${FILE%.lzo}" + ;; + + lzma) + rc_halt "lzma -d ${FILE}" + VAL="${FILE%.lzma}" + ;; + + gzip) + rc_halt "gunzip ${FILE}" + VAL="${FILE%.gz}" + ;; + + bzip2) + rc_halt "bunzip2 ${FILE}" + VAL="${FILE%.bz2}" + ;; + + xz) + rc_halt "xz -d ${FILE}" + VAL="${FILE%.xz}" + ;; + + zip) + rc_halt "unzip ${FILE}" + VAL="${FILE%.zip}" + ;; + + *) + exit_err "ERROR: ${COMPRESSION} compression is not supported" + ;; + esac + fi + + export VAL +} + write_image() { + local IMAGE_FILE + local DEVICE_FILE + IMAGE_FILE="$1" DEVICE_FILE="$2" if [ -z "${IMAGE_FILE}" ] then - echo "ERROR: Image file not specified!" - exit 1 + exit_err "ERROR: Image file not specified!" fi if [ -z "${DEVICE_FILE}" ] then - echo "ERROR: Device file not specified!" - exit 1 + exit_err "ERROR: Device file not specified!" fi if [ ! -f "${IMAGE_FILE}" ] then - echo "ERROR: '${IMAGE_FILE}' does not exist!" - exit 1 + exit_err "ERROR: '${IMAGE_FILE}' does not exist!" fi DEVICE_FILE="${DEVICE_FILE#/dev/}" @@ -312,16 +408,21 @@ write_image() if [ ! -c "${DEVICE_FILE}" ] then - echo "ERROR: '${DEVICE_FILE}' is not a character device!" - exit 1 + exit_err "ERROR: '${DEVICE_FILE}' is not a character device!" fi - if [ "${RES}" = "0" ] + if iscompressed "${IMAGE_FILE}" then - rc_halt "dd if=${IMAGE_FILE} of=${DEVICE_FILE} ibs=16k obs=16k" + local COMPRESSION + + get_compression_type "${IMAGE_FILE}" + COMPRESSION="${VAL}" + + decompress_file "${IMAGE_FILE}" "${COMPRESSION}" + IMAGE_FILE="${VAL}" fi - return 0 + rc_halt "dd if=${IMAGE_FILE} of=${DEVICE_FILE} bs=128k" }; install_fresh() @@ -329,45 +430,57 @@ install_fresh() # Lets start setting up the disk slices now setup_disk_slice - # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels - setup_disk_label + if [ -z "${ROOTIMAGE}" ] + then + + # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels + setup_disk_label - # Now we've setup the bsdlabels, lets go ahead and run newfs / zfs - # to setup the filesystems - setup_filesystems + # Now we've setup the bsdlabels, lets go ahead and run newfs / zfs + # to setup the filesystems + setup_filesystems - # Lets mount the partitions now - mount_all_filesystems + # Lets mount the partitions now + mount_all_filesystems - # We are ready to begin extraction, lets start now - init_extraction + # We are ready to begin extraction, lets start now + init_extraction - # Check if we have any optional modules to load - install_components + # Check if we have any optional modules to load + install_components - # Check if we have any packages to install - install_packages + # Check if we have any packages to install + install_packages - # Do any localization in configuration - run_localize + # Do any localization in configuration + run_localize - # Save any networking config on the installed system - save_networking_install + # Save any networking config on the installed system + save_networking_install - # Now add any users - setup_users + # Now add any users + setup_users - # Now run any commands specified - run_commands + # Now run any commands specified + run_commands - # Do any last cleanup / setup before unmounting - run_final_cleanup + # Do any last cleanup / setup before unmounting + run_final_cleanup - # Unmount and finish up - unmount_all_filesystems + # Unmount and finish up + unmount_all_filesystems + fi echo_log "Installation finished!" -} +}; + +install_image() +{ + # We are ready to begin extraction, lets start now + init_extraction + + echo_log "Installation finished!" +}; install_upgrade() { @@ -397,4 +510,4 @@ install_upgrade() unmount_upgrade echo_log "Upgrade finished!" -} +}; |