Files
@ 4d7f924adca6
Branch filter:
Location: ChaosStuff/cnc-dashboard/flashEMMC.sh
4d7f924adca6
1.7 KiB
text/x-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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #!/usr/bin/env bash
DEV=$1
IMAGE_NAME=ArchLinuxARM-odroid-c2-latest.tar.gz
# Fast mirror, but I'm not sure we can trust it...
DOWNLOAD_LINK=https://mirrors.dotsrc.org/archlinuxarm/os/
HASH_LINK=https://de3.mirror.archlinuxarm.org/os/
checkRoot() {
[[ "$EUID" -eq 0 ]] || { echo "Run script (as root) or (with sudo)"; exit 1; }
}
diskInfo() {
[[ -e /dev/"$DEV" ]] || { echo "ERROR: Drive doesn't exist" && exit 1; }
fdisk -l /dev/"$DEV"
echo
}
verifyRightDrive() {
sleep 3
read -n 1 -r -p "Is this the right drive? [y/N] " response
if [[ "$response" =~ ^([yY])$ ]]
then
return 0
else
echo
exit 1
fi
}
umountInitially() {
BLKDEVS=$(find /dev/ -name "${DEV}"*)
for LINE in $BLKDEVS; do
sudo umount "$LINE"
done
}
zeroBeginning() {
dd if=/dev/zero of=/dev/"$DEV" bs=1M count=8
}
partitionEMMC() {
fdisk -W always /dev/"$DEV" << EOF
o
n
p
1
w
EOF
}
createEXT4fs() {
mkfs.ext4 -O ^metadata_csum,^64bit /dev/"${DEV}"1
}
cdToScript() {
TMP=$(dirname "$0")
cd "$TMP" || exit
mkdir flashEMMC
cd flashEMMC || exit
}
unmountFS() {
umount root
}
panic() {
cdToScript
unmountFS
exit 1
}
downloadImage() {
rm ${IMAGE_NAME}
wget ${DOWNLOAD_LINK}${IMAGE_NAME}
wget ${HASH_LINK}${IMAGE_NAME}.md5
md5sum -c ${IMAGE_NAME}.md5 || { echo "Hash of image is incorrect"; panic; }
}
extractImage() {
bsdtar -xpf ArchLinuxARM-odroid-c2-latest.tar.gz -C root
}
mountFS() {
mkdir root
mount /dev/"${DEV}"1 root
[ -e ${IMAGE_NAME}.md5 ] && md5sum -c ${IMAGE_NAME}.md5 || downloadImage && extractImage
}
flashBootloader() {
cd root/boot || exit
./sd_fusing.sh /dev/"${DEV}"
cd ../..
}
main() {
checkRoot
diskInfo
verifyRightDrive
umountInitially
zeroBeginning
partitionEMMC
createEXT4fs
cdToScript
mountFS
flashBootloader
unmountFS
}
main
|