jitty-scripts/idd.sh

139 lines
3.5 KiB
Bash
Raw Normal View History

2016-05-02 20:05:03 -07:00
#!/bin/bash
# Paths
MOUNTPATH="/mnt/mediadrive"
DEVICEDIR="/dev"
HOMEDIR="/home"
2016-05-02 20:05:03 -07:00
# 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"
2016-07-06 13:52:27 -07:00
BWHITE="\e[1m"
2016-05-02 20:05:03 -07:00
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
2016-07-06 13:52:27 -07:00
Options(){
printf "${BWHITE}[Q]${NC} - Quit\n"
}
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
}
2016-05-02 20:05:03 -07:00
case "$1" in
-d) if [ -f /usr/bin/pv ];then
clear
printf "${LCYAN}idd - interactive dd${NC}\n"
printf "${LPURPLE}********************************${NC}\n"
2016-07-06 13:52:27 -07:00
Options
2016-05-02 20:05:03 -07:00
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
2016-07-06 13:52:27 -07:00
Quit ${filepath}
2016-05-02 20:05:03 -07:00
clear
2016-07-06 13:52:27 -07:00
Options
echo
2016-05-02 20:05:03 -07:00
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
2016-07-06 13:52:27 -07:00
Quit ${devname}
2016-05-02 20:05:03 -07:00
echo
printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n"
printf "${LCYAN}Please wait ...${NC}\n"
echo
2016-05-03 22:03:33 -07:00
pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync
2016-05-02 20:05:03 -07:00
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"
2016-07-06 13:52:27 -07:00
Options
2016-05-02 20:05:03 -07:00
echo
printf "${LGREEN}Image files (img, iso) in ${HOMEDIR}${NC}\n"
2016-05-02 20:05:03 -07:00
printf "${LBLUE}-------------------------------------------${NC}\n"
find ${HOMEDIR} -regex ".*\.\(img\|iso\)" | grep [.iso,.img]
2016-05-02 20:05:03 -07:00
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
2016-07-06 13:52:27 -07:00
Quit ${filepath}
2016-05-02 20:05:03 -07:00
clear
2016-07-06 13:52:27 -07:00
Options
echo
2016-05-02 20:05:03 -07:00
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
2016-07-06 13:52:27 -07:00
Quit ${devname}
2016-05-02 20:05:03 -07:00
echo
printf "${YELLOW}Writing${NC} ${LGREEN}${filepath}${NC} to ${LGREEN}/dev/${devname}${NC}\n"
printf "${LCYAN}Please wait ...${NC}\n"
echo
2016-05-03 22:03:33 -07:00
pv -tpreb ${filepath} | dd of=${DEVICEDIR}/${devname};sync
2016-05-02 20:05:03 -07:00
printf "${LGREEN}Done writing file${NC}\n"
else
echo "${0}: pv command not found in /usr/bin"
fi
;;
esac