Mini Shell
Direktori : /etc/profile.d/ |
|
Current File : //etc/profile.d/rads-autocomplete.sh |
# :vim set ts=4 sw=4 expandtab syntax=sh:
#
# IMH RADS bash autocomplete
# Rev 2 (08 Feb 2016)
# J. Hipps <jacobh@inmotionhosting.com>
#
# Check if the directory /usr/local/cpanel/bin exists.
# Exit the script if it does not.
[ ! -d "/usr/local/cpanel/bin" ] && return
###############################################################################
## account-review
## check_cpu
## unsuspend_user
## fixperms
## switch
## send_pp_email
__autocomplete_user()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
# auto-complete username
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
}
complete -F __autocomplete_user account-review
complete -F __autocomplete_user check_cpu
complete -F __autocomplete_user unsuspend_user
complete -F __autocomplete_user fixperms
complete -F __autocomplete_user switch
complete -F __autocomplete_user send_pp_email
complete -F __autocomplete_user hostsfilemods
###############################################################################
## whoowns
_whoowns()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
# auto-complete domain names
COMPREPLY=( $(compgen -W "$(sudo cat /etc/userdomains | awk -F: '{print $1}' | grep -v '^\*$')" -- $cur) )
}
complete -F _whoowns whoowns
###############################################################################
## modify-account
_modify_account()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
# option lists
opListLong="--new-user --owner --password --domain --theme --cgi --no-cgi --shell --no-shell --ip --package --bandwidth --quota --reseller --no-reseller --acl --self --no-self --ns --custom-ns --allow --deny --force"
opListShort="-u -o -w -d -t -c -s -i -p -b -q -r -a -D -b -h -v"
opSysOps="--list-users --list-themes --list-ips --list-packages --list-resellers --list-acls --summary --info --debug --bleach --no-color --man --help --version"
# auto-complete username
if [[ $cword == 1 ]]; then
COMPREPLY=( $(compgen -W "$(\ls /var/cpanel/users/)" -- $cur) )
return 0
fi
# auto-complete options
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort $opSysOps" -- $cur) )
return 0
fi
# param completion
case "$prev" in
-p|-a|--package|--acl)
COMPREPLY=( $(compgen -W "$(\ls -p /var/cpanel/packages/ | grep -v /)" -- $cur) )
return 0
;;
-i|--ip)
COMPREPLY=( $(compgen -W "$(ip a s | grep inet | grep -v -E '(127.0.0.1|inet6| 192.168)' | awk '{print $2}' | sed 's/\/.*//')" -- $cur) )
return 0
;;
-o|--owner)
COMPREPLY=( $(compgen -W "$(cat /var/cpanel/resellers | awk -F: '{print $1}')" -- $cur) )
return 0
;;
esac
}
complete -F _modify_account modify-account
###############################################################################
## check_user
## check_crons
_check_user()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
opListLong="--recent --full"
opListShort=""
# auto-complete options
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
return 0
fi
# auto-complete username
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
}
complete -F _check_user check_user
complete -F _check_user check_crons
###############################################################################
## nlp
_nlp()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
opListLong="--with-ptr --no-ptr"
opListShort="-n -w -p -P -h"
# auto-complete options
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
return 0
fi
# auto-complete domlogs path
if [ -f /etc/cpanel/ea4/is_ea4 ]; then
DOMLOGS_PATH=/var/log/apache2/domlogs
else
DOMLOGS_PATH=/usr/local/apache/domlogs
fi
if [[ "$cur" == /* ]]; then
COMPREPLY=( $(compgen -W "$(find $DOMLOGS_PATH/*)" -- $cur) )
return 0
fi
# auto-complete username
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
}
complete -F _nlp nlp
###############################################################################
## suspend_user
_suspend_user()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
opListLong="--sched --moved --tos --ra --cancel --billing --orphan"
opListShort="-u -m"
# auto-complete username
if [ $cword == 1 ] || [ "$prev" == "-u" ]; then
COMPREPLY=( $(compgen -W "$(\ls /var/cpanel/users/)" -- $cur) )
return 0
fi
# auto-complete options
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
return 0
fi
}
complete -F _suspend_user suspend_user
###############################################################################
## check_exim
_check_exim()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
opListLong="--dirtotals --listdirs --queuebysender --queuebybounceback --bouncesbydomain --recipientisp --recipienttest --fullmbox --fwdtotals --lines --status"
opListShort="-h"
# auto-complete options
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
return 0
fi
}
complete -F _check_exim check_exim
###############################################################################
## check_mysql
_check_mysql()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
opListLong="--sockets --active --kill --killqueries --killselects"
opListShort="-h"
# auto-complete username
if [[ "$prev" == "--kill" ]]; then
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
return 0
fi
# auto-complete options
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
return 0
fi
}
complete -F _check_mysql check_mysql
###############################################################################
## shellscan
_shellscan()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
opListLong="--listsigs --dir --user --signame --matches --outfile --auto-quarantine --no-quarantine"
opListShort="-l -d -u -s -m -o -h -y -n"
# auto-complete username
if [ "$prev" == "-u" ] || [ "$prev" == "--user" ]; then
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
return 0
fi
# auto-complete options
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
return 0
fi
}
complete -F _shellscan shellscan.py
###############################################################################
## disk_cleanup.py
_disk_cleanup()
{
local cur prev words cword
words="$COMP_WORDS"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
opModes="delete note"
delOptsLong="--help --core --zip --backup --softaculous --temp"
delOptsShort="-h -c -z -b -s -t -a"
noteOptsLong="--help --wordpress"
noteOptsShort="-h -w"
# auto-complete operation modes
if [[ $cword == 1 ]]; then
COMPREPLY=( $(compgen -W "$opModes" -- $cur) )
return 0
fi
# auto-complete options for each op mode
case "$prev" in
delete)
COMPREPLY=( $(compgen -W "$delOptsLong $delOptsShort" -- $cur) )
return 0
;;
note)
COMPREPLY=( $(compgen -W "$noteOptsLong $noteOptsShort" -- $cur) )
return 0
;;
esac
}
complete -F _disk_cleanup disk_cleanup.py
Zerion Mini Shell 1.0