mirror of
https://github.com/kevinveenbirkenbach/linux-image-manager.git
synced 2024-11-22 15:11:04 +01:00
Implemented set_device_path function
This commit is contained in:
parent
df1fcfff63
commit
af6e17b4c5
@ -17,3 +17,15 @@ echo_partition_name(){
|
|||||||
echo "$1$2"
|
echo "$1$2"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Routine to echo the full sd-card-path
|
||||||
|
set_device_path(){
|
||||||
|
info "Available devices:"
|
||||||
|
ls -lasi /dev/ | grep -E "sd|mm"
|
||||||
|
question "Please type in the name of the device: /dev/" && read -r device
|
||||||
|
device_path="/dev/$device"
|
||||||
|
if [ ! -b "$device_path" ]
|
||||||
|
then
|
||||||
|
error "$device_path is not valid device."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
@ -3,14 +3,19 @@
|
|||||||
# shellcheck disable=SC2015 # Deactivating bool hint
|
# shellcheck disable=SC2015 # Deactivating bool hint
|
||||||
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh failed." && exit 1)
|
||||||
|
|
||||||
|
info "Starting chroot..."
|
||||||
|
|
||||||
|
set_device_path
|
||||||
|
|
||||||
info "Making mount dir..." &&
|
info "Making mount dir..." &&
|
||||||
mkdir -p /mnt/raspbian ||
|
mkdir -p /mnt/raspbian ||
|
||||||
error
|
error
|
||||||
|
|
||||||
|
|
||||||
root_mount_path="/mnt/raspbian"
|
root_mount_path="/mnt/raspbian"
|
||||||
boot_mount_path="/mnt/raspbian/boot"
|
boot_mount_path="/mnt/raspbian/boot"
|
||||||
root_partition_path=$(echo_partition_name $1 "2")
|
root_partition_path=$(echo_partition_name $device_path "2")
|
||||||
boot_partition_path=$(echo_partition_name $1 "1")
|
boot_partition_path=$(echo_partition_name $device_path "1")
|
||||||
|
|
||||||
info "Mount partitions..."
|
info "Mount partitions..."
|
||||||
mount -o rw "$boot_partition_path" "$boot_mount_path" ||
|
mount -o rw "$boot_partition_path" "$boot_mount_path" ||
|
||||||
|
@ -5,6 +5,7 @@ source "$(dirname "$(readlink -f "${0}")")/base.sh" || (echo "Loading base.sh fa
|
|||||||
|
|
||||||
info "Setupscript for images started..."
|
info "Setupscript for images started..."
|
||||||
|
|
||||||
|
info "Define functions..."
|
||||||
destructor(){
|
destructor(){
|
||||||
info "Cleaning up..."
|
info "Cleaning up..."
|
||||||
sed -i 's/^#CHROOT //g' "$root_mount_path""etc/ld.so.preload"
|
sed -i 's/^#CHROOT //g' "$root_mount_path""etc/ld.so.preload"
|
||||||
@ -23,16 +24,14 @@ destructor(){
|
|||||||
info "Define variables..."
|
info "Define variables..."
|
||||||
working_folder="/tmp/raspberry-pi-tools-$(date +%s)/";
|
working_folder="/tmp/raspberry-pi-tools-$(date +%s)/";
|
||||||
|
|
||||||
info "Define functions..."
|
|
||||||
|
|
||||||
info "Create temporary working folder in $working_folder";
|
|
||||||
mkdir -v "$working_folder"
|
|
||||||
|
|
||||||
info "Checking if root..."
|
info "Checking if root..."
|
||||||
if [ "$(id -u)" != "0" ];then
|
if [ "$(id -u)" != "0" ];then
|
||||||
error "This script must be executed as root!"
|
error "This script must be executed as root!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
info "Create temporary working folder in $working_folder";
|
||||||
|
mkdir -v "$working_folder"
|
||||||
|
|
||||||
info "Configure user..."
|
info "Configure user..."
|
||||||
question "Please type in a valid username from which the SSH-Key should be copied:" && read -r origin_username;
|
question "Please type in a valid username from which the SSH-Key should be copied:" && read -r origin_username;
|
||||||
getent passwd "$origin_username" > /dev/null 2 || error "User $origin_username doesn't exist.";
|
getent passwd "$origin_username" > /dev/null 2 || error "User $origin_username doesn't exist.";
|
||||||
@ -46,20 +45,11 @@ if [ ! -d "$image_folder" ]; then
|
|||||||
mkdir -v "$image_folder"
|
mkdir -v "$image_folder"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Selecting sd-card..."
|
set_device_path
|
||||||
info "Show available devices..."
|
|
||||||
ls -lasi /dev/ | grep -E "sd|mm"
|
|
||||||
question "Please type in the name of the correct device: /dev/" && read -r device
|
|
||||||
sd_card_path="/dev/$device"
|
|
||||||
|
|
||||||
if [ ! -b "$sd_card_path" ]
|
if mount | grep -q "$device_path"
|
||||||
then
|
then
|
||||||
error "$sd_card_path is not valid device."
|
error "Device $device_path is allready mounted. Umount with \"umount $device_path*\"."
|
||||||
fi
|
|
||||||
|
|
||||||
if mount | grep -q "$sd_card_path"
|
|
||||||
then
|
|
||||||
error "Device $sd_card_path is allready mounted. Umount with \"umount $sd_card_path*\"."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
question "Select which Raspberry Pi version should be used:" && read -r version
|
question "Select which Raspberry Pi version should be used:" && read -r version
|
||||||
@ -167,8 +157,8 @@ root_mount_path="$working_folder""root/"
|
|||||||
mkdir -v "$boot_mount_path"
|
mkdir -v "$boot_mount_path"
|
||||||
mkdir -v "$root_mount_path"
|
mkdir -v "$root_mount_path"
|
||||||
|
|
||||||
boot_partition_path=$(echo_partition_name $sd_card_path "1")
|
boot_partition_path=$(echo_partition_name $device_path "1")
|
||||||
root_partition_path=$(echo_partition_name $sd_card_path "2")
|
root_partition_path=$(echo_partition_name $device_path "2")
|
||||||
|
|
||||||
mount_partitions(){
|
mount_partitions(){
|
||||||
info "Mount boot and root partition..."
|
info "Mount boot and root partition..."
|
||||||
@ -177,15 +167,15 @@ mount_partitions(){
|
|||||||
info "The following mounts refering this setup exist:" && mount | grep "$working_folder"
|
info "The following mounts refering this setup exist:" && mount | grep "$working_folder"
|
||||||
}
|
}
|
||||||
|
|
||||||
question "Should the image be transfered to $sd_card_path?(y/n)" && read -r transfer_image
|
question "Should the image be transfered to $device_path?(y/n)" && read -r transfer_image
|
||||||
if [ "$transfer_image" = "y" ]
|
if [ "$transfer_image" = "y" ]
|
||||||
then
|
then
|
||||||
|
|
||||||
question "Should $sd_card_path be overwritten with zeros before copying?(y/n)" && read -r copy_zeros_to_device
|
question "Should $device_path be overwritten with zeros before copying?(y/n)" && read -r copy_zeros_to_device
|
||||||
if [ "$copy_zeros_to_device" = "y" ]
|
if [ "$copy_zeros_to_device" = "y" ]
|
||||||
then
|
then
|
||||||
info "Overwritting..."
|
info "Overwritting..."
|
||||||
dd if=/dev/zero of="$sd_card_path" bs=1M || error "Overwritting $sd_card_path failed."
|
dd if=/dev/zero of="$device_path" bs=1M || error "Overwritting $device_path failed."
|
||||||
else
|
else
|
||||||
info "Skipping Overwritting..."
|
info "Skipping Overwritting..."
|
||||||
fi
|
fi
|
||||||
@ -209,7 +199,7 @@ if [ "$transfer_image" = "y" ]
|
|||||||
echo "" #and then press ENTER twice to accept the default first and last sector.
|
echo "" #and then press ENTER twice to accept the default first and last sector.
|
||||||
echo ""
|
echo ""
|
||||||
echo "w" #Write the partition table and exit by typing w.
|
echo "w" #Write the partition table and exit by typing w.
|
||||||
)| fdisk "$sd_card_path" || error "Creating partitions failed. Try to execute this script with the overwritting parameter."
|
)| fdisk "$device_path" || error "Creating partitions failed. Try to execute this script with the overwritting parameter."
|
||||||
|
|
||||||
info "Format boot partition..."
|
info "Format boot partition..."
|
||||||
mkfs.vfat "$boot_partition_path" || error "Format boot is not possible."
|
mkfs.vfat "$boot_partition_path" || error "Format boot is not possible."
|
||||||
@ -228,11 +218,11 @@ if [ "$transfer_image" = "y" ]
|
|||||||
|
|
||||||
;;
|
;;
|
||||||
"moode")
|
"moode")
|
||||||
unzip -p "$image_path" | sudo dd of="$sd_card_path" bs=1M conv=fsync || error "DD $image_path to $sd_card_path failed."
|
unzip -p "$image_path" | sudo dd of="$device_path" bs=1M conv=fsync || error "DD $image_path to $device_path failed."
|
||||||
sync
|
sync
|
||||||
;;
|
;;
|
||||||
"retropie")
|
"retropie")
|
||||||
gunzip -c "$image_path" | sudo dd of="$sd_card_path" bs=1M conv=fsync
|
gunzip -c "$image_path" | sudo dd of="$device_path" bs=1M conv=fsync
|
||||||
sync
|
sync
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
Loading…
Reference in New Issue
Block a user