add make_image function

This commit is contained in:
Son
2020-10-06 13:15:59 +02:00
parent 40bd48d49c
commit 15790bb6dc
3 changed files with 27 additions and 14 deletions

View File

@@ -147,6 +147,7 @@ function make_swap (){
fi
}
# Print current config.
function print_config (){
log "Compilation info" bold
if [[ "$hw_model" == *rpi* ]]; then
@@ -154,8 +155,28 @@ function print_config (){
log "Hardware model: $(tput sgr0) $name_model" cyan
else
log "Hardware model: $(tput sgr0) $hw_model" cyan
fi
fi
log "Architecture: $(tput sgr0) $architecture" cyan
log "The basedir thinks it is: $(tput sgr0) ${basedir}" cyan
sleep 1
}
# Calculate the space to create the image and create.
function make_image() {
# Calculate the space to create the image.
root_size=$(du -s -B1 "${work_dir}" --exclude="${work_dir}"/boot | cut -f1)
root_extra=$((root_size/1024/1000*5*1024/5))
raw_size=$(($((free_space*1024))+root_extra+$((bootsize*1024))+4096))
img_size=$(echo "${raw_size}"Ki | numfmt --from=iec-i --to=si)
# Create the disk image
log "Creating image file ${imagename}.img $img_size" green
fallocate -l "$img_size" "${current_dir}"/"${imagename}".img
}
# Clean up all the temporary build stuff and remove the directories.
function clean_build() {
log "Cleaning up the temporary build files..." yellow
rm -rf "${basedir}"
log "Done." green
log "Your image is: $(tput sgr0) ${imagename}.img.xz" bold
}

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env bash
# Calculate the space to create the image.
root_size=$(du -s -B1 "${work_dir}" --exclude="${work_dir}"/boot | cut -f1)
root_extra=$((root_size/1024/1000*5*1024/5))
raw_size=$(($((free_space*1024))+root_extra+$((bootsize*1024))+4096))

View File

@@ -214,11 +214,10 @@ proc /proc proc defaults 0 0
/dev/mmcblk0p2 / $fstype defaults,noatime 0 1
EOF
# Calculate the space to create the image.
include size_img
# Create the disk and partition it
log "Creating image file ${imagename}.img" green
fallocate -l $(echo "${raw_size}"Ki | numfmt --from=iec-i --to=si) "${current_dir}"/"${imagename}".img
# Calculate the space to create the image and create.
make_image
# Create the disk partitions it
parted -s "${current_dir}"/"${imagename}".img mklabel msdos
parted -s "${current_dir}"/"${imagename}".img mkpart primary fat32 1MiB "${bootsize}"MiB
parted -s -a minimal "${current_dir}"/"${imagename}".img mkpart primary "$fstype" "${bootsize}"MiB 100%
@@ -264,5 +263,4 @@ include compress_img
# Clean up all the temporary build stuff and remove the directories.
# Comment this out to keep things around if you want to see what may have gone wrong.
log "Cleaning up the temporary build files..." green
rm -rf "${basedir}"
clean_build