|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# info: search for available commands |
| 4 | +# |
| 5 | +# This function searches for available Hestia Control Panel commands |
| 6 | +# and returns results based on the specified criteria. |
| 7 | +# |
| 8 | +# Originally developed for VestaCP by Federico Krum |
| 9 | +# https://github.com/FastDigitalOceanDroplets/VestaCP/blob/master/files/v-search-command |
| 10 | + |
| 11 | +#----------------------------------------------------------# |
| 12 | +# Variable&Function # |
| 13 | +#----------------------------------------------------------# |
| 14 | +source $HESTIA/func/main.sh |
| 15 | + |
| 16 | +#----------------------------------------------------------# |
| 17 | +# Verifications # |
| 18 | +#----------------------------------------------------------# |
| 19 | +if [ $# -eq 0 ]; then |
| 20 | + echo "ERROR: No search arguments specified." |
| 21 | + echo "Usage: v-search-command ARG1 [ARG2] [ARG...]" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +#----------------------------------------------------------# |
| 26 | +# Action # |
| 27 | +#----------------------------------------------------------# |
| 28 | + |
| 29 | +SearchPath=`ls -a $HESTIA/bin/ | sort` |
| 30 | +TotalItems=`ls -a $HESTIA/bin/ | sort | wc -l` |
| 31 | + |
| 32 | +for i; do |
| 33 | + SearchResults=`echo $SearchPath | tr " " "\n" | grep $i` |
| 34 | + FoundItems=`echo $SearchResults | tr " " "\n" | grep $i | wc -l` |
| 35 | +done |
| 36 | + |
| 37 | +if [ -z "$SearchResults" ]; then |
| 38 | + echo "No available commands were found matching the specified critera." |
| 39 | + echo "There are a total of $TotalItems commands available." |
| 40 | +else |
| 41 | + echo "Command Search Results" |
| 42 | + echo "=================================" |
| 43 | + echo $SearchResults | tr " " "\n" |
| 44 | + echo "=================================" |
| 45 | + echo "Found $FoundItems matching items in $TotalItems commands." |
| 46 | +fi |
| 47 | +exit |
0 commit comments