Skip to content

Instantly share code, notes, and snippets.

@Nircek
Last active June 19, 2022 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nircek/2101dc89d0898754ca6aa67b8e799b27 to your computer and use it in GitHub Desktop.
Save Nircek/2101dc89d0898754ca6aa67b8e799b27 to your computer and use it in GitHub Desktop.
#!/bin/bash
function confirm() {
# https://stackoverflow.com/a/1885534/6732111
read -p "Is it ok? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
}
# sudo dd if=/dev/zero of=/dev/sdb bs=4M count=6 oflag=direct; ls /dev/sdb*
[[ $# != 2 ]] && { echo "usage: $0 /dev/sd* img.iso"; exit; };
ls -lah "$2"
stat --printf="%s\n" "$2" # src: https://unix.stackexchange.com/a/16644/450009
lsblk -b --output SIZE -n -d "$1"
echo
echo $ sudo dd "of=$1" "if=$2"
confirm || exit
sudo dd bs=4M status=progress conv=fsync oflag=direct "of=$1" "if=$2"
sleep 2
printf "p\nn\n\n\n\n\np\n" | sudo fdisk --wipe=never -t gpt "$1"
confirm || exit
printf "p\nn\n\n\n\n\np\nw\nq\n" | sudo fdisk --wipe=never -t gpt "$1"
sync
sudo partprobe "$1"
sleep 2
ls $1*
part=$(ls $1* | tail -n1)
echo "The last partition is '$part'."
confirm || exit
sudo mkfs.ext4 "$part"
mnt="/tmp/$(uuidgen)"
mnt="${mnt,,}" # https://serverfault.com/a/103366/947767
echo "Random temporary dir: $mnt"
confirm || exit
sudo mkdir "$mnt"
sudo mount "$part" "$mnt"
echo "inxi -pildfForumxxxv8c0tmc||inxi -pildfForumxxxv 7 -c 0 -tmc" | sudo tee "$mnt/gather.sh" > /dev/null # https://gist.github.com/Nircek/acb62cdebd3b6029e160551dfc636c52
sudo chown -R 1000:1000 "$mnt"
ls -lah "$mnt"
echo Reinsert your USB stick to tease gvfs/udisks2...
@Nircek
Copy link
Author

Nircek commented Jan 7, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment