Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disk image manipulation scripts #953

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,8 @@ docs/manual/_markdown_manual

# Status File
display-status.txt

# archives and disk images
*.img
*.gz
*.xz
15 changes: 15 additions & 0 deletions scripts/image_testing/chroot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash


if [ $(whoami) != "root" ] ; then
echo "Please run as root."
exit
fi

# perhaps this is the least commonly used util. perhaps not.
if [ "$(dpkg --get-selections qemu-user-static)" ] ; then
apt install binfmt-support qemu-user-static
fi

chroot root /bin/bash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a case could be made here to set up bindmounts or instances of namespaced filesystems (/sys, /proc, /dev, etc), but there's a nonzero likelihood that a setup like this could damage the user's system; thus, with the loss of some functionality, we explicitly do not do this.

rm -v root/root/.bash_history
54 changes: 54 additions & 0 deletions scripts/image_testing/flash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# flashes an amplipi disk image to an amplipi; attempts to launch rpiboot,
# autodetect the amplipi disk, prompt the user, flash it, and finally
# send a terminal bell.

# check user
if [ $(whoami) != "root" ] ; then
echo "Please become root."
exit
fi

# check dependencies
for i in whiptail rpiboot partprobe; do
if [ ! $(which ${i} ]; then
echo "Dependency ${i} not found; please install it or place it in your \$PATH"
exit
fi
done

set -u

if [ -z "$(ls /dev/disk/by-id/usb-RPi*)" ]; then
rpiboot
sleep .2
partprobe
fi

set -e

dev=$(ls /dev/disk/by-id/usb-RPi* | grep -v part)
parts=$(ls /dev/disk/by-id/usb-RPi* | grep part)

set +e
for part in ${parts}; do
umount ${part}
done
set -e

sync

whiptail --yesno "is this the correct device? \n ${dev}" 10 50

dd if=${1} of=${dev} bs=2M oflag=dsync status=progress

echo "syncing to disk..."
sync
sleep 5

echo "done!"

# I would use `notify-send` here, but it doesn't function for me
# in `sudo -i` 🥴
# https://youtu.be/Dp11DjaUc5A
tput bel
24 changes: 24 additions & 0 deletions scripts/image_testing/mount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

function help() {
echo "${0}: mounts an AmpliPi disk image into the relative directory 'root'"
echo "usage: ${0} [disk image]"
}

if [ -z ${1} ]; then
help
exit
fi

if [ $(whoami) != "root" ] ; then
echo "Please become root."
exit
fi

set -eu

lo=$(losetup --find --show --partscan ${1})

mkdir -p root/boot
mount ${lo}p2 root
mount ${lo}p1 root/boot
13 changes: 13 additions & 0 deletions scripts/image_testing/umount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [ $(whoami) != "root" ] ; then
echo "Please become root."
exit
fi

set -eu

sync
umount root/boot
umount root
losetup -D
Loading