Changeset - 4d7f924adca6
[Approved]
0 1 0
Dennis Fink - 2 years ago 2022-06-08 22:22:40
dennis.fink@c3l.lu
Use cd ... || exit in case cd fails.

https://www.shellcheck.net/wiki/SC2164
1 file changed with 3 insertions and 3 deletions:
2 comments (0 inline, 2 general)
flashEMMC.sh
Show inline comments
 
@@ -37,78 +37,78 @@ umountInitially() {
 

	
 
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"
 
	cd "$TMP" || exit
 
	mkdir flashEMMC
 
	cd 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
 
	cd root/boot || exit
 
	./sd_fusing.sh /dev/"${DEV}"
 
	cd ../..
 
}
 

	
 

	
 
main() {
 
	checkRoot
 
	diskInfo
 
	verifyRightDrive
 
	umountInitially
 
	zeroBeginning
 
	partitionEMMC
 
	createEXT4fs
 
	cdToScript
 
	mountFS
 
	flashBootloader
 
	unmountFS
 
}
 

	
 
main
Dennis Fink (metalgamer) 2 years ago comment on pull request "Fixed some shellcheck warnings"

Status change: Under review

x 2 years ago comment on pull request "Fixed some shellcheck warnings"

Status change: Approved

Answer is "ok" (via Matrix chat)
2 comments (0 inline, 2 general)