MRTestRepo/aliases/bash_aliases

106 lines
5.4 KiB
Bash
Raw Normal View History

2022-07-19 18:52:03 +00:00
alias ISO-datestamps='echo -en "\n Searching for files ...\r"; for i in /dev/sd[a-z] $(du -ahx ~/ 2>&1 | grep -v "\.iso". | grep "\.iso"| cut -f2) $(du -ahx / 2>&1 | grep -v "\.iso". | grep "\.iso"| cut -f2); do string=$(sudo hexdump -Cs 33598 -n16 $i | head -1 | cut -f2 -d"|" | cut -c"1-14"); [ "$string" != "" ] && echo " $string $i" ; done | sort -u'
alias date_of_iso='for i in ./*.iso ./*/*.iso /dev/sd[a-z]; do echo " $(sudo hexdump -C -s33598 -n16 $i 2>/dev/null |head -1 | cut -f2 -d"|" | cut -c-14) $i" ; done | sort'
2022-07-19 18:52:03 +00:00
alias cgrep='grep --color=always'
alias grep='grep --color=auto'
alias less='less -g'
alias ls='ls --color=auto'
2022-07-19 18:52:03 +00:00
alias locate='du -ah / 2>&1 | grep '
alias snipe='du -ah ./ 2>&1 | grep '
alias pep-writer='write-out-iso'
2022-07-19 18:52:03 +00:00
alias plot-boot='systemd-analyze plot > /tmp/boot_plot.svg ; x-www-browser file:///tmp/boot_plot.svg &'
alias timed='clear; neofetch; systemd-analyze'
alias update-aliases='echo -en "\n\tUpdating aliases:\t"; for i in $(alias | grep "alias ". | cut -f1 -d= | cut -f2 -d" "); do echo -en "$i\t"; done ;echo; alias | tee ~/.bash_aliases > /dev/null'
alias vi='busybox vi'
alias vicr='for i in ./* ; do [ -f $i ] && vi -R "$i" ; done'
alias view='vi -R'
alias write-out-iso='
sysc="\033[00m"
grey="\033[30;01m"
red="\033[31;01m"
green="\033[32;01m"
yellow="\033[33;01m"
blue="\033[34;01m"
violet="\033[35;01m"
aqua="\033[36;01m"
white="\033[37;01m"
2022-07-19 18:52:03 +00:00
iso=" "
dev=" "
line1="${green}Type or copy-n-paste a file name from above.${sysc}"
line2="${green}Type the full path to your USB device. ${yellow}(/dev/sdX)${sysc}"
line3="The block device ${yellow}${dev}${sysc} was found and seems Ok to use."
2022-07-19 18:52:03 +00:00
lsblk_cmd="lsblk -o PATH,VENDOR,MODEL,SIZE,HOTPLUG,RM"
_abort="${green}To abort this now, press ${white}Ctrl+C${sysc} ."
2022-07-19 18:52:03 +00:00
_anykey="Hit any key"
_coward="Cowardly refusing to write to"
_empty="${red}This field cannot be empty${sysc}"
2022-07-19 18:52:03 +00:00
_cancel="to cancel"
_continue="to continue"
_knownISO="to enter the full path to the ${white}ISO${sysc}."
_laststep="${aqua}This is the final step.${sysc}"
2022-07-19 18:52:03 +00:00
_missing="File not found."
_mounted="${red}The location is mounted.${sysc}"
2022-07-19 18:52:03 +00:00
_noblock="is not a block device."
_nochecks="No checks were done to determine this is an ISO image."
_noDEV="The location ${white}${dev}${sysc} does not exist yet, Plug in a USB ?"
2022-07-19 18:52:03 +00:00
_noISO="No ISO found in this directory."
_notlisted="Check your file name or the location and retry."
_passwd="${white}To write to a USB, your password may be required.${sysc}"
2022-07-19 18:52:03 +00:00
_re_enter="to Re-Enter the location"
_restart1="To start over, Press ${white}Ctrl+C${sysc},"
2022-07-19 18:52:03 +00:00
_restart2="then move to a folder with the ISO."
_retry="to retry"
_search="Searching ${blue}${PWD}${sysc} for ISOs ."
_write="${green}Hit ${white}ANY${green} key to write the file to"
2022-07-19 18:52:03 +00:00
clear
echo -en "\n\t${_passwd}\n\t"
sudo clear || echo -e "\tFailed password."
2022-07-19 18:52:03 +00:00
until [ ! -z "${iso}" ] && [ -e "${iso}" ] && ! (mount | grep -q "${iso}")
do clear
2022-07-19 18:52:03 +00:00
echo -e "\n ${_search}\n"
for i in ./*.iso ./*/*.iso ; do ls $i 2>/dev/null ; done | /bin/grep "\.iso" &&
2022-07-19 18:52:03 +00:00
echo -en "\n\t${line1}\n\n" || (
echo -en "\n\t${_noISO} \n\n ${_restart1} ${_restart2}\n\n Or ${_anykey} ${_knownISO}"
2022-07-19 18:52:03 +00:00
read -n1 -p " " pause && echo )
read -p " Path to ISO = " iso
[ -z "${iso}" ] && (echo -en "\n${_empty}." ; read -n1 -p " ${_anykey} ${_continue}. " back) && continue
[ ! -e "${iso}" ] && (echo -en "\n${_missing}." ; read -n1 -p " ${_anykey} ${_retry}. " back) && continue
( mount | grep -q "${iso}" ) && (echo -en "\n${_mounted}" ; read -n1 -p " ${_anykey} ${_retry}. " back) && continue
done
until [ ! -z $dev ] && [ -b $dev ] && ! (mount | grep -q $dev) && [ $dev != "/dev/sda" ] && [ $dev != "/dev/nvme01" ]
do clear
echo -e "\n\t ${green}Choose a block device to write the ISO to.${sysc}"
echo -e "\n ${white}ISO${sysc} -----> ${white}$iso${sysc}\n "
2022-07-19 18:52:03 +00:00
# echo -e "\n$($lsblk_cmd)\n" ; read -p "$line2 " dev
echo -e "\n$($lsblk_cmd)\n" | grep -Ew "(PATH|/dev/sd[a-z])"; echo -en "\n $line2 "; read dev
2022-07-19 18:52:03 +00:00
[ -z $dev ] && (echo -en "${_empty}."; read -n1 -p " ${_anykey} ${_continue}. " back) && continue
[ ! -e $dev ] && (echo -en "${_noDEV}\n\n"; read -n1 -p " ${_anykey} ${_retry}. " back) && continue
[ ! -b $dev ] && (echo -en "${dev} ${_noblock}"; read -n1 -p " ${_anykey} ${_retry}. " back) && continue
(mount | grep -q "$dev") && (echo -en "\n${_mounted}"; read -n1 -p " ${_anykey} ${_retry}. " back) && continue
[ $dev = "/dev/sda" ] && (echo -en "${_coward} ${dev} ."; read -n1 -p " ${_anykey} ${_retry}. " back) && continue
[ $dev = "/dev/nvme01" ] && (echo -en "${_coward} ${dev} ."; read -n1 -p " ${_anykey} ${_retry}. " back) && continue
done
clear
echo -e "\n\t\t${_laststep}\n"
# echo -e " \t${_anykey} ${_continue}.\n"
echo -e " ${white}ISO${sysc} -----> ${white}${iso}${sysc} "
2022-07-19 18:52:03 +00:00
# echo -e " Device --> ${dev}\n "
# echo -e "$($lsblk_cmd ${dev})" | grep -Ew "(PATH|/dev/sd[a-z])"
echo -en " ${white}Device${sysc} --> "
2022-07-19 18:52:03 +00:00
($lsblk_cmd ${dev}) | /bin/grep -w ${dev}
echo -e "\n\tThe file ${white}$iso${sysc} exists."
echo -e "\t(${_nochecks})"
echo -e "\tThe block device ${yellow}${dev}${sysc} was found and seems Ok to use.\n\n"
echo -e "\t${_abort}"
echo -en "\t${_write} ${yellow}$dev${sysc} . "
2022-07-19 18:52:03 +00:00
read -n1 go
echo -e "\n ${aqua}Writing ${white}${iso}${aqua} to ${yellow}$dev${aqua} ...${sysc}"
2022-07-19 18:52:03 +00:00
sudo dd bs=4M oflag=direct status=progress if="${iso}" of=${dev}'