forked from paklids/rpi-terraform-rke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_sd.sh
executable file
·32 lines (31 loc) · 1.04 KB
/
write_sd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# tested on OSX (Big Sur)
# be sure to `brew install pv` before starting
# and edit vars as needed below:
sdcard="/dev/disk2"
imgfile="$HOME/Downloads/ubuntu-20.10-preinstalled-server-arm64+raspi.img"
userdatafile="$HOME/Desktop/user-data"
networkconfigfile="$HOME/Desktop/network-config"
#
layout="$(df -h)"
imgsize=$(ls -la $imgfile | awk '{ print $5 }')
#
echo -e "$layout\n\n\t SD Card is at $sdcard\n"
#
read -p "Are you sure that you want to write $imgfile of $imgsize to $sdcard? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo -e "\n\tUnmounting disk\n"
diskutil unmountDisk $sdcard
echo -e "\n\tWriting to SDcard now...\n"
dd if=$imgfile bs=524288 | pv -s $imgsize | dd of=$sdcard bs=524288
fi
read -p "Would you like to copy network-config and user-data to $sdcard? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
mntlocation=$(df -h | grep $sdcard | awk '{ print $9 }')
cp -f $userdatafile $mntlocation/
cp -f $networkconfigfile $mntlocation/
fi