Compare commits

..

No commits in common. "558cc6213e76e13cd42f88d162e9d4202fad370f" and "dd65e038108774a8ebaf4f1bc3356118aadbc52c" have entirely different histories.

2 changed files with 46 additions and 78 deletions

62
achar
View File

@ -1,6 +1,5 @@
#!/bin/bash
## 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
## Author : Ze'ev Schurmann
## Company : ZAKS Web
@ -13,7 +12,7 @@
## USAGE
##
## From the bash terminal, type:
## $ achar {command} {context}
## $ achar {command} {hostname}
##
## COMMANDS
##
@ -23,7 +22,6 @@
##
## disable - disables auto completion of hostnames for current system user
## $ achar disable
## * does not delete the list of hosts stored at ~/.achar/hosts
##
## enable - enables auto completion of hostnames for current system user
## $ achar enable
@ -31,26 +29,15 @@
## help - displays this block of text
## $ achar help
##
## license - displays the GPL3 and Later license
## $ achar license
##
## list - list all existing hosts from your list of common hosts
## $ achar list
## * You can use context to search for a specific hostname or part there of
## $ achar list username
## $ achar list part-of-hostname
## * You can use grep to search for a specific hostname or part there of
## $ achar list | grep username
## $ achar list | grep hostname
##
## remove - removes an existing host from your list of common hosts
## $ achar remove username@hostname.domainname.tld
## $ achar remove 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
## $ achar rem username@hostname.domainname.tld
## $ achar rem username@1.2.3.4
##
## update - checks for an update to ACHAR and prompts you to install it
## $ achar update
@ -64,7 +51,9 @@ function achar_add {
local username_and_hostname
username_and_hostname=$1
validate_achar_installation hosts
validate_host "$username_and_hostname"
if [[ -z $(cat ~/.achar/hosts | grep "$username_and_hostname") ]]; then
@ -74,6 +63,7 @@ function achar_add {
else
echo "$username_and_hostname is already added!" >&2
exit 1
fi
@ -144,10 +134,6 @@ function achar_help {
echo "${line:3}"
elif [[ ${line:0:2} == "#!" ]]; then
donothing=0
else
echo
@ -162,6 +148,7 @@ function achar_help {
function achar_license {
echo
curl -s https://git.zaks.web.za/zaks-web/achar/raw/branch/main/LICENSE | fmt
if [[ $? != 0 ]]; then
@ -216,12 +203,9 @@ function achar_remove {
function achar_reset {
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
touch ~/.achar/hosts
}
@ -239,11 +223,10 @@ function achar_uninstall {
echo
echo "If you want to disable the autocompletions, then"
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 "Press ENTER to continue or CTRL+C to STOP!"
read text
rm $script_path
else
@ -307,8 +290,8 @@ function achar_update {
fi
echo "Current version is $version_number"
echo "Latest version is $stable_version_number"
echo "current version is $version_number"
echo "latest version is $stable_version_number"
update_available="false"
for ((i=0; i<${#version_number_array[@]}; i++)); do
@ -343,12 +326,6 @@ function achar_update {
if [[ $update_available == "true" ]]; then
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
@ -362,6 +339,7 @@ function validate_achar_installation {
local achar_installation_error_code=""
local what_test
what_test=$1
if [[ -d ~/.achar ]]; then
@ -395,6 +373,7 @@ function validate_achar_installation {
else
echo "File corrupt: ~/.achar/completions" >&2
exit 1
fi
@ -486,6 +465,7 @@ function validate_host {
if [[ -z $1 ]]; then
echo "Unexpected Error!"
exit 1
fi
@ -496,6 +476,7 @@ function validate_host {
if [[ ${#temp_array[@]} != 1 ]]; then
echo "Invalid Hostname!"
exit 1
fi
@ -508,6 +489,7 @@ function validate_host {
if [[ ${#temp_array[@]} != 2 ]]; then
echo "Invalid Hostname!"
exit 1
fi
@ -526,6 +508,7 @@ function validate_host {
else
echo "Hostname is not an valid!"
exit 1
fi
@ -533,6 +516,7 @@ function validate_host {
if [[ ${username:0:1} =~ ^[0-9]$ ]] || [[ ! $username =~ ^[A-Za-z0-9_.-]+$ ]]; then
echo "Username is not a valid format!"
exit 1
fi

View File

@ -1,6 +1,5 @@
#!/bin/bash
## 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
## Author : Ze'ev Schurmann
## Company : ZAKS Web
@ -13,7 +12,7 @@
## USAGE
##
## From the bash terminal, type:
## $ achar {command} {context}
## $ achar {command} {hostname}
##
## COMMANDS
##
@ -23,7 +22,6 @@
##
## disable - disables auto completion of hostnames for current system user
## $ achar disable
## * does not delete the list of hosts stored at ~/.achar/hosts
##
## enable - enables auto completion of hostnames for current system user
## $ achar enable
@ -31,26 +29,15 @@
## help - displays this block of text
## $ achar help
##
## license - displays the GPL3 and Later license
## $ achar license
##
## list - list all existing hosts from your list of common hosts
## $ achar list
## * You can use context to search for a specific hostname or part there of
## $ achar list username
## $ achar list part-of-hostname
## * You can use grep to search for a specific hostname or part there of
## $ achar list | grep username
## $ achar list | grep hostname
##
## remove - removes an existing host from your list of common hosts
## $ achar remove username@hostname.domainname.tld
## $ achar remove 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
## $ achar rem username@hostname.domainname.tld
## $ achar rem username@1.2.3.4
##
## update - checks for an update to ACHAR and prompts you to install it
## $ achar update
@ -64,7 +51,9 @@ function achar_add {
local username_and_hostname
username_and_hostname=$1
validate_achar_installation hosts
validate_host "$username_and_hostname"
if [[ -z $(cat ~/.achar/hosts | grep "$username_and_hostname") ]]; then
@ -74,6 +63,7 @@ function achar_add {
else
echo "$username_and_hostname is already added!" >&2
exit 1
fi
@ -144,10 +134,6 @@ function achar_help {
echo "${line:3}"
elif [[ ${line:0:2} == "#!" ]]; then
donothing=0
else
echo
@ -162,6 +148,7 @@ function achar_help {
function achar_license {
echo
curl -s https://git.zaks.web.za/zaks-web/achar/raw/branch/main/LICENSE | fmt
if [[ $? != 0 ]]; then
@ -216,12 +203,9 @@ function achar_remove {
function achar_reset {
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
touch ~/.achar/hosts
}
@ -239,11 +223,10 @@ function achar_uninstall {
echo
echo "If you want to disable the autocompletions, then"
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 "Press ENTER to continue or CTRL+C to STOP!"
read text
rm $script_path
else
@ -307,8 +290,8 @@ function achar_update {
fi
echo "Current version is $version_number"
echo "Latest version is $stable_version_number"
echo "current version is $version_number"
echo "latest version is $stable_version_number"
update_available="false"
for ((i=0; i<${#version_number_array[@]}; i++)); do
@ -343,12 +326,6 @@ function achar_update {
if [[ $update_available == "true" ]]; then
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
@ -362,6 +339,7 @@ function validate_achar_installation {
local achar_installation_error_code=""
local what_test
what_test=$1
if [[ -d ~/.achar ]]; then
@ -395,6 +373,7 @@ function validate_achar_installation {
else
echo "File corrupt: ~/.achar/completions" >&2
exit 1
fi
@ -486,6 +465,7 @@ function validate_host {
if [[ -z $1 ]]; then
echo "Unexpected Error!"
exit 1
fi
@ -496,6 +476,7 @@ function validate_host {
if [[ ${#temp_array[@]} != 1 ]]; then
echo "Invalid Hostname!"
exit 1
fi
@ -508,6 +489,7 @@ function validate_host {
if [[ ${#temp_array[@]} != 2 ]]; then
echo "Invalid Hostname!"
exit 1
fi
@ -526,6 +508,7 @@ function validate_host {
else
echo "Hostname is not an valid!"
exit 1
fi
@ -533,6 +516,7 @@ function validate_host {
if [[ ${username:0:1} =~ ^[0-9]$ ]] || [[ ! $username =~ ^[A-Za-z0-9_.-]+$ ]]; then
echo "Username is not a valid format!"
exit 1
fi