-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
rtertiaer
wants to merge
1
commit into
main
Choose a base branch
from
disk_image_manipulation_scripts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,3 +188,8 @@ docs/manual/_markdown_manual | |
|
||
# Status File | ||
display-status.txt | ||
|
||
# archives and disk images | ||
*.img | ||
*.gz | ||
*.xz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
rm -v root/root/.bash_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.