You are here

/etc/profile.d/globaliases.sh

Submitted by Alan Mels on Fri, 10/12/2018 - 03:32

0) file=/etc/profile.d/globaliases.sh

cat > /etc/profile.d/globaliases.sh << 'EOT'
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
export EDITOR="nano"
 
if [ -d /opt/remi/php74 ]; then
  source /opt/remi/php74/enable
elif [ -d /opt/remi/php73 ]; then
  source /opt/remi/php73/enable
elif [ -d /opt/remi/php72 ]; then
  source /opt/remi/php72/enable
fi
 
alias wget='wget --no-check-certificate'
alias frw='firewall-cmd'
alias genpass='openssl rand -base64 12'
alias myip='curl ipinfo.io/ip'
alias re3='systemctl restart httpd && systemctl restart varnish && systemctl restart pound'
alias ?='history'  # DISPLAYS HISTORY
alias l='ls -la'
alias x='exit'
alias l.='ls -dl .* --color=auto'
alias fix-sl='find . -type f -name .htaccess -exec sed -i "s/FollowSymLinks/SymLinksIfOwnerMatch/g" {} \; | find . -type f -name file.inc -exec sed -i "s/FollowSymLinks/SymLinksIfOwnerMatch/g" {} \;'
alias s1='nano /etc/hosts'
alias s2='nano /etc/hostname'
alias s3='nano /etc/postfix/main.cf'
alias s4='nano /etc/varnish/default.vcl'
alias s5='nano /etc/varnish/varnish.params'
alias s6='nano /etc/pound.cfg'
alias yum='yum -y'
alias dnf='dnf -y'
alias recall="history |grep $1"
 
allow () {
  firewall-cmd --permanent --add-source=$1 && firewall-cmd --reload && firewall-cmd --list-all
}
 
unallow () {
  firewall-cmd --permanent --remove-source=$1 && firewall-cmd --reload && firewall-cmd --list-all
}
 
block () {
  firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='$1' reject" && firewall-cmd --reload && firewall-cmd --list-all
}
 
unblock () {
  firewall-cmd --permanent --remove-rich-rule="rule family='ipv4' source address='$1' reject" && firewall-cmd --reload && firewall-cmd --list-all
}
 
 
tardir () {
tar cvzf ${1}.tar.gz ${1}
}
 
# Extract compressed file
extract () {
  if [ -f $1 ] && [ -r $1 ] ; then
    case $1 in
      (*.tar.bz|*.tbz)  tar -xjf $1;;
      (*.tar.bz2|*.tbz2)  tar xjf $1;;
      (*.tar.gz|*.tgz)    tar xzf $1;;
      (*.bz2)             bunzip2 $1;;
      (*.rar)             rar x $1;;
      (*.gz)              gunzip $1;;
      (*.tar)             tar xf $1;;
      (*.zip)             unzip $1;;
      (*.Z)               uncompress $1;;
      (*.7z)              7z x $1;;
      (*.deb)             sudo dpkg -i $1;;
      (*.rpm)             sudo alien -dik $1;;
      (*)                 echo "extract: unsupported format $1" ;;
  esac
    rm -rf $1
    ls -l
  else
    echo "extract: file not found or unreadable: $1"
  fi
}
 
# Find a file with a pattern in file name
function fn() { find . -type f -iname '*'$1'*' -ls ; }
# Find a file with a pattern in the content of the file
function fs() { grep -Ril "$1" .; }
 
function check_hack() {
for i in $(find /home/*/public_html -type d -prune); do if [ -d $i ]; then find $i -type f -name '*.php' | xargs grep -l 'eval *(' --color && find $i -type f -name '*.php' | xargs grep -l 'base64_decode *(' --color && find $i -type f -name '*.php' | xargs grep -l 'gzinflate *(' --color && find $i -size 494c -name '*.php' && grep -Rl PCT4BA6ODSE $i; fi; done
for i in $(find /home/*/domains/*/public_html/ -type d -prune); do if [ -d $i ]; then find $i -type f -name '*.php' | xargs grep -l 'eval *(' --color && find $i -type f -name '*.php' | xargs grep -l 'base64_decode *(' --color && find $i -type f -name '*.php' | xargs grep -l 'gzinflate *(' --color && find $i -size 494c -name '*.php' && grep -Rl PCT4BA6ODSE $i; fi; done
}
 
function check_drupal() {
for i in $(find /home/*/public_html -type d -prune); do drush -r $i status | grep Drupal; done 
for i in $(find /home/*/domains/*/public_html/ -type d -prune); do drush -r $i status | grep Drupal; done
}
 
chownuser () {
user=`pwd | cut -d '/' -f3`
chown -R $user.$user .
}
 
audit () {
drush dl site_audit && drush dl drupalgeddon && drush cache-clear drush && drush asec
}
 
##########################################################
#Userprompt. See "User Configuration" section            #
##########################################################

#=========================================================
#Terminal Color Codes
#=========================================================
WHITE='\[\033[1;37m\]'
LIGHTGRAY='\[\033[0;37m\]'
GRAY='\[\033[1;30m\]'
BLACK='\[\033[0;30m\]'
RED='\[\033[0;31m\]'
LIGHTRED='\[\033[1;31m\]'
GREEN='\[\033[0;32m\]'
LIGHTGREEN='\[\033[1;32m\]'
BROWN='\[\033[0;33m\]' #Orange
YELLOW='\[\033[1;33m\]'
BLUE='\[\033[0;34m\]'
LIGHTBLUE='\[\033[1;34m\]'
PURPLE='\[\033[0;35m\]'
PINK='\[\033[1;35m\]' #Light Purple
CYAN='\[\033[0;36m\]'
LIGHTCYAN='\[\033[1;36m\]'
DEFAULT='\[\033[0m\]'
 
#=========================================================
# User Configuration
#=========================================================
# Colors
cLINES=$GRAY #Lines and Arrow
cBRACKETS=$GRAY # Brackets around each data item
cERROR=$LIGHTRED # Error block when previous command did not return 0
cTIME=$LIGHTGRAY # The current time
cMPX1=$YELLOW # Color for terminal multiplexer threshold 1
cMPX2=$RED # Color for terminal multiplexer threshold 2
cBGJ1=$YELLOW # Color for background job threshold 1
cBGJ2=$RED # Color for background job threshold 2
cSTJ1=$YELLOW # Color for background job threshold 1
cSTJ2=$RED # Color for  background job threshold 2
cSSH=$PINK # Color for brackets if session is an SSH session
cUSR=$LIGHTBLUE # Color of user
cUHS=$GRAY # Color of the user and hostname separator, probably '@'
cHST=$LIGHTGREEN # Color of hostname
cRWN=$RED # Color of root warning
cPWD=$BLUE # Color of current directory
cCMD=$DEFAULT # Color of the command you type

# Enable block
eNL=1  # Have a newline between previous command output and new prompt
eERR=1 # Previous command return status tracker
eMPX=1 # Terminal multiplexer tracker enabled
eSSH=1 # Track if session is SSH
eBGJ=1 # Track background jobs
eSTJ=1 # Track stopped jobs
eUSH=1 # Show user and host
ePWD=1 # Show current directory

# Block settins
MPXT1="0" # Terminal multiplexer threshold 1 value
MPXT2="2" # Terminal multiplexer threshold 2 value
BGJT1="0" # Background job threshold 1 value
BGJT2="2" # Background job threshold 2 value
STJT1="0" # Stopped job threshold 1 value
STJT2="2" # Stopped job threshold 2 value
UHS="@"
 
function promptcmd()
{
        PREVRET=$?
        #=========================================================
        #check if user is in ssh session
        #=========================================================
        if [[ $SSH_CLIENT ]] || [[ $SSH2_CLIENT ]]; then
                lSSH_FLAG=1
        else
                lSSH_FLAG=0
        fi
 
        #=========================================================
        # Insert a new line to clear space from previous command
        #=========================================================
        PS1="\n"
 
        #=========================================================
        # Beginning of first line (arrow wrap around and color setup)
        #=========================================================
        PS1="${PS1}${cLINES}\342\224\214\342\224\200"
 
        #=========================================================
        # First Dynamic Block - Previous Command Error
        #=========================================================
        if [ $PREVRET -ne 0 ] ; then
                PS1="${PS1}${cBRACKETS}[${cERROR}:(${cBRACKETS}]${cLINES}\342\224\200"
        fi
 
        #=========================================================
        # First static block - Current time
        #=========================================================
        PS1="${PS1}${cBRACKETS}[${cTIME}\t${cBRACKETS}]${cLINES}\342\224\200"
 
        #=========================================================
        # Detached Screen Sessions
        #=========================================================
        hTMUX=0
        hSCREEN=0
        MPXC=0
        hash tmux --help 2>/dev/null || hTMUX=1
        hash screen --version 2>/dev/null || hSCREEN=1
        if [ $hTMUX -eq 0 ] && [ $hSCREEN -eq 0 ] ; then
                MPXC=$(echo "$(screen -ls | grep -c -i detach) + $(tmux ls 2>/dev/null | grep -c -i -v attach)" | bc)
        elif [ $hTMUX -eq 0 ] && [ $hSCREEN -eq 1 ] ; then
                MPXC=$(tmux ls 2>/dev/null | grep -c -i -v attach)
        elif [ $hTMUX -eq 1 ] && [ $hSCREEN -eq 0 ] ; then
                MPXC=$(screen -ls | grep -c -i detach)
        fi
        if [[ $MPXC -gt $MPXT2 ]] ; then
                PS1="${PS1}${cBRACKETS}[${cMPX2}\342\230\220:${MPXC}${cBRACKETS}]${cLINES}\342\224\200"
        elif [[ $MPXC -gt $MPXT1 ]] ; then
                PS1="${PS1}${cBRACKETS}[${cMPX1}\342\230\220:${MPXC}${cBRACKETS}]${cLINES}\342\224\200"
        fi
 
        #=========================================================
        # Backgrounded running jobs
        #=========================================================
        BGJC=$(jobs -r | wc -l )
        if [ $BGJC -gt $BGJT2 ] ; then
                PS1="${PS1}${cBRACKETS}[${cBGJ2}&:${BGJC}${cBRACKETS}]${cLINES}\342\224\200"
        elif [ $BGJC -gt $BGJT1 ] ; then
                PS1="${PS1}${cBRACKETS}[${cBGJ1}&:${BGJC}${cBRACKETS}]${cLINES}\342\224\200"
        fi
 
        #=========================================================
        # Stopped Jobs
        #=========================================================
        STJC=$(jobs -s | wc -l )
        if [ $STJC -gt $STJT2 ] ; then
                PS1="${PS1}${cBRACKETS}[${cSTJ2}\342\234\227:${STJC}${cBRACKETS}]${cLINES}\342\224\200"
        elif [ $STJC -gt $STJT1 ] ; then
                PS1="${PS1}${cBRACKETS}[${cSTJ1}\342\234\227:${STJC}${cBRACKETS}]${cLINES}\342\224\200"
        fi
 
        #=========================================================
        # Second Static block - User@host
        #=========================================================
        # set color for brackets if user is in ssh session
        if [ $lSSH_FLAG -eq 1 ] ; then
                sesClr="$cSSH"
        else
                sesClr="$cBRACKETS"
        fi
        # don't display user if root
        if [ $EUID -eq 0 ] ; then
                PS1="${PS1}${sesClr}[${cRWN}!"
        else
                PS1="${PS1}${sesClr}[${cUSR}\u${cUHS}${UHS}"
        fi
        PS1="${PS1}${cHST}\H${sesClr}]${cLINES}\342\224\200"
 
        #=========================================================
        # Third Static Block - Current Directory
        #=========================================================
        PS1="${PS1}[${cPWD}\w${cBRACKETS}]"
 
        #=========================================================
        # Second Line
        #=========================================================
        PS1="${PS1}\n${cLINES}\342\224\224\342\224\200\342\224\200> ${cCMD}"
}
 
function load_prompt () {
    # Get PIDs
	local parent_process=$(tr -d '\0' < /proc/$PPID/cmdline | cut -d \. -f 1)
	local my_process=$(tr -d '\0' < /proc/$$/cmdline | cut -d \. -f 1)
 
 
    if  [[ $parent_process == script* ]]; then
        PROMPT_COMMAND=""
        PS1="\t - \# - \u@\H { \w }\$ "
    elif [[ $parent_process == emacs* || $parent_process == xemacs* ]]; then
        PROMPT_COMMAND=""
        PS1="\u@\H { \w }\$ "
    else
        export DAY=$(date +%A)
        PROMPT_COMMAND=promptcmd
     fi
    export PS1 PROMPT_COMMAND
}
 
load_prompt
EOT