commit
7464ecda62
@ -0,0 +1,2 @@ |
||||
# clear out the screen |
||||
clear |
||||
@ -0,0 +1,10 @@ |
||||
if [ -x /usr/bin/apt-get ]; then |
||||
alias agi='sudo apt-get install' |
||||
alias agr='sudo apt-get remove' |
||||
alias agu='sudo apt-get update' |
||||
alias acs='apt-cache search' |
||||
alias cddeb='cd /var/cache/apt/archives' |
||||
alias apt-upgrades="sudo apt update && sudo apt -y upgrade && notify-send 'Updates Complete' 'Your system updated successfully!' -u normal -t 7500 -i checkbox-checked-symbolic" |
||||
else |
||||
alias {agi,agr,agu,acs,cddeb,apt-upgrades}='echo "Sorry, apt-get is not installed"' |
||||
fi |
||||
@ -0,0 +1,8 @@ |
||||
alias m3u="mplayer -playlist" |
||||
#shuffle mp3/ogg etc by default |
||||
alias shuffle='mplayer --shuffle *' |
||||
#play all music files from the current directory |
||||
alias playwave='for i in *.wav; do mplayer "$i"; done' |
||||
alias playogg='for i in *.ogg; do mplayer "$i"; done' |
||||
alias playmp3='for i in *.mp3; do mplayer "$i"; done' |
||||
|
||||
@ -0,0 +1,43 @@ |
||||
auto-pkg-install() { |
||||
|
||||
if [ "$EUID" -eq 0 ]; then |
||||
USE_SUPER="" |
||||
elif groups "$USER" | grep -o "sudo" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
elif groups "$USER" | grep -o "doas" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="doas" |
||||
elif groups "$USER" | grep -o "wheel" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
elif groups "$USER" | grep -o "admin" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
else |
||||
USE_SUPER="error" |
||||
fi |
||||
|
||||
if [ "$USE_SUPER" == "error" ]; then |
||||
echo "Please run as root!" |
||||
return 1 |
||||
fi |
||||
|
||||
if [ -z "$1" ]; then |
||||
echo "Please give a package name to install!" |
||||
return 1 |
||||
fi |
||||
|
||||
declare -A osInfo; |
||||
osInfo[/etc/redhat-release]="yum install" |
||||
osInfo[/etc/arch-release]="pacman -S" |
||||
osInfo[/etc/gentoo-release]="emerge" |
||||
osInfo[/etc/SuSE-release]="zypper install" |
||||
osInfo[/etc/debian_version]="apt install" |
||||
osInfo[/etc/alpine-release]="apk add --no-cache" |
||||
for f in "${!osInfo[@]}" |
||||
do |
||||
if [[ -f $f ]];then |
||||
${USE_SUPER} ${osInfo[$f]} "$1" |
||||
fi |
||||
done |
||||
|
||||
} |
||||
|
||||
alias aip='auto-pkg-install' |
||||
@ -0,0 +1,14 @@ |
||||
#RSYNC |
||||
alias backup="rsync --progress --info=progress2 -ravz" |
||||
|
||||
export BACKUP_TO=~/MyBackups |
||||
mybackup() { |
||||
if [ ! -d "$BACKUP_TO" ]; then |
||||
mkdir "$BACKUP_TO" |
||||
fi |
||||
if [ -d "$BACKUP_TO" ]; then |
||||
backup $@ "$BACKUP_TO" |
||||
else |
||||
echo -e "\nSorry unable to Backup to $BACKUP_TO \n" |
||||
fi |
||||
} |
||||
@ -0,0 +1,23 @@ |
||||
alias cd.='pwd' |
||||
alias cd..='cd ..' |
||||
alias cd,,='cd ..' |
||||
alias ..='cd ..' |
||||
alias ,,='cd ..' |
||||
alias ...='cd ../..' |
||||
alias up2='cd ../..' |
||||
alias up3='cd ../../..' |
||||
alias up4='cd ../../../..' |
||||
# useage up 3 cd ../../.. |
||||
up(){ |
||||
local d="" |
||||
limit=$1 |
||||
for ((i=1 ; i <= limit ; i++)) |
||||
do |
||||
d=$d/.. |
||||
done |
||||
d=$(echo $d | sed 's/^\///') |
||||
if [ -z "$d" ]; then |
||||
d=.. |
||||
fi |
||||
cd $d |
||||
} |
||||
@ -0,0 +1,63 @@ |
||||
coder-dir() { |
||||
if [ $UID -ne 0 ]; then |
||||
if [ -d "$1" ]; then |
||||
sudo find "$1" -type d -exec chgrp coders {} \; |
||||
sudo find "$1" -type d -exec chmod g+s {} \; |
||||
sudo find "$1" -type f -exec chgrp coders {} \; |
||||
sudo find "$1" -type f -exec chmod 664 {} \; |
||||
sudo find "$1" -type d -exec chmod 775 {} \; |
||||
else |
||||
echo "DIR not found" |
||||
fi |
||||
else |
||||
if [ -d "$1" ]; then |
||||
find "$1" -type d -exec chgrp coders {} \; |
||||
find "$1" -type d -exec chmod g+s {} \; |
||||
find "$1" -type f -exec chgrp coders {} \; |
||||
find "$1" -type f -exec chmod 664 {} \; |
||||
find "$1" -type d -exec chmod 775 {} \; |
||||
else |
||||
echo "DIR not found" |
||||
fi |
||||
fi |
||||
} |
||||
www-data-dir() { |
||||
if [ $UID -ne 0 ]; then |
||||
if [ -d "$1" ]; then |
||||
sudo find "$1" -type d -exec chgrp www-data {} \; |
||||
sudo find "$1" -type d -exec chmod g+s {} \; |
||||
sudo find "$1" -type f -exec chgrp www-data {} \; |
||||
sudo find "$1" -type f -exec chmod 664 {} \; |
||||
sudo find "$1" -type d -exec chmod 775 {} \; |
||||
else |
||||
echo "DIR not found" |
||||
fi |
||||
else |
||||
if [ -d "$1" ]; then |
||||
find "$1" -type d -exec chgrp www-data {} \; |
||||
find "$1" -type d -exec chmod g+s {} \; |
||||
find "$1" -type f -exec chgrp www-data {} \; |
||||
find "$1" -type f -exec chmod 664 {} \; |
||||
find "$1" -type d -exec chmod 775 {} \; |
||||
else |
||||
echo "DIR not found" |
||||
fi |
||||
fi |
||||
} |
||||
web-dir() { |
||||
if [ $UID -ne 0 ]; then |
||||
if [ -d "$1" ]; then |
||||
sudo find "$1" -type f -exec chmod 664 {} \; |
||||
sudo find "$1" -type d -exec chmod 775 {} \; |
||||
else |
||||
echo "DIR not found" |
||||
fi |
||||
else |
||||
if [ -d "$1" ]; then |
||||
find "$1" -type f -exec chmod 664 {} \; |
||||
find "$1" -type d -exec chmod 775 {} \; |
||||
else |
||||
echo "DIR not found" |
||||
fi |
||||
fi |
||||
} |
||||
@ -0,0 +1,56 @@ |
||||
#cheat-sheet |
||||
chmod-cheat() { |
||||
echo "chmod =:" |
||||
echo "1 = execute only" |
||||
echo "2 = write only" |
||||
echo "3 = write and execute (1+2)" |
||||
echo "4 = read only" |
||||
echo "5 = read and execute (4+1)" |
||||
echo "6 = read and write (4+2)" |
||||
echo "7 = read and write and execute (4+2+1)" |
||||
echo "qmod =:" |
||||
echo "web) 0644" |
||||
echo "safe) 0640" |
||||
echo "sbin) 0550" |
||||
echo "bin) 0555" |
||||
echo "exe) 0555" |
||||
echo "+w) 0660" |
||||
echo "write) 0664" |
||||
echo "readonly) 0440" |
||||
echo "+775) 775" |
||||
echo -e "\nqmod (MODE) /path/file\n" |
||||
} |
||||
qmod() { |
||||
if [ -e "$2" ]; then |
||||
if [ -n "$1" ]; then |
||||
if [ -d "$2" ] && [ "$3" == "-R" ] |
||||
then |
||||
OPTION="-R" |
||||
else |
||||
OPTION="" |
||||
fi |
||||
case $1 in |
||||
web) /bin/chmod $OPTION 0644 "$2" ;; |
||||
safe) /bin/chmod $OPTION 0640 "$2" ;; |
||||
sbin) /bin/chmod $OPTION 0550 "$2" ;; |
||||
bin) /bin/chmod $OPTION 0555 "$2" ;; |
||||
exe) /bin/chmod $OPTION 0555 "$2" ;; |
||||
+w) /bin/chmod $OPTION 0660 "$2" ;; |
||||
write) /bin/chmod $OPTION 0664 "$2" ;; |
||||
readonly) /bin/chmod $OPTION 0440 "$2" ;; |
||||
+775) /bin/chmod $OPTION 775 "$2" ;; |
||||
775) echo "are you sure? If so, do chmod +775 file" ;; |
||||
*) /bin/chmod $OPTION $1 "$2" ;; |
||||
esac |
||||
if [ $? -eq 0 ]; then |
||||
echo "$1 chmod complete on $2" |
||||
else |
||||
echo "$1 chmod on $2 FAILED!!!" |
||||
fi |
||||
else |
||||
chmod-cheat |
||||
fi |
||||
else |
||||
chmod-cheat |
||||
fi |
||||
} |
||||
@ -0,0 +1,52 @@ |
||||
alias goto-trash-can='mv --force -t ~/.local/share/Trash/files ' |
||||
alias mv2trash='goto-trash-can' |
||||
|
||||
prompt_to_wipe() { |
||||
read -rp "Type 'wipe' to confirm deletion: " response |
||||
if [[ "$response" == "wipe" ]]; then |
||||
return 0 # user chose to wipe |
||||
else |
||||
return 1 # user did not choose to wipe |
||||
fi |
||||
} |
||||
|
||||
wipe-and-shred-file-permanently() { |
||||
if ! prompt_to_wipe; then |
||||
echo "Aborting..." |
||||
return 0 |
||||
fi |
||||
shred -z -v -u $@ |
||||
} |
||||
empty-the-file-contents() { |
||||
if [[ -z "$1" ]]; then |
||||
echo "Usage: empty-the-file-contents <filename>" |
||||
return 1 |
||||
fi |
||||
|
||||
if ! prompt_to_wipe; then |
||||
echo "Aborting..." |
||||
return 0 |
||||
fi |
||||
|
||||
local filename="$1" |
||||
local need_sudo="" |
||||
|
||||
# Check if file exists |
||||
if [[ ! -e "$filename" ]]; then |
||||
echo "Error: File '$filename' does not exist." >&2 |
||||
return 1 |
||||
fi |
||||
|
||||
# Check if current user owns the file |
||||
if [[ ! -O "$filename" ]]; then |
||||
echo "You don't own '$filename'. Trying with sudo..." |
||||
need_sudo="sudo" |
||||
fi |
||||
|
||||
# Empty the file while preserving permissions |
||||
$need_sudo truncate -s 0 "$filename" && echo "Successfully emptied '$filename'." || { |
||||
echo "Failed to empty '$filename'." >&2 |
||||
return 1 |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,2 @@ |
||||
#xrandr --output DisplayPort-2 --same-as DisplayPort-1 |
||||
alias clone-displays='xrandr --output DP-3 --same-as DP-2' |
||||
@ -0,0 +1,65 @@ |
||||
alias docker="sudo docker" |
||||
alias dc="docker container" |
||||
alias dv="docker volume" |
||||
alias dkps="docker ps --format '{{.ID}} - {{.Names}} - {{.Status}} - {{.Image}}'" |
||||
dklogs() { |
||||
docker logs -f `docker ps | grep $1 | awk '{print $1}'` |
||||
} |
||||
dkstats() { |
||||
if [ $# -eq 0 ] |
||||
then docker stats --no-stream; |
||||
else docker stats --no-stream | grep $1; |
||||
fi |
||||
} |
||||
dktop() { |
||||
docker stats --format "table {{.Container}}\t{{.Name}}\t{{.CPUPerc}} {{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}" |
||||
} |
||||
|
||||
# Get latest container ID |
||||
alias dl="docker ps -l -q" |
||||
|
||||
# Get container process |
||||
alias dps="docker ps" |
||||
|
||||
# Get process included stop container |
||||
alias dpa="docker ps -a" |
||||
|
||||
# Get images |
||||
alias di="docker images" |
||||
|
||||
# Get container IP |
||||
alias dip="docker inspect --format '{{ .NetworkSettings.IPAddress }}'" |
||||
|
||||
# Run deamonized container, e.g., $dkd base /bin/echo hello |
||||
alias dkd="docker run -d -P" |
||||
|
||||
# Run interactive container, e.g., $dki base /bin/bash |
||||
alias dki="docker run -i -t -P" |
||||
|
||||
# Execute interactive container, e.g., $dex base /bin/bash |
||||
alias dex="docker exec -i -t" |
||||
|
||||
# Stop all containers |
||||
dstop() { docker stop $(docker ps -a -q); } |
||||
|
||||
# Remove all containers |
||||
#drm() { docker rm $(docker ps -a -q); } |
||||
|
||||
# Stop and Remove all containers |
||||
#alias drmf='docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)' |
||||
|
||||
# Remove all images |
||||
#dri() { docker rmi $(docker images -q); } |
||||
|
||||
# Dockerfile build, e.g., $dbu tcnksm/test |
||||
dbu() { docker build -t=$1 .; } |
||||
|
||||
# Show all alias related docker |
||||
dalias() { alias | grep 'docker' | sed "s/^\([^=]*\)=\(.*\)/\1 => \2/"| sed "s/['|\']//g" | sort; } |
||||
|
||||
# Bash into running container |
||||
dbash() { docker exec -it $(docker ps -aqf "name=$1") bash; } |
||||
|
||||
# Format output as Vert. |
||||
alias dvps="docker ps --format $DFORMAT" |
||||
export DFORMAT="\nID\t{{.ID}}\nIMAGE\t{{.Image}}\nCOMMAND\t{{.Command}}\nCREATED\t{{.RunningFor}}\nSTATUS\t{{.Status}}\nPORTS\t{{.Ports}}\nNAMES\t{{.Names}}\n" |
||||
@ -0,0 +1,28 @@ |
||||
word() { |
||||
wordgrinder "$1".wg |
||||
} |
||||
# Convert each typed tab to spaces, Do not automatically hard-wrap the current line, 4 space for tab |
||||
alias n='nano -wET 4' |
||||
g() { |
||||
geany "$1" & |
||||
} |
||||
doc() { |
||||
libreoffice --nologo "$1" & |
||||
} |
||||
pdf() { |
||||
evince "$1" & |
||||
} |
||||
alias ef='$EDITOR' |
||||
alias vf='$VISUAL' |
||||
calias() { |
||||
if [ -f "$_CUSTOM_ENV_PATH${1/.env/}.env" ]; then |
||||
$EDITOR "$_CUSTOM_ENV_PATH${1/.env/}.env" |
||||
elif [ -f "$_ENV_PATH${1/.env/}.env" ]; then |
||||
$EDITOR "$_ENV_PATH${1/.env/}.env" |
||||
elif [ "$1" == "me" ]; then |
||||
$EDITOR "${_ENV_PATH}editors.env" |
||||
else |
||||
cmd |
||||
echo "calias command_name" |
||||
fi |
||||
} |
||||
@ -0,0 +1,215 @@ |
||||
if [ -x /usr/bin/nautilus ]; then |
||||
FILE_MGR=/usr/bin/nautilus |
||||
elif [ -x /usr/bin/dolphin ]; then |
||||
FILE_MGR=/usr/bin/dolphin |
||||
elif [ -x /usr/bin/krusader ]; then |
||||
FILE_MGR=/usr/bin/krusader |
||||
elif [ -x /usr/bin/konqueror ]; then |
||||
FILE_MGR=/usr/bin/konqueror |
||||
elif [ -x /usr/bin/pcmanfm ]; then |
||||
FILE_MGR=/usr/bin/pcmanfm |
||||
elif [ -x /usr/bin/thunar ]; then |
||||
FILE_MGR=/usr/bin/thunar |
||||
else |
||||
FILE_MGR=/usr/bin/nautilus |
||||
fi |
||||
# safety features |
||||
alias cp='cp -iv' |
||||
alias mv='mv -iv' |
||||
alias ln="ln -i" # prompt whether to remove destinations |
||||
alias chown="chown --preserve-root" |
||||
alias chmod="chmod --preserve-root" |
||||
alias chgrp="chgrp --preserve-root" |
||||
alias rm='rm -I --preserve-root' |
||||
if [ -x /usr/bin/lsd ]; then |
||||
alias ls='lsd' |
||||
alias l='lsd -a' |
||||
else |
||||
alias l='ls -CF' |
||||
fi |
||||
# enable color support of ls and also add handy aliases |
||||
if [ -x /usr/bin/dircolors ]; then |
||||
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" |
||||
if [ -x /usr/bin/lsd ]; then |
||||
alias ls='lsd --color=auto' |
||||
else |
||||
alias ls='ls --color=auto' |
||||
fi |
||||
alias dir='dir --color=auto' |
||||
alias vdir='vdir --color=auto' |
||||
|
||||
alias grep='grep --color=auto' |
||||
alias fgrep='fgrep --color=auto' |
||||
alias egrep='egrep --color=auto' |
||||
fi |
||||
|
||||
# some more ls aliases |
||||
ll() { |
||||
if [ -x /usr/bin/lsd ]; then |
||||
if [ $(lsd -alF --color=always $@ | wc -l) -gt 20 ]; then |
||||
lsd -alF --color=always $@ | less -R -X |
||||
else |
||||
lsd -alF --color=always $@ |
||||
fi |
||||
else |
||||
if [ $(ls -alF --color=always $@ | wc -l) -gt 20 ]; then |
||||
ls -alF --color=always $@ | less -r -X |
||||
else |
||||
ls -alF --color=always $@ |
||||
fi |
||||
fi |
||||
} |
||||
alias la='ls -alh' |
||||
alias ls-la='ls -la' |
||||
new-stuff-only-sub-dirs-too() { |
||||
if [ -x /usr/bin/lsd ]; then |
||||
find . -type d -name '.git' -prune -o -type f -newermt "$(date -d '14 days ago' +%Y-%m-%d)" -exec /usr/bin/lsd -lt --color=always {} + |
||||
else |
||||
find . -type d -name '.git' -prune -o -type f -newermt "$(date -d '14 days ago' +%Y-%m-%d)" -exec /usr/bin/ls -lt {} + |
||||
fi |
||||
} |
||||
new-stuff-only() { |
||||
if [ -x /usr/bin/lsd ]; then |
||||
find . -maxdepth 1 -type f -newermt "$(date -d '14 days ago' +%Y-%m-%d)" -exec /usr/bin/lsd -lt --color=always {} + |
||||
else |
||||
find . -maxdepth 1 -type f -newermt "$(date -d '14 days ago' +%Y-%m-%d)" -exec /usr/bin/ls -lt {} + |
||||
fi |
||||
} |
||||
alias dirs="ls -al | grep '^d'" |
||||
alias cls='clear' |
||||
#Sort by file size |
||||
alias lt='/bin/ls --human-readable --size -1 -S --classify' |
||||
alias sym-links='find -type l' |
||||
show() { |
||||
if [ -z $1 ]; then |
||||
$FILE_MGR . & |
||||
else |
||||
$FILE_MGR $1 & |
||||
fi |
||||
} |
||||
cdocs() { |
||||
$FILE_MGR ~/Documents/"$1" & |
||||
} |
||||
documents() { |
||||
cd ~/Documents/"$1" |
||||
} |
||||
downloads() { |
||||
cd ~/Downloads/"$1" |
||||
} |
||||
desktop() { |
||||
cd ~/Desktop/"$1" |
||||
} |
||||
music() { |
||||
cd ~/Music/"$1" |
||||
} |
||||
videos() { |
||||
cd ~/Videos/"$1" |
||||
} |
||||
photos() { |
||||
cd ~/Pictures/"$1" |
||||
} |
||||
alias aliases='cd $_ENV_PATH' |
||||
alias space-used='ncdu' |
||||
www() { |
||||
cd /var/www/"$1" |
||||
} |
||||
alias md='mkdir -p' |
||||
mcd() { |
||||
mkdir -p "$1" |
||||
cd "$1" |
||||
} |
||||
alias e='exit' |
||||
alias bye='exit' |
||||
# Auto cd into folder by just typing the name of the directory |
||||
shopt -s autocd |
||||
#Search for a specific file |
||||
#Use: "findfile example" |
||||
#Results: prints any files that begin with "example", is not case-sensitive, picks up any file type (ex. result: ExampleTest.docx) |
||||
findfile() { |
||||
if [ -x /usr/bin/fdfind ]; then |
||||
fdfind "$@" |
||||
return |
||||
fi |
||||
file="$@" |
||||
file+="*" |
||||
find . -iname "$file" 2>&1 | grep -v "Operation not permitted" |
||||
} |
||||
#Search for all files with a specific extension |
||||
#Use: "findext swift" |
||||
#Results: prints all .swift files |
||||
findext() { |
||||
ext="*." |
||||
ext+="$@" |
||||
find . -iname "$ext" 2>&1 | grep -v "Operation not permitted" |
||||
} |
||||
lfile() { |
||||
findfile "$@" | less |
||||
} |
||||
lext() { |
||||
findext "$@" | less |
||||
} |
||||
# same as cp file{,_BACKUP} |
||||
cpt() { |
||||
if [ -z "$1" ]; then |
||||
echo "cpt file file_BACKUP" |
||||
echo "Will copy the file to file_BACKUP" |
||||
echo "Same as doing: cp file{,_BACKUP}" |
||||
return |
||||
fi |
||||
if [ -z "$2" ]; then |
||||
cp "$1" "$1"_BACKUP |
||||
else |
||||
cp "$1" "$1"_"$2" |
||||
fi |
||||
} |
||||
# same as mv dirname{,_OLD} |
||||
mvt() { |
||||
if [ -z "$1" ]; then |
||||
echo "mvt existingDir newName" |
||||
echo "Will rename the folder with existingDir_newName" |
||||
echo "Same as doing: mv DirName{,_OLD}" |
||||
return |
||||
fi |
||||
if [ -z "$2" ]; then |
||||
mv "$1" "$1"_OLD |
||||
else |
||||
mv "$1" "$1"_"$2" |
||||
fi |
||||
} |
||||
# mv file to ORIGNAL_file, make/edit new file |
||||
erase_config() { |
||||
if [ -z "$1" ]; then |
||||
echo "Rename, then Erase Config File, then edit new one." |
||||
return |
||||
fi |
||||
mv "$1" ORIGNAL_"$1" |
||||
touch "$1" |
||||
$EDITOR "$1" |
||||
} |
||||
|
||||
# Find text within given files |
||||
lookfor() { |
||||
if [ -x /usr/bin/rg ]; then |
||||
rg "$@" |
||||
return |
||||
fi |
||||
if [ -z "$2" ]; then |
||||
grep -rnw . -e "$1" |
||||
else |
||||
if [ -z "$3" ]; then |
||||
grep -rnw "$2" -e "$1" |
||||
else |
||||
grep "$3" -rnw "$2" -e "$1" |
||||
fi |
||||
fi |
||||
} |
||||
# list all files of type and do line count Example: list-count *.yaml |
||||
list-count() { |
||||
total_files=$(ls -1 "$@" | wc -l) |
||||
echo "Total # of files = $total_files" |
||||
} |
||||
tree-count() { |
||||
tree -P "$@" -I "tmp|node_modules|vendor|cache|test" |
||||
} |
||||
alias file-count='find . -type f | wc -l' |
||||
alias see-mounted="mount | awk -F' ' '{ printf \"%s\t%s\n\",\$1,\$3; }' | column -t | egrep ^/dev/ | sort" |
||||
@ -0,0 +1,18 @@ |
||||
#git |
||||
alias gs='git status' |
||||
alias g.='git add .' |
||||
alias gc='git commit -a -m' |
||||
alias mpull='git pull origin master' |
||||
alias mpush='git push origin master' |
||||
alias mainpull='git pull origin main' |
||||
alias mainpush='git push origin main' |
||||
alias pull='git pull' |
||||
alias push='git push' |
||||
alias gb='git branch' |
||||
alias branch='git branch' |
||||
alias clone='git clone' |
||||
alias checkout='git checkout' |
||||
alias gdiff="git diff" |
||||
alias gw='git whatchanged' |
||||
# No matter how far down into your Git project's directory hierarchy you have descended, the command cg now returns you to the top. |
||||
alias cg='cd `git rev-parse --show-toplevel`' |
||||
@ -0,0 +1,181 @@ |
||||
gcd_help() { |
||||
/bin/echo "Usage: to auto cd into a git project." |
||||
/bin/echo "By Default with no arguments -> list all git projects." |
||||
/bin/echo "\$ gcd PROJECT -> will cd into project folder and give git status." |
||||
/bin/echo "Commands: \$ gcd PROJECT [auto, pull, push, nostatus, addall]" |
||||
/bin/echo "NEW: \$ gcd-push -> to push an git repo dir, and \$ gcd-pop -> to pop last dir" |
||||
/bin/echo "[nopop] -> will not gpop before it does its gpush" |
||||
/bin/echo "\$ gcd-pop -> will go back to last folder used by gcd-push" |
||||
/bin/echo "To edit Projects List: \$ gcd editprojects" |
||||
} |
||||
|
||||
gcd_branch() { |
||||
echo "You are on Git Branch: " |
||||
/usr/bin/git branch --list |
||||
} |
||||
GIT_DIR_STACK=() |
||||
git_dirs() { |
||||
if [ ${#GIT_DIR_STACK[@]} -eq 0 ]; then |
||||
echo "Empty Stack" 1>&2 |
||||
return 1 |
||||
fi |
||||
printf "Git Push Dirs: " |
||||
for s in "${GIT_DIR_STACK[@]}"; do |
||||
if [ -z "$1" ] || [ ! "${GIT_DIR_STACK[-1]}" == "$s" ]; then |
||||
printf "$s " |
||||
fi |
||||
done |
||||
echo -e "\n" |
||||
} |
||||
|
||||
git_pushd() { |
||||
if [ ${#GIT_DIR_STACK[@]} -eq 0 ]; then |
||||
GIT_DIR_STACK+=( $(pwd) ) |
||||
fi |
||||
if [ ! -z "$1" ]; then |
||||
local gitdirname=$1 |
||||
local nopush=false |
||||
for s in "${GIT_DIR_STACK[@]}"; do |
||||
if [ "$s" == "$gitdirname" ]; then |
||||
nopush=true |
||||
break; |
||||
fi |
||||
done |
||||
if [ "$nopush" == false ]; then |
||||
GIT_DIR_STACK+=( "$gitdirname" ) |
||||
else |
||||
echo "Already in Stack..." |
||||
fi |
||||
if [ -z "$2" ]; then |
||||
git_dirs here |
||||
fi |
||||
cd $gitdirname |
||||
fi |
||||
} |
||||
|
||||
git_popd() { |
||||
if [[ ${GIT_DIR_STACK[@]} ]]; then |
||||
if [ ${#GIT_DIR_STACK[@]} -eq 2 ]; then |
||||
cd ${GIT_DIR_STACK[-2]} |
||||
echo "Stack now empty." |
||||
GIT_DIR_STACK=() |
||||
elif [ ${#GIT_DIR_STACK[@]} -gt 2 ]; then |
||||
cd ${GIT_DIR_STACK[-2]} |
||||
if [ -z "$1" ]; then |
||||
git_dirs here |
||||
fi |
||||
unset GIT_DIR_STACK[-1] |
||||
else |
||||
echo "Empty Stack" 1>&2 |
||||
return 1 |
||||
fi |
||||
else |
||||
echo "Empty Stack" 1>&2 |
||||
return 1 |
||||
fi |
||||
} |
||||
|
||||
alias gcd-push='git_pushd' |
||||
alias gcd-pop='git_popd' |
||||
alias gcd-dirs='git_dirs' |
||||
|
||||
gcd_x() { |
||||
if [ -z "$2" ]; then |
||||
git_popd 2> /dev/null > /dev/null |
||||
git_pushd "$1" |
||||
elif [ "$2" == "nopop" ]; then |
||||
git_pushd "$1" |
||||
else |
||||
cd "$1" |
||||
fi |
||||
} |
||||
|
||||
gcd() { |
||||
#set -x |
||||
local git_projects=~/.gitprojects |
||||
|
||||
if [ ! -r $git_projects ]; then |
||||
/opt/profiles/scripts/locate_gits.sh |
||||
if [ $? -eq 0 ]; then |
||||
mv /tmp/gitprojects $git_projects |
||||
else |
||||
echo "Opps!!" |
||||
exit 1 |
||||
fi |
||||
fi |
||||
|
||||
if [ -z "$1" ]; then |
||||
/bin/echo |
||||
elif [ $1 == "--help" ] || [ $1 == "-help" ] || [ $1 == "help" ] || [ $1 == "?" ]; then |
||||
gcd_help |
||||
return 0 |
||||
elif [ $1 == "editprojects" ]; then |
||||
$EDITOR "$git_projects" |
||||
return 0 |
||||
elif [ $1 == "me" ]; then |
||||
$EDITOR ${_ENV_PATH}git_cd.env |
||||
return 0 |
||||
fi |
||||
|
||||
IFSOLD=$IFS |
||||
IFS=','; |
||||
found="false" |
||||
while read -r label mycommand desc; |
||||
do |
||||
[[ $label =~ ^#.* ]] && continue |
||||
if [ -z "$1" ]; then |
||||
/bin/echo "gcd ${label} , PATH= ${mycommand}, DESC: ${desc}" |
||||
else |
||||
[[ "$label" == "$1" ]] && { found="true"; break; } |
||||
fi |
||||
done < "$git_projects" |
||||
IFS=$IFSOLD |
||||
|
||||
if [ "$found" == "true" ] && [ ! -z $mycommand ]; then |
||||
if [ -z $2 ]; then |
||||
gcd_x "$mycommand" |
||||
/usr/bin/git status |
||||
elif [ $2 == "nopop" ]; then |
||||
gcd_x "$mycommand" nopop |
||||
/usr/bin/git status |
||||
elif [ $2 == "auto" ]; then |
||||
/opt/profiles/scripts/git/dogit "$mycommand" |
||||
gcd_x "$mycommand" $3 |
||||
elif [ $2 == "pull" ]; then |
||||
/opt/profiles/scripts/git/gpull "$mycommand" |
||||
gcd_x "$mycommand" $3 |
||||
elif [ $2 == "push" ]; then |
||||
/opt/profiles/scripts/git/gpull-and-push "$mycommand" |
||||
gcd_x "$mycommand" $3 |
||||
elif [ $2 == "nostatus" ]; then |
||||
gcd_x "$mycommand" $3 |
||||
elif [ $2 == "addall" ]; then |
||||
gcd_x "$mycommand" $3 |
||||
/usr/bin/git add . |
||||
/usr/bin/git status |
||||
else |
||||
gcd_help |
||||
fi |
||||
fi |
||||
#set +x |
||||
} |
||||
|
||||
gpcd() { |
||||
local gcmdlist=() |
||||
IFSOLD=$IFS |
||||
IFS=','; |
||||
while read -r label mycommand desc; do |
||||
[[ $label =~ ^#.* ]] && continue |
||||
if [ "$label" == "$1" ]; then |
||||
gcd $@ |
||||
return 0 |
||||
fi |
||||
gcmdlist+=("$label" "$desc") |
||||
done < ~/.gitprojects |
||||
IFS=$IFSOLD |
||||
command=$(dialog --ok-label "CD" --cancel-label "EXIT" --output-fd 1 \ |
||||
--colors \ |
||||
--menu "Select git project:" 0 0 0 "${gcmdlist[@]}") |
||||
clear |
||||
gcd $command $@ |
||||
} |
||||
@ -0,0 +1,28 @@ |
||||
go-lang() { |
||||
if [ "$(which go | wc -l)" -eq 1 ]; then |
||||
if [ -z "$1" ]; then |
||||
echo "build - Compile packages and dependencies." |
||||
echo "download - Downloads the module to local cache." |
||||
echo "init - Init new module in current DIR." |
||||
echo "get - Adds dependencies to current module and install them." |
||||
echo "tidy - Add missing and remove unused modules." |
||||
echo "vendor - Make vendored copy of dependencies." |
||||
else |
||||
case "$1" in |
||||
build) go build;; |
||||
download) go mod download;; |
||||
init) go mod init "$2";; |
||||
get) go get "$2";; |
||||
tidy) go mod tidy;; |
||||
vendor) go mod vendor;; |
||||
*) go-lang;; |
||||
esac |
||||
fi |
||||
else |
||||
echo "Go Lang, not install yet!" |
||||
echo "Goto: https://go.dev/dl/ Grab the TAR file..." |
||||
echo "rm -rf /usr/local/go && tar -C /usr/local -xzf GO_FILE_HERE.tar.gz" |
||||
echo "ln -s /usr/local/go/bin/go /usr/local/bin/" |
||||
fi |
||||
} |
||||
alias gx='go-lang' |
||||
@ -0,0 +1,15 @@ |
||||
# CHANGE the below GPG_EMAIL !!!!!!!! to your's |
||||
export XGPG_EMAIL="Bob@home.local" |
||||
# You might want a smaller pwd for site compatibility?? |
||||
export XNEW_PASSWORD_SIZE=26 |
||||
export XGPG_PASS_STORE=~/.password-store |
||||
export XGPG_APP="/usr/bin/gpg" |
||||
# Un-comment below if gpg is not in the: /usr/bin path! |
||||
#export XGPG_APP="$(which gpg)" |
||||
|
||||
new-pwd() { |
||||
~/dotfiles/scripts/gpg/new-pwd.sh $@ |
||||
} |
||||
new-mempass() { |
||||
~/dotfiles/scripts/gpg/new-mempass.sh $@ |
||||
} |
||||
@ -0,0 +1,12 @@ |
||||
echo -e "Kernel & CPU:" `uname -rp` |
||||
|
||||
# print this months calendar out |
||||
#cal |
||||
|
||||
if [ -f awesome.txt ]; then |
||||
cat awesome.txt |
||||
fi |
||||
|
||||
if [ -f mysite.txt ]; then |
||||
cat mysite.txt |
||||
fi |
||||
@ -0,0 +1,4 @@ |
||||
alias helm-dry='helm install --dry-run --debug' |
||||
alias helm-pull='helm pull' |
||||
alias helm-repo='helm repo' |
||||
alias minikube-start='minikube start' |
||||
@ -0,0 +1,88 @@ |
||||
# Type alias-find command for help on that alias |
||||
alias-find() { |
||||
grep "$1" *.sh |
||||
} |
||||
|
||||
alias-new() { |
||||
if [ -z "$1" ]; then |
||||
echo "Create new alias called?" |
||||
else |
||||
pushd ~/dotfiles/.aliases.d |
||||
nano "${1//.sh".sh |
||||
if [ -f ".sane_checker.sum" ]; then |
||||
echo -e "Enter sudo password for sane_checker...\n" |
||||
sudo chattr -i ".sane_checker.sum" |
||||
sudo chmod 644 ".sane_checker.sum" |
||||
rm ".sane_checker.sum" |
||||
fi |
||||
popd |
||||
fi |
||||
} |
||||
alias alias-update='alias-new' |
||||
|
||||
alias-help() { |
||||
echo -e "Alias Help:\n" |
||||
echo -e "my-aliases - will use fzf selection box to pick an alias to edit.\n" |
||||
echo -e "alias-find - will search for a given command and tell which alias file contains it.\n" |
||||
echo -e "aliases - will cd into aliases folder.\n" |
||||
echo -e "alias-new - Followed by a filename will make a new alais file.\n" |
||||
echo -e "cmd - will less out alias command file.\n" |
||||
echo -e "cmds - will list all alias command files.\n" |
||||
echo -e "cmds-print - will print all alias commands.\n" |
||||
echo -e "calias - will edit alias command env file.\n" |
||||
echo -e "alias-reload - will reload bashrc...\n" |
||||
echo -e "cheat - Followed by Cheat file to view. If empty, all cheat files are displayed.\n" |
||||
echo -e "cheats - will cd into cheats folder.\n" |
||||
} |
||||
cheats="~/dotfiles/cheats/" |
||||
alias cheats="cd ${cheats}" |
||||
alias list-cheats='ls -1 ~/dotfiles/cheats/*.txt | sed -e "s,${cheats},,g"' |
||||
cheat() { |
||||
if [ -f ~/dotfiles/cheats/$1.txt ]; then |
||||
less -X ~/dotfiles/cheats/$1.txt |
||||
else |
||||
if [ -f ~/dotfiles/cheats/$1 ]; then |
||||
less -X ~/dotfiles/cheats/$1 |
||||
else |
||||
list-cheats |
||||
fi |
||||
fi |
||||
} |
||||
|
||||
alias alias-reload='unalias -a && . $HOME/.bashrc' |
||||
alias alias-guide='dialog --title "Alias Profiles Guide" --textbox /opt/profiles/cheats/guide 0 0; clear' |
||||
|
||||
my-aliases() { |
||||
local sys_aliases=$(find "~/dotfiles/.aliases.d" -type f -name "*.env") |
||||
local all_the_aliases=("$sys_aliases") |
||||
local selected_alias=$(printf "%s\n" "${all_the_aliases[@]}" | fzf --prompt "Select Alias file: ") |
||||
if [ -z "$selected_alias" ]; then |
||||
echo "No Alias selected." |
||||
return 1 |
||||
fi |
||||
nano "$selected_alias" |
||||
} |
||||
|
||||
cmds-print() { |
||||
lpstat -d | grep "no system default destination" |
||||
if [ $? -eq 0 ]; then |
||||
if [ -z $1 ]; then |
||||
echo "Please enter pritner dest:" |
||||
lpstat -t |
||||
else |
||||
lpoptions -d $1 |
||||
fi |
||||
else |
||||
echo "..." > /tmp/pcommands.txt |
||||
for f in ~/dotfiles/.aliases.d/*.sh; do |
||||
if [ "$f" == "kubectl-cheat-sheet.sh" ]; then |
||||
# skip large file |
||||
continue |
||||
fi |
||||
|
||||
echo "Reading Aliases for ${f}" >> /tmp/pcommands.txt |
||||
cat "${f}" >> /tmp/pcommands.txt |
||||
done |
||||
lpr /tmp/pcommands.txt |
||||
fi |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
# don't put duplicate lines or lines starting with space in the history. |
||||
# See bash(1) for more options |
||||
export HISTCONTROL=ignoreboth |
||||
|
||||
# append to the history file, don't overwrite it |
||||
shopt -s histappend |
||||
|
||||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) |
||||
export HISTSIZE=10000 |
||||
export HISTFILESIZE=10000 |
||||
|
||||
export HISTTIMEFORMAT="%d/%m/%y %T " |
||||
|
||||
# check the window size after each command and, if necessary, |
||||
# update the values of LINES and COLUMNS. |
||||
shopt -s checkwinsize |
||||
@ -0,0 +1,8 @@ |
||||
# A host-based intrusion detection system. |
||||
alias ids-scan='sudo tripwire -m c -v -c /etc/tripwire/tw.cfg' |
||||
ids-update() { |
||||
DIR=/var/lib/tripwire/report |
||||
HOST=`hostname -s` |
||||
LAST_REPORT=`sudo ls -1t $DIR/$HOST-*.twr | head -1` |
||||
sudo tripwire --update --twrfile "$LAST_REPORT" |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,2 @@ |
||||
[ -f ~/.kube-ps1 ] && alias kube-ps='source ~/.kube-ps1' |
||||
[ ! -f ~/.kube-ps1 ] && alias kube-ps='echo "Sorry kube prompt file not found!"' |
||||
@ -0,0 +1,69 @@ |
||||
alias hg='history|grep' |
||||
alias hl='history|less -X' |
||||
|
||||
hh() { |
||||
if [ -z "$1" ]; then |
||||
history 15 |
||||
else |
||||
history $1 |
||||
fi |
||||
} |
||||
alias watch-logs='sudo tail -F' |
||||
alias changed-files='find . -mtime -30 | less' |
||||
search() { |
||||
find . -name "$1" -print |
||||
} |
||||
match() { |
||||
if [ -z "$2" ]; then |
||||
echo "usage: match \"search_for_pattern\" file or files" |
||||
else |
||||
grep -n "$@" | less |
||||
fi |
||||
} |
||||
abc() { |
||||
if [ -n "$2" ]; then |
||||
_f_do_as "$1" sort "$1" | grep "$2" |
||||
else |
||||
_f_do_as "$1" sort "$1" |
||||
fi |
||||
} |
||||
short-asc() { |
||||
abc "$@" | head |
||||
} |
||||
alias short='sed 100q' |
||||
view-long() { |
||||
_f_do_as "$1" sed 500q $1 | less |
||||
} |
||||
save-long() { |
||||
if [ -n "$2" ]; then |
||||
_f_do_as "$1" sed 500q $1 > $2 |
||||
else |
||||
echo "example: save-long in-file out-file" |
||||
fi |
||||
} |
||||
head-log() { |
||||
if [ -n "$2" ]; then |
||||
_f_do_as "$1" head -n 2000 $1 > $2 |
||||
else |
||||
_f_do_as "$1" head -n 2000 $1 | less |
||||
fi |
||||
} |
||||
tail-log() { |
||||
if [ -n "$2" ]; then |
||||
_f_do_as "$1" tail -n 2000 $1 > $2 |
||||
else |
||||
_f_do_as "$1" tail -n 2000 $1 | less |
||||
fi |
||||
} |
||||
logs-find-errors() { |
||||
_f_do_as "$1" grep -Rni "error" $@ | less |
||||
} |
||||
logs-find-notices() { |
||||
_f_do_as "$1" grep -Rni "notice" $@ | less |
||||
} |
||||
logs-find-warnings() { |
||||
_f_do_as "$1" grep -Rni "warning" $@ | less |
||||
} |
||||
logs-find-deprecated() { |
||||
_f_do_as "$1" grep -Rni "deprecated" $@ | less |
||||
} |
||||
@ -0,0 +1,13 @@ |
||||
# wget -c will resume getting a partially-downloaded file. |
||||
alias wget='wget -c' |
||||
#Maintance |
||||
alias cleantmp='find /tmp -atime +3 -exec rm -f {} ";"' |
||||
alias uuids='awk '\''/^UUID/ {print $1}'\'' /etc/fstab' |
||||
#View systgem log for XX Unit ex: nginx |
||||
alias jlog='journalctl -xeu' |
||||
alias findlarge='find -size +1G -ls' |
||||
inodes() { |
||||
inum=$(ls -i "$1" | awk '{print $1}') |
||||
echo -e "\n Scaning system for iNode # $inum \n" |
||||
find / -inum "$inum" 2>/dev/null |
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
link-file() { |
||||
if [[ -n "$1" && -n "$2" && -f "$1" && ! -f "$2" ]]; then |
||||
ln -s "$1" "$2" |
||||
else |
||||
echo "link /home/username/SOURCE_FILE /opt/new_LINK" |
||||
fi |
||||
} |
||||
|
||||
link-dir() { |
||||
if [[ -n "$1" && -n "$2" && -d "$1" && ! -f "$2" ]]; then |
||||
ln -s "$1" "$2" |
||||
else |
||||
echo "link /home/username/SOURCE_DIR /opt/new_LINK" |
||||
fi |
||||
} |
||||
@ -0,0 +1,32 @@ |
||||
#CPU and Memory useage |
||||
# pass options to free |
||||
alias meminfo='free -m -l -t' |
||||
|
||||
#File Useage |
||||
# Disks and File System useage |
||||
alias df='df -HTa --total' |
||||
# Disk Usage for a folder in useful sizes |
||||
du() { |
||||
du -ach $1 | sort -h |
||||
} |
||||
alias disks=df |
||||
alias useage=du |
||||
alias home='echo "Please wait... Calculating Size of Home..." && du -s /home' |
||||
|
||||
# get top process eating memory |
||||
alias psmem='ps auxf | sort -nr -k 4' |
||||
alias psmem10='ps auxf | sort -nr -k 4 | head -10' |
||||
|
||||
# get top process eating cpu |
||||
alias pscpu='ps auxf | sort -nr -k 3' |
||||
alias pscpu10='ps auxf | sort -nr -k 3 | head -10' |
||||
|
||||
# Get server cpu info |
||||
alias cpuinfo='lscpu' |
||||
alias cpudetails='sudo lshw -C cpu' |
||||
|
||||
alias memdetails='sudo lshw -C memory' |
||||
alias netdetails='sudo lshw -C network' |
||||
alias diskdetails='sudo lshw -C disk' |
||||
|
||||
alias fhere='find . -name ' |
||||
@ -0,0 +1,109 @@ |
||||
alias lock='gnome-screensaver-command --lock' |
||||
alias view-mounted="mount | awk -F' ' '{ printf \"%s\t%s\n\",\$1,\$3; }' | column -t | egrep ^/dev/ | sort" |
||||
mounted() { |
||||
if [ -z $1 ]; then |
||||
mount | column -t |
||||
else |
||||
sudo mount | column -t | grep "$@" |
||||
fi |
||||
} |
||||
# sudo apt install bat |
||||
alias bat='batcat' |
||||
alias bc='clear;batcat' |
||||
alias bs='clear;batcat -l bash' |
||||
alias o='less' |
||||
alias print='lpr' |
||||
|
||||
# line "*" 50 |
||||
# will ouput a line with: ************************************************** |
||||
line() { printf -v _L %$2s; printf -- "${_L// /$1}"; } |
||||
alias stars='line "*" 50' |
||||
|
||||
long-password() { |
||||
if [ -z "$1" ]; then |
||||
local random_string=$(openssl rand -base64 24) |
||||
else |
||||
local random_string=$(openssl rand -base64 "$1") |
||||
fi |
||||
local possible_symbols='@#,%.&*()^?' |
||||
local num_symbols=$((RANDOM % ${#possible_symbols} + 1)) |
||||
extra_symbols=$(echo "$possible_symbols" | fold -w1 | shuf | head -n "$num_symbols" | tr -d '\n') |
||||
local combined_string="${random_string}${extra_symbols}" |
||||
local shuffled_string=$(echo "$combined_string" | fold -w1 | shuf | tr -d '\n') |
||||
echo "$shuffled_string" |
||||
} |
||||
good-pass() { |
||||
local password=$(long-password) |
||||
# Get the length of the password |
||||
local password_length=${#password} |
||||
# Calculate half the length of the password |
||||
local half_length=$((password_length / 2)) |
||||
# Generate a random starting position between 0 and half_length |
||||
local start_position=$((RANDOM % (password_length - half_length + 1))) |
||||
# Calculate a random length for the substring between half_length and password_length |
||||
local substring_length=$((RANDOM % (password_length - half_length + 1) + half_length)) |
||||
# Extract the substring |
||||
local substring=${password:start_position:substring_length} |
||||
echo "$substring" |
||||
} |
||||
gpg-make-pwd() { |
||||
local edt=$(date +%Y%m%d-%H%M%S) |
||||
long-password > ~/Desktop/.gpg_pwd_${edt}.txt |
||||
echo "Made long password at: ~/Desktop/.gpg_pwd_${edt}.txt" |
||||
if [ "$1" == "show" ]; then |
||||
echo -e "\033[0;31m" |
||||
cat ~/Desktop/.gpg_pwd_${edt}.txt |
||||
echo -e "\033[0m" |
||||
else |
||||
echo -e "\033[0;31m cat ~/Desktop/.gpg_pwd_${edt}.txt \033[0m \n" |
||||
fi |
||||
echo "This is a hidden file, so to list it: ls -la ~/Desktop/.gpg*" |
||||
echo "Becareful not to leave it where it is!!!" |
||||
} |
||||
|
||||
function looooooooong { |
||||
START=$(date +%s.%N) |
||||
$* |
||||
EXIT_CODE=$? |
||||
END=$(date +%s.%N) |
||||
DIFF=$(echo "$END - $START" | bc) |
||||
RES=$(python -c "diff = $DIFF; min = int(diff / 60); print('%s min' % min)") |
||||
result="$1 completed in $RES, exit code $EXIT_CODE." |
||||
echo -e "\n⏰ $result" |
||||
} |
||||
|
||||
# apt install wofi |
||||
newnote() { |
||||
local folder="$HOME/notes/" |
||||
mkdir -p "$folder" |
||||
local name |
||||
if [ -z "$1" ]; then |
||||
name="$(wofi --show dmenu -p "Enter a name: ")" || return 1 |
||||
# Fallback to Timestamp if user just hit enter |
||||
: "${name:=$(date +%F_%T | tr ':' '-')}" |
||||
$editor $folder$name".md" 2>&1 |
||||
else |
||||
$editor "$folder$1.md" |
||||
fi |
||||
} |
||||
|
||||
notes() { \ |
||||
local folder="$HOME/notes/" |
||||
if [ -z "$1" ]; then |
||||
choice=$(echo -e "New\n$(command ls -t1 $folder)" | wofi --show dmenu -L 25 -i -p "Choose note or create new: ") |
||||
case $choice in |
||||
New) newnote ;; |
||||
*.md) $editor "$folder$choice" 2>&1 ;; |
||||
*) return 1 ;; |
||||
esac |
||||
else |
||||
$editor "$folder$1.md" |
||||
fi |
||||
} |
||||
|
||||
|
||||
alias cht='/opt/profiles/scripts/cht.sh' |
||||
|
||||
alias create-archive='/opt/profiles/scripts/create_archive.sh' |
||||
|
||||
alias bible-quote='/opt/profiles/scripts/bible_quotes.sh' |
||||
@ -0,0 +1,68 @@ |
||||
#Networking |
||||
alias ip='ip --color=always' |
||||
alias addr='ip addr' |
||||
alias ipr='ip route' |
||||
alias public-ip='dig +short myip.opendns.com @208.67.222.222 @208.67.220.220' |
||||
alias myip='/bin/ip -c -br -f inet addr show' |
||||
alias myipv6='/bin/ip -c -br -6 addr show' |
||||
alias mymac='/bin/ip -c -br link show' |
||||
alias ipstats='/sbin/ifconfig -a' |
||||
alias quickping='time ping -c 5' |
||||
alias fastping='ping -c 100 -i .250 -s 2' |
||||
alias qping='ping -c 5 -i .250 -s 2' |
||||
|
||||
# agi-get install ipcalc |
||||
ip-v() { |
||||
if [ -z "$1" ]; then |
||||
echo "ip-v 192.168.32.0/24" |
||||
else |
||||
ipcalc $1 |
||||
fi |
||||
} |
||||
|
||||
# Lists all open UDP/TCP ports |
||||
alias connections='netstat -tulanp' |
||||
alias connections-common='netstat -t -4' # TCP IPv4 |
||||
alias openports='sudo ss -tunlp' |
||||
alias tcp='sudo lsof -nP -iTCP -sTCP:LISTEN' |
||||
alias udp='sudo lsof -nP -iUDP' |
||||
whatsonport() { |
||||
sudo lsof -i ":$1" |
||||
} |
||||
# Wake up remote PC/Sever |
||||
alias ipwake='/usr/bin/wakeonlan -i' |
||||
alias wake='echo "WakeOnLAN File with MAC and IP" && /usr/bin/wakeonlan -f' |
||||
|
||||
# Firewall IP Tables |
||||
alias ipt='sudo /sbin/iptables' |
||||
# Display all firewall rules |
||||
alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers' |
||||
alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers' |
||||
alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers' |
||||
alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers' |
||||
|
||||
# ufw |
||||
alias ufw-list='sudo ufw status numbered' |
||||
alias ufw-allow='sudo ufw allow' |
||||
alias ufw-re='sudo ufw reload' |
||||
alias rfw='sudo ufw reload' |
||||
alias ufw?='ufw --help' |
||||
|
||||
export FW='ufw' # iptlist |
||||
alias firewall='sudo "$FW"' |
||||
|
||||
#More Networking |
||||
export LAN='eth0' |
||||
export WAN='eth1' |
||||
alias dnstop='dnstop -l 5 "$LAN"' |
||||
alias vnstat='vnstat -i "$LAN"' |
||||
alias iftop='iftop -i "$LAN"' |
||||
alias tcpdump='tcpdump -i "$LAN"' |
||||
alias ethtool='ethtool "$LAN"' |
||||
|
||||
# Get Wireless Status |
||||
alias iwconfig='iwconfig wlo1' |
||||
alias wifi-low-power='sudo iwconfig wlo1 txpower 1dBm' |
||||
alias wifi=iwconfig |
||||
|
||||
alias essh="$EDITOR ~/.ssh/config" |
||||
@ -0,0 +1,76 @@ |
||||
## You should use these on servers instead of default commands...!! |
||||
#set nice levels for common commands |
||||
|
||||
#The niceness value ranges from -20 (highest priority) to 19 (lowest priority). |
||||
#A value of 2 is close to the default priority (0). |
||||
#A value of 17 is close to the lowest possible priority (19). |
||||
alias speed-up='echo -e "Grant Import-Fastest-CPU-time-to-process-this-task \r\n"; sudo nice -n -19' |
||||
alias speed-down='echo -e "Mark this as slowest-yelding-background-process-task \r\n"; nice -n 19' |
||||
|
||||
alias ncfg='nice -n 2 ./configure' |
||||
alias nmake='nice -n 2 make' |
||||
alias nmakeinstall='sudo nice -n 2 make install' |
||||
alias ncp='nice -n 17 cp -iv' |
||||
alias nmv='nice -n 17 mv -iv' |
||||
alias nrm='nice -n 17 rm -I --preserve-root' |
||||
alias ncurl='nice -n 17 curl' |
||||
alias nl='nice -n 17 ls --color=auto -alh' |
||||
alias nn='nice -n 17 nano' |
||||
ng() { |
||||
nice -n 17 geany $1 & |
||||
} |
||||
alias no='nice -n 17 less' |
||||
alias nless='nice -n 17 less' |
||||
alias ngrep='nice -n 17 grep --color=auto' |
||||
alias nhg='history | nice -n 17 grep --color=auto' |
||||
|
||||
#NICE apt-get |
||||
alias nagi='sudo nice -n 2 apt-get install' |
||||
alias nagr='sudo nice -n 2 apt-get remove' |
||||
alias nagu='sudo nice -n 2 apt-get update' |
||||
alias nacs='nice -n 2 apt-cache search' |
||||
|
||||
#NICE RSYNC |
||||
alias nbackup="nice -n 2 rsync --progress -ravz" |
||||
alias nrsync="nice -n 2 rsync" |
||||
|
||||
#NICE git |
||||
alias ngs='nice -n 17 git status' |
||||
alias ngc='nice -n 17 git commit -a -m' |
||||
alias nmpull='nice -n 17 git pull origin master' |
||||
alias nmpush='nice -n 17 git push origin master' |
||||
alias npull='nice -n 17 git pull origin' |
||||
alias npush='nice -n 17 git push origin' |
||||
alias ngb='nice -n 17 git branch' |
||||
alias nbranch='nice -n 17 git branch' |
||||
alias nclone='nice -n 17 git clone' |
||||
alias ncheckout='nice -n 17 git checkout' |
||||
alias ngitolite='nice -n 17 git clone gitolite:' |
||||
|
||||
#NICE tar |
||||
nmaketar() { |
||||
if [ -e "$1" ]; then |
||||
nice -n 17 tar cvzf "$1.tgz" "$@" |
||||
else |
||||
if [ -e "$2" ]; then |
||||
x="" |
||||
for var in "$@" |
||||
do |
||||
if [ -e "$var" ]; then |
||||
x+=$var |
||||
x+=" " |
||||
fi |
||||
done |
||||
nice -n 17 tar cvzf "$1.tgz" $x |
||||
else |
||||
if [ -n "$1" ]; then |
||||
nice -n 17 tar cvzf "$1.tgz" * |
||||
else |
||||
nice -n 17 tar cvzf all.tgz * |
||||
fi |
||||
fi |
||||
fi |
||||
} |
||||
alias ntar='nice -n 17 tar' |
||||
alias nungz='nice -n 17 tar xvfz' |
||||
alias nuntar='nice -n 17 tar xvf' |
||||
@ -0,0 +1,5 @@ |
||||
alias nvidia-on="sudo tee /proc/acpi/bbswitch <<<ON" |
||||
alias nvidia-off="sudo tee /proc/acpi/bbswitch <<<OFF" |
||||
alias nvidia-is-on="cat /proc/acpi/bbswitch" |
||||
alias nvidia-check64="optirun glxspheres64" |
||||
alias nvidia-check32="optirun glxspheres32" |
||||
@ -0,0 +1,21 @@ |
||||
recording_banner() { |
||||
if [ $(ps -C obs | wc -l) == "2" ]; then |
||||
# if [ -x /opt/profiles/custom_aliases/host_of_show.sh ]; then |
||||
# /opt/profiles/custom_aliases/host_of_show.sh |
||||
# fi |
||||
echo -ne "\033[1;34mRecording on\033[5;33m:\033[0;0m\033[2;37m "; |
||||
# print date and time |
||||
date +"%A, %B %-d, %Y %r" |
||||
echo -ne "\033[0m\033[37m" |
||||
else |
||||
# if [ -x /opt/profiles/custom_aliases/banner.sh ]; then |
||||
# /opt/profiles/custom_aliases/banner.sh |
||||
# fi |
||||
echo -ne "\033[0m\033[37m" |
||||
date +"%A, %B %-d, %Y %r" |
||||
fi |
||||
} |
||||
recording_banner |
||||
|
||||
alias mysite='clear; cat /opt/profiles/mysite.txt; recording_banner' |
||||
|
||||
@ -0,0 +1,14 @@ |
||||
if [ -x /usr/bin/pacman ]; then |
||||
alias pacu='sudo pacman -Syu' # update, add 'a' to the list of letters to update AUR packages if you use yaourt |
||||
alias pac='sudo pacman -S' # install |
||||
alias pacr='sudo pacman -Rs' # remove |
||||
alias pacs='pacman -Ss' # search |
||||
alias paci='pacman -Si' # info |
||||
alias paclo='pacman -Qdt' # list orphans |
||||
alias pacro='paclo && sudo pacman -Rns $(pacman -Qtdq)' # remove orphans |
||||
alias pacc='sudo pacman -Scc' # clean cache |
||||
alias paclf='pacman -Ql' # list files |
||||
alias pac-upgrades="sudo pacman -Syu && notify-send 'Updates Complete' 'Your system updated successfully!' -u normal -t 7500 -i checkbox-checked-symbolic" |
||||
else |
||||
alias {pacu,pac,pacr,pacs,paci,paclo,pacro,pacc,paclf,pac-upgrades}='echo "Sorry, pacman is not installed"' |
||||
fi |
||||
@ -0,0 +1,15 @@ |
||||
# alternative to yay with some cool options |
||||
# made in Rust!!! yeah! |
||||
if [ -x /usr/bin/paru ]; then |
||||
alias eparu="sudo $EDITOR /etc/paru.conf" |
||||
alias paru="paru --bottomup" |
||||
alias pupdate="paru -Syyu --bottomup --cleanafter --nocombinedupgrade --useask --upgrademenu" |
||||
alias aur-show="paru -Gp" |
||||
alias aur-download="paru -G" |
||||
alias pinstall="paru" |
||||
alias pfm-install"paru -S --fm=vim" |
||||
alias psearch="paru --bottomup" |
||||
alias pshow="paru -Si" |
||||
else |
||||
alias {paru,pupdate,aur-show,aur-download,pinstall,pfm-install,psearch,pshow}='echo "Sorry, paru is not installed"' |
||||
fi |
||||
@ -0,0 +1,19 @@ |
||||
# apt install pass |
||||
# pass: the standard unix password manager |
||||
decent-pass() { |
||||
if [ -z "$1" ]; then |
||||
echo "Enter system name, example: email/bob@example.com" |
||||
return 0 |
||||
fi |
||||
if [ -z "$2" ]; then |
||||
pass generate -c "$1" 16 |
||||
else |
||||
pass generate -c "$1" "$2" |
||||
fi |
||||
} |
||||
alias save-pass='pass insert -m ' |
||||
alias help-pass='man pass' |
||||
|
||||
alias pass-help='man pass' |
||||
alias pass-save='save-pass' |
||||
alias pass-decent='decent-pass' |
||||
@ -0,0 +1,50 @@ |
||||
php-web() { |
||||
if [ -z "$1" ]; then |
||||
php -S 127.0.0.1:9980 -t /var/www |
||||
else |
||||
php -S 127.0.0.1:9980 -t "$1" |
||||
fi |
||||
} |
||||
|
||||
export MYLANIP=`ip -4 --color=never addr show enp2s0 | grep inet | awk '{print $2}' | cut -d/ -f1` |
||||
p() { |
||||
if [ -z "$1" ]; then |
||||
php -S "$MYLANIP":9980 & |
||||
else |
||||
php -S "$MYLANIP":9980 -t "$1" & |
||||
fi |
||||
job_output=$(jobs -l | tail -n 1) |
||||
job_number=$(echo "$job_output" | awk '{print $1}' | tr -d '[]+\-') |
||||
job_pid=$! |
||||
local RED='\033[0;31m' |
||||
local NC='\033[0m' |
||||
echo -e "\n To ${RED}Stop php: kill %$job_number ${NC}\n To make active: fg %$job_number \n" |
||||
echo -e "PID # $job_pid \n \t To end this program: kill -9 $job_pid" |
||||
echo -e "Remember Ctrl+C = Terminate an active Program and Ctrl+Z = Stop/Suspend an running Program \n" |
||||
} |
||||
|
||||
php-lang() { |
||||
if [ "$(which php | wc -l)" -eq 1 ]; then |
||||
if [ -z "$1" ]; then |
||||
echo "version - Displays the version #." |
||||
echo "modules - Lists installed modules." |
||||
echo "run - Runs a Script." |
||||
echo "shell - Does an interactive shell." |
||||
echo "info - Dumps like PHP_info." |
||||
echo "web - Run with built-in web server on 127.0.0.1:9980 [web ROOT]" |
||||
else |
||||
case "$1" in |
||||
version) php -v;; |
||||
modules) php -m;; |
||||
run) php -f "$2";; |
||||
shell) php -a;; |
||||
info) php -i | less;; |
||||
web) php-web "$2";; |
||||
*) php-lang;; |
||||
esac |
||||
fi |
||||
else |
||||
echo "PHP, not install yet!" |
||||
echo "Do use your package manager to install PHP." |
||||
fi |
||||
} |
||||
@ -0,0 +1,68 @@ |
||||
#programming |
||||
alias view-hex='xxd' |
||||
alias cdiff='colordiff' |
||||
alias cmm='./configure && make && sudo make install' |
||||
alias code='codium' |
||||
alias c11='g++ -std=c++11' |
||||
export BOOST='/opt/boost_1_55_0' |
||||
alias c14='g++-4.9 -std=c++14 -pedantic -Wall -I $BOOST' |
||||
alias boost='c++ -I $BOOST' |
||||
alias gor='go run -v -x' |
||||
alias gob='go build -v -x' |
||||
|
||||
qt2py() { |
||||
if [ -f "$1.ui" ]; then |
||||
pyuic5 -x "$1.ui" -o "$1.py" |
||||
else |
||||
echo "Enter a qt.ui file to convert into python" |
||||
fi |
||||
} |
||||
|
||||
so-find() { |
||||
ldconfig -p | grep "$1" |
||||
} |
||||
|
||||
# Validate my shell scripts |
||||
# apt install shellcheck ?? |
||||
# https://www.shellcheck.net |
||||
# https://github.com/koalaman/shellcheck/releases |
||||
alias bashc='shellcheck' |
||||
|
||||
# Free Basic Compiler |
||||
alias qb='fbc -lang qb ' |
||||
|
||||
#phpstan |
||||
phx() { |
||||
local target="$1" |
||||
local input_level="$2" |
||||
local level=7 |
||||
local stanexec="./vendor/bin/phpstan" |
||||
if [[ -x "$stanexec" ]]; then |
||||
local stan="$stanexec" |
||||
else |
||||
local stan="phpx" |
||||
fi |
||||
# Check if input_level is a number between 0 and 10 |
||||
if [[ "$input_level" =~ ^[0-9]+$ ]] && (( input_level >= 0 && input_level <= 10 )); then |
||||
level="$input_level" |
||||
fi |
||||
if [[ -z "$target" ]]; then |
||||
"$stan" |
||||
else |
||||
"$stan" analyse --level="$level" "$target" |
||||
fi |
||||
} |
||||
#sudo apt-get install aspell aspell-en |
||||
#composer require peckphp/peck --dev |
||||
#./vendor/bin/peck --init |
||||
alias phck='./vendor/bin/peck' |
||||
#composer require rector/rector --dev |
||||
alias phrector-dry='./vendor/bin/rector src --dry-run' |
||||
alias phre='./vendor/bin/rector' |
||||
#composer remove phpunit/phpunit |
||||
#composer require pestphp/pest --dev --with-all-dependencies |
||||
#./vendor/bin/pest --init |
||||
alias pe-cc='./vendor/bin/pest --parallel --coverage' |
||||
alias pe-tc='./vendor/bin/pest --type-coverage --min=100' |
||||
alias pe-arch='./vendor/bin/pest --arch' |
||||
alias pe-pa='./vendor/bin/pest --parallel' |
||||
@ -0,0 +1,80 @@ |
||||
#calendar and notes |
||||
alias appointments='calcurse -D ~/.calcurse -C ~/.calcurse/config' |
||||
alias todo='calcurse -D ~/.calcurse -C ~/.calcurse/config --todo' |
||||
alias todays='calcurse -D ~/.calcurse -C ~/.calcurse/config --appointment' |
||||
alias anythingon='calcurse -D ~/.calcurse -C ~/.calcurse/config -a -d' |
||||
alias apts='$EDITOR ~/.calcurse/apts' |
||||
alias todos='$EDITOR ~/.calcurse/todo' |
||||
todays |
||||
# |
||||
#Screen Dim/BlueScreen |
||||
alias night='redshift -o 3500' |
||||
|
||||
alias speak-file='RHVoice-test -i' |
||||
|
||||
#Better Copying |
||||
alias cpv='rsync -avh --info=progress2' |
||||
|
||||
function count() { |
||||
if [ -z "$1" ]; then |
||||
/bin/ls -1 | wc -l |
||||
else |
||||
/bin/ls -1 $@ | wc -l |
||||
fi |
||||
} |
||||
|
||||
see() { |
||||
if [ $# -eq 0 ]; then |
||||
echo "Usage: see <filename>" |
||||
return 1 |
||||
fi |
||||
|
||||
filename="$1" |
||||
if [ -d "$filename" ]; then |
||||
echo "Opening directory: $filename" |
||||
nautilus "$filename" & |
||||
return 0 |
||||
fi |
||||
extension="${filename##*.}" |
||||
|
||||
case "$extension" in |
||||
wg) |
||||
echo "Opening wordgrinder document $filename" |
||||
wordgrinder "$filename" |
||||
;; |
||||
doc|odt) |
||||
echo "Opening Word document: $filename" |
||||
libreoffice --nologo "$filename" & |
||||
;; |
||||
txt) |
||||
echo "Opeing Text document: $filename" |
||||
gedit "$filename" & |
||||
;; |
||||
pdf) |
||||
echo "Opening PDF document: $filename" |
||||
evince "$filename" & |
||||
;; |
||||
html|php|js|css) |
||||
echo "Opening web document: $filename" |
||||
geany "$filename" & |
||||
;; |
||||
epub) |
||||
echo "Opening ePub document: $filename" |
||||
mupdf "$filename" & |
||||
;; |
||||
*) |
||||
echo "Unsupported file type: $extension" |
||||
return 1 |
||||
;; |
||||
esac |
||||
} |
||||
|
||||
s() { # do sudo if no argument given, ! or last do previous cmd |
||||
if [[ $# == 0 ]]; then |
||||
sudo -i |
||||
elif [[ "$1" == "!" || "$1" == "last" ]]; then |
||||
sudo $(history -p '!!') |
||||
else |
||||
sudo "$@" |
||||
fi |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
#Reboot routers |
||||
rebootlinksys() { |
||||
curl -u "admin:$2" "http://$1/setup.cgi?todo=reboot" |
||||
} |
||||
|
||||
rebootnetgear() { |
||||
wget --output-document=/dev/null --user="admin" --password="$2" "http://$1/setup.cgi?next_file=diag.htm&todo=reboot" |
||||
} |
||||
|
||||
ssh-reboot() { |
||||
if [ -n "$2" ]; then |
||||
ssh "$1"@"$2" sudo -S /sbin/reboot |
||||
else |
||||
ssh "root@$1" /sbin/reboot |
||||
fi |
||||
} |
||||
@ -0,0 +1,17 @@ |
||||
alias find-servers='~/dotfiles/scripts/common_networking.sh' |
||||
alias sshto='~/dotfiles/scripts/sshto/sshto.sh' |
||||
alias gp="~/dotfiles/scripts/git/gitprojects.sh" |
||||
alias dogit="~/dotfiles/scripts/git/dogit" |
||||
alias pwdgen="~/dotfiles/scripts/pwd_gen.sh" |
||||
alias sites='~/dotfiles/scripts/websites.sh' |
||||
|
||||
z() { |
||||
if [ -x /usr/local/bin/NoANSI ]; then |
||||
_f_do_as "$1" /usr/bin/cat $@ | /usr/local/bin/NoANSI |
||||
else |
||||
echo -e "Download my NoANSI GO Project from https://github.com/technowizardbob/no_ansi \r\n" |
||||
fi |
||||
} |
||||
zx() { |
||||
$@ | /usr/local/bin/NoANSI |
||||
} |
||||
@ -0,0 +1,24 @@ |
||||
alias findblanks='sudo awk -F: '\''($2 == "") {print}'\'' /etc/shadow' |
||||
alias findrootusers='sudo awk -F: '\''($3 == "0") {print}'\'' /etc/passwd' |
||||
alias findusers='sudo awk -F: '\''($3 >=1000) {print $1,$6}'\'' /etc/passwd' |
||||
alias findnobody-files='find / -path /proc -prune -o -path /sys -prune -o -path /dev -prune -o \( -nouser -o -nogroup \) -ls 2> /dev/null' |
||||
alias mempass='shuf -n 3 /usr/share/dict/british-english | sed "s/./\u&/" | tr -cd "[A-Za-z]"; echo $(shuf -i0-999 -n 1)' |
||||
alias uchecker='curl -s -L https://kernelcare.com/uchecker | sudo python' |
||||
alias find-ow='find / -perm -o=w ! -type l ! -path "/proc/*" ! -path "/sys/*" ! -path "/run/*" ! -path "/dev/*" ! -path "/tmp/*" 2>/dev/null' |
||||
alias find-sticky='find /bin/ -perm /4000 -user root' |
||||
|
||||
# Pass the username to these: |
||||
alias belongstouser='find / -user' |
||||
taruserdata() { |
||||
find / -user "$1" -not -path '/proc/*' -not -path '/sys/*' -not -path '/run/*' -not -path "*/.git/*" -not -path "*/node_modules/*" -not -path "*/vendor/*" -not -path "*/nbproject/*" -not -path "*/logs/*" -not -path "*/tmp/*" -not -path "*/cache/*" -not -path "*/trash/*" -not -path "*/.gvfs/*" -exec tar -rf "$1".tar {} \; |
||||
} |
||||
userdata() { |
||||
find / -user "$1" -not -path '/proc/*' -not -path '/sys/*' -not -path '/run/*' -not -path "*/.git/*" -not -path "*/node_modules/*" -not -path "*/vendor/*" -not -path "*/nbproject/*" -not -path "*/logs/*" -not -path "*/tmp/*" -not -path "*/cache/*" -not -path "*/trash/*" -not -path "*/.gvfs/*" 2> /dev/null |
||||
} |
||||
alias userprocess='ps -aux | grep' |
||||
alias pwdinfo='chage -l' |
||||
# Look inside of programs to see what payload it has. |
||||
str() { |
||||
strings "$1" | less |
||||
} |
||||
alias vscan='/usr/bin/sudo /usr/bin/clamscan -v --move=/var/lib/clamav/quarantine --log=/var/log/clamav/results.log' |
||||
@ -0,0 +1,108 @@ |
||||
cserial() { |
||||
local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 |
||||
local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 |
||||
# Does the device file exist |
||||
if [ -e "$file" ]; then |
||||
# Check for read and write permissions |
||||
if [ -r "$file" ] && [ -w "$file" ]; then |
||||
/usr/bin/cu -l "$file" -s ${baud_rate} |
||||
else |
||||
/usr/bin/echo "Device File $1 needs both read and write access!" |
||||
fi |
||||
else |
||||
/usr/bin/echo "Device File $1 does not exist!" |
||||
fi |
||||
} |
||||
tserial() { |
||||
local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 |
||||
local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 |
||||
# Does the device file exist |
||||
if [ -e "$file" ]; then |
||||
# Check for read and write permissions |
||||
if [ -r "$file" ] && [ -w "$file" ]; then |
||||
/usr/bin/tip -$baud_rate $1 |
||||
else |
||||
/usr/bin/echo "Device File $1 needs both read and write access!" |
||||
fi |
||||
else |
||||
/usr/bin/echo "Device File $1 does not exist!" |
||||
fi |
||||
} |
||||
pserial() { |
||||
local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 |
||||
local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 |
||||
# Does the device file exist |
||||
if [ -e "$file" ]; then |
||||
# Check for read and write permissions |
||||
if [ -r "$file" ] && [ -w "$file" ]; then |
||||
/usr/bin/putty "$file" -serial -sercfg ${baud_rate},8,n,1,N |
||||
else |
||||
/usr/bin/echo "Device File $1 needs both read and write access!" |
||||
fi |
||||
else |
||||
/usr/bin/echo "Device File $1 does not exist!" |
||||
fi |
||||
} |
||||
sserial() { |
||||
local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 |
||||
local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 |
||||
# Does the device file exist |
||||
if [ -e "$file" ]; then |
||||
# Check for read and write permissions |
||||
if [ -r "$file" ] && [ -w "$file" ]; then |
||||
/usr/bin/screen "$file" $baud_rate |
||||
else |
||||
/usr/bin/echo "Device File $1 needs both read and write access!" |
||||
fi |
||||
else |
||||
/usr/bin/echo "Device File $1 does not exist!" |
||||
fi |
||||
} |
||||
mserial() { |
||||
local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 |
||||
local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 |
||||
# Does the device file exist |
||||
if [ -e "$file" ]; then |
||||
# Check for read and write permissions |
||||
if [ -r "$file" ] && [ -w "$file" ]; then |
||||
/usr/bin/minicom -D "$file" -b $baud_rate |
||||
else |
||||
/usr/bin/echo "Device File $1 needs both read and write access!" |
||||
fi |
||||
else |
||||
/usr/bin/echo "Device File $1 does not exist!" |
||||
fi |
||||
} |
||||
|
||||
serial() { |
||||
if [ -z "$1" ]; then |
||||
echo "Example: serial DEVICE_NAME BAUD_RATE" |
||||
echo "Ex useage: serial ttyUSB0 115200" |
||||
return 0 |
||||
fi |
||||
if id -nG "$USER" | grep -qw "dialout"; then |
||||
echo -e "\n" |
||||
else |
||||
echo -e "To avoid running as Root, you should add yourself to the dialout group, so you can use serial...without being Root.\n" |
||||
echo -e "You will need sudo access to do this, if you do not have SUDOers access, say no. \r\n Have an Admin do: usermod -a -G dialout $USER" |
||||
echo -e "Do you want to add $USER to the dialout Group? \r\n" |
||||
read -p "IF so, Type 'Yes' to continue: " response |
||||
if [ "$response" = "Yes" ]; then |
||||
echo -e "Adding $USER to dialout Group, enter sudo password" |
||||
sudo usermod -a -G dialout $USER |
||||
fi |
||||
fi |
||||
if [ -x /usr/bin/minicom ]; then |
||||
mserial $@ |
||||
elif [ -x /usr/bin/putty ]; then |
||||
pserial $@ |
||||
elif [ -x /usr/bin/screen ]; then |
||||
sserial $@ |
||||
elif [ -x /usr/bin/tip ]; then |
||||
tserial $@ |
||||
elif [ -x /usr/bin/cu ]; then |
||||
cserial $@ |
||||
else |
||||
echo -e "Opps no minicom, putty, screen, cu, or tip programs installed!" |
||||
fi |
||||
} |
||||
@ -0,0 +1,4 @@ |
||||
alias show-enabled-services="sudo systemctl list-unit-files --state enabled" |
||||
alias show-running-services="sudo systemctl list-units --type service --state running" |
||||
alias show-active-services="sudo systemctl -t service --state active" |
||||
alias whatsup='service --status-all' |
||||
@ -0,0 +1,19 @@ |
||||
# OpenSSH authentication agent - |
||||
# This will hold your Password for the private key file, |
||||
# for use in the Current Shell session only as it does not store this data. |
||||
ssha() { |
||||
if [ -r "$1" ]; then |
||||
eval $(ssh-agent) && ssh-add "$1" |
||||
else |
||||
echo -e "This requires a Private SSH Key! Please give path & key File! \r\n Example: ~/.ssh/id_rsa" |
||||
fi |
||||
} |
||||
gpg-ssh() { |
||||
if [ -n "$(which gpg)" ] && [ -n "$(gpg --list-key)" ]; then |
||||
GPG_SOCK=$(gpgconf --list-dirs agent-ssh-socket) |
||||
if [ -S "$GPG_SOCK" ]; then |
||||
export SSH_AUTH_SOCK=$GPG_SOCK |
||||
fi |
||||
fi |
||||
} |
||||
gpg-ssh |
||||
@ -0,0 +1,138 @@ |
||||
maketar() { |
||||
if [ -e "$1" ]; then |
||||
tar cvzf "$1.tgz" "$@" |
||||
else |
||||
if [ -e "$2" ]; then |
||||
x="" |
||||
for var in "$@" |
||||
do |
||||
if [ -e "$var" ]; then |
||||
x+=$var |
||||
x+=" " |
||||
fi |
||||
done |
||||
tar cvzf "$1.tgz" $x |
||||
else |
||||
if [ -n "$1" ]; then |
||||
tar cvzf "$1.tgz" * |
||||
else |
||||
tar cvzf all.tgz * |
||||
fi |
||||
fi |
||||
fi |
||||
|
||||
errstatus=$? |
||||
if [ -z "$1" ]; then |
||||
NAME=all |
||||
else |
||||
NAME=$1 |
||||
fi |
||||
|
||||
if [ $errstatus -eq 0 ]; then |
||||
echo "Successfully, made tar archive called $NAME.tgz" |
||||
return 0 |
||||
else |
||||
echo "Failed, to make tar archive called $NAME.tgz" |
||||
return $errstatus |
||||
fi |
||||
} |
||||
|
||||
bk() { |
||||
local outbase="" |
||||
local verbose=1 |
||||
|
||||
# Parse options |
||||
while [[ $# -gt 0 ]]; do |
||||
case "$1" in |
||||
-o|--output) |
||||
outbase="$2"; shift 2 ;; |
||||
-q|--quiet) |
||||
verbose=0; shift ;; |
||||
-h|--help|help) |
||||
echo "Usage: bk -o NAME file/dir [file/dir ...]" |
||||
echo "Creates NAME.YYYYMMDD-HHMMSS.tgz from the given paths." |
||||
return 0 ;; |
||||
--) shift; break ;; |
||||
-*) |
||||
echo "Unknown option: $1" >&2 |
||||
return 1 ;; |
||||
*) |
||||
break ;; |
||||
esac |
||||
done |
||||
|
||||
if [[ -z "$outbase" || $# -lt 1 ]]; then |
||||
echo "Usage: bk -o NAME file/dir [file/dir ...]" >&2 |
||||
return 1 |
||||
fi |
||||
|
||||
local stamp |
||||
stamp="$(date +%Y%m%d-%H%M%S)" |
||||
local myoutfile="${outbase%.tgz}.$stamp.tgz" |
||||
|
||||
if [[ -e "$myoutfile" ]]; then |
||||
echo "Refusing to overwrite existing file: $myoutfile" >&2 |
||||
return 1 |
||||
fi |
||||
|
||||
# Exclude the archive itself in case you’re archiving CWD |
||||
local exclude_arg=(--exclude="./$(basename "$myoutfile")") |
||||
|
||||
(( verbose )) && echo "Making tar file $outfile" |
||||
tar -czf "$myoutfile" "${exclude_arg[@]}" "$@" |
||||
} |
||||
|
||||
function extract { |
||||
if [ -z "$1" ]; then |
||||
echo "Usage: extract <path/file_name>.<deb|rpm|zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>" |
||||
return 0 |
||||
fi |
||||
|
||||
for n in "$@"; do |
||||
if [ ! -f "$n" ]; then |
||||
echo "'$n' - File doesn't exist" |
||||
return 1 |
||||
fi |
||||
done |
||||
|
||||
# Initialize an array |
||||
exit_statuses=() |
||||
|
||||
for n in "$@"; do |
||||
NAME=${n%.*} |
||||
echo -e "\n Extacting from: $NAME ..." |
||||
case "${n%,}" in |
||||
*.deb) sudo nice -n 17 dpkg -i $n ;; |
||||
*.rpm) sudo nice -n 17 rpm -ivh $n ;; |
||||
*.tar.bz2) nice -n 17 tar xvjf "$n" ;; |
||||
*.tar.gz) nice -n 17 tar xvzf "$n" ;; |
||||
*.tar.xz) nice -n 17 tar xvJf "$n" ;; |
||||
*.lzma) nice -n 17 unlzma "$n" ;; |
||||
*.bz2) nice -n 17 bunzip2 "$n" ;; |
||||
*.rar) nice -n 17 unrar x -ad "$n" ;; |
||||
*.gz) nice -n 17 gunzip "$n" ;; |
||||
*.tar) nice -n 17 tar xvf "$n" ;; |
||||
*.tbz2) nice -n 17 tar xvjf "$n" ;; |
||||
*.tgz) nice -n 17 tar xvzf "$n" ;; |
||||
*.zip) nice -n 17 unzip "$n" ;; |
||||
*.Z) nice -n 17 uncompress "$n" ;; |
||||
*.7z) nice -n 17 7z x "$n" ;; |
||||
*.xz) nice -n 17 unxz "$n" ;; |
||||
*.exe) nice -n 17 cabextract "$n" ;; |
||||
*) echo "Extract: $n - Unknown archive method!"; |
||||
return 1 ;; |
||||
esac |
||||
|
||||
exit_statuses+=($?) |
||||
done |
||||
|
||||
# Check for error status codes |
||||
for status in "${exit_statuses[@]}"; do |
||||
if (( status > 0 )); then |
||||
echo "Unable to Extract something...!" |
||||
return $status |
||||
fi |
||||
done |
||||
echo "Success! Extracted all files..." |
||||
return 0 |
||||
} |
||||
@ -0,0 +1,7 @@ |
||||
test-email() { |
||||
if [ -z "$1" ]; then |
||||
echo "Send a Test email to which user? root or $USER" |
||||
else |
||||
echo "Testing..." | mail -s "Just a Quick Test" $1 |
||||
fi |
||||
} |
||||
@ -0,0 +1 @@ |
||||
alias amazon-backup='s3backup' |
||||
@ -0,0 +1,58 @@ |
||||
alias t='/opt/profiles/scripts/t.sh' |
||||
td() { |
||||
if [ -z "$1" ]; then |
||||
tmux detach -s myCode |
||||
else |
||||
tmux detach -s "$1" |
||||
fi |
||||
} |
||||
ta() { |
||||
if [ -z "$1" ]; then |
||||
tmux attach-session -t myCode |
||||
else |
||||
tmux attach-session -t "$1" |
||||
fi |
||||
} |
||||
tks() { |
||||
if [ -z "$1" ]; then |
||||
tmux kill-session -t myCode |
||||
else |
||||
tmux kill-session -t "$1" |
||||
fi |
||||
} |
||||
tn() { |
||||
if [ -z "$1" ]; then |
||||
echo "Assign tmux session a name!" |
||||
return 1 |
||||
fi |
||||
tmux new-session -d -s "$1" |
||||
} |
||||
tna() { |
||||
if [ -z "$1" ]; then |
||||
echo "Assign tmux session a name!" |
||||
return 1 |
||||
fi |
||||
tmux new-session -d -s "$1" -n work |
||||
tmux new-window -t "$1" -d -n work2 |
||||
tmux split-window -v -t "$1" |
||||
tmux send-keys -t "$1":work.2 "clear" Enter |
||||
tmux select-pane -t "$1":work.1 |
||||
tmux attach-session -t "$1" |
||||
} |
||||
tl() { |
||||
local tlses=$(tmux list-sessions | cut -d ':' -f 1) |
||||
if [ -z "$tlses" ]; then |
||||
echo "Sessions not found" |
||||
return 1 |
||||
fi |
||||
local resultses=$(echo $tlses | tr ' ' '\n' | fzf) |
||||
if [ -z "$resultses" ]; then |
||||
echo "Session not found" |
||||
return 1 |
||||
fi |
||||
if [ -n "$TMUX" ]; then |
||||
tmux switch-client -t "$resultses" |
||||
else |
||||
tmux attach-session -t "$resultses" |
||||
fi |
||||
} |
||||
@ -0,0 +1 @@ |
||||
umask 0002 |
||||
@ -0,0 +1,6 @@ |
||||
alias v="vagrant global-status" |
||||
alias vup="vagrant up" |
||||
alias vhalt="vagrant halt" |
||||
alias vssh="vagrant ssh" |
||||
alias vreload="vagrant reload" |
||||
alias vrebuild="vagrant destroy --force && vagrant up" |
||||
@ -0,0 +1 @@ |
||||
alias mp4='totem' |
||||
@ -0,0 +1,9 @@ |
||||
if [ -x /usr/bin/vim ] || [ -x /usr/bin/vi ]; then |
||||
alias v-conf="$EDITOR ~/.vimrc" |
||||
alias va-conf="$EDITOR ~/.vim/autocmds.vim" |
||||
alias vc-conf="$EDITOR ~/.vim/config.vim" |
||||
alias vf-conf="$EDITOR ~/.vim/functions.vim" |
||||
alias vm-conf="$EDITOR ~/.vim/mappings.vim" |
||||
else |
||||
alias {v-conf,va-config,vc-conf,vf-conf,vm-conf}='echo "Sorry, vim not installed"' |
||||
fi |
||||
@ -0,0 +1,24 @@ |
||||
#Web |
||||
alias chrome='/opt/google/chrome/chrome &' |
||||
|
||||
DNS_FAMILY1=1.1.1.3 |
||||
DNS_FAMILY2=1.0.0.3 |
||||
DNS_OPEN1=208.67.222.222 |
||||
DNS_OPEN2=208.67.220.220 |
||||
DNS_GOOGLE1=8.8.8.8 |
||||
DNS_GOOGLE2=8.8.4.4 |
||||
|
||||
privatefox() { |
||||
if [ ! -d ~/work ]; then |
||||
mkdir ~/work |
||||
fi |
||||
firejail --seccomp --private=~/work --dns=$DNS_OPEN1 --dns=$DNS_OPEN2 firefox -no-remote -private-window $@ & |
||||
} |
||||
safefox() { |
||||
if [ ! -d ~/work ]; then |
||||
mkdir ~/work |
||||
fi |
||||
firejail --seccomp --x11 --name=SecureMode --private=~/work --dns=$DNS_FAMILY1 --dns=$DNS_FAMILY2 firefox -private-window -no-remote -safe-mode $@ & |
||||
} |
||||
#my default browser |
||||
alias web='privatefox' |
||||
@ -0,0 +1,34 @@ |
||||
PHP_FPM=php8.4-fpm |
||||
|
||||
#Debug Web Server |
||||
alias errors=fpm_errors |
||||
alias fpm_errors='sudo tail /var/log/${PHP_FPM}.log' |
||||
alias ap_errors='sudo tail /var/log/apache2/error.log' |
||||
alias hh_errors='sudo tail /var/log/hhvm/error.log' |
||||
alias ng_errors='sudo tail /var/log/nginx/error.log' |
||||
|
||||
# Get web server headers # |
||||
# -k Allow insecure server connections, self-signed... |
||||
alias header='curl -k -I ' |
||||
|
||||
# Find out if remote server supports gzip / mod_deflate or not # |
||||
alias headerc='curl -k -I --compressed ' |
||||
|
||||
# Controll Web Servers |
||||
alias fpm-status='service $PHP_FPM status' |
||||
alias fpm-start='service $PHP_FPM start' |
||||
alias fpm-reload='service $PHP_FPM reload' |
||||
alias ngreload='sudo /usr/sbin/nginx -s reload' |
||||
alias ngtest='sudo /usr/sbin/nginx -t' |
||||
alias a2='sudo service apache2 restart' |
||||
alias hh_restart='sudo service hhvm restart' |
||||
alias t7='sudo /etc/init.d/tomcat7 restart' |
||||
alias lightyload='sudo /etc/init.d/lighttpd reload' |
||||
alias lightytest='sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -t' |
||||
alias httpdreload='sudo /usr/sbin/apachectl -k graceful' |
||||
alias httpdtest='sudo /usr/sbin/apachectl -t && /usr/sbin/apachectl -t -D DUMP_VHOSTS' |
||||
|
||||
# Is gzip working? |
||||
function is_gzip { |
||||
curl -I -H 'Accept-Encoding: gzip,deflate' $1 |grep "Content-Encoding" |
||||
} |
||||
@ -0,0 +1,14 @@ |
||||
#Check if Root |
||||
if [ $UID -ne 0 ]; then |
||||
# This is not a root user: |
||||
echo -ne "\033[36m" |
||||
echo "Welcome, " `whoami` |
||||
echo "This is a protected system! All access is logged." |
||||
echo -ne "\033[0m" |
||||
alias reboot='sudo reboot' |
||||
else |
||||
# Wow, got root: |
||||
echo -ne "\033[36m" |
||||
echo "You are logged in as an admin becareful! This is a restricted system." |
||||
echo -ne "\033[0m" |
||||
fi |
||||
@ -0,0 +1,10 @@ |
||||
#Windows to linux |
||||
alias attrib='chmod' |
||||
alias chdir='cd' |
||||
alias copy='cp' |
||||
alias del='rm' |
||||
alias deltree='rm -r' |
||||
alias edit='nano' |
||||
alias ff='whereis' |
||||
alias mem='top' |
||||
alias move='mv' |
||||
@ -0,0 +1,10 @@ |
||||
if [ -x /usr/bin/yay ]; then |
||||
alias yai='yay -S' # install package(s) |
||||
alias yas='yay -Ss' # search packages |
||||
alias yad='yay -Si' # description of the package |
||||
alias yau='yay -Syu' # update all packages |
||||
alias yar='yay -Rns' # remove package(s) |
||||
alias yac='yay -Yc' # clean unwanted packages |
||||
else |
||||
alias {yai,yas,yad,yau,yar,yac}='echo "Sorry, yay not installed"' |
||||
fi |
||||
@ -0,0 +1,5 @@ |
||||
# apt install youtube-dl ?? |
||||
# https://github.com/ytdl-org/youtube-dl |
||||
alias ytd='youtube-dl -f 136' # 720p |
||||
alias ytdl='youtube-dl -f 134' # 360p |
||||
alias ytda='youtube-dl -f 140' # audio |
||||
@ -0,0 +1 @@ |
||||
../scripts/helper/check_mail.sh |
||||
@ -0,0 +1,4 @@ |
||||
# Get Zephir: https://zephir-lang.com/en |
||||
alias zcompile="zephir api -v" |
||||
alias p2z="php2zephir php2zephir:zep:create" |
||||
alias zbuild="zephir build" |
||||
@ -0,0 +1,24 @@ |
||||
_f_do_as() { |
||||
local file_name="$1" |
||||
shift # Remove the first argment (the file) |
||||
if [ -r "$file_name" ]; then |
||||
$@ |
||||
else |
||||
$USE_SUPER $@ |
||||
fi |
||||
} |
||||
|
||||
if [ -f ~/dotfiles/scripts/scan_aliases.sh ]; then |
||||
source "~/dotfiles/scripts/scan_aliases.sh" |
||||
else |
||||
SANE_TEST_FAILED=0 |
||||
fi |
||||
|
||||
if [ $SANE_TEST_FAILED -eq 0 ]; then |
||||
# Load aliases from ~/.aliases.d |
||||
if [ -d ~/.aliases.d ]; then |
||||
for f in ~/.aliases.d/*.sh; do |
||||
[ -r "$f" ] && . "$f" |
||||
done |
||||
fi |
||||
fi |
||||
@ -0,0 +1,79 @@ |
||||
# ~/.bashrc: executed by bash(1) for non-login shells. |
||||
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) |
||||
# for examples |
||||
|
||||
# If not running interactively, don't do anything |
||||
[ -z "$PS1" ] && return |
||||
|
||||
# If set, the pattern "**" used in a pathname expansion context will |
||||
# match all files and zero or more directories and subdirectories. |
||||
#shopt -s globstar |
||||
|
||||
# make less more friendly for non-text input files, see lesspipe(1) |
||||
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" |
||||
|
||||
# set variable identifying the chroot you work in (used in the prompt below) |
||||
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then |
||||
debian_chroot=$(cat /etc/debian_chroot) |
||||
fi |
||||
|
||||
# set a fancy prompt (non-color, unless we know we "want" color) |
||||
case "$TERM" in |
||||
xterm-color) color_prompt=yes;; |
||||
esac |
||||
|
||||
# uncomment for a colored prompt, if the terminal has the capability; turned |
||||
# off by default to not distract the user: the focus in a terminal window |
||||
# should be on the output of commands, not on the prompt |
||||
force_color_prompt=yes |
||||
|
||||
if [ -n "$force_color_prompt" ]; then |
||||
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then |
||||
# We have color support; assume it's compliant with Ecma-48 |
||||
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such |
||||
# a case would tend to support setf rather than setaf.) |
||||
color_prompt=yes |
||||
else |
||||
color_prompt= |
||||
fi |
||||
fi |
||||
|
||||
if [ "$color_prompt" = yes ]; then |
||||
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]$(__git_ps1 " (%s)"):\[\033[01;34m\]\w\[\033[00m\]\$ ' |
||||
source ~/dotfiles/scripts/helper/.git_bash_prompt |
||||
else |
||||
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' |
||||
fi |
||||
|
||||
# git with Colors |
||||
#PS1="\[$GREEN\]\t\[$RED\]-\[$BLUE\]\u\[$YELLOW\]\[$YELLOW\]\w\[\033[m\]\[$MAGENTA\]\$(__git_ps1)\[$WHITE\]\$ " |
||||
|
||||
unset color_prompt force_color_prompt |
||||
|
||||
# If this is an xterm set the title to user@host:dir |
||||
case "$TERM" in |
||||
xterm*|rxvt*) |
||||
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" |
||||
;; |
||||
*) |
||||
;; |
||||
esac |
||||
|
||||
# Add an "alert" alias for long running commands. Use like so: |
||||
# sleep 10; alert |
||||
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' |
||||
|
||||
# Alias definitions. |
||||
# You may want to put all your additions into a separate file like |
||||
# ~/.bash_aliases, instead of adding them here directly. |
||||
# See /usr/share/doc/bash-doc/examples in the bash-doc package. |
||||
|
||||
# enable programmable completion features (you don't need to enable |
||||
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile |
||||
# sources /etc/bash.bashrc). |
||||
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then |
||||
. /etc/bash_completion |
||||
fi |
||||
if [ -f ~/.bash_aliases ]; then |
||||
. ~/.bash_aliases |
||||
fi |
||||
@ -0,0 +1,22 @@ |
||||
# ~/.profile: executed by the command interpreter for login shells. |
||||
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login |
||||
# exists. |
||||
# see /usr/share/doc/bash/examples/startup-files for examples. |
||||
# the files are located in the bash-doc package. |
||||
|
||||
# the default umask is set in /etc/profile; for setting the umask |
||||
# for ssh logins, install and configure the libpam-umask package. |
||||
umask 0002 |
||||
|
||||
# if running bash |
||||
if [ -n "$BASH_VERSION" ]; then |
||||
# include .bashrc if it exists |
||||
if [ -f "$HOME/.bashrc" ]; then |
||||
. "$HOME/.bashrc" |
||||
fi |
||||
fi |
||||
|
||||
# set PATH so it includes user's private bin directories |
||||
PATH="$HOME/bin:$HOME/.local/bin:$PATH" |
||||
|
||||
export PATH="$HOME/.cargo/bin:$PATH" |
||||
@ -0,0 +1,22 @@ |
||||
The MIT License |
||||
|
||||
Copyright (c) 2021 Robert Strutts |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining |
||||
a copy of this software and associated documentation files (the |
||||
"Software"), to deal in the Software without restriction, including |
||||
without limitation the rights to use, copy, modify, merge, publish, |
||||
distribute, sublicense, and/or sell copies of the Software, and to |
||||
permit persons to whom the Software is furnished to do so, subject to |
||||
the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be |
||||
included in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
@ -0,0 +1,8 @@ |
||||
# my dotfiles |
||||
|
||||
## stow |
||||
``` |
||||
$ sudo apt install stow |
||||
$ cd ~/dotfiles |
||||
$ stow . |
||||
``` |
||||
@ -0,0 +1,53 @@ |
||||
File test operators |
||||
|
||||
The test command includes the following FILE operators that allow you to test for particular types of files: |
||||
|
||||
-b FILE - True if the FILE exists and is a special block file. |
||||
-c FILE - True if the FILE exists and is a special character file. |
||||
-d FILE - True if the FILE exists and is a directory. |
||||
-e FILE - True if the FILE exists and is a file, regardless of type (node, directory, socket, etc.). |
||||
-f FILE - True if the FILE exists and is a regular file (not a directory or device). |
||||
-G FILE - True if the FILE exists and has the same group as the user running the command. |
||||
-h FILE - True if the FILE exists and is a symbolic link. |
||||
-g FILE - True if the FILE exists and has set-group-id (sgid) flag set. |
||||
-k FILE - True if the FILE exists and has a sticky bit flag set. |
||||
-L FILE - True if the FILE exists and is a symbolic link. |
||||
-O FILE - True if the FILE exists and is owned by the user running the command. |
||||
-p FILE - True if the FILE exists and is a pipe. |
||||
-r FILE - True if the FILE exists and is readable. |
||||
-S FILE - True if the FILE exists and is a socket. |
||||
-s FILE - True if the FILE exists and has nonzero size. |
||||
-u FILE - True if the FILE exists, and set-user-id (suid) flag is set. |
||||
-w FILE - True if the FILE exists and is writable. |
||||
-x FILE - True if the FILE exists and is executable. |
||||
|
||||
Comparison operators are operators that compare values and return true or false. When comparing strings in Bash you can use the following operators: |
||||
|
||||
-eq - equals, -ne - not equal to |
||||
string1 = string2 and string1 == string2 - The equality operator returns true if the operands are equal. |
||||
Use the = operator with the test [ command. |
||||
Use the == operator with the [[ command for pattern matching. |
||||
string1 != string2 - The inequality operator returns true if the operands are not equal. |
||||
string1 =~ regex- The regex operator returns true if the left operand matches the extended regular expression on the right. |
||||
string1 > string2 - The greater than operator returns true if the left operand is greater than the right sorted by lexicographical (alphabetical) order. |
||||
string1 < string2 - The less than operator returns true if the right operand is greater than the right sorted by lexicographical (alphabetical) order. |
||||
-z string - True if the string length is zero. |
||||
-n string - True if the string length is non-zero. |
||||
|
||||
Following are a few points to be noted when comparing strings: |
||||
|
||||
A blank space must be used between the binary operator and the operands. |
||||
Always use double quotes around the variable names to avoid any word splitting or globbing issues. |
||||
Bash does not segregate variables by “type”, variables are treated as integer or string depending on the context. |
||||
|
||||
There are multiple ways to check if a string contains a substring: |
||||
|
||||
One approach is to use surround the substring with asterisk symbols * which means match all characters. |
||||
|
||||
EX block: |
||||
|
||||
if [ -z "$1" ];then |
||||
echo "Please enter something!" |
||||
else |
||||
echo "Thanks..." |
||||
fi |
||||
@ -0,0 +1,38 @@ |
||||
0 = none |
||||
1 = execute only |
||||
2 = write only |
||||
3 = write and execute (1+2) |
||||
4 = read only |
||||
5 = read and execute (4+1) |
||||
6 = read and write (4+2) |
||||
7 = read and write and execute (4+2+1) |
||||
|
||||
+ allow, - deny |
||||
|
||||
+r adds read access |
||||
+w adds write access |
||||
+x allows execution |
||||
|
||||
u = user, g = group, o = other |
||||
# Change file permissions Examples: |
||||
chmod +r file.txt |
||||
chmod u+r g+r file.txt |
||||
chmod o-w file.txt |
||||
|
||||
# ( user group other ), so 664 is u:r/w g:r/w o:r |
||||
chmod 664 file.txt |
||||
|
||||
#Change ownership of a file: chown owner:group file |
||||
chown dave:www-data file.txt |
||||
|
||||
# Add write protection, must be root....: |
||||
chattr +i data.txt |
||||
|
||||
# Remove write protection, must be root....: |
||||
chattr -i data.txt |
||||
|
||||
# Change all directories to 775 |
||||
find /var/www/myproject -type d -exec chmod 775 {} \; |
||||
|
||||
# Change all file to 664 |
||||
find /var/www/myproject -type f -exec chmod 664 {} \; |
||||
@ -0,0 +1,52 @@ |
||||
% kubernetes, k8s |
||||
|
||||
# Print all contexts |
||||
kubectl config get-contexts |
||||
|
||||
# Print current context of kubeconfig |
||||
kubectl config current-context |
||||
|
||||
# Set context of kubeconfig |
||||
kubectl config use-context <context> |
||||
|
||||
# Print resource documentation |
||||
kubectl explain <resource> |
||||
|
||||
# Get nodes (add option '-o wide' for details) |
||||
kubectl get nodes |
||||
|
||||
# Get namespaces |
||||
kubectl get namespaces |
||||
|
||||
# Get pods from namespace (add option '-o wide' for details) |
||||
kubectl get pods -n <namespace> |
||||
|
||||
# Get pods from all namespace (add option '-o wide' for details) |
||||
kubectl get pods --all-namespaces |
||||
|
||||
# Get services from namespace |
||||
kubectl get services -n <namespace> |
||||
|
||||
# Get details from resource on namespace |
||||
kubectl describe <resource>/<name> -n <namespace> |
||||
|
||||
# Print logs from namespace |
||||
kubectl logs -f pods/<name> -n <namespace> |
||||
|
||||
# Get deployments |
||||
kubectl get deployments -n <namespace> |
||||
|
||||
# Edit deployments |
||||
kubectl edit deployment/<name> -n <namespace> |
||||
|
||||
# Drain node in preparation for maintenance |
||||
kubectl drain <name> |
||||
|
||||
# Mark node as schedulable |
||||
kubectl uncordon <name> |
||||
|
||||
# Mark node as unschedulable |
||||
kubectl cordon <name> |
||||
|
||||
# Display resource (cpu/memory/storage) usage |
||||
kubectl top <type> |
||||
@ -0,0 +1,69 @@ |
||||
sudo !! - Will rerun the last command but done as ROOT |
||||
|
||||
|
||||
=============================== |
||||
How to make a .deb package: |
||||
mkdir packageName |
||||
mkdir packageName/DEBIAN |
||||
mkdir -p packageName/usr/bin |
||||
|
||||
$ nano packageName/DEBIAN/control |
||||
Package: {THE Name} |
||||
Version: 1.0 |
||||
Section: custom |
||||
Priority: optional |
||||
Architecture: all |
||||
Essential: no |
||||
Installed-Size: 1024 [note: this is the size on Disk after Install] |
||||
Maintainer: {MyName} |
||||
Description: {Does...this...} |
||||
|
||||
-----------------EOF |
||||
|
||||
Add the executables to the packageName/usr/bin folder. |
||||
Then run: $ dpkg-deb --build packageName |
||||
mv packageName.deb packageName-1.0_amd64.deb |
||||
|
||||
--Copy file to another PC, then install it, |
||||
on that PC: $ dpkg -i packageName-1.0_amd64.deb |
||||
|
||||
=========================================================== |
||||
The RedHat way, see DJ Ware's video: |
||||
https://youtu.be/iBVZ2-NIQ6I?t=1620 |
||||
|
||||
sudo dnf install -y rpmdevtools rpmlint |
||||
rpmdev-setuptree |
||||
|
||||
tar --create --file packageName-1.0.0.tar.gz packageNameExecutableFile |
||||
mv packageName-1.0.0.tar.gz rpmbuild/SOURCES |
||||
|
||||
rpmdev-newspec MySpecFile |
||||
nano MySpecFile.spec |
||||
Name: {THE Name - CHANGEME} |
||||
Version: 1.0.0 |
||||
... |
||||
Summary: {Does...this... - CHANGEME} |
||||
BuildArch: x86_64 |
||||
... |
||||
%install |
||||
rm -rf $RPM_BUILD_ROOT |
||||
mkdir -p $RPM_BUILD_ROOT/%{_bindir} |
||||
cp %{name} $RPM_BUILD_ROOT/%{_bindir} |
||||
|
||||
%clean |
||||
rm -rf $RPM_BUILD_ROOT |
||||
|
||||
%files |
||||
%{_bindir}/%{name} |
||||
|
||||
----------------EOF |
||||
|
||||
$ tree rpmbuild # To see folder structure |
||||
cd rpmbuild |
||||
|
||||
mv MySpecFile.spec rpmbuild/SPECS |
||||
rpmlint ~/rpmbuild/SPECS/MySpecFile.spec |
||||
rpmbuild -ba ~/rpmbuild/SPECS/MySpecFile.spec |
||||
|
||||
copy this file: ~/rpmbuild/RPMS/x86_64/packageName-1.0.0...x86_64.rpm |
||||
then run: dnf install on that file... |
||||
@ -0,0 +1,42 @@ |
||||
\ Escape |
||||
|
||||
\^ Beginning of line |
||||
\$ End of line |
||||
\* Match any # of previous or none |
||||
\+ Match any # of previous |
||||
\< Start of word |
||||
\> End of word |
||||
\b A word boundary |
||||
\B A non-word boundary |
||||
\A The begining of the input |
||||
\G The end of the previous match |
||||
\Z The end of the input but the final terminator, if any |
||||
\z The end of the input |
||||
\? Optional |
||||
\i Case-insensitive matching |
||||
\g Global match |
||||
|
||||
\. Any one character, except newline |
||||
[a-z] Any lowercase letter |
||||
[A-Z] Any uppercase letter |
||||
[A-Za-z] Any Letter |
||||
\d OR [0-9] Any digit |
||||
\D OR [^0-9] Any non-digit |
||||
\s Any white space character [ \t\n\x0B\f\r] |
||||
\S Any non-white space character [^\s] |
||||
\w A word character [a-zA-Z_0-9] |
||||
\W A non-word character [^\w] |
||||
|
||||
\{n\} Match exactly n times |
||||
\{n,\} Match at least n times |
||||
\{x,y\} Match at least x times, but no more than y times |
||||
*? Match 0 or more times, but a few times as possible |
||||
+? Match 1 or more times, but a few times as possible |
||||
?? Match 0 or 1 times, but as few times as possible |
||||
\{x,y\}? Match at least x times, no more than y times, and as few times as possible |
||||
(a|b) a or b |
||||
|
||||
Ex email pattern: grep "\S\+@\S\+\.[A-Za-z]\{2,6\}" file |
||||
OR grep -rIhEo "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b" file |
||||
|
||||
Ex URL pattern: grep "https\?://\S*\.[a-z]\+" file |
||||
@ -0,0 +1,19 @@ |
||||
Extracting Files: |
||||
tar xvjf FILE.tar.bz2 |
||||
tar xvzf FILE.tar.gz |
||||
tar xvJf FILE.tar.xz |
||||
tar xvf FILE.tar |
||||
tar xvzf FILE.tgz |
||||
tar xvjf FILE.tbz2 |
||||
gunzip FILE.gz |
||||
unxz FILE.xz |
||||
unlzma FILE.lzma |
||||
bunzip2 FILE.bz2 |
||||
unrar x -ad FILE.rar |
||||
unzip FILE.zip |
||||
uncompress FILE.Z |
||||
7z x FILE.7z |
||||
|
||||
Compressing Files: |
||||
tar cvzf FILE.tgz files |
||||
tar cvfj FILE.tar.bz2 files |
||||
@ -0,0 +1,139 @@ |
||||
# tmux shortcuts & cheatsheet |
||||
start new: |
||||
tmux |
||||
|
||||
start new with session name: |
||||
tmux new -s myname |
||||
|
||||
attach: |
||||
tmux a # (or at, or attach) |
||||
|
||||
attach to named: |
||||
tmux a -t myname |
||||
|
||||
list sessions: |
||||
tmux ls |
||||
|
||||
kill session: |
||||
tmux kill-session -t myname |
||||
|
||||
In tmux, hit the prefix `ctrl+b` (my modified prefix is ctrl+space) and then: |
||||
|
||||
## List all shortcuts |
||||
to see all the shortcuts keys in tmux simply use the `bind-key ?` in my case that would be `CTRL-space ?` |
||||
|
||||
## Sessions |
||||
:new<CR> new session |
||||
s list sessions |
||||
$ name session |
||||
|
||||
##Windows (tabs) |
||||
c create window |
||||
w list windows |
||||
n next window |
||||
p previous window |
||||
f find window |
||||
, name window |
||||
& kill window |
||||
|
||||
##Panes (splits) |
||||
| vertical split (default was %) |
||||
- horizontal split (default was ") |
||||
o swap panes |
||||
q show pane numbers |
||||
x kill pane |
||||
+ break pane into window (e.g. to select text by mouse to copy) |
||||
- restore pane from window |
||||
⍽ space - toggle between layouts |
||||
<prefix> q (Show pane numbers, when the numbers show up type the key to goto that pane) |
||||
<prefix> { (Move the current pane left) |
||||
<prefix> } (Move the current pane right) |
||||
<prefix> z toggle pane zoom |
||||
<prefix> arrow key - move to pane |
||||
<alt> arrow key - move to pane |
||||
|
||||
##Sync Panes |
||||
You can do this by switching to the appropriate window, typing your Tmux prefix (commonly Ctrl-B or Ctrl-space) and then a colon to bring up a Tmux command line, and typing: |
||||
``` |
||||
:setw synchronize-panes |
||||
``` |
||||
You can optionally add on or off to specify which state you want; otherwise the option is simply toggled. This option is specific to one window, so it won’t change the way your other sessions or windows operate. When you’re done, toggle it off again by repeating the command. [tip source](http://blog.sanctum.geek.nz/sync-tmux-panes/) |
||||
|
||||
|
||||
## Resizing Panes |
||||
You can also resize panes if you don’t like the layout defaults. I personally rarely need to do this, though it’s handy to know how. Here is the basic syntax to resize panes: |
||||
PREFIX : resize-pane -D (Resizes the current pane down) |
||||
PREFIX : resize-pane -U (Resizes the current pane upward) |
||||
PREFIX : resize-pane -L (Resizes the current pane left) |
||||
PREFIX : resize-pane -R (Resizes the current pane right) |
||||
PREFIX : resize-pane -D 20 (Resizes the current pane down by 20 cells) |
||||
PREFIX : resize-pane -U 20 (Resizes the current pane upward by 20 cells) |
||||
PREFIX : resize-pane -L 20 (Resizes the current pane left by 20 cells) |
||||
PREFIX : resize-pane -R 20 (Resizes the current pane right by 20 cells) |
||||
PREFIX : resize-pane -t 2 -L 20 (Resizes the pane with the id of 2 left by 20 cells) |
||||
|
||||
## Copy mode: |
||||
Pressing PREFIX [ places us in Copy mode. We can then use our movement keys to move our cursor around the screen. By default, the arrow keys work. we set our configuration file to use Vim keys for moving between windows and resizing panes so we wouldn’t have to take our hands off the home row. tmux has a vi mode for working with the buffer as well. To enable it, add this line to .tmux.conf: |
||||
|
||||
setw -g mode-keys vi |
||||
|
||||
With this option set, we can use h, j, k, and l to move around our buffer. |
||||
|
||||
To get out of Copy mode, we just press the ENTER key. Moving around one character at a time isn’t very efficient. Since we enabled vi mode, we can also use some other visible shortcuts to move around the buffer. |
||||
|
||||
For example, we can use "w" to jump to the next word and "b" to jump back one word. And we can use "f", followed by any character, to jump to that character on the same line, and "F" to jump backwards on the line. |
||||
|
||||
Function vi emacs |
||||
Back to indentation ^ M-m |
||||
Clear selection Escape C-g |
||||
Copy selection Enter M-w |
||||
Cursor down j Down |
||||
Cursor left h Left |
||||
Cursor right l Right |
||||
Cursor to bottom line L |
||||
Cursor to middle line M M-r |
||||
Cursor to top line H M-R |
||||
Cursor up k Up |
||||
Delete entire line d C-u |
||||
Delete to end of line D C-k |
||||
End of line $ C-e |
||||
Goto line : g |
||||
Half page down C-d M-Down |
||||
Half page up C-u M-Up |
||||
Next page C-f Page down |
||||
Next word w M-f |
||||
Paste buffer p C-y |
||||
Previous page C-b Page up |
||||
Previous word b M-b |
||||
Quit mode q Escape |
||||
Scroll down C-Down or J C-Down |
||||
Scroll up C-Up or K C-Up |
||||
Search again n n |
||||
Search backward ? C-r |
||||
Search forward / C-s |
||||
Start of line 0 C-a |
||||
Start selection Space C-Space |
||||
Transpose chars C-t |
||||
|
||||
## Misc |
||||
d detach |
||||
t big clock |
||||
? list shortcuts |
||||
: prompt |
||||
|
||||
## Configurations Options: |
||||
# Mouse support - set to on if you want to use the mouse |
||||
* setw -g mode-mouse off |
||||
* set -g mouse-select-pane off |
||||
* set -g mouse-resize-pane off |
||||
* set -g mouse-select-window off |
||||
|
||||
# Set the default terminal mode to 256color mode |
||||
set -g default-terminal "screen-256color" |
||||
|
||||
# enable activity alerts |
||||
setw -g monitor-activity on |
||||
set -g visual-activity on |
||||
|
||||
# Center the window list |
||||
set -g status-justify centre |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,2 @@ |
||||
pass gnupg2 xclip dialog mlocate wofi expect fonts-powerline fonts-hack-ttf firejail mutt mosh sshfs git tmux fzf bat ranger neofetch htop ncdu ripgrep fd-find |
||||
|
||||
@ -0,0 +1,378 @@ |
||||
#!/usr/bin/env bash |
||||
|
||||
# Kubernetes prompt helper for bash/zsh |
||||
# Displays current context and namespace |
||||
|
||||
# Copyright 2021 Jon Mosco |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
# Debug |
||||
[[ -n $DEBUG ]] && set -x |
||||
|
||||
# Default values for the prompt |
||||
# Override these values in ~/.zshrc or ~/.bashrc |
||||
KUBE_PS1_BINARY="${KUBE_PS1_BINARY:-kubectl}" |
||||
KUBE_PS1_SYMBOL_ENABLE="${KUBE_PS1_SYMBOL_ENABLE:-true}" |
||||
KUBE_PS1_SYMBOL_DEFAULT=${KUBE_PS1_SYMBOL_DEFAULT:-$'\u2388'} |
||||
KUBE_PS1_SYMBOL_PADDING="${KUBE_PS1_SYMBOL_PADDING:-true}" |
||||
KUBE_PS1_SYMBOL_USE_IMG="${KUBE_PS1_SYMBOL_USE_IMG:-false}" |
||||
KUBE_PS1_NS_ENABLE="${KUBE_PS1_NS_ENABLE:-true}" |
||||
KUBE_PS1_CONTEXT_ENABLE="${KUBE_PS1_CONTEXT_ENABLE:-true}" |
||||
KUBE_PS1_PREFIX="${KUBE_PS1_PREFIX-(}" |
||||
KUBE_PS1_SEPARATOR="${KUBE_PS1_SEPARATOR-|}" |
||||
KUBE_PS1_DIVIDER="${KUBE_PS1_DIVIDER-:}" |
||||
KUBE_PS1_SUFFIX="${KUBE_PS1_SUFFIX-)}" |
||||
|
||||
KUBE_PS1_SYMBOL_COLOR="${KUBE_PS1_SYMBOL_COLOR-blue}" |
||||
KUBE_PS1_CTX_COLOR="${KUBE_PS1_CTX_COLOR-red}" |
||||
KUBE_PS1_NS_COLOR="${KUBE_PS1_NS_COLOR-cyan}" |
||||
KUBE_PS1_BG_COLOR="${KUBE_PS1_BG_COLOR}" |
||||
|
||||
KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}" |
||||
KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled" |
||||
KUBE_PS1_LAST_TIME=0 |
||||
KUBE_PS1_CLUSTER_FUNCTION="${KUBE_PS1_CLUSTER_FUNCTION}" |
||||
KUBE_PS1_NAMESPACE_FUNCTION="${KUBE_PS1_NAMESPACE_FUNCTION}" |
||||
|
||||
# Determine our shell |
||||
if [ "${ZSH_VERSION-}" ]; then |
||||
KUBE_PS1_SHELL="zsh" |
||||
elif [ "${BASH_VERSION-}" ]; then |
||||
KUBE_PS1_SHELL="bash" |
||||
fi |
||||
|
||||
_kube_ps1_init() { |
||||
[[ -f "${KUBE_PS1_DISABLE_PATH}" ]] && KUBE_PS1_ENABLED=off |
||||
|
||||
case "${KUBE_PS1_SHELL}" in |
||||
"zsh") |
||||
_KUBE_PS1_OPEN_ESC="%{" |
||||
_KUBE_PS1_CLOSE_ESC="%}" |
||||
_KUBE_PS1_DEFAULT_BG="%k" |
||||
_KUBE_PS1_DEFAULT_FG="%f" |
||||
setopt PROMPT_SUBST |
||||
autoload -U add-zsh-hook |
||||
add-zsh-hook precmd _kube_ps1_update_cache |
||||
zmodload -F zsh/stat b:zstat |
||||
zmodload zsh/datetime |
||||
;; |
||||
"bash") |
||||
_KUBE_PS1_OPEN_ESC=$'\001' |
||||
_KUBE_PS1_CLOSE_ESC=$'\002' |
||||
_KUBE_PS1_DEFAULT_BG=$'\033[49m' |
||||
_KUBE_PS1_DEFAULT_FG=$'\033[39m' |
||||
[[ $PROMPT_COMMAND =~ _kube_ps1_update_cache ]] || PROMPT_COMMAND="_kube_ps1_update_cache;${PROMPT_COMMAND:-:}" |
||||
;; |
||||
esac |
||||
} |
||||
|
||||
_kube_ps1_color_fg() { |
||||
local KUBE_PS1_FG_CODE |
||||
case "${1}" in |
||||
black) KUBE_PS1_FG_CODE=0;; |
||||
red) KUBE_PS1_FG_CODE=1;; |
||||
green) KUBE_PS1_FG_CODE=2;; |
||||
yellow) KUBE_PS1_FG_CODE=3;; |
||||
blue) KUBE_PS1_FG_CODE=4;; |
||||
magenta) KUBE_PS1_FG_CODE=5;; |
||||
cyan) KUBE_PS1_FG_CODE=6;; |
||||
white) KUBE_PS1_FG_CODE=7;; |
||||
# 256 |
||||
[0-9]|[1-9][0-9]|[1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-6]) KUBE_PS1_FG_CODE="${1}";; |
||||
*) KUBE_PS1_FG_CODE=default |
||||
esac |
||||
|
||||
if [[ "${KUBE_PS1_FG_CODE}" == "default" ]]; then |
||||
KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_FG}" |
||||
return |
||||
elif [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then |
||||
KUBE_PS1_FG_CODE="%F{$KUBE_PS1_FG_CODE}" |
||||
elif [[ "${KUBE_PS1_SHELL}" == "bash" ]]; then |
||||
if tput setaf 1 &> /dev/null; then |
||||
KUBE_PS1_FG_CODE="$(tput setaf ${KUBE_PS1_FG_CODE})" |
||||
elif [[ $KUBE_PS1_FG_CODE -ge 0 ]] && [[ $KUBE_PS1_FG_CODE -le 256 ]]; then |
||||
KUBE_PS1_FG_CODE="\033[38;5;${KUBE_PS1_FG_CODE}m" |
||||
else |
||||
KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_FG}" |
||||
fi |
||||
fi |
||||
echo ${_KUBE_PS1_OPEN_ESC}${KUBE_PS1_FG_CODE}${_KUBE_PS1_CLOSE_ESC} |
||||
} |
||||
|
||||
_kube_ps1_color_bg() { |
||||
local KUBE_PS1_BG_CODE |
||||
case "${1}" in |
||||
black) KUBE_PS1_BG_CODE=0;; |
||||
red) KUBE_PS1_BG_CODE=1;; |
||||
green) KUBE_PS1_BG_CODE=2;; |
||||
yellow) KUBE_PS1_BG_CODE=3;; |
||||
blue) KUBE_PS1_BG_CODE=4;; |
||||
magenta) KUBE_PS1_BG_CODE=5;; |
||||
cyan) KUBE_PS1_BG_CODE=6;; |
||||
white) KUBE_PS1_BG_CODE=7;; |
||||
# 256 |
||||
[0-9]|[1-9][0-9]|[1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-6]) KUBE_PS1_BG_CODE="${1}";; |
||||
*) KUBE_PS1_BG_CODE=$'\033[0m';; |
||||
esac |
||||
|
||||
if [[ "${KUBE_PS1_BG_CODE}" == "default" ]]; then |
||||
KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_BG}" |
||||
return |
||||
elif [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then |
||||
KUBE_PS1_BG_CODE="%K{$KUBE_PS1_BG_CODE}" |
||||
elif [[ "${KUBE_PS1_SHELL}" == "bash" ]]; then |
||||
if tput setaf 1 &> /dev/null; then |
||||
KUBE_PS1_BG_CODE="$(tput setab ${KUBE_PS1_BG_CODE})" |
||||
elif [[ $KUBE_PS1_BG_CODE -ge 0 ]] && [[ $KUBE_PS1_BG_CODE -le 256 ]]; then |
||||
KUBE_PS1_BG_CODE="\033[48;5;${KUBE_PS1_BG_CODE}m" |
||||
else |
||||
KUBE_PS1_BG_CODE="${DEFAULT_BG}" |
||||
fi |
||||
fi |
||||
echo ${OPEN_ESC}${KUBE_PS1_BG_CODE}${CLOSE_ESC} |
||||
} |
||||
|
||||
_kube_ps1_binary_check() { |
||||
command -v $1 >/dev/null |
||||
} |
||||
|
||||
_kube_ps1_symbol() { |
||||
[[ "${KUBE_PS1_SYMBOL_ENABLE}" == false ]] && return |
||||
|
||||
case "${KUBE_PS1_SHELL}" in |
||||
bash) |
||||
if ((BASH_VERSINFO[0] >= 4)) && [[ $'\u2388' != "\\u2388" ]]; then |
||||
KUBE_PS1_SYMBOL="${KUBE_PS1_SYMBOL_DEFAULT}" |
||||
KUBE_PS1_SYMBOL_IMG=$'\u2638\ufe0f' |
||||
else |
||||
KUBE_PS1_SYMBOL=$'\xE2\x8E\x88' |
||||
KUBE_PS1_SYMBOL_IMG=$'\xE2\x98\xB8' |
||||
fi |
||||
;; |
||||
zsh) |
||||
KUBE_PS1_SYMBOL="${KUBE_PS1_SYMBOL_DEFAULT}" |
||||
KUBE_PS1_SYMBOL_IMG="\u2638";; |
||||
*) |
||||
KUBE_PS1_SYMBOL="k8s" |
||||
esac |
||||
|
||||
if [[ "${KUBE_PS1_SYMBOL_USE_IMG}" == true ]]; then |
||||
KUBE_PS1_SYMBOL="${KUBE_PS1_SYMBOL_IMG}" |
||||
fi |
||||
|
||||
if [[ "${KUBE_PS1_SYMBOL_PADDING}" == true ]]; then |
||||
echo "${KUBE_PS1_SYMBOL} " |
||||
else |
||||
echo "${KUBE_PS1_SYMBOL}" |
||||
fi |
||||
|
||||
} |
||||
|
||||
_kube_ps1_split() { |
||||
type setopt >/dev/null 2>&1 && setopt SH_WORD_SPLIT |
||||
local IFS=$1 |
||||
echo $2 |
||||
} |
||||
|
||||
_kube_ps1_file_newer_than() { |
||||
local mtime |
||||
local file=$1 |
||||
local check_time=$2 |
||||
|
||||
if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then |
||||
mtime=$(zstat +mtime "${file}") |
||||
elif stat -c "%s" /dev/null &> /dev/null; then |
||||
# GNU stat |
||||
mtime=$(stat -L -c %Y "${file}") |
||||
else |
||||
# BSD stat |
||||
mtime=$(stat -L -f %m "$file") |
||||
fi |
||||
|
||||
[[ "${mtime}" -gt "${check_time}" ]] |
||||
} |
||||
|
||||
_kube_ps1_update_cache() { |
||||
local return_code=$? |
||||
|
||||
[[ "${KUBE_PS1_ENABLED}" == "off" ]] && return $return_code |
||||
|
||||
if ! _kube_ps1_binary_check "${KUBE_PS1_BINARY}"; then |
||||
# No ability to fetch context/namespace; display N/A. |
||||
KUBE_PS1_CONTEXT="BINARY-N/A" |
||||
KUBE_PS1_NAMESPACE="N/A" |
||||
return |
||||
fi |
||||
|
||||
if [[ "${KUBECONFIG}" != "${KUBE_PS1_KUBECONFIG_CACHE}" ]]; then |
||||
# User changed KUBECONFIG; unconditionally refetch. |
||||
KUBE_PS1_KUBECONFIG_CACHE=${KUBECONFIG} |
||||
_kube_ps1_get_context_ns |
||||
return |
||||
fi |
||||
|
||||
# kubectl will read the environment variable $KUBECONFIG |
||||
# otherwise set it to ~/.kube/config |
||||
local conf |
||||
for conf in $(_kube_ps1_split : "${KUBECONFIG:-${HOME}/.kube/config}"); do |
||||
[[ -r "${conf}" ]] || continue |
||||
if _kube_ps1_file_newer_than "${conf}" "${KUBE_PS1_LAST_TIME}"; then |
||||
_kube_ps1_get_context_ns |
||||
return |
||||
fi |
||||
done |
||||
|
||||
return $return_code |
||||
} |
||||
|
||||
_kube_ps1_get_context() { |
||||
if [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then |
||||
KUBE_PS1_CONTEXT="$(${KUBE_PS1_BINARY} config current-context 2>/dev/null)" |
||||
# Set namespace to 'N/A' if it is not defined |
||||
KUBE_PS1_CONTEXT="${KUBE_PS1_CONTEXT:-N/A}" |
||||
|
||||
if [[ ! -z "${KUBE_PS1_CLUSTER_FUNCTION}" ]]; then |
||||
KUBE_PS1_CONTEXT=$($KUBE_PS1_CLUSTER_FUNCTION $KUBE_PS1_CONTEXT) |
||||
fi |
||||
fi |
||||
} |
||||
|
||||
_kube_ps1_get_ns() { |
||||
if [[ "${KUBE_PS1_NS_ENABLE}" == true ]]; then |
||||
KUBE_PS1_NAMESPACE="$(${KUBE_PS1_BINARY} config view --minify --output 'jsonpath={..namespace}' 2>/dev/null)" |
||||
# Set namespace to 'default' if it is not defined |
||||
KUBE_PS1_NAMESPACE="${KUBE_PS1_NAMESPACE:-default}" |
||||
|
||||
if [[ ! -z "${KUBE_PS1_NAMESPACE_FUNCTION}" ]]; then |
||||
KUBE_PS1_NAMESPACE=$($KUBE_PS1_NAMESPACE_FUNCTION $KUBE_PS1_NAMESPACE) |
||||
fi |
||||
fi |
||||
} |
||||
|
||||
_kube_ps1_get_context_ns() { |
||||
# Set the command time |
||||
if [[ "${KUBE_PS1_SHELL}" == "bash" ]]; then |
||||
if ((BASH_VERSINFO[0] >= 4 && BASH_VERSINFO[1] >= 2)); then |
||||
KUBE_PS1_LAST_TIME=$(printf '%(%s)T') |
||||
else |
||||
KUBE_PS1_LAST_TIME=$(date +%s) |
||||
fi |
||||
elif [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then |
||||
KUBE_PS1_LAST_TIME=$EPOCHSECONDS |
||||
fi |
||||
|
||||
_kube_ps1_get_context |
||||
_kube_ps1_get_ns |
||||
} |
||||
|
||||
# Set kube-ps1 shell defaults |
||||
_kube_ps1_init |
||||
|
||||
_kubeon_usage() { |
||||
cat <<"EOF" |
||||
Toggle kube-ps1 prompt on |
||||
|
||||
Usage: kubeon [-g | --global] [-h | --help] |
||||
|
||||
With no arguments, turn off kube-ps1 status for this shell instance (default). |
||||
|
||||
-g --global turn on kube-ps1 status globally |
||||
-h --help print this message |
||||
EOF |
||||
} |
||||
|
||||
_kubeoff_usage() { |
||||
cat <<"EOF" |
||||
Toggle kube-ps1 prompt off |
||||
|
||||
Usage: kubeoff [-g | --global] [-h | --help] |
||||
|
||||
With no arguments, turn off kube-ps1 status for this shell instance (default). |
||||
|
||||
-g --global turn off kube-ps1 status globally |
||||
-h --help print this message |
||||
EOF |
||||
} |
||||
|
||||
kubeon() { |
||||
if [[ "${1}" == '-h' || "${1}" == '--help' ]]; then |
||||
_kubeon_usage |
||||
elif [[ "${1}" == '-g' || "${1}" == '--global' ]]; then |
||||
rm -f -- "${KUBE_PS1_DISABLE_PATH}" |
||||
elif [[ "$#" -ne 0 ]]; then |
||||
echo -e "error: unrecognized flag ${1}\\n" |
||||
_kubeon_usage |
||||
return |
||||
fi |
||||
|
||||
KUBE_PS1_ENABLED=on |
||||
} |
||||
|
||||
kubeoff() { |
||||
if [[ "${1}" == '-h' || "${1}" == '--help' ]]; then |
||||
_kubeoff_usage |
||||
elif [[ "${1}" == '-g' || "${1}" == '--global' ]]; then |
||||
mkdir -p -- "$(dirname "${KUBE_PS1_DISABLE_PATH}")" |
||||
touch -- "${KUBE_PS1_DISABLE_PATH}" |
||||
elif [[ $# -ne 0 ]]; then |
||||
echo "error: unrecognized flag ${1}" >&2 |
||||
_kubeoff_usage |
||||
return |
||||
fi |
||||
|
||||
KUBE_PS1_ENABLED=off |
||||
} |
||||
|
||||
# Build our prompt |
||||
kube_ps1() { |
||||
[[ "${KUBE_PS1_ENABLED}" == "off" ]] && return |
||||
[[ -z "${KUBE_PS1_CONTEXT}" ]] && [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]] && return |
||||
|
||||
local KUBE_PS1 |
||||
local KUBE_PS1_RESET_COLOR="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_FG}${_KUBE_PS1_CLOSE_ESC}" |
||||
|
||||
# Background Color |
||||
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="$(_kube_ps1_color_bg ${KUBE_PS1_BG_COLOR})" |
||||
|
||||
# Prefix |
||||
[[ -n "${KUBE_PS1_PREFIX}" ]] && KUBE_PS1+="${KUBE_PS1_PREFIX}" |
||||
|
||||
# Symbol |
||||
KUBE_PS1+="$(_kube_ps1_color_fg $KUBE_PS1_SYMBOL_COLOR)$(_kube_ps1_symbol)${KUBE_PS1_RESET_COLOR}" |
||||
|
||||
if [[ -n "${KUBE_PS1_SEPARATOR}" ]] && [[ "${KUBE_PS1_SYMBOL_ENABLE}" == true ]]; then |
||||
KUBE_PS1+="${KUBE_PS1_SEPARATOR}" |
||||
fi |
||||
|
||||
# Context |
||||
if [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then |
||||
KUBE_PS1+="$(_kube_ps1_color_fg $KUBE_PS1_CTX_COLOR)${KUBE_PS1_CONTEXT}${KUBE_PS1_RESET_COLOR}" |
||||
fi |
||||
|
||||
# Namespace |
||||
if [[ "${KUBE_PS1_NS_ENABLE}" == true ]]; then |
||||
if [[ -n "${KUBE_PS1_DIVIDER}" ]] && [[ "${KUBE_PS1_CONTEXT_ENABLE}" == true ]]; then |
||||
KUBE_PS1+="${KUBE_PS1_DIVIDER}" |
||||
fi |
||||
KUBE_PS1+="$(_kube_ps1_color_fg ${KUBE_PS1_NS_COLOR})${KUBE_PS1_NAMESPACE}${KUBE_PS1_RESET_COLOR}" |
||||
fi |
||||
|
||||
# Suffix |
||||
[[ -n "${KUBE_PS1_SUFFIX}" ]] && KUBE_PS1+="${KUBE_PS1_SUFFIX}" |
||||
|
||||
# Close Background color if defined |
||||
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_BG}${_KUBE_PS1_CLOSE_ESC}" |
||||
|
||||
echo "${KUBE_PS1}" |
||||
} |
||||
@ -0,0 +1,82 @@ |
||||
MAIL_FOLDER=/var/mail |
||||
|
||||
if groups "$USER" | grep -o "sudo" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
elif groups "$USER" | grep -o "doas" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="doas" |
||||
elif groups "$USER" | grep -o "wheel" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
elif groups "$USER" | grep -o "admin" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
elif [ "$EUID" -eq 0 ]; then |
||||
USE_SUPER="\$" |
||||
else |
||||
USE_SUPER="" |
||||
fi |
||||
|
||||
del_mail() { |
||||
if [ ! -f "$MAIL_FOLDER/$1" ]; then |
||||
return |
||||
fi |
||||
if [ $(sudo cat "$MAIL_FOLDER/$1" | wc -l) -eq 0 ]; then |
||||
sudo rm "$MAIL_FOLDER/$1" |
||||
return |
||||
fi |
||||
|
||||
read -r -p "Would you like to save your mail or delete it [save or delete] : " keep |
||||
if [ "$keep" == "delete" ] || [ "$keep" == "del" ]; then |
||||
echo "Attempting to erase mail for user $1." |
||||
sudo rm "$MAIL_FOLDER/$1" |
||||
fi |
||||
} |
||||
|
||||
read_mail() { |
||||
if [ ! -f "$MAIL_FOLDER/$1" ]; then |
||||
return |
||||
fi |
||||
|
||||
if [ $EUID -ne 0 ] && [ -z "$USE_SUPER" ]; then |
||||
echo "Have your Root user check the mailbox for ${MAIL_FOLDER}/$1 has Mail in it!" |
||||
return |
||||
fi |
||||
|
||||
echo "Checking if $1 has any mail...." |
||||
if [ $(sudo cat "$MAIL_FOLDER/$1" | wc -l) -eq 0 ]; then |
||||
echo "No new mail" |
||||
sudo rm "$MAIL_FOLDER/$1" |
||||
return |
||||
fi |
||||
echo "$1 HAS Mail!!!" |
||||
if [ -x /usr/bin/mutt ]; then |
||||
if [ "$1" == "root" ]; then |
||||
sudo mutt -f "$MAIL_FOLDER/$1" |
||||
else |
||||
mutt -f "$MAIL_FOLDER/$1" |
||||
fi |
||||
elif [ -x /usr/bin/mail ]; then |
||||
read -r -p "Check mail via [ mail, less, nano, tail, read, or cat ] : " check |
||||
case $check in |
||||
mail) sudo mail -u "$1";; |
||||
less) sudo less "$MAIL_FOLDER/$1";; |
||||
nano) sudo nano "$MAIL_FOLDER/$1";; |
||||
tail) sudo tail -n 50 "$MAIL_FOLDER/$1";; |
||||
*) sudo cat "$MAIL_FOLDER/$1";; |
||||
esac |
||||
else |
||||
read -r -p "Check mail via [ less, nano, tail, read, or cat ] : " check |
||||
case $check in |
||||
less) sudo less "$MAIL_FOLDER/$1";; |
||||
nano) sudo nano "$MAIL_FOLDER/$1";; |
||||
tail) sudo tail -n 50 "$MAIL_FOLDER/$1";; |
||||
*) sudo cat "$MAIL_FOLDER/$1";; |
||||
esac |
||||
fi |
||||
del_mail "$1" |
||||
} |
||||
|
||||
# Check for Root Mail Alerts, to keep up to date on Security Issues |
||||
read_mail root |
||||
|
||||
if [ "$USER" != "root" ]; then |
||||
read_mail "$USER" |
||||
fi |
||||
@ -0,0 +1,85 @@ |
||||
_parse_gpg_system_name() { |
||||
if [ ! -x $XGPG_APP ]; then |
||||
echo -e "Please install the gpg program!\n" |
||||
return 1 |
||||
fi |
||||
if [ $(which pass | wc -l) -ne 1 ]; then |
||||
echo "You should install the pass program!" |
||||
echo -e "pass: the standard unix password manager.\n" |
||||
fi |
||||
if [ ! -d "$XGPG_PASS_STORE" ]; then |
||||
echo -e "GPG PASS program has not made the ~/.password-store folder yet! Bailing!\n" |
||||
return 1 |
||||
fi |
||||
if [ -z $(which mktemp) ]; then |
||||
XNP_GPG_TEMP=/tmp/np |
||||
else |
||||
XNP_GPG_TEMP=$(mktemp) |
||||
fi |
||||
|
||||
saveIFS=$IFS |
||||
IFS="/" |
||||
local parts=($1) |
||||
IFS=$saveIFS |
||||
local count_gp=${#parts[@]} |
||||
|
||||
local part1=${parts[0]} |
||||
if [ $count_gp -eq 1 ]; then |
||||
myGPG_folder="" |
||||
myGPG_file="$part1" |
||||
return 0 |
||||
fi |
||||
if [ $count_gp -eq 2 ]; then |
||||
local part2=${parts[1]} |
||||
myGPG_folder="$XGPG_PASS_STORE/$part1" |
||||
myGPG_file="$part2" |
||||
return 0 |
||||
fi |
||||
if [ $count_gp -gt 2 ]; then |
||||
local part2=${parts[1]} |
||||
local lastthing=${1##*/} |
||||
myGPG_folder="$XGPG_PASS_STORE/$part1/$part2" |
||||
myGPG_file="$lastthing" |
||||
return 0 |
||||
fi |
||||
echo "Invaild System Name." |
||||
return 1 |
||||
} |
||||
|
||||
_do_gpg_stuff() { |
||||
if [ -f $XNP_GPG_TEMP.gpg ]; then |
||||
rm $XNP_GPG_TEMP.gpg |
||||
fi |
||||
|
||||
read -r -p "Enter extra comments (optional):" comments |
||||
if [ -n "$comments" ]; then |
||||
echo "$comments" >> $XNP_GPG_TEMP |
||||
fi |
||||
|
||||
if [ -z "$1" ]; then |
||||
$XGPG_APP -r "$XGPG_EMAIL" --encrypt $XNP_GPG_TEMP |
||||
if [ $? -ne 0 ]; then |
||||
echo "GPG unable to find user's email of $GPG_EMAIL" |
||||
echo "Edit by: cmd gpg --edit" |
||||
rm $XNP_GPG_TEMP |
||||
return 1 |
||||
fi |
||||
else |
||||
$XGPG_APP -r "$1" --encrypt $XNP_GPG_TEMP |
||||
if [ $? -ne 0 ]; then |
||||
echo "GPG unable to find user's email of $1" |
||||
rm $XNP_GPG_TEMP |
||||
return 1 |
||||
fi |
||||
fi |
||||
|
||||
cat $XNP_GPG_TEMP |
||||
rm $XNP_GPG_TEMP |
||||
|
||||
if [ -n "$myGPG_folder" ]; then |
||||
mkdir -p "$myGPG_folder" |
||||
mv $XNP_GPG_TEMP.gpg "$myGPG_folder/$myGPG_file.gpg" |
||||
else |
||||
mv $XNP_GPG_TEMP.gpg "$XGPG_PASS_STORE/$myGPG_file.gpg" |
||||
fi |
||||
} |
||||
@ -0,0 +1,26 @@ |
||||
#!/bin/bash |
||||
source ${_PROFILES_PATH}scripts/gpg/common-helper.sh |
||||
|
||||
new-mempass() { |
||||
if [ -z "$1" ]; then |
||||
echo "Please assign system-name, example: email/bob@example.com" |
||||
else |
||||
_parse_gpg_system_name "$1" |
||||
if [ $? -ne 0 ]; then |
||||
rm $XNP_GPG_TEMP |
||||
return 1 |
||||
fi |
||||
if [ -z "$myGPG_file" ]; then |
||||
rm $XNP_GPG_TEMP |
||||
return 1 |
||||
fi |
||||
|
||||
local syb_size=2 |
||||
local syb1=$(tr -dc '!@#^&*(){}[];:,.?' < /dev/urandom | head -c $syb_size) |
||||
local syb2=$(tr -dc '!@#^&*(){}[];:,.?' < /dev/urandom | head -c $syb_size) |
||||
|
||||
echo -e "$syb1$(shuf -n 3 /usr/share/dict/british-english | sed "s/./\u&/" | tr -cd "[A-Za-z]"; echo $(shuf -i0-999 -n 1))$syb2" > $XNP_GPG_TEMP |
||||
_do_gpg_stuff "$2" |
||||
fi |
||||
} |
||||
new-mempass "$1" "$2" |
||||
@ -0,0 +1,26 @@ |
||||
#!/bin/bash |
||||
source ${_PROFILES_PATH}scripts/gpg/common-helper.sh |
||||
|
||||
new-pwd() { |
||||
if [ -z "$1" ]; then |
||||
echo "Please assign system-name, example: email/bob@example.com" |
||||
else |
||||
_parse_gpg_system_name "$1" |
||||
if [ $? -ne 0 ]; then |
||||
rm $XNP_GPG_TEMP |
||||
return 1 |
||||
fi |
||||
if [ -z "$myGPG_file" ]; then |
||||
rm $XNP_GPG_TEMP |
||||
return 1 |
||||
fi |
||||
|
||||
local syb_size=3 |
||||
local syb1=$(tr -dc '!@#^&*(){}[];:,.?' < /dev/urandom | head -c $syb_size) |
||||
local syb2=$(tr -dc '!@#^&*(){}[];:,.?' < /dev/urandom | head -c $syb_size) |
||||
|
||||
echo "$syb1$(openssl rand -base64 $XNEW_PASSWORD_SIZE)$syb2" > $XNP_GPG_TEMP |
||||
_do_gpg_stuff "$2" |
||||
fi |
||||
} |
||||
new-pwd "$1" "$2" |
||||
@ -0,0 +1,13 @@ |
||||
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } |
||||
|
||||
GPG_VER=$(gpg --version | head -n1 | grep -E -o "[0-9.]+") |
||||
|
||||
cd ~/.ssh || { echo "Unable to CD into ~.ssh"; exit 1; } |
||||
|
||||
gv=$(version "$GPG_VER") |
||||
compair_to_version=$(version "2.1.17") |
||||
if [ "$gv" -ge "$compair_to_version" ]; then |
||||
gpg --full-generate-key |
||||
else |
||||
gpg --default-new-key-algo rsa4096 --gen-key |
||||
fi |
||||
@ -0,0 +1,210 @@ |
||||
#!/bin/bash |
||||
|
||||
SANE_CHECKER="~/dotfiles/.data/.sane_checker.sum" |
||||
SANE_CERTS="~/dotfiles/.data/.sane_certs.sum" |
||||
export SHA_SUM_APP=/usr/bin/sha256sum |
||||
error_status=$(mktemp) |
||||
|
||||
if groups "$USER" | grep -o "sudo" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
elif groups "$USER" | grep -o "doas" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="doas" |
||||
elif groups "$USER" | grep -o "wheel" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
elif groups "$USER" | grep -o "admin" >/dev/null 2>/dev/null; then |
||||
USE_SUPER="sudo" |
||||
elif [ "$EUID" -eq 0 ]; then |
||||
USE_SUPER="\$" |
||||
else |
||||
USE_SUPER="" |
||||
fi |
||||
export USE_SUPER |
||||
SANE_TEST_FAILED=0 |
||||
|
||||
tmpsum=$(mktemp -u --suffix ".sum.tmp") |
||||
tmpsum2=$(mktemp -u --suffix ".sum2.tmp") |
||||
|
||||
# Spinner function with multiple animation styles |
||||
_my_spinner() { |
||||
local pid=$1 |
||||
local style=${2:-0} |
||||
local delay=0.1 |
||||
|
||||
case $style in |
||||
0) local chars='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏' ;; # Braille dots |
||||
1) local chars='▁▂▃▄▅▆▇█▇▆▅▄▃▂▁' ;; # Growing bar |
||||
2) local chars='_-~+=*@#.?' ;; # Arrows |
||||
3) local chars='◐◓◑◒' ;; # Circle |
||||
4) local chars='⣾⣽⣻⢿⡿⣟⣯⣷' ;; # Detailed Braille |
||||
esac |
||||
|
||||
local color='\e[34m' # Blue color |
||||
local reset='\e[0m' |
||||
|
||||
# Hide cursor |
||||
tput civis |
||||
|
||||
while kill -0 $pid 2>/dev/null; do |
||||
# Save cursor position |
||||
echo -en "\e7" |
||||
|
||||
for ((i=0; i<${#chars}; i++)); do |
||||
# Restore cursor position |
||||
echo -en "\e8" |
||||
echo -en "\e[H${color}[${chars:$i:1}] Scanning Files...${reset}" |
||||
sleep $delay |
||||
done |
||||
done |
||||
|
||||
# Show cursor |
||||
tput cnorm |
||||
# Clear line |
||||
echo -en "\r\033[K" |
||||
} |
||||
|
||||
|
||||
#shaXsum |
||||
require_root() { |
||||
local sane_file_name="$1" |
||||
local temp_file="$2" |
||||
if [ "$EUID" -eq 0 ]; then |
||||
mv "$temp_file" "$sane_file_name" |
||||
chown root:root "$sane_file_name" |
||||
chmod 444 "$sane_file_name" |
||||
chattr +i "$sane_file_name" |
||||
else |
||||
echo "Trying to make sane sum file Immutable for security purposes, Please enter ROOT password when prompted." |
||||
if [ -n "$USE_SUPER" ] && sudo --validate; then |
||||
sudo mv "$temp_file" "$sane_file_name" |
||||
sudo chown root:root "$sane_file_name" |
||||
sudo chmod 444 "$sane_file_name" |
||||
sudo chattr +i "$sane_file_name" |
||||
else |
||||
echo "Please have a ROOT user make this file: $sane_file_name Immutable!" |
||||
fi |
||||
fi |
||||
} |
||||
prompter_for_fix() { |
||||
echo "Verify the integerity of your aliases scripts, then run:" |
||||
if [ ! -w "$SANE_CHECKER" ]; then |
||||
echo -e "\r\n sudo chattr -i \"$SANE_CHECKER\" \r\n sudo chmod 664 \"$SANE_CHECKER\" \r\n sudo rm $SANE_CHECKER" |
||||
else |
||||
echo -e "sudo rm $SANE_CHECKER" |
||||
fi |
||||
} |
||||
good=1 |
||||
if [ ! -f "$SANE_CHECKER" ]; then |
||||
echo -e "\033[0;34m 1st run added to sane sum file! \033[0m" |
||||
$SHA_SUM_APP {~/dotfiles/scripts/*.sh,~/dotfiles/.aliases.d/*.sh,~/.bash_aliases,~/.bashrc,~/.bash_logout,~/dotfiles/scripts/helper/.git_bash_prompt,~/.profile,~/dotfiles/scripts/helper/.kube-ps1,~/dotfiles/scripts/helper/theme} > "$tmpsum" 2>/dev/null |
||||
require_root "$SANE_CHECKER" "$tmpsum" |
||||
good=0 |
||||
else |
||||
if [ -w "$SANE_CHECKER" ]; then |
||||
echo -e "\033[0;31m Warning -- sane sum Security file is Mutable! Please have a Root User run: \r\n \033[0m sudo chmod 444 \"$SANE_CHECKER\" \r\n AND then run \r\n sudo chattr +i \"$SANE_CHECKER\" \r\n" |
||||
good=0 |
||||
fi |
||||
fi |
||||
if [ ! -f "$SANE_CERTS" ]; then |
||||
echo -e "\033[0;34m 1st run added to sane certs sum file! \033[0m" |
||||
$SHA_SUM_APP /etc/ssl/certs/* > "$tmpsum2" 2>/dev/null |
||||
require_root "$SANE_CERTS" "$tmpsum2" |
||||
good=0 |
||||
else |
||||
if [ -w "$SANE_CERTS" ]; then |
||||
echo -e "\033[0;31m Warning -- sane sum Cert Security file is Mutable! Please have a Root User run: \r\n \033[0m sudo chmod 444 \"$SANE_CERTS\" \r\n AND then run \r\n sudo chattr +i \"$SANE_CERTS\" \r\n" |
||||
good=0 |
||||
fi |
||||
fi |
||||
check_certificates() { |
||||
if [ -f "$SANE_CHECKER" ]; then |
||||
for FILE in ~/dotfiles/scripts/*.sh; do |
||||
if [ -f "$FILE" ] && ! grep -q "$FILE" "$SANE_CHECKER"; then |
||||
echo -e "\033[0;31m $FILE is a new file! \r\n Please Scan it for viruses. \033[0m" >> "$error_status" |
||||
SANE_TEST_FAILED=1 |
||||
fi |
||||
done |
||||
for FILE in ~/dotfiles/.aliases.d/*.sh; do |
||||
if [ -f "$FILE" ] && ! grep -q "$FILE" "$SANE_CHECKER"; then |
||||
echo -e "\033[0;31m $FILE is a new file! \r\n Please Scan it for viruses. \033[0m" >> "$error_status" |
||||
SANE_TEST_FAILED=1 |
||||
fi |
||||
done |
||||
if ! $SHA_SUM_APP --quiet -c "$SANE_CHECKER"; then |
||||
echo -e "\033[0;31m Danger...? Failed Sane checker!! \033[0m" >> "$error_status" |
||||
SANE_TEST_FAILED=1 |
||||
fi |
||||
fi |
||||
|
||||
if [ "$SANE_TEST_FAILED" -eq 1 ]; then |
||||
return 1 |
||||
else |
||||
return 0 |
||||
fi |
||||
} |
||||
# Create a temporary file to store the exit status |
||||
temp_status=$(mktemp) |
||||
|
||||
if [ "$good" -eq 1 ]; then |
||||
# Run the check in background and capture its exit status |
||||
(check_certificates; echo $? > "$temp_status") & |
||||
# Start spinner with style 0 (can be changed to 1-4 for different animations) |
||||
_my_spinner $! 0 |
||||
# Wait for background process to complete |
||||
wait |
||||
# Read the exit status and clean up |
||||
exit_status=$(cat "$temp_status") |
||||
if [ "$exit_status" -eq 1 ]; then |
||||
prompter_for_fix |
||||
SANE_TEST_FAILED=1 |
||||
else |
||||
SANE_TEST_FAILED=$exit_status |
||||
fi |
||||
fi |
||||
# sed to remove any evil ANSI codes |
||||
cat "$error_status" | sed -r 's/\x1b\[[0-9;]*m//g' |
||||
rm "$error_status" |
||||
rm "$temp_status" |
||||
|
||||
_do_scan_ssl_certs() { |
||||
if [ -f "$SANE_CERTS" ]; then |
||||
changed=0 |
||||
for cert in /etc/ssl/certs/*; do |
||||
if [ -f "$cert" ]; then # Only process regular files |
||||
if ! grep -q "$($SHA_SUM_APP "$cert")" "$SANE_CERTS"; then |
||||
echo -e "\033[0;31mWARNING: Modified or new cert found: $cert \r\n \033[0m" >> "$ssl_error_status" |
||||
changed=1 |
||||
fi |
||||
fi |
||||
done |
||||
if [ "$changed" -eq 1 ]; then |
||||
echo "Please -- Verify the integerity of your SSL Certs, then run:" >> "$ssl_error_status" |
||||
if [ ! -w "$SANE_CERTS" ]; then |
||||
echo -e "\r\n sudo chattr -i \"$SANE_CERTS\" \r\n sudo chmod 664 \"$SANE_CERTS\" \r\n sudo rm $SANE_CERTS" >> "$ssl_error_status" |
||||
else |
||||
echo -e "sudo rm $SANE_CERTS" >> "$ssl_error_status" |
||||
fi |
||||
SANE_TEST_FAILED=1 |
||||
else |
||||
echo -e "SSL Certs look the same..." >> "$ssl_error_status" |
||||
fi |
||||
fi |
||||
} |
||||
|
||||
scan_ssl_certs() { |
||||
clear |
||||
ssl_error_status=$(mktemp) |
||||
# Run the check in background and capture its exit status |
||||
(_do_scan_ssl_certs) & |
||||
# Start spinner with style 0 (can be changed to 1-4 for different animations) |
||||
_my_spinner $! 0 |
||||
# Wait for background process to complete |
||||
wait |
||||
cat "$ssl_error_status" | sed -r 's/\x1b\[[0-9;]*m//g' |
||||
rm "$ssl_error_status" |
||||
} |
||||
|
||||
# Unset the function |
||||
unset -f require_root |
||||
unset -f prompter_for_fix |
||||
unset -f check_certificates |
||||
source ~/dotfiles/scripts/helper/scan_libs.sh |
||||
@ -0,0 +1,41 @@ |
||||
#!/bin/bash |
||||
|
||||
# Function to check the SHA-256 hash of an environment variable |
||||
check_env_var_hash() { |
||||
local env_var_name="$1" |
||||
local hash_file="~/dotfiles/.data/.${env_var_name}_hash_${USER}.sum" |
||||
|
||||
# Get the current value of the specified environment variable |
||||
local current_value=$(/usr/bin/printenv "$env_var_name") |
||||
|
||||
# Compute the SHA-256 hash of the current environment variable value |
||||
local current_hash=$(/usr/bin/echo -n "$current_value" | $SHA_SUM_APP | /usr/bin/awk '{print $1}') |
||||
|
||||
# Check if the hash file exists |
||||
if [[ -f "$hash_file" ]]; then |
||||
# Read the previous hash from the file |
||||
local previous_hash=$(/usr/bin/cat "$hash_file") |
||||
|
||||
# Compare the current hash with the previous hash |
||||
if [[ "$current_hash" != "$previous_hash" ]]; then |
||||
/usr/bin/echo -e "\033[0;31m Danger...? Change detected in $env_var_name!!! ENV VAR \033[0m" |
||||
export SANE_TEST_FAILED=1 |
||||
return 1 |
||||
fi |
||||
else |
||||
/usr/bin/echo "Hash file for $env_var_name does not exist. Creating new hash file." |
||||
# Save the current hash to the hash file |
||||
/usr/bin/echo "$current_hash" > "$hash_file" |
||||
if [ "$USE_SUPER" == "error" ]; then |
||||
echo -e "Have an Admin lock down this file: $hash_file" |
||||
return 0 |
||||
fi |
||||
${USE_SUPER} chown root:root "$hash_file" |
||||
${USE_SUPER} chmod 444 "$hash_file" |
||||
${USE_SUPER} chattr +i "$hash_file" |
||||
fi |
||||
} |
||||
|
||||
check_env_var_hash "LD_PRELOAD" |
||||
check_env_var_hash "LD_LIBRARY_PATH" |
||||
check_env_var_hash "PATH" |
||||
@ -0,0 +1,38 @@ |
||||
# Get the terminal width using tput |
||||
width=$(tput cols) |
||||
|
||||
if is_normal_theme; then |
||||
|
||||
if [ $UID -ne 0 ]; then |
||||
FP="${BK_GREEN}${WHITE}░▒«${UPC}\u@\h»${GREEN}${SEGMENT_SEPARATOR}" |
||||
else |
||||
FP="${BK_GREEN}${WHITE}░▒«${UPC}${RED}■╠╬${DIM}!¡ as ${RESET}${BK_GREEN}${RED}Root${DIM} ¡!${RESET}${BK_GREEN}${RED}╬╣■${WHITE}@\h»${GREEN}${SEGMENT_SEPARATOR}" |
||||
fi |
||||
|
||||
prompt_color='\[\033[;32m\]' |
||||
info_color='\[\033[1;34m\]' |
||||
|
||||
WD="$WHITE$BK_BLUE\w${COLOR_NONE}${BLUE}${SEGMENT_SEPARATOR}${WHITE}" |
||||
BP="$PS_SYMBOL${WHITE}${BRANCH}${WD}" |
||||
|
||||
len=${#PWD} |
||||
if [ "$len" -gt 35 ] || [ "$width" -lt 70 ]; then |
||||
NLT="\n│\n├────" |
||||
else |
||||
NLT="" |
||||
fi |
||||
|
||||
if [ "$len" -lt 12 ]; then |
||||
PS1+=${FP}${BP}$info_color''${PROMPT_SYMBOL}'\[\033[0m\] ' |
||||
else |
||||
PS1+=$prompt_color'┌────'${FP}''$prompt_color${NLT}${BP}''$prompt_color'\n│\n'$prompt_color'└─'$info_color''${PROMPT_SYMBOL}'\[\033[0m\] ' |
||||
fi |
||||
else |
||||
WD="\w${COLOR_NONE}${WHITE}" |
||||
if [ $UID -ne 0 ]; then |
||||
UR="${WHITE}\u" |
||||
else |
||||
UR="${RED}|as ¡Root!|${COLOR_NONE}${WHITE}" |
||||
fi |
||||
PS1+="${WHITE}┌─${CYAN}${UPC}${UR}@\h ${BRANCH} ${WD}\n└─ ${PROMPT_SYMBOL} " |
||||
fi |
||||
@ -0,0 +1,61 @@ |
||||
#!/usr/bin/env bash |
||||
# rename_postfix.sh [-n|--dry-run] [-v] POSTFIX REPLACEMENT |
||||
set -o errexit -o pipefail |
||||
set -o nounset |
||||
|
||||
dry_run=0 |
||||
verbose=0 |
||||
|
||||
# ---- Parse flags |
||||
while [[ $# -gt 0 ]]; do |
||||
case "$1" in |
||||
-n|--dry-run) dry_run=1; shift ;; |
||||
-v|--verbose) verbose=1; shift ;; |
||||
--) shift; break ;; |
||||
-*) echo "Unknown option: $1" >&2; exit 2 ;; |
||||
*) break ;; |
||||
esac |
||||
done |
||||
|
||||
if [[ $# -lt 2 ]]; then |
||||
echo "Usage: ${0##*/} [-n|--dry-run] [-v] old_extension new_extension" >&2 |
||||
echo "Example: $0 .env .sh" |
||||
exit 2 |
||||
fi |
||||
|
||||
old_ext="$1" |
||||
new_ext="$2" |
||||
|
||||
if [[ -z "$new_ext" ]]; then |
||||
echo "Refusing to run: new_ext cannot be empty." >&2 |
||||
exit 2 |
||||
fi |
||||
|
||||
# Match files in current dir whose names start with $postfix |
||||
# nullglob: if no matches, the glob expands to nothing (prevents literal) |
||||
shopt -s nullglob |
||||
|
||||
# Include dotfiles if the postfix starts with a dot (like .env) |
||||
# (Bash already matches dotfiles when the pattern itself starts with a dot.) |
||||
# Handle spaces safely by quoting $f everywhere. |
||||
for file in *"$old_ext"; do |
||||
[[ -e "$file" ]] || continue |
||||
|
||||
base="${file%$old_ext}" # strip the old extension |
||||
new_file="${base}${new_ext}" |
||||
|
||||
# Skip if nothing changes |
||||
[[ "$file" == "$new_file" ]] && continue |
||||
|
||||
if (( dry_run )); then |
||||
printf '[DRY-RUN] mv -- %q %q\n' "$file" "$new_file" |
||||
else |
||||
# -n: don't overwrite existing files accidentally |
||||
# Add -v if requested |
||||
if (( verbose )); then |
||||
mv -vn -- "$file" "$new_file" |
||||
else |
||||
mv -n -- "$file" "$new_file" |
||||
fi |
||||
fi |
||||
done |
||||
@ -0,0 +1,64 @@ |
||||
#!/usr/bin/env bash |
||||
# rename_prefix.sh [-n|--dry-run] [-v] PREFIX REPLACEMENT |
||||
set -o errexit -o pipefail |
||||
set -o nounset |
||||
|
||||
dry_run=0 |
||||
verbose=0 |
||||
|
||||
# ---- Parse flags |
||||
while [[ $# -gt 0 ]]; do |
||||
case "$1" in |
||||
-n|--dry-run) dry_run=1; shift ;; |
||||
-v|--verbose) verbose=1; shift ;; |
||||
--) shift; break ;; |
||||
-*) echo "Unknown option: $1" >&2; exit 2 ;; |
||||
*) break ;; |
||||
esac |
||||
done |
||||
|
||||
if [[ $# -lt 2 ]]; then |
||||
echo "Usage: ${0##*/} [-n|--dry-run] [-v] PREFIX REPLACEMENT" >&2 |
||||
exit 2 |
||||
fi |
||||
|
||||
prefix=$1 |
||||
replacement=$2 |
||||
|
||||
if [[ -z "$prefix" ]]; then |
||||
echo "Refusing to run: PREFIX cannot be empty." >&2 |
||||
exit 2 |
||||
fi |
||||
|
||||
# Match files in current dir whose names start with $prefix |
||||
# nullglob: if no matches, the glob expands to nothing (prevents literal) |
||||
shopt -s nullglob |
||||
|
||||
# Include dotfiles if the prefix starts with a dot (like .env) |
||||
# (Bash already matches dotfiles when the pattern itself starts with a dot.) |
||||
# Handle spaces safely by quoting $f everywhere. |
||||
for f in -- "$prefix"*; do |
||||
[[ -e "$f" ]] || continue |
||||
|
||||
dir=$(dirname -- "$f") |
||||
base=$(basename -- "$f") |
||||
|
||||
# Replace only if $prefix is at the START of the filename |
||||
newbase="${base/#$prefix/$replacement}" |
||||
newpath="$dir/$newbase" |
||||
|
||||
# Skip if nothing changes |
||||
[[ "$f" == "$newpath" ]] && continue |
||||
|
||||
if (( dry_run )); then |
||||
printf '[DRY-RUN] mv -- %q %q\n' "$f" "$newpath" |
||||
else |
||||
# -n: don't overwrite existing files accidentally |
||||
# Add -v if requested |
||||
if (( verbose )); then |
||||
mv -vn -- "$f" "$newpath" |
||||
else |
||||
mv -n -- "$f" "$newpath" |
||||
fi |
||||
fi |
||||
done |
||||
@ -0,0 +1,19 @@ |
||||
#!/bin/bash |
||||
|
||||
prompt_to_setup() { |
||||
cat debian_deps.list |
||||
read -rp "Do you want to install these packages (y/n)?: " response |
||||
if [[ "$response" == "y" ]]; then |
||||
return 0 # user choose to install |
||||
else |
||||
return 1 # user choose to not install |
||||
fi |
||||
} |
||||
|
||||
if [ -x /usr/bin/apt ] || [ -x /bin/apt ]; then |
||||
if [ -r debian_deps.list ] && prompt_to_setup; then |
||||
sudo apt update && sudo apt install $(cat debian_deps.list) |
||||
else |
||||
echo "Install aborted..." |
||||
fi |
||||
fi |
||||
@ -0,0 +1,23 @@ |
||||
The MIT License |
||||
|
||||
Copyright (c) 2019-2020 Ivan Marov <ie.marov@gmail.com> |
||||
Copyright (c) 2021 Robert Strutts |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining |
||||
a copy of this software and associated documentation files (the |
||||
"Software"), to deal in the Software without restriction, including |
||||
without limitation the rights to use, copy, modify, merge, publish, |
||||
distribute, sublicense, and/or sell copies of the Software, and to |
||||
permit persons to whom the Software is furnished to do so, subject to |
||||
the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be |
||||
included in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
@ -0,0 +1,30 @@ |
||||
A simple terminal GUI interface for SSH config files. |
||||
|
||||
Credits for sshto: go to the original creator Ivan Marov. |
||||
|
||||
.SH AUTHOR |
||||
Ivan Marov <ie.marov@gmail.com> |
||||
.SH GITHUB |
||||
https://github.com/vaniacer/sshto |
||||
|
||||
Copyright: 2019-2020 Ivan Marov |
||||
License: MIT |
||||
|
||||
All code in scripts/sshto and it's sub-fodlers were based on work by Ivan Marov. |
||||
Ivan's repo is a nice smaller script, take a look...at his repo listed above. |
||||
|
||||
-=-=- |
||||
Robert Strutts - changes: What have I added in this adapted form of works: |
||||
* Auto config file generation when .ssh folder does not exist: |
||||
- Finds remote servers and tries to create an entry for it from /etc/hosts file. |
||||
- Auto generate RSA/GPG key pairs for a new account. |
||||
* $ sshto [optional group based on server names] |
||||
- Just load into view the optional name of servers group |
||||
IE: $ sshto work |
||||
* config file "ignore" option...to hide host from main menu |
||||
- IE: Host github #ignore |
||||
* Menu Command to Copy main Bash Aliases (compresses and creates installer script). |
||||
* Mosh client connection |
||||
* SFTP via GUI file MGR |
||||
* Mount will mount into /mnt |
||||
* Key Copy asks which key to use |
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,41 @@ |
||||
REMOTE=5901 # Remote port for tunneling. |
||||
LOCAL=5901 # Local port for tunneling. |
||||
GUEST=$USER # Alternative username to login with. |
||||
DEST="$HOME" # Destination folder on target server to download\upload files. |
||||
TIME=60 # Timer for tunneling command. Tunnel will be closed after 60 seconds, but it will stay open if used. |
||||
LSEXIT=false # Perform ls on exit true|false. |
||||
home=$PWD # Destination folder on local server to download\upload files and sshfs mount. |
||||
sshdir=~/.ssh # Ssh configfiles folder |
||||
knwhosts="$sshdir"/known_hosts # Path to known_hosts file |
||||
sshfsopt= # Sshfs options (-o allow_other) [[would allow ALL users access]] |
||||
SSH_OPT= # SSH Options |
||||
|
||||
if [ -z "$EDITOR" ]; then |
||||
EDITOR=nano # Editor nano or vim |
||||
fi |
||||
|
||||
if [ -d "$HOME" ]; then |
||||
HPATH=$HOME |
||||
elif [ -d "/home/$USER" ]; then |
||||
HPATH=/home/$USER |
||||
else |
||||
echo "Unable to Find user HOME folder!!!!" |
||||
exit 1 |
||||
fi |
||||
|
||||
# SSH key to use (Add my ssh key to host). |
||||
if [ ! -d "$HPATH/.ssh" ]; then |
||||
echo "Let's setup SSH...." |
||||
elif [ -r "$HPATH/.ssh/${USER}_rsa.pub" ]; then |
||||
KEY=$HPATH/.ssh/${USER}_rsa.pub |
||||
elif [ -r "$HPATH/.ssh/${USER}.pub" ]; then |
||||
KEY=$HPATH/.ssh/${USER}.pub |
||||
elif [ -r "$HPATH/.ssh/id_rsa.pub" ]; then |
||||
KEY=$HPATH/.ssh/id_rsa.pub |
||||
else |
||||
KEY=$(ls $HPATH/.ssh/*.pub 2> /dev/null | head -1) |
||||
fi |
||||
#echo $KEY |
||||
|
||||
# Save selected context for current user |
||||
tmpfile=/tmp/sshtorc-${USER} |
||||
@ -0,0 +1,477 @@ |
||||
HOSTS_FILE=/etc/hosts |
||||
split="1" # Default of no Split!!! |
||||
|
||||
pkey() { |
||||
if [ -f "$PK" ]; then |
||||
USE_PRIVATE_KEY=$PK |
||||
elif [ -f "${PK}.private" ]; then |
||||
USE_PRIVATE_KEY=${PK}.private |
||||
else |
||||
USE_PRIVATE_KEY=$HPATH/.ssh/id_rsa |
||||
fi |
||||
} |
||||
|
||||
choose_key() { |
||||
local homes=$HPATH/.ssh/ |
||||
local pubs=$(find "$homes" -type f -iname "*.pub" 2> /dev/null) |
||||
if [ -z "$pubs" ]; then |
||||
PK=${homes}${USER} |
||||
pkey |
||||
return 0 |
||||
fi |
||||
|
||||
nonpub="" |
||||
akeys=() |
||||
realkeys=() |
||||
indexforkeys=() |
||||
|
||||
IFSOLD=$IFS |
||||
IFS=$'\n' |
||||
|
||||
local pubs_count=0 |
||||
local option_no=0 |
||||
for k in $pubs; do |
||||
pubs_count=$((pubs_count+1)) |
||||
nonpub=${k/.pub/} |
||||
option_no=$((option_no+1)) |
||||
akeys+=( "$option_no" "${nonpub/$homes/}" ) |
||||
indexforkeys+=( "$option_no" ) |
||||
realkeys+=( "$nonpub" ) |
||||
done |
||||
|
||||
IFS=$IFSOLD |
||||
|
||||
if [ "$pubs_count" -eq "1" ]; then |
||||
PK=$nonpub |
||||
pkey |
||||
return 0 |
||||
elif [ "$pubs_count" -eq "0" ]; then |
||||
PK=$HPATH/.ssh/${USER} |
||||
pkey |
||||
return 0 |
||||
fi |
||||
|
||||
if [ "${#akeys[@]}" -eq "0" ]; then |
||||
PK=$HPATH/.ssh/${USER} |
||||
pkey |
||||
return 0 |
||||
fi |
||||
|
||||
usekey=$(dialog --ok-label "Use this Key" --cancel-label "Back" --output-fd 1 \ |
||||
--colors \ |
||||
--menu "Select key:" 0 0 0 "${akeys[@]}") |
||||
|
||||
match=false |
||||
c=0 |
||||
for no in "${indexforkeys[@]}"; do |
||||
c=$((c+1)) |
||||
if [ "$usekey" = "$no" ]; then |
||||
match=true |
||||
break |
||||
fi |
||||
done |
||||
|
||||
if [ "$match" = false ]; then |
||||
PK=$HPATH/.ssh/${USER} |
||||
pkey |
||||
return 0 |
||||
fi |
||||
|
||||
d=0 |
||||
for i in "${realkeys[@]}"; do |
||||
d=$((d+1)) |
||||
if [ "$d" = "$c" ]; then |
||||
PK=$i |
||||
pkey |
||||
return 0 |
||||
fi |
||||
done |
||||
|
||||
PK=$HPATH/.ssh/${USER} |
||||
pkey |
||||
} |
||||
|
||||
ask_to_edit_hosts() { |
||||
dialog --output-fd 1 --title "Edit Host File" \ |
||||
--backtitle "Add servers to your /etc/hosts file as SUDOer?" \ |
||||
--yesno "Would you like to add any servers as SUDO user?" 7 60 |
||||
EDIT_HOSTS=$? |
||||
clear |
||||
} |
||||
|
||||
default_ssh_port() { |
||||
SSH_PORT=22 |
||||
new_port=$(dialog --ok-label "OK" --cancel-label "BACK" --output-fd 1 --max-input 5 \ |
||||
--aspect 100 --colors --inputbox 'Change default SSH port#' 10 30 "$SSH_PORT") |
||||
SSH_PORT=${new_port:-$SSH_PORT} |
||||
} |
||||
|
||||
default_username() { |
||||
DEFAULT_USER=$USER |
||||
new_user=$(dialog --ok-label "OK" --cancel-label "BACK" --output-fd 1 \ |
||||
--aspect 100 --colors --inputbox 'Change default SSH USER' 10 30 "$DEFAULT_USER") |
||||
DEFAULT_USER=${new_user:-$DEFAULT_USER} |
||||
} |
||||
|
||||
split_hosts_file() { |
||||
echo "# Private/Remote Servers" > /tmp/localhosts_remotes |
||||
echo "# Local-Hosts IPv4" > /tmp/localhosts_ip4 |
||||
echo "# Local-Hosts IPv6" > /tmp/localhosts_ip6 |
||||
comment="" |
||||
|
||||
IFSOLD=$IFS |
||||
IFS=$'\n' |
||||
for item in $(cat "$HOSTS_FILE"); do |
||||
tipaddr=$(echo "$item" | awk '{print $1}') |
||||
thostname=$(echo "$item" | awk '{print $2}') |
||||
#lcase=$(echo "$thostname" | tr '[A-Z]' '[a-z]') |
||||
#rhost=${lcase/ssh-/} |
||||
#rhost=${rhost/h-/} |
||||
#rhost=${rhost/host-/} |
||||
if [ $(echo $tipaddr | awk -F. '{ printf("%d\n", $1); }') = "127" ]; then |
||||
#echo "Skipped IPv4 Loopback" |
||||
if [ -n "$comment" ]; then |
||||
echo "$comment" >> /tmp/localhosts_ip4 |
||||
comment="" |
||||
fi |
||||
echo "$item" >> /tmp/localhosts_ip4 |
||||
elif [ $(echo $tipaddr | grep -c "::") -ge 1 ]; then |
||||
#echo "Skipped IPv6 Loopback" |
||||
if [ -n "$comment" ]; then |
||||
echo "$comment" >> /tmp/localhosts_ip6 |
||||
comment="" |
||||
fi |
||||
echo "$item" >> /tmp/localhosts_ip6 |
||||
elif [ $(echo $tipaddr | grep -c "^#") -ge 1 ]; then |
||||
#echo "Skipped Comment" |
||||
|
||||
if [ "$item" != "# Private/Remote Servers" ] && \ |
||||
[ "$item" != "# Local-Hosts IPv4" ] && \ |
||||
[ "$item" != "# Local-Hosts IPv6" ] && \ |
||||
[ "$item" != "# Script will include Localhosts back in automatically" ] && \ |
||||
[ "$item" != "#" ]; then |
||||
if [ -n "$comment" ]; then |
||||
comment+=$(printf "\n%s" "$item") |
||||
else |
||||
comment=$item |
||||
fi |
||||
fi |
||||
continue |
||||
else |
||||
#echo "Found Private/Remote Host" |
||||
if [ -n "$comment" ]; then |
||||
echo "$comment" >> /tmp/localhosts_remotes |
||||
comment="" |
||||
fi |
||||
echo "$item" >> /tmp/localhosts_remotes |
||||
fi |
||||
done |
||||
|
||||
IFS=$IFSOLD |
||||
|
||||
cat /tmp/localhosts_ssh > /tmp/localhosts_main |
||||
cat /tmp/localhosts_remotes >> /tmp/localhosts_main |
||||
echo -e "\n#\n# Script will include Localhosts back in automatically" >> /tmp/localhosts_main |
||||
} |
||||
|
||||
thostname="" |
||||
hostnames=() |
||||
deduper() { |
||||
if [ ${#hostnames[@]} -eq 0 ]; then |
||||
hostnames+=("$thostname") |
||||
return 0 |
||||
fi |
||||
local dup=false |
||||
for x in "${hostnames[@]}"; do |
||||
if [ "$x" = "$thostname" ]; then |
||||
dup=true |
||||
break |
||||
fi |
||||
done |
||||
if [ $dup = false ]; then |
||||
hostnames+=("$thostname") |
||||
fi |
||||
} |
||||
|
||||
ask_to_split() { |
||||
dialog --output-fd 1 --title "Split Host File" \ |
||||
--backtitle "Hosts file too large, temporary..split it?" \ |
||||
--yesno "Local Hosts will be placed at bottom of host file." 7 60 |
||||
|
||||
split=$? |
||||
clear |
||||
} |
||||
|
||||
admin_step() { |
||||
|
||||
ask_to_edit_hosts |
||||
if [ "$EDIT_HOSTS" = "0" ]; then |
||||
echo "Editing Hosts file..." |
||||
else |
||||
return 0 |
||||
fi |
||||
|
||||
if [ $(wc -l "$HOSTS_FILE" | awk -F. '{ printf("%d\n", $1); }') -gt 500 ]; then |
||||
ask_to_split |
||||
fi |
||||
|
||||
echo "Updating Hosts" |
||||
if [ ! -d "$HPATH/.dotfile_backups" ]; then |
||||
mkdir "$HPATH/.dotfile_backups" 2> /dev/null |
||||
fi |
||||
local bknow=$(date +"%m_%d_%Y_%H_%M_%S") |
||||
cp "$HOSTS_FILE" "$HPATH/.dotfile_backups/host${bknow}" 2> /dev/null |
||||
|
||||
if [ "$split" = "0" ]; then |
||||
split_hosts_file |
||||
else |
||||
if [ -x /usr/bin/tee ] || [ -x /bin/tee ]; then |
||||
echo -e "# Please add all your SSH Servers to this list:" | cat - "$HOSTS_FILE" | sudo tee "$HOSTS_FILE" |
||||
fi |
||||
|
||||
if [ -z "$EDITOR" ]; then |
||||
sudo nano "$HOSTS_FILE" |
||||
else |
||||
sudo "$EDITOR" "$HOSTS_FILE" |
||||
fi |
||||
sudo sed -i '/# Please add all your SSH Servers to this list:/d' "$HOSTS_FILE" |
||||
return 1 |
||||
fi |
||||
|
||||
if [ -z "$EDITOR" ]; then |
||||
nano /tmp/localhosts_main |
||||
else |
||||
"$EDITOR" /tmp/localhosts_main |
||||
fi |
||||
|
||||
sed -i '/# Script will include Localhosts back in automatically/d' /tmp/localhosts_main |
||||
} |
||||
|
||||
admin_check() { |
||||
if [ $UID -eq 0 ]; then |
||||
admin_step |
||||
else |
||||
sudoers_power=$(groups "$USER" | grep " sudo") |
||||
admin_power=$(groups "$USER" | grep " admin") |
||||
wheel_power=$(groups "$USER" | grep " wheel") |
||||
if [ -n "$sudoers_power" ] || [ -n "$admin_power" ] || [ -n "$wheel_power" ]; then |
||||
admin_step |
||||
fi |
||||
fi |
||||
} |
||||
|
||||
clean_up_split() { |
||||
if [ "$split" = "0" ]; then |
||||
cat /tmp/localhosts_ip4 >> /tmp/localhosts_main |
||||
cat /tmp/localhosts_ip6 >> /tmp/localhosts_main |
||||
echo -e "\n Original $HOSTS_FILE file Backed up at: $HPATH/.dotfile_backups/host${bknow}" |
||||
echo "Cleaning up hosts file...." |
||||
sudo mv -f "$HOSTS_FILE" "${HOSTS_FILE}_old" |
||||
sudo mv /tmp/localhosts_main "$HOSTS_FILE" |
||||
sudo chown root:root "$HOSTS_FILE" |
||||
sudo chmod 644 "$HOSTS_FILE" |
||||
rm -f /tmp/localhosts_* |
||||
fi |
||||
} |
||||
|
||||
findhosts() { |
||||
|
||||
admin_check |
||||
|
||||
if [ "$split" = "0" ]; then |
||||
read_hosts=/tmp/localhosts_main |
||||
else |
||||
read_hosts=$HOSTS_FILE |
||||
fi |
||||
|
||||
IFSOLD=$IFS |
||||
IFS=$'\n' |
||||
|
||||
for item in $(cat "$read_hosts"); do |
||||
tipaddr=$(echo "$item" | awk '{print $1}') |
||||
thostname=$(echo "$item" | awk '{print $2}') |
||||
lcase=$(echo "$thostname" | tr '[A-Z]' '[a-z]') |
||||
|
||||
if [ "$(echo $tipaddr | awk -F. '{ printf("%d\n", $1); }')" = "127" ]; then |
||||
#echo "Skipped IPv4 Loopback" |
||||
continue |
||||
elif [ "$(echo $tipaddr | grep -c "::")" -ge 1 ]; then |
||||
#echo "Skipped IPv6 Loopback" |
||||
continue |
||||
elif [ "$(echo $tipaddr | grep -c "^#")" -ge 1 ]; then |
||||
#echo "Skipped Comment" |
||||
continue |
||||
else |
||||
deduper |
||||
fi |
||||
done |
||||
|
||||
IFS=$IFSOLD |
||||
|
||||
clean_up_split |
||||
|
||||
} |
||||
|
||||
edit_configs() { |
||||
IFSOLD=$IFS |
||||
IFS=$'\n' |
||||
|
||||
local aconfig=() |
||||
local cfgs=$(ls $HPATH/.ssh/config*) |
||||
local realconfig=() |
||||
local realindex=() |
||||
local p="" |
||||
local r="" |
||||
local cdd |
||||
for cdd in $cfgs; do |
||||
realconfig+=( "$cdd" ) |
||||
p=$HPATH/.ssh/ |
||||
r=${cdd/$p/} |
||||
de=${r/configs_/} |
||||
de=${de/.conf/} |
||||
realindex+=( "$de" ) |
||||
aconfig+=( "$de" "$r" ) |
||||
done |
||||
|
||||
if [ "${#aconfig[@]}" -eq "0" ]; then |
||||
return 1 |
||||
fi |
||||
|
||||
editme=$(dialog --ok-label "Edit this config" --cancel-label "Back" --output-fd 1 \ |
||||
--colors \ |
||||
--menu "Select SSH file:" 0 0 0 "${aconfig[@]}") |
||||
|
||||
local match=false |
||||
local c=0 |
||||
local no |
||||
for no in "${realindex[@]}"; do |
||||
c=$((c+1)) |
||||
# echo "$no" |
||||
if [ "$editme" = "$no" ]; then |
||||
match=true |
||||
break |
||||
fi |
||||
done |
||||
|
||||
if [ "$match" = false ]; then |
||||
return 0 |
||||
fi |
||||
|
||||
local d=0 |
||||
local i |
||||
for i in "${realconfig[@]}"; do |
||||
d=$((d+1)) |
||||
if [ "$d" = "$c" ]; then |
||||
"$EDITOR" "$i" |
||||
break |
||||
fi |
||||
done |
||||
|
||||
IFS=$IFSOLD |
||||
} |
||||
|
||||
if [ ! -r "$HPATH/.ssh/config" ]; then |
||||
choose_key |
||||
default_ssh_port |
||||
default_username |
||||
clear |
||||
findhosts |
||||
|
||||
prefix="" |
||||
#prefix_num=$(dialog --output-fd 1 --menu "SSH name prefixes:" 0 0 0 1 "None" 2 "s-" 3 "ssh-") |
||||
#case "$prefix_num" in |
||||
# '2') prefix="s-";; |
||||
# '3') prefix="ssh-";; |
||||
# *) prefix="";; |
||||
#esac |
||||
|
||||
# Begin Dummy Configs |
||||
echo "Include $HPATH/.ssh/configs_*.conf |
||||
|
||||
# Edit the following SSHTO config file: |
||||
# What servers do you want to connect to?" > "$HPATH/.ssh/config" |
||||
|
||||
if [ -r "$HPATH/.ssh/configs_work.conf" ]; then |
||||
bknow=$(date +"%m_%d_%Y_%H_%M_%S") |
||||
mv "$HPATH/.ssh/configs_work.conf" "$HPATH/.ssh/bk_configs_work${bknow}.old" 2> /dev/null |
||||
fi |
||||
|
||||
echo "#Host Group #My Work Server's#" > "$HPATH/.ssh/configs_work.conf" |
||||
|
||||
if [ "${#hostnames[@]}" -eq "0" ]; then |
||||
echo "Host ${prefix}mysite |
||||
HostName YOURsiteHERE.com OR IP of computer |
||||
Port $SSH_PORT |
||||
User $DEFAULT_USER |
||||
IdentityFile $USE_PRIVATE_KEY" >> "$HPATH/.ssh/configs_work.conf" |
||||
else |
||||
for h in "${hostnames[@]}"; do |
||||
ch=${h/host-/} |
||||
ch=${ch/h-/} |
||||
ch=${ch/s-/} |
||||
ch=${ch/ssh-/} |
||||
echo "Host ${prefix}${ch} |
||||
HostName ${h} |
||||
Port $SSH_PORT |
||||
User $DEFAULT_USER |
||||
IdentityFile $USE_PRIVATE_KEY" >> "$HPATH/.ssh/configs_work.conf" |
||||
|
||||
done |
||||
fi |
||||
|
||||
echo "Host github #ignore |
||||
HostName github.com |
||||
Port 22 |
||||
User git |
||||
IdentityFile $USE_PRIVATE_KEY |
||||
|
||||
# --- default for all NOT Defined hosts..! --- |
||||
Host * |
||||
Protocol 2 |
||||
HostKeyAlgorithms sk-ssh-ed25519@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa |
||||
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group18-sha512,diffie-hellman-group16-sha512 |
||||
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr |
||||
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256 |
||||
StrictHostKeyChecking ask |
||||
VerifyHostKeyDNS ask |
||||
User root |
||||
Port 22 |
||||
ServerAliveInterval 300 |
||||
ServerAliveCountMax 3 |
||||
ForwardAgent no |
||||
ForwardX11 no |
||||
ForwardX11Trusted no |
||||
PermitLocalCommand no |
||||
HashKnownHosts yes |
||||
TCPKeepAlive yes |
||||
SendEnv LANG LC_* |
||||
" >> "$HPATH/.ssh/config" |
||||
|
||||
if [ ! -r "$HPATH/.ssh/configs_home.conf" ]; then |
||||
echo "#Host Group #My Home Lab# |
||||
Host ${prefix}lab #ignore |
||||
HostName lab1 |
||||
Port $SSH_PORT |
||||
User $DEFAULT_USER |
||||
IdentityFile $USE_PRIVATE_KEY" > "$HPATH/.ssh/configs_home.conf" |
||||
fi |
||||
|
||||
if [ ! -r "$HPATH/.ssh/EXAMPLEconfigs_proxy.conf" ]; then |
||||
echo "#Host Group #Proxies's# |
||||
# Forward all local port 3128 traffic to port 3128 on the remote vps1.cyberciti.biz server |
||||
# $ ssh -f -N proxyus |
||||
Host proxyus #ignore |
||||
HostName vps1.cyberciti.biz |
||||
User breakfree |
||||
IdentityFile $HPATH/.ssh/vps1.cyberciti.biz.key |
||||
LocalForward 3128 127.0.0.1:3128" > "$HPATH/.ssh/EXAMPLEconfigs_proxy.conf" |
||||
fi |
||||
|
||||
chmod 644 "$HPATH/.ssh/config" |
||||
chmod 644 "$HPATH/.ssh/configs_work.conf" |
||||
chmod 644 "$HPATH/.ssh/configs_home.conf" |
||||
chmod 644 "$HPATH/.ssh/EXAMPLEconfigs_proxy.conf" |
||||
|
||||
edit_configs |
||||
|
||||
fi |
||||
@ -0,0 +1,24 @@ |
||||
#-------------------------+--------------------------------+---------+ |
||||
# Text color | Background color | | |
||||
#-----------+-------------+--------------+-----------------+ | |
||||
# Base color|Lighter shade| Base color | Lighter shade | | |
||||
#-----------+-------------+--------------+-----------------+ | |
||||
BLK='\e[30m'; blk='\e[90m'; BBLK='\e[40m'; bblk='\e[100m' #| Black | |
||||
RED='\e[31m'; red='\e[91m'; BRED='\e[41m'; bred='\e[101m' #| Red | |
||||
GRN='\e[32m'; grn='\e[92m'; BGRN='\e[42m'; bgrn='\e[102m' #| Green | |
||||
YLW='\e[33m'; ylw='\e[93m'; BYLW='\e[43m'; bylw='\e[103m' #| Yellow | |
||||
BLU='\e[34m'; blu='\e[94m'; BBLU='\e[44m'; bblu='\e[104m' #| Blue | |
||||
MGN='\e[35m'; mgn='\e[95m'; BMGN='\e[45m'; bmgn='\e[105m' #| Magenta | |
||||
CYN='\e[36m'; cyn='\e[96m'; BCYN='\e[46m'; bcyn='\e[106m' #| Cyan | |
||||
WHT='\e[37m'; wht='\e[97m'; BWHT='\e[47m'; bwht='\e[107m' #| White | |
||||
#----------------------------------------------------------+---------+ |
||||
# Effects | |
||||
#--------------------------------------------------------------------+ |
||||
DEF='\e[0m' #Default color and effects | |
||||
BLD='\e[1m' #Bold\brighter | |
||||
DIM='\e[2m' #Dim\darker | |
||||
CUR='\e[3m' #Italic font | |
||||
UND='\e[4m' #Underline | |
||||
INV='\e[7m' #Inverted | |
||||
COF='\e[?25l' #Cursor Off | |
||||
CON='\e[?25h' #Cursor On | |
||||
@ -0,0 +1,26 @@ |
||||
new_list() { |
||||
list=() |
||||
match="" |
||||
for item in "${fullist[@]}"; { |
||||
case $item:$match in |
||||
-*\ *\ *-:1) break;; |
||||
-*\ $filter\ *-:*) match=1;; |
||||
esac |
||||
[[ $match ]] && list+=( "$item" ) |
||||
} |
||||
[[ ${list[*]} ]] && echo "filter='$filter'" > "$tmpfile" || { list=( "${fullist[@]}" ); rm "$tmpfile"; } |
||||
} |
||||
|
||||
editconfig() { edit_configs; update_hosts; } |
||||
|
||||
contents_menu () { |
||||
filter=$(dialog --output-fd 1 --ok-label "SELECT" --cancel-label "BACK" \ |
||||
--extra-button --extra-label "Edit" \ |
||||
--no-items --menu "Select list of hosts:" 0 0 0 "All" "${content[@]}") |
||||
case $filter:$? in |
||||
All:0) list=( "${fullist[@]}" );; |
||||
*:0) new_list;; |
||||
*:3) editconfig;; |
||||
esac |
||||
main_dialog |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
do='--output-fd 1 --colors' # dialog common options |
||||
ap='--aspect 100' # aspect 100 |
||||
eb='--extra-button' # extra |
||||
hb='--help-button' # buttons |
||||
cl='--cancel-label' # and |
||||
el='--extra-label' # short |
||||
hl='--help-label' # label |
||||
ol='--ok-label' # names |
||||
|
||||
# Dialog buttons order and exit codes |
||||
#<OK> <Extra> <Cancel> <Help> |
||||
# 0 3 1 2 |
||||
|
||||
D(){ # dialog creator |
||||
local opts=() |
||||
[[ $1 ]] && opts+=("$ol" "$1") |
||||
[[ $2 ]] && opts+=("$el" "$2" "$eb") |
||||
[[ $3 ]] && opts+=("$cl" "$3") |
||||
[[ $4 ]] && opts+=("$hl" "$4" "$hb") |
||||
shift 4 |
||||
dialog "${opts[@]}" $do "$@" |
||||
} |
||||
@ -0,0 +1,42 @@ |
||||
if [ -z "$_PROFILES_PATH" ]; then |
||||
_MAIN_PATHC=/opt/profiles/scripts/ |
||||
else |
||||
_MAIN_PATHC=${_PROFILES_PATH}scripts/ |
||||
fi |
||||
|
||||
|
||||
if [ ! -d ~/.ssh ]; then |
||||
${_MAIN_PATHC}make_a_key.sh |
||||
fi |
||||
|
||||
refresh() { |
||||
cmdlist=() |
||||
IFSOLD=$IFS |
||||
IFS=','; |
||||
while read -r label mycommand desc; |
||||
do |
||||
[[ $label =~ ^#.* ]] && continue |
||||
|
||||
desc=${desc/!GUEST/$GUEST} |
||||
desc=${desc/!REMOTE/$REMOTE} |
||||
desc=${desc/!LOCAL/$LOCAL} |
||||
desc=${desc/!DEST/$DEST} |
||||
desc=${desc/!home/$home} |
||||
desc=${desc/!target/$target} |
||||
|
||||
cmdlist+=("$label" "$desc" ) |
||||
done < "${_RUN_CMDS_FILE}" |
||||
IFS=$IFSOLD |
||||
} |
||||
|
||||
cmd() { |
||||
IFSOLD=$IFS |
||||
IFS=',' |
||||
while read -r label user_command desc; |
||||
do |
||||
[[ $label =~ ^#.* ]] && continue |
||||
[[ "$command" == "$label" ]] && break |
||||
done < "${_RUN_CMDS_FILE}" |
||||
IFS=$IFSOLD |
||||
[[ "$command" == "$label" ]] && { $user_command; return; } |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
install_help=" |
||||
${BLD}sshto$DEF requires that the package '${GRN}%b$DEF' is installed. |
||||
Type this into the terminal and press return: |
||||
|
||||
${BLD}%b$DEF |
||||
|
||||
Then run ${BLD}sshto$DEF again |
||||
" |
||||
how_to_install() { |
||||
local package=$1 |
||||
which yum &> /dev/null && installer="yum -y install $package" |
||||
which brew &> /dev/null && installer="brew install $package" |
||||
which apt-get &> /dev/null && installer="apt-get install -y $package" |
||||
printf -- "$install_help" "$package" "$installer" |
||||
[[ $2 ]] && exit $2 |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue