Compare commits

...

9 commits

Author SHA1 Message Date
Tobias Powalowski
8798835dd1 add check on blockdevice 2024-08-13 23:25:12 +02:00
Tobias Powalowski
0e47c265fc use _root_check 2024-08-13 23:14:54 +02:00
Tobias Powalowski
8ce119af52 add CHANGELOG 2024-08-13 23:11:00 +02:00
Tobias Powalowski
e484509280 fixed completion 2024-08-13 23:01:11 +02:00
Tobias Powalowski
8fad4ba2af add restore-usbstick bash completion 2024-08-13 22:57:11 +02:00
Tobias Powalowski
32596ba842 better message 2024-08-13 19:41:16 +02:00
Tobias Powalowski
7e711098f2 better message 2024-08-13 19:40:54 +02:00
Tobias Powalowski
707e94936f add Options 2024-08-13 19:38:36 +02:00
Tobias Powalowski
73de7f47c0 add more -h|--h|--help|-help|? 2024-08-13 19:37:33 +02:00
6 changed files with 48 additions and 35 deletions

View file

@ -3,6 +3,7 @@ On the road to 2024.08:
Environment: Environment:
- updated and unified usage information in all scripts - updated and unified usage information in all scripts
- added clean-blockdevice.sh script - added clean-blockdevice.sh script
- added bash completion for restore-usbstick.sh and clean-blockdevice.sh
--- ---
Highlights 2024.07: Highlights 2024.07:
- kernel 6.10.x - kernel 6.10.x

View file

@ -16,19 +16,19 @@ _usage()
} }
################################################## ##################################################
[[ -z "${1}" ]] && _usage [[ -z "${1}" ]] && _usage
### check for root _root_check
if ! [[ ${UID} -eq 0 ]]; then
echo "ERROR: Please run as root user!"
exit 1
fi
echo -e "\e[1mCleaning blockdevice(s) $*...\e[m" echo -e "\e[1mCleaning blockdevice(s) $*...\e[m"
echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on $* now! \e[m" echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on $* now! \e[m"
sleep 10 sleep 10
#shellcheck disable=SC2068 #shellcheck disable=SC2068
for i in $@; do for i in $@; do
echo -e "\e[1mSTEP 1/2:\e[m Cleaning ${i} filesystem signatures..." if [[ -b "${i}" ]]; then
wipefs -f -a "${i}" echo -e "\e[1mSTEP 1/2:\e[m Cleaning ${i} filesystem signatures..."
echo -e "\e[1mSTEP 2/2:\e[m Cleaning ${i} partition table..." wipefs -f -a "${i}"
dd if=/dev/zero of="${i}" bs=1M count=10 echo -e "\e[1mSTEP 2/2:\e[m Cleaning ${i} partition table..."
echo -e "\e[1mFinished ${i}.\e[m" dd if=/dev/zero of="${i}" bs=1M count=10
echo -e "\e[1mFinished ${i}.\e[m"
else
echo -e "\e[1m\e[91mError: ${i} not a valid blockdevice! \e[m"
fi
done done

View file

@ -14,22 +14,19 @@ _usage()
exit 0 exit 0
} }
################################################## ##################################################
[[ -z "${1}" ]] && _usage "$@" [[ -z "${1}" ]] && _usage
### check for root _root_check
if ! [[ ${UID} -eq 0 ]]; then if [[ -b "${1}" ]]; then
echo "ERROR: Please run as root user!" echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on ${1} now! \e[m"
exit 1 sleep 10
fi # clean partitiontable
echo -e "\e[91mWARNING: 10 seconds for hitting CTRL+C to stop the process on ${1} now! \e[m" echo -e "\e[1mRestoring USB STICK...\e[m"
sleep 10 echo -e "\e[1mSTEP 1/3:\e[m Cleaning partition table..."
# clean partitiontable dd if=/dev/zero of="${1}" bs=512 count=2048
echo -e "\e[1mRestoring USB STICK...\e[m" wipefs -a "${1}"
echo -e "\e[1mSTEP 1/3:\e[m Cleaning partition table..." # create new MBR and partition on <DEVICE>
dd if=/dev/zero of="${1}" bs=512 count=2048 echo -e "\e[1mSTEP 2/3:\e[m Create new MBR and partitiontable..."
wipefs -a "${1}" fdisk "${1}" <<EOF
# create new MBR and partition on <DEVICE>
echo -e "\e[1mSTEP 2/3:\e[m Create new MBR and partitiontable..."
fdisk "${1}" <<EOF
n n
p p
1 1
@ -39,9 +36,12 @@ t
b b
w w
EOF EOF
# wait for partitiontable to be resynced # wait for partitiontable to be resynced
sleep 5 sleep 5
# create FAT32 filesystem on <device-partition> # create FAT32 filesystem on <device-partition>
echo -e "\e[1mSTEP 3/3:\e[m Create FAT32 filesystem..." echo -e "\e[1mSTEP 3/3:\e[m Create FAT32 filesystem..."
mkfs.vfat -F32 "${1}"1 mkfs.vfat -F32 "${1}"1
echo -e "\e[1mFinished.\e[m" echo -e "\e[1mFinished.\e[m"
else
echo -e "\e[1m\e[91mError: ${1} not a valid blockdevice! \e[m"
fi

View file

@ -17,7 +17,7 @@ _DIR="${2}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case ${1} in case ${1} in
-name=*|--name=*) NAME="$(echo "${1}" | rg -o '=(.*)' -r '$1')" ;; -name=*|--name=*) NAME="$(echo "${1}" | rg -o '=(.*)' -r '$1')" ;;
-h|--h|?) _usage ;; -h|--h|-help|--help|?) _usage ;;
esac esac
shift shift
done done

View file

@ -14,6 +14,7 @@ _usage() {
echo -e "\e[1m---------------\e[m" echo -e "\e[1m---------------\e[m"
echo "Tool for creating an archboot initramfs image." echo "Tool for creating an archboot initramfs image."
echo echo
echo "Options:"
echo " -h Display this message and exit" echo " -h Display this message and exit"
echo " -c <config> Use <config> file" echo " -c <config> Use <config> file"
echo " -g <path> Generate cpio image and write to specified <path>" echo " -g <path> Generate cpio image and write to specified <path>"
@ -38,12 +39,12 @@ while [ $# -gt 0 ]; do
_TARGET_DIR="${1}" _TARGET_DIR="${1}"
;; ;;
-g) shift -g) shift
[[ -d "${1}" ]] && _abort "Invalid image path -- ${1} is a directory!" [[ -d "${1}" ]] && _abort "Invalid image path -- ${1} is an existing directory!"
if ! _GENERATE_IMAGE="$(readlink -f "${1}")" || [[ ! -e "${_GENERATE_IMAGE%/*}" ]]; then if ! _GENERATE_IMAGE="$(readlink -f "${1}")" || [[ ! -e "${_GENERATE_IMAGE%/*}" ]]; then
_abort "Unable to write to path!" "${1}" _abort "Unable to write to path!" "${1}"
fi fi
;; ;;
-h) _usage -h|--h|-help|--help|?) _usage
;; ;;
esac esac
shift shift

View file

@ -0,0 +1,11 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# created by Tobias Powalowski <tpowa@archlinux.org>
_restore_usbstick()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
compopt -o bashdefault -o default
COMPREPLY=( $(compgen -W "$(lsblk -pnro NAME,TRAN,TYPE | rg '(.*) disk$' -r '$1' | rg (.*) usb$' -r '$1')" -- $cur) )
return 0
}
complete -F _restore_usbstick restore-usbstick.sh