linux-image-manager/scripts/image/base.sh

66 lines
2.0 KiB
Bash
Raw Normal View History

2020-05-15 12:00:03 +02:00
#!/bin/bash
#
# Offers base functions for the image management
#
# shellcheck disable=SC2034 #Deactivate checking of unused variables
2020-05-19 11:10:06 +02:00
# shellcheck disable=SC2010 # ls | grep allowed
2020-05-15 12:00:03 +02:00
# shellcheck source=/dev/null # Deactivate SC1090
2020-05-19 11:10:06 +02:00
# shellcheck disable=SC2015 # Deactivate bools hints
2020-05-15 12:00:03 +02:00
source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1)
# Writes the full partition name
# @parameter $1 is device path
# @parameter $2 is the partition number
echo_partition_name(){
if [ "${device_path:5:1}" != "s" ]
2020-05-15 12:00:03 +02:00
then
2020-05-15 14:13:47 +02:00
echo "$device_path""p""$1"
2020-05-15 12:00:03 +02:00
else
2020-05-15 14:13:47 +02:00
echo "$device_path$1"
2020-05-15 12:00:03 +02:00
fi
}
2020-05-15 12:23:07 +02:00
set_partition_paths(){
info "Setting partition paths..."
root_partition_path=$(echo_partition_name "2")
boot_partition_path=$(echo_partition_name "1")
}
2020-05-15 14:10:24 +02:00
make_mount_folders(){
info "Preparing mount paths..." &&
boot_mount_path="$working_folder_path""boot/" &&
root_mount_path="$working_folder_path""root/" &&
mkdir -v "$boot_mount_path" &&
mkdir -v "$root_mount_path" ||
error
}
make_working_folder(){
working_folder_path="/tmp/raspberry-pi-tools-$(date +%s)/" &&
info "Create temporary working folder in $working_folder_path" &&
mkdir -v "$working_folder_path" ||
error
}
mount_partitions(){
info "Mount boot and root partition..." &&
mount "$boot_partition_path" "$boot_mount_path" &&
mount "$root_partition_path" "$root_mount_path" &&
info "The following mounts refering this setup exist:" && mount | grep "$working_folder_path" ||
error
}
mount_binds(){
info "Mount chroot environments..." &&
chroot_sys_mount_path="$root_mount_path""sys/" &&
chroot_proc_mount_path="$root_mount_path""proc/" &&
chroot_dev_mount_path="$root_mount_path""dev/" &&
chroot_dev_pts_mount_path="$root_mount_path""dev/pts" &&
mount --bind "$boot_mount_path" "$root_mount_path""/boot" &&
mount --bind /dev "$chroot_dev_mount_path" &&
mount --bind /sys "$chroot_sys_mount_path" &&
mount --bind /proc "$chroot_proc_mount_path" &&
mount --bind /dev/pts "$chroot_dev_pts_mount_path" ||
error
}