mirror of
https://github.com/kevinveenbirkenbach/raspberry-pi-tools.git
synced 2024-11-22 18:11:03 +01:00
Added optional copying to sd_card
This commit is contained in:
parent
7a4f700f0f
commit
30f1d3e021
15
README.md
15
README.md
@ -19,13 +19,14 @@ To install a Linux distribution manually on a SD card type in:
|
|||||||
To pase the configuration to the program use this syntax:
|
To pase the configuration to the program use this syntax:
|
||||||
```bash
|
```bash
|
||||||
(
|
(
|
||||||
echo "$USER" #The username
|
echo "$USER" # The username
|
||||||
echo "mmcblk1" #The device
|
echo "mmcblk1" # The device
|
||||||
echo "3" #The raspberry pi number
|
echo "3" # The raspberry pi number
|
||||||
echo "arch" #The operation system
|
echo "arch" # The operation system
|
||||||
echo "user_password" #The user password
|
echo "y" # Transfer image
|
||||||
echo "root_password" #The root password
|
echo "user_password" # The user password
|
||||||
echo "y" #Copy wifi configurations to target system
|
echo "root_password" # The root password
|
||||||
|
echo "y" # Copy wifi configurations to target system
|
||||||
)| sudo bash ./sd_setup.sh
|
)| sudo bash ./sd_setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
105
sd_setup.sh
105
sd_setup.sh
@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# shellcheck disable=SC2010 # ls | grep allowed
|
# shellcheck disable=SC2010 # ls | grep allowed
|
||||||
|
# shellcheck disable=SC2143 # Suppress wrong grep -q warning
|
||||||
|
|
||||||
echo "Setupscript for Raspberry Pi SD's"
|
echo "Setupscript for Raspberry Pi SD's"
|
||||||
echo
|
echo
|
||||||
@ -176,60 +177,70 @@ mount_partitions(){
|
|||||||
echo "The following mounts refering this setup exist:" && mount | grep "$working_folder"
|
echo "The following mounts refering this setup exist:" && mount | grep "$working_folder"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Copy data to $sd_card_path..."
|
echo "Should the image be transfered to $sd_card_path?(y/n)"
|
||||||
|
read -r transfer_image
|
||||||
|
if [ "$transfer_image" = "y" ]
|
||||||
|
then
|
||||||
|
echo "Starting image transfer..."
|
||||||
|
case "$os" in
|
||||||
|
"arch")
|
||||||
|
echo "Execute fdisk..."
|
||||||
|
( echo "o" #Type o. This will clear out any partitions on the drive.
|
||||||
|
echo "p" #Type p to list partitions. There should be no partitions left
|
||||||
|
echo "n" #Type n,
|
||||||
|
echo "p" #then p for primary,
|
||||||
|
echo "1" #1 for the first partition on the drive,
|
||||||
|
echo "" #press ENTER to accept the default first sector,
|
||||||
|
echo "+100M" #then type +100M for the last sector.
|
||||||
|
echo "t" #Type t,
|
||||||
|
echo "c" #then c to set the first partition to type W95 FAT32 (LBA).
|
||||||
|
echo "n" #Type n,
|
||||||
|
echo "p" #then p for primary,
|
||||||
|
echo "2" #2 for the second partition on the drive,
|
||||||
|
echo "" #and then press ENTER twice to accept the default first and last sector.
|
||||||
|
echo ""
|
||||||
|
echo "w" #Write the partition table and exit by typing w.
|
||||||
|
)| fdisk "$sd_card_path" || error "Creating partitions failed. Try \"sudo dd if=/dev/zero of=$sd_card_path bs=1M\""
|
||||||
|
|
||||||
case "$os" in
|
echo "Format boot partition..."
|
||||||
"arch")
|
mkfs.vfat "$boot_partition_path" || error "Format boot is not possible."
|
||||||
echo "Execute fdisk..."
|
|
||||||
( echo "o" #Type o. This will clear out any partitions on the drive.
|
|
||||||
echo "p" #Type p to list partitions. There should be no partitions left
|
|
||||||
echo "n" #Type n,
|
|
||||||
echo "p" #then p for primary,
|
|
||||||
echo "1" #1 for the first partition on the drive,
|
|
||||||
echo "" #press ENTER to accept the default first sector,
|
|
||||||
echo "+100M" #then type +100M for the last sector.
|
|
||||||
echo "t" #Type t,
|
|
||||||
echo "c" #then c to set the first partition to type W95 FAT32 (LBA).
|
|
||||||
echo "n" #Type n,
|
|
||||||
echo "p" #then p for primary,
|
|
||||||
echo "2" #2 for the second partition on the drive,
|
|
||||||
echo "" #and then press ENTER twice to accept the default first and last sector.
|
|
||||||
echo ""
|
|
||||||
echo "w" #Write the partition table and exit by typing w.
|
|
||||||
)| fdisk "$sd_card_path" || error "Creating partitions failed. Try \"sudo dd if=/dev/zero of=$sd_card_path bs=1M\""
|
|
||||||
|
|
||||||
echo "Format boot partition..."
|
echo "Format root partition..."
|
||||||
mkfs.vfat "$boot_partition_path" || error "Format boot is not possible."
|
mkfs.ext4 "$root_partition_path" || error "Format root is not possible."
|
||||||
|
|
||||||
echo "Format root partition..."
|
mount_partitions;
|
||||||
mkfs.ext4 "$root_partition_path" || error "Format root is not possible."
|
|
||||||
|
|
||||||
mount_partitions;
|
echo "Root files will be transfered to sd-card..."
|
||||||
|
bsdtar -xpf "$image_path" -C "$root_mount_path"
|
||||||
|
sync
|
||||||
|
|
||||||
echo "Root files will be transfered to sd-card..."
|
echo "Boot files will be transfered to sd-card..."
|
||||||
bsdtar -xpf "$image_path" -C "$root_mount_path"
|
mv -v "$root_mount_path/boot/"* "$boot_mount_path"
|
||||||
sync
|
|
||||||
|
|
||||||
echo "Boot files will be transfered to sd-card..."
|
;;
|
||||||
mv -v "$root_mount_path/boot/"* "$boot_mount_path"
|
"moode")
|
||||||
|
unzip -p "$image_path" | sudo dd of="$sd_card_path" bs=1M conv=fsync || error "DD to $sd_card_path failed."
|
||||||
|
sync
|
||||||
|
;;
|
||||||
|
"retropie")
|
||||||
|
gunzip -c "$image_path" | sudo dd of="$sd_card_path" bs=1M conv=fsync
|
||||||
|
sync
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error "Image transfer for operation system \"$os\" is not supported yet!";
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo "Skipping image transfer..."
|
||||||
|
fi
|
||||||
|
|
||||||
;;
|
echo "Start regular mounting procedure..."
|
||||||
"moode")
|
if [ "$(mount | grep -q "$boot_mount_path")" ] && [ "$(mount | grep -q "$root_mount_path")" ]
|
||||||
unzip -p "$image_path" | sudo dd of="$sd_card_path" bs=1M conv=fsync || error "DD to $sd_card_path failed."
|
then
|
||||||
sync
|
echo "Everything allready mounted. Skipping..."
|
||||||
|
else
|
||||||
mount_partitions;
|
mount_partitions
|
||||||
;;
|
fi
|
||||||
"retropie")
|
|
||||||
gunzip -c "$image_path" | sudo dd of="$sd_card_path" bs=1M conv=fsync
|
|
||||||
sync
|
|
||||||
|
|
||||||
mount_partitions;
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
error "Image transfer for operation system \"$os\" is not supported yet!";
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo "Define target paths..."
|
echo "Define target paths..."
|
||||||
target_home_path="$root_mount_path/home/";
|
target_home_path="$root_mount_path/home/";
|
||||||
|
Loading…
Reference in New Issue
Block a user