Compare commits
No commits in common. "558cc6213e76e13cd42f88d162e9d4202fad370f" and "dd65e038108774a8ebaf4f1bc3356118aadbc52c" have entirely different histories.
558cc6213e
...
dd65e03810
62
achar
62
achar
|
@ -1,6 +1,5 @@
|
||||||
#!/bin/bash
|
|
||||||
## Title : ACHAR - Auto Completion of Hosts Add/Remove script
|
## Title : ACHAR - Auto Completion of Hosts Add/Remove script
|
||||||
## Version : 0.2
|
## Version : 0.1
|
||||||
## GIT Repo : https://git.zaks.web.za/zaks-web/achar
|
## GIT Repo : https://git.zaks.web.za/zaks-web/achar
|
||||||
## Author : Ze'ev Schurmann
|
## Author : Ze'ev Schurmann
|
||||||
## Company : ZAKS Web
|
## Company : ZAKS Web
|
||||||
|
@ -13,7 +12,7 @@
|
||||||
## USAGE
|
## USAGE
|
||||||
##
|
##
|
||||||
## From the bash terminal, type:
|
## From the bash terminal, type:
|
||||||
## $ achar {command} {context}
|
## $ achar {command} {hostname}
|
||||||
##
|
##
|
||||||
## COMMANDS
|
## COMMANDS
|
||||||
##
|
##
|
||||||
|
@ -23,7 +22,6 @@
|
||||||
##
|
##
|
||||||
## disable - disables auto completion of hostnames for current system user
|
## disable - disables auto completion of hostnames for current system user
|
||||||
## $ achar disable
|
## $ achar disable
|
||||||
## * does not delete the list of hosts stored at ~/.achar/hosts
|
|
||||||
##
|
##
|
||||||
## enable - enables auto completion of hostnames for current system user
|
## enable - enables auto completion of hostnames for current system user
|
||||||
## $ achar enable
|
## $ achar enable
|
||||||
|
@ -31,26 +29,15 @@
|
||||||
## help - displays this block of text
|
## help - displays this block of text
|
||||||
## $ achar help
|
## $ achar help
|
||||||
##
|
##
|
||||||
## license - displays the GPL3 and Later license
|
|
||||||
## $ achar license
|
|
||||||
##
|
|
||||||
## list - list all existing hosts from your list of common hosts
|
## list - list all existing hosts from your list of common hosts
|
||||||
## $ achar list
|
## $ achar list
|
||||||
## * You can use context to search for a specific hostname or part there of
|
## * You can use grep to search for a specific hostname or part there of
|
||||||
## $ achar list username
|
## $ achar list | grep username
|
||||||
## $ achar list part-of-hostname
|
## $ achar list | grep hostname
|
||||||
##
|
##
|
||||||
## remove - removes an existing host from your list of common hosts
|
## remove - removes an existing host from your list of common hosts
|
||||||
## $ achar remove username@hostname.domainname.tld
|
## $ achar rem username@hostname.domainname.tld
|
||||||
## $ achar remove username@1.2.3.4
|
## $ achar rem username@1.2.3.4
|
||||||
##
|
|
||||||
## reset - deletes all saved hosts
|
|
||||||
## $ achar reset
|
|
||||||
##
|
|
||||||
## uninstall - uninstalls achar from your system
|
|
||||||
## $ sudo achar uninstall
|
|
||||||
## # achar uninstall
|
|
||||||
## * does not delete the list of hosts stored at ~/.achar/hosts
|
|
||||||
##
|
##
|
||||||
## update - checks for an update to ACHAR and prompts you to install it
|
## update - checks for an update to ACHAR and prompts you to install it
|
||||||
## $ achar update
|
## $ achar update
|
||||||
|
@ -64,7 +51,9 @@ function achar_add {
|
||||||
local username_and_hostname
|
local username_and_hostname
|
||||||
|
|
||||||
username_and_hostname=$1
|
username_and_hostname=$1
|
||||||
|
|
||||||
validate_achar_installation hosts
|
validate_achar_installation hosts
|
||||||
|
|
||||||
validate_host "$username_and_hostname"
|
validate_host "$username_and_hostname"
|
||||||
|
|
||||||
if [[ -z $(cat ~/.achar/hosts | grep "$username_and_hostname") ]]; then
|
if [[ -z $(cat ~/.achar/hosts | grep "$username_and_hostname") ]]; then
|
||||||
|
@ -74,6 +63,7 @@ function achar_add {
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "$username_and_hostname is already added!" >&2
|
echo "$username_and_hostname is already added!" >&2
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -144,10 +134,6 @@ function achar_help {
|
||||||
|
|
||||||
echo "${line:3}"
|
echo "${line:3}"
|
||||||
|
|
||||||
elif [[ ${line:0:2} == "#!" ]]; then
|
|
||||||
|
|
||||||
donothing=0
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
@ -162,6 +148,7 @@ function achar_help {
|
||||||
function achar_license {
|
function achar_license {
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
curl -s https://git.zaks.web.za/zaks-web/achar/raw/branch/main/LICENSE | fmt
|
curl -s https://git.zaks.web.za/zaks-web/achar/raw/branch/main/LICENSE | fmt
|
||||||
|
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
|
@ -216,12 +203,9 @@ function achar_remove {
|
||||||
function achar_reset {
|
function achar_reset {
|
||||||
|
|
||||||
validate_achar_installation hosts
|
validate_achar_installation hosts
|
||||||
echo "This will delete all saved hosts and"
|
|
||||||
echo "and start from scratch."
|
|
||||||
echo
|
|
||||||
echo "Press ENTER to continue or CTRL+C to STOP!"
|
|
||||||
read text
|
|
||||||
rm ~/.achar/hosts
|
rm ~/.achar/hosts
|
||||||
|
|
||||||
touch ~/.achar/hosts
|
touch ~/.achar/hosts
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -239,11 +223,10 @@ function achar_uninstall {
|
||||||
echo
|
echo
|
||||||
echo "If you want to disable the autocompletions, then"
|
echo "If you want to disable the autocompletions, then"
|
||||||
echo "you must run \"achar disable\" for each user."
|
echo "you must run \"achar disable\" for each user."
|
||||||
echo "This is recommended if you are planning to install"
|
|
||||||
echo "a new version."
|
|
||||||
echo
|
echo
|
||||||
echo "Press ENTER to continue or CTRL+C to STOP!"
|
echo "Press ENTER to continue or CTRL+C to STOP!"
|
||||||
read text
|
read text
|
||||||
|
|
||||||
rm $script_path
|
rm $script_path
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -307,8 +290,8 @@ function achar_update {
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Current version is $version_number"
|
echo "current version is $version_number"
|
||||||
echo "Latest version is $stable_version_number"
|
echo "latest version is $stable_version_number"
|
||||||
update_available="false"
|
update_available="false"
|
||||||
|
|
||||||
for ((i=0; i<${#version_number_array[@]}; i++)); do
|
for ((i=0; i<${#version_number_array[@]}; i++)); do
|
||||||
|
@ -343,12 +326,6 @@ function achar_update {
|
||||||
if [[ $update_available == "true" ]]; then
|
if [[ $update_available == "true" ]]; then
|
||||||
|
|
||||||
echo "Update is avaiable!"
|
echo "Update is avaiable!"
|
||||||
echo
|
|
||||||
echo "First run \"achar disable\" for all users."
|
|
||||||
echo "Then run \"achar uninstall\" as root or sudo."
|
|
||||||
echo "Lastly, follow the instructions at"
|
|
||||||
echo "https://git.zaks.web.za/zaks-web/achar"
|
|
||||||
echo "to install the latest version."
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
@ -362,6 +339,7 @@ function validate_achar_installation {
|
||||||
|
|
||||||
local achar_installation_error_code=""
|
local achar_installation_error_code=""
|
||||||
local what_test
|
local what_test
|
||||||
|
|
||||||
what_test=$1
|
what_test=$1
|
||||||
|
|
||||||
if [[ -d ~/.achar ]]; then
|
if [[ -d ~/.achar ]]; then
|
||||||
|
@ -395,6 +373,7 @@ function validate_achar_installation {
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "File corrupt: ~/.achar/completions" >&2
|
echo "File corrupt: ~/.achar/completions" >&2
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -486,6 +465,7 @@ function validate_host {
|
||||||
if [[ -z $1 ]]; then
|
if [[ -z $1 ]]; then
|
||||||
|
|
||||||
echo "Unexpected Error!"
|
echo "Unexpected Error!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -496,6 +476,7 @@ function validate_host {
|
||||||
if [[ ${#temp_array[@]} != 1 ]]; then
|
if [[ ${#temp_array[@]} != 1 ]]; then
|
||||||
|
|
||||||
echo "Invalid Hostname!"
|
echo "Invalid Hostname!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -508,6 +489,7 @@ function validate_host {
|
||||||
if [[ ${#temp_array[@]} != 2 ]]; then
|
if [[ ${#temp_array[@]} != 2 ]]; then
|
||||||
|
|
||||||
echo "Invalid Hostname!"
|
echo "Invalid Hostname!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -526,6 +508,7 @@ function validate_host {
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "Hostname is not an valid!"
|
echo "Hostname is not an valid!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -533,6 +516,7 @@ function validate_host {
|
||||||
if [[ ${username:0:1} =~ ^[0-9]$ ]] || [[ ! $username =~ ^[A-Za-z0-9_.-]+$ ]]; then
|
if [[ ${username:0:1} =~ ^[0-9]$ ]] || [[ ! $username =~ ^[A-Za-z0-9_.-]+$ ]]; then
|
||||||
|
|
||||||
echo "Username is not a valid format!"
|
echo "Username is not a valid format!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
62
src/achar.sh
62
src/achar.sh
|
@ -1,6 +1,5 @@
|
||||||
#!/bin/bash
|
|
||||||
## Title : ACHAR - Auto Completion of Hosts Add/Remove script
|
## Title : ACHAR - Auto Completion of Hosts Add/Remove script
|
||||||
## Version : 0.2
|
## Version : 0.1
|
||||||
## GIT Repo : https://git.zaks.web.za/zaks-web/achar
|
## GIT Repo : https://git.zaks.web.za/zaks-web/achar
|
||||||
## Author : Ze'ev Schurmann
|
## Author : Ze'ev Schurmann
|
||||||
## Company : ZAKS Web
|
## Company : ZAKS Web
|
||||||
|
@ -13,7 +12,7 @@
|
||||||
## USAGE
|
## USAGE
|
||||||
##
|
##
|
||||||
## From the bash terminal, type:
|
## From the bash terminal, type:
|
||||||
## $ achar {command} {context}
|
## $ achar {command} {hostname}
|
||||||
##
|
##
|
||||||
## COMMANDS
|
## COMMANDS
|
||||||
##
|
##
|
||||||
|
@ -23,7 +22,6 @@
|
||||||
##
|
##
|
||||||
## disable - disables auto completion of hostnames for current system user
|
## disable - disables auto completion of hostnames for current system user
|
||||||
## $ achar disable
|
## $ achar disable
|
||||||
## * does not delete the list of hosts stored at ~/.achar/hosts
|
|
||||||
##
|
##
|
||||||
## enable - enables auto completion of hostnames for current system user
|
## enable - enables auto completion of hostnames for current system user
|
||||||
## $ achar enable
|
## $ achar enable
|
||||||
|
@ -31,26 +29,15 @@
|
||||||
## help - displays this block of text
|
## help - displays this block of text
|
||||||
## $ achar help
|
## $ achar help
|
||||||
##
|
##
|
||||||
## license - displays the GPL3 and Later license
|
|
||||||
## $ achar license
|
|
||||||
##
|
|
||||||
## list - list all existing hosts from your list of common hosts
|
## list - list all existing hosts from your list of common hosts
|
||||||
## $ achar list
|
## $ achar list
|
||||||
## * You can use context to search for a specific hostname or part there of
|
## * You can use grep to search for a specific hostname or part there of
|
||||||
## $ achar list username
|
## $ achar list | grep username
|
||||||
## $ achar list part-of-hostname
|
## $ achar list | grep hostname
|
||||||
##
|
##
|
||||||
## remove - removes an existing host from your list of common hosts
|
## remove - removes an existing host from your list of common hosts
|
||||||
## $ achar remove username@hostname.domainname.tld
|
## $ achar rem username@hostname.domainname.tld
|
||||||
## $ achar remove username@1.2.3.4
|
## $ achar rem username@1.2.3.4
|
||||||
##
|
|
||||||
## reset - deletes all saved hosts
|
|
||||||
## $ achar reset
|
|
||||||
##
|
|
||||||
## uninstall - uninstalls achar from your system
|
|
||||||
## $ sudo achar uninstall
|
|
||||||
## # achar uninstall
|
|
||||||
## * does not delete the list of hosts stored at ~/.achar/hosts
|
|
||||||
##
|
##
|
||||||
## update - checks for an update to ACHAR and prompts you to install it
|
## update - checks for an update to ACHAR and prompts you to install it
|
||||||
## $ achar update
|
## $ achar update
|
||||||
|
@ -64,7 +51,9 @@ function achar_add {
|
||||||
local username_and_hostname
|
local username_and_hostname
|
||||||
|
|
||||||
username_and_hostname=$1
|
username_and_hostname=$1
|
||||||
|
|
||||||
validate_achar_installation hosts
|
validate_achar_installation hosts
|
||||||
|
|
||||||
validate_host "$username_and_hostname"
|
validate_host "$username_and_hostname"
|
||||||
|
|
||||||
if [[ -z $(cat ~/.achar/hosts | grep "$username_and_hostname") ]]; then
|
if [[ -z $(cat ~/.achar/hosts | grep "$username_and_hostname") ]]; then
|
||||||
|
@ -74,6 +63,7 @@ function achar_add {
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "$username_and_hostname is already added!" >&2
|
echo "$username_and_hostname is already added!" >&2
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -144,10 +134,6 @@ function achar_help {
|
||||||
|
|
||||||
echo "${line:3}"
|
echo "${line:3}"
|
||||||
|
|
||||||
elif [[ ${line:0:2} == "#!" ]]; then
|
|
||||||
|
|
||||||
donothing=0
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
@ -162,6 +148,7 @@ function achar_help {
|
||||||
function achar_license {
|
function achar_license {
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
curl -s https://git.zaks.web.za/zaks-web/achar/raw/branch/main/LICENSE | fmt
|
curl -s https://git.zaks.web.za/zaks-web/achar/raw/branch/main/LICENSE | fmt
|
||||||
|
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
|
@ -216,12 +203,9 @@ function achar_remove {
|
||||||
function achar_reset {
|
function achar_reset {
|
||||||
|
|
||||||
validate_achar_installation hosts
|
validate_achar_installation hosts
|
||||||
echo "This will delete all saved hosts and"
|
|
||||||
echo "and start from scratch."
|
|
||||||
echo
|
|
||||||
echo "Press ENTER to continue or CTRL+C to STOP!"
|
|
||||||
read text
|
|
||||||
rm ~/.achar/hosts
|
rm ~/.achar/hosts
|
||||||
|
|
||||||
touch ~/.achar/hosts
|
touch ~/.achar/hosts
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -239,11 +223,10 @@ function achar_uninstall {
|
||||||
echo
|
echo
|
||||||
echo "If you want to disable the autocompletions, then"
|
echo "If you want to disable the autocompletions, then"
|
||||||
echo "you must run \"achar disable\" for each user."
|
echo "you must run \"achar disable\" for each user."
|
||||||
echo "This is recommended if you are planning to install"
|
|
||||||
echo "a new version."
|
|
||||||
echo
|
echo
|
||||||
echo "Press ENTER to continue or CTRL+C to STOP!"
|
echo "Press ENTER to continue or CTRL+C to STOP!"
|
||||||
read text
|
read text
|
||||||
|
|
||||||
rm $script_path
|
rm $script_path
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -307,8 +290,8 @@ function achar_update {
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Current version is $version_number"
|
echo "current version is $version_number"
|
||||||
echo "Latest version is $stable_version_number"
|
echo "latest version is $stable_version_number"
|
||||||
update_available="false"
|
update_available="false"
|
||||||
|
|
||||||
for ((i=0; i<${#version_number_array[@]}; i++)); do
|
for ((i=0; i<${#version_number_array[@]}; i++)); do
|
||||||
|
@ -343,12 +326,6 @@ function achar_update {
|
||||||
if [[ $update_available == "true" ]]; then
|
if [[ $update_available == "true" ]]; then
|
||||||
|
|
||||||
echo "Update is avaiable!"
|
echo "Update is avaiable!"
|
||||||
echo
|
|
||||||
echo "First run \"achar disable\" for all users."
|
|
||||||
echo "Then run \"achar uninstall\" as root or sudo."
|
|
||||||
echo "Lastly, follow the instructions at"
|
|
||||||
echo "https://git.zaks.web.za/zaks-web/achar"
|
|
||||||
echo "to install the latest version."
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
@ -362,6 +339,7 @@ function validate_achar_installation {
|
||||||
|
|
||||||
local achar_installation_error_code=""
|
local achar_installation_error_code=""
|
||||||
local what_test
|
local what_test
|
||||||
|
|
||||||
what_test=$1
|
what_test=$1
|
||||||
|
|
||||||
if [[ -d ~/.achar ]]; then
|
if [[ -d ~/.achar ]]; then
|
||||||
|
@ -395,6 +373,7 @@ function validate_achar_installation {
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "File corrupt: ~/.achar/completions" >&2
|
echo "File corrupt: ~/.achar/completions" >&2
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -486,6 +465,7 @@ function validate_host {
|
||||||
if [[ -z $1 ]]; then
|
if [[ -z $1 ]]; then
|
||||||
|
|
||||||
echo "Unexpected Error!"
|
echo "Unexpected Error!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -496,6 +476,7 @@ function validate_host {
|
||||||
if [[ ${#temp_array[@]} != 1 ]]; then
|
if [[ ${#temp_array[@]} != 1 ]]; then
|
||||||
|
|
||||||
echo "Invalid Hostname!"
|
echo "Invalid Hostname!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -508,6 +489,7 @@ function validate_host {
|
||||||
if [[ ${#temp_array[@]} != 2 ]]; then
|
if [[ ${#temp_array[@]} != 2 ]]; then
|
||||||
|
|
||||||
echo "Invalid Hostname!"
|
echo "Invalid Hostname!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -526,6 +508,7 @@ function validate_host {
|
||||||
else
|
else
|
||||||
|
|
||||||
echo "Hostname is not an valid!"
|
echo "Hostname is not an valid!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -533,6 +516,7 @@ function validate_host {
|
||||||
if [[ ${username:0:1} =~ ^[0-9]$ ]] || [[ ! $username =~ ^[A-Za-z0-9_.-]+$ ]]; then
|
if [[ ${username:0:1} =~ ^[0-9]$ ]] || [[ ! $username =~ ^[A-Za-z0-9_.-]+$ ]]; then
|
||||||
|
|
||||||
echo "Username is not a valid format!"
|
echo "Username is not a valid format!"
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue