Pull request #1 from ChaosStuff/cnc-dashboard#metalgamer

Title: Fixed some shellcheck warnings (Closed)

Shellcheck (https://www.shellcheck.net/) is a tool to help common pitfalls in shell scripting.

This fixes some common mistakes.
Closed, Approved
git pull https://projects.c3l.lu/ChaosStuff/cnc-dashboard metalgamer
2022-06-08 22:33:16
Dennis Fink (metalgamer)
metalgamer@c3l.lu

Git pull requests don't support iterating yet.

Reviewers

  • x
Pull Request Content
3 comments (0 inline, 3 general)
Showing 7 commits
7 Dennis Fink d7197ecf1533
23 months ago
6 Dennis Fink 10c0cde7f869
23 months ago
5 Dennis Fink cdf411165c6e
23 months ago
4 Dennis Fink 664cd0ed6b61
23 months ago
3 Dennis Fink 4d7f924adca6
23 months ago
2 Dennis Fink 30b325c925ad
23 months ago
1 Dennis Fink cb413875da2f
23 months ago
Common ancestor: c3309581c2ac
3 files changed with 18 insertions and 15 deletions:
ansible.sh
Show inline comments
 
#!/usr/bin/env bash
 
ansible-galaxy install -r requirements.yml
 

	
 
if [ -z ${1+x} ]; then
 
	echo "var is unset"; 
 
	PLAYBOOK=site.yml
 
else
 
	PLAYBOOK=$1
 
fi
 

	
 
# Agent running causes issues because SSH seems to prioritise those keys by default
 
SSH_AUTH_SOCK=/dev/null
 
ansible-playbook -v -i hosts.yml $PLAYBOOK
 
ansible-playbook -v -i hosts.yml "$PLAYBOOK"
flashEMMC.sh
Show inline comments
 
@@ -4,18 +4,18 @@ 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() {
 
	[ `id -u` -eq 0 ] || { echo "Run script (as root) or (with sudo)"; exit 1; }
 
	[[ "$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
 
	[[ -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
 
@@ -26,44 +26,44 @@ verifyRightDrive() {
 
		echo
 
		exit 1
 
	fi
 
}
 

	
 
umountInitially() {
 
	BLKDEVS=$(find /dev/ -name ${DEV}*)
 
	BLKDEVS=$(find /dev/ -name "${DEV}"*)
 
	for LINE in $BLKDEVS; do
 
		sudo umount $LINE
 
		sudo umount "$LINE"
 
	done
 
}
 

	
 
zeroBeginning() {
 
	dd if=/dev/zero of=/dev/$DEV bs=1M count=8
 
	dd if=/dev/zero of=/dev/"$DEV" bs=1M count=8
 
}
 

	
 
partitionEMMC() {
 
fdisk -W always /dev/$DEV << EOF
 
fdisk -W always /dev/"$DEV" << EOF
 
o
 
n
 
p
 
1
 

	
 

	
 

	
 
w
 
EOF
 
}
 

	
 
createEXT4fs() {
 
	mkfs.ext4 -O ^metadata_csum,^64bit /dev/${DEV}1
 
	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
 
}
 

	
 
@@ -83,19 +83,19 @@ downloadImage() {
 
extractImage() {
 
	bsdtar -xpf ArchLinuxARM-odroid-c2-latest.tar.gz -C root
 
}
 

	
 
mountFS() {
 
	mkdir root
 
	mount /dev/${DEV}1 root
 
	mount /dev/"${DEV}"1 root
 
	[ -e ${IMAGE_NAME}.md5 ] && md5sum -c ${IMAGE_NAME}.md5 || downloadImage && extractImage
 
}
 

	
 
flashBootloader() {
 
	cd root/boot
 
	./sd_fusing.sh /dev/${DEV}
 
	cd root/boot || exit
 
	./sd_fusing.sh /dev/"${DEV}"
 
	cd ../..
 
}
 

	
 

	
 
main() {
 
	checkRoot
init.sh
Show inline comments
 
#!/usr/bin/env bash
 

	
 
generateKey() {
 
	touch sshKey
 
	touch sshKey.pub
 
	rm sshKey
 
	rm sshKey.pub
 
	ssh-keygen -t ed25519 -f ./sshKey -q -N "" -C ""
 
}
 

	
 
deployKey() {
 
	sshpass -p alarm ssh-copy-id -i ./sshKey.pub -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PubkeyAuthentication=false alarm@$1
 
	sshpass -p alarm ssh-copy-id -i ./sshKey.pub -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PubkeyAuthentication=false alarm@"$1"
 
}
 

	
 
# If keys are present, we just need to deploy it and destroy the SSH Agent
 
# Otherwise, we genrate a key and then deploy it
 
# The key can be present on the remote host multiple times,
 
# -> not a big issue, just not clean, but it works
Dennis Fink (metalgamer) 1 year and 11 months ago comment on pull request "Fixed some shellcheck warnings"

Status change: Under review

x 1 year and 11 months ago comment on pull request "Fixed some shellcheck warnings"
I see no problem with this contribution, but unrelated, it does make me realize the lack of CI/CD.

Since commit 22eaaa79cfda added a LICENSE to facilitate contribution and distribution, I am legally obliged to ask the following:
Do you license these changes under the project's license (BSD 3 clause as readable in LICENSE in the latest master commit at the time of writing, which is 22eaaa79cfda) ?
x 1 year and 11 months ago comment on pull request "Fixed some shellcheck warnings"

Status change: Approved

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