interactive dd script
This commit is contained in:
parent
945697ad26
commit
19b1bf3d21
109
idd.sh
Executable file
109
idd.sh
Executable file
@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Paths
|
||||
MOUNTPATH="/mnt/mediadrive"
|
||||
DEVICEDIR="/dev"
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
LRED="\033[1;31m"
|
||||
BLUE="\033[0;34m"
|
||||
LBLUE="\033[1;34m"
|
||||
GREEN="\033[0;32m"
|
||||
LGREEN="\033[1;32m"
|
||||
YELLOW="\033[1;33m"
|
||||
CYAN="\033[0;36m"
|
||||
LCYAN="\033[1;36m"
|
||||
PURPLE="\033[0;35m"
|
||||
LPURPLE="\033[1;35m"
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
printf "${LRED}This script must be run as root${NC}\n" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
|
||||
-d) if [ -f /usr/bin/pv ];then
|
||||
clear
|
||||
|
||||
printf "${LCYAN}idd - interactive dd${NC}\n"
|
||||
printf "${LPURPLE}********************************${NC}\n"
|
||||
echo
|
||||
printf "${LGREEN}Image files (img, iso) in ${2}${NC}\n"
|
||||
printf "${LBLUE}-------------------------------------------${NC}\n"
|
||||
|
||||
find $2 -regex ".*\.\(img\|iso\)" | grep [.iso,.img]
|
||||
if [ ! $? = 0 ];then
|
||||
printf "${LRED}No image files found${NC}\n"
|
||||
fi
|
||||
printf "${LBLUE}-------------------------------------------${NC}\n"
|
||||
|
||||
printf "${YELLOW}Copy & paste full file path here: ${NC}"
|
||||
read filepath
|
||||
|
||||
clear
|
||||
printf "${LGREEN}List of DEVICES in ${DEVICEDIR}/${NC}\n"
|
||||
printf "${LBLUE}-------------------------------------------${NC}\n"
|
||||
lsblk
|
||||
printf "${LBLUE}-------------------------------------------${NC}\n"
|
||||
echo
|
||||
printf "${YELLOW}Enter name of device${NC} (${LCYAN}example${NC}, ${LBLUE}sdb${NC}): "
|
||||
read devname
|
||||
|
||||
echo
|
||||
|
||||
printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n"
|
||||
printf "${LCYAN}Please wait ...${NC}\n"
|
||||
echo
|
||||
dd if=${filepath} | pv | dd of=${DEVICEDIR}/${devname};sync
|
||||
printf "${LGREEN}Done writing file${NC}\n"
|
||||
else
|
||||
echo "${0}: Please install 'pv' with your package manager"
|
||||
fi
|
||||
;;
|
||||
-h) echo """
|
||||
usage: idd -d [directory]
|
||||
"""
|
||||
;;
|
||||
*) if [ -f /usr/bin/pv ];then
|
||||
clear
|
||||
|
||||
printf "${LCYAN}idd - interactive dd${NC}\n"
|
||||
printf "${LPURPLE}********************************${NC}\n"
|
||||
echo
|
||||
printf "${LGREEN}Image files (img, iso) in ${HOME}${NC}\n"
|
||||
printf "${LBLUE}-------------------------------------------${NC}\n"
|
||||
|
||||
find ${HOME} -regex ".*\.\(img\|iso\)" | grep [.iso,.img]
|
||||
if [ ! $? = 0 ];then
|
||||
printf "${LRED}No image files found${NC}\n"
|
||||
fi
|
||||
|
||||
printf "${LBLUE}-------------------------------------------${NC}\n"
|
||||
|
||||
printf "${YELLOW}Copy & paste full file path here: ${NC}"
|
||||
read filepath
|
||||
|
||||
clear
|
||||
printf "${LGREEN}List of DEVICES in ${DEVICEDIR}/${NC}\n"
|
||||
printf "${LBLUE}-------------------------------------------${NC}\n"
|
||||
lsblk
|
||||
printf "${LBLUE}-------------------------------------------${NC}\n"
|
||||
echo
|
||||
printf "${YELLOW}Enter name of device${NC} (${LCYAN}example${NC}, ${LBLUE}sdb${NC}): "
|
||||
read devname
|
||||
|
||||
echo
|
||||
|
||||
printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n"
|
||||
printf "${LCYAN}Please wait ...${NC}\n"
|
||||
echo
|
||||
dd if=${filepath} | pv | dd of=${DEVICEDIR}/${devname};sync
|
||||
printf "${LGREEN}Done writing file${NC}\n"
|
||||
else
|
||||
echo "${0}: pv command not found in /usr/bin"
|
||||
fi
|
||||
;;
|
||||
esac
|
Loading…
x
Reference in New Issue
Block a user