160 lines
3.9 KiB
Bash
Executable File
160 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Paths
|
|
MOUNTPATH="/mnt/mediadrive"
|
|
DEVICEDIR="/dev"
|
|
HOMEDIR="/home"
|
|
|
|
# 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"
|
|
BWHITE="\e[1m"
|
|
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
|
|
|
|
Options(){
|
|
|
|
printf "${BWHITE}[Q]${NC} - Quit\n"
|
|
}
|
|
|
|
CheckFile(){
|
|
if [ ! -f "${1}" ];then
|
|
printf "${LRED}${1} is not a valid file path${NC}\n"
|
|
exit 0;
|
|
fi
|
|
}
|
|
|
|
CheckDev(){
|
|
if [ ! -b "${1}" ];then
|
|
printf "${LRED}${1} is not a valid block device${NC}\n"
|
|
exit 0;
|
|
fi
|
|
}
|
|
|
|
Quit(){
|
|
if [ "${1}" = "q" ];then
|
|
echo
|
|
printf "${LRED}Exiting......${NC}\n"
|
|
echo
|
|
exit 0;
|
|
elif [ "${1}" = "Q" ];then
|
|
echo
|
|
printf "${LRED}Exiting......${NC}\n"
|
|
echo
|
|
exit 0;
|
|
fi
|
|
}
|
|
|
|
case "$1" in
|
|
|
|
-d) if [ -f /usr/bin/pv ];then
|
|
clear
|
|
printf "${LCYAN}idd - interactive dd${NC}\n"
|
|
printf "${LPURPLE}********************************${NC}\n"
|
|
Options
|
|
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
|
|
CheckFile ${filepath}
|
|
Quit ${filepath}
|
|
clear
|
|
Options
|
|
echo
|
|
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
|
|
DEVPATH="${DEVICEDIR}/${devname}"
|
|
CheckDev ${DEVPATH}
|
|
Quit ${devname}
|
|
|
|
echo
|
|
|
|
printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n"
|
|
printf "${LCYAN}Please wait ...${NC}\n"
|
|
echo
|
|
pv -tpreb ${filepath} | 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"
|
|
Options
|
|
echo
|
|
printf "${LGREEN}Image files (img, iso) in ${HOMEDIR}${NC}\n"
|
|
printf "${LBLUE}-------------------------------------------${NC}\n"
|
|
|
|
find ${HOMEDIR} -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
|
|
CheckFile ${filepath}
|
|
|
|
Quit ${filepath}
|
|
|
|
clear
|
|
Options
|
|
echo
|
|
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
|
|
|
|
DEVPATH="${DEVICEDIR}/${devname}"
|
|
CheckDev ${DEVPATH}
|
|
Quit ${devname}
|
|
|
|
echo
|
|
|
|
printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n"
|
|
printf "${LCYAN}Please wait ...${NC}\n"
|
|
echo
|
|
pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync
|
|
printf "${LGREEN}Done writing file${NC}\n"
|
|
else
|
|
echo "${0}: pv command not found in /usr/bin"
|
|
fi
|
|
;;
|
|
esac
|