2024-08-12 22:59:58 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
# archboot-restore-usbstick.sh - restore usbstick to FAT32
|
|
|
|
# by Tobias Powalowski <tpowa@archlinux.org>
|
|
|
|
. /usr/lib/archboot/common.sh
|
|
|
|
_usage()
|
|
|
|
{
|
|
|
|
echo -e "\e[1m\e[36mARCHBOOT\e[m \e[1m- Clean blockdevice\e[m"
|
|
|
|
echo -e "\e[1m----------------------------\e[m"
|
|
|
|
echo -e "This script removes all filesystem signatures"
|
2024-08-13 15:26:58 +02:00
|
|
|
echo -e "and partition table from the device."
|
2024-08-13 15:20:00 +02:00
|
|
|
echo -e "\e[1m\e[91mWARNING: ALL DATA WILL BE LOST ON THE DEVICE(S)! \e[m"
|
2024-08-12 22:59:58 +02:00
|
|
|
echo ""
|
2024-08-13 15:20:00 +02:00
|
|
|
echo -e "Usage: \e[1m${_BASENAME} <device(s)>\e[m"
|
2024-08-12 22:59:58 +02:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
##################################################
|
|
|
|
[[ -z "${1}" ]] && _usage "$@"
|
|
|
|
### check for root
|
|
|
|
if ! [[ ${UID} -eq 0 ]]; then
|
|
|
|
echo "ERROR: Please run as root user!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-08-13 15:26:58 +02:00
|
|
|
echo -e "\e[1mCleaning blockdevice(s) $*...\e[m"
|
2024-08-13 15:29:30 +02:00
|
|
|
echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on $* now! \e[m"
|
2024-08-13 15:26:58 +02:00
|
|
|
sleep 10
|
2024-08-13 15:20:00 +02:00
|
|
|
#shellcheck disable=SC2068
|
|
|
|
for i in $@; do
|
2024-08-13 15:26:58 +02:00
|
|
|
echo -e "\e[1mSTEP 1/2:\e[m Cleaning ${i} filesystem signatures..."
|
2024-08-13 15:20:00 +02:00
|
|
|
wipefs -f -a "${i}"
|
2024-08-13 15:26:58 +02:00
|
|
|
echo -e "\e[1mSTEP 2/2:\e[m Cleaning ${i} partition table..."
|
2024-08-13 15:20:00 +02:00
|
|
|
dd if=/dev/zero of="${i}" bs=1M count=10
|
|
|
|
echo -e "\e[1mFinished ${i}.\e[m"
|
|
|
|
done
|