Compare commits

..

2 Commits

Author SHA1 Message Date
Ze'ev Schurmann 558cc6213e v0.2 - Reworked code 2024-08-01 20:05:58 +02:00
Ze'ev Schurmann 1e869ee9f2 v0.2 - updated and neatened code 2024-08-01 20:03:40 +02:00
2 changed files with 78 additions and 46 deletions

62
achar
View File

@ -1,5 +1,6 @@
#!/bin/bash
## Title : ACHAR - Auto Completion of Hosts Add/Remove script
## Version : 0.1
## Version : 0.2
## GIT Repo : https://git.zaks.web.za/zaks-web/achar
## Author : Ze'ev Schurmann
## Company : ZAKS Web
@ -12,7 +13,7 @@
## USAGE
##
## From the bash terminal, type:
## $ achar {command} {hostname}
## $ achar {command} {context}
##
## COMMANDS
##
@ -22,6 +23,7 @@
##
## 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
@ -29,15 +31,26 @@
## 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 grep to search for a specific hostname or part there of
## $ achar list | grep username
## $ achar list | grep hostname
## * You can use context to search for a specific hostname or part there of
## $ achar list username
## $ achar list part-of-hostname
##
## remove - removes an existing host from your list of common hosts
## $ achar rem username@hostname.domainname.tld
## $ achar rem username@1.2.3.4
## $ 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
##
## update - checks for an update to ACHAR and prompts you to install it
## $ achar update
@ -51,9 +64,7 @@ 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
@ -63,7 +74,6 @@ function achar_add {
else
echo "$username_and_hostname is already added!" >&2
exit 1
fi
@ -134,6 +144,10 @@ function achar_help {
echo "${line:3}"
elif [[ ${line:0:2} == "#!" ]]; then
donothing=0
else
echo
@ -148,7 +162,6 @@ 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
@ -203,9 +216,12 @@ 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
}
@ -223,10 +239,11 @@ 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
@ -290,8 +307,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
@ -326,6 +343,12 @@ 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
@ -339,7 +362,6 @@ function validate_achar_installation {
local achar_installation_error_code=""
local what_test
what_test=$1
if [[ -d ~/.achar ]]; then
@ -373,7 +395,6 @@ function validate_achar_installation {
else
echo "File corrupt: ~/.achar/completions" >&2
exit 1
fi
@ -465,7 +486,6 @@ function validate_host {
if [[ -z $1 ]]; then
echo "Unexpected Error!"
exit 1
fi
@ -476,7 +496,6 @@ function validate_host {
if [[ ${#temp_array[@]} != 1 ]]; then
echo "Invalid Hostname!"
exit 1
fi
@ -489,7 +508,6 @@ function validate_host {
if [[ ${#temp_array[@]} != 2 ]]; then
echo "Invalid Hostname!"
exit 1
fi
@ -508,7 +526,6 @@ function validate_host {
else
echo "Hostname is not an valid!"
exit 1
fi
@ -516,7 +533,6 @@ 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,5 +1,6 @@
#!/bin/bash
## Title : ACHAR - Auto Completion of Hosts Add/Remove script
## Version : 0.1
## Version : 0.2
## GIT Repo : https://git.zaks.web.za/zaks-web/achar
## Author : Ze'ev Schurmann
## Company : ZAKS Web
@ -12,7 +13,7 @@
## USAGE
##
## From the bash terminal, type:
## $ achar {command} {hostname}
## $ achar {command} {context}
##
## COMMANDS
##
@ -22,6 +23,7 @@
##
## 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
@ -29,15 +31,26 @@
## 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 grep to search for a specific hostname or part there of
## $ achar list | grep username
## $ achar list | grep hostname
## * You can use context to search for a specific hostname or part there of
## $ achar list username
## $ achar list part-of-hostname
##
## remove - removes an existing host from your list of common hosts
## $ achar rem username@hostname.domainname.tld
## $ achar rem username@1.2.3.4
## $ 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
##
## update - checks for an update to ACHAR and prompts you to install it
## $ achar update
@ -51,9 +64,7 @@ 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
@ -63,7 +74,6 @@ function achar_add {
else
echo "$username_and_hostname is already added!" >&2
exit 1
fi
@ -134,6 +144,10 @@ function achar_help {
echo "${line:3}"
elif [[ ${line:0:2} == "#!" ]]; then
donothing=0
else
echo
@ -148,7 +162,6 @@ 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
@ -203,9 +216,12 @@ 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
}
@ -223,10 +239,11 @@ 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
@ -290,8 +307,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
@ -326,6 +343,12 @@ 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
@ -339,7 +362,6 @@ function validate_achar_installation {
local achar_installation_error_code=""
local what_test
what_test=$1
if [[ -d ~/.achar ]]; then
@ -373,7 +395,6 @@ function validate_achar_installation {
else
echo "File corrupt: ~/.achar/completions" >&2
exit 1
fi
@ -465,7 +486,6 @@ function validate_host {
if [[ -z $1 ]]; then
echo "Unexpected Error!"
exit 1
fi
@ -476,7 +496,6 @@ function validate_host {
if [[ ${#temp_array[@]} != 1 ]]; then
echo "Invalid Hostname!"
exit 1
fi
@ -489,7 +508,6 @@ function validate_host {
if [[ ${#temp_array[@]} != 2 ]]; then
echo "Invalid Hostname!"
exit 1
fi
@ -508,7 +526,6 @@ function validate_host {
else
echo "Hostname is not an valid!"
exit 1
fi
@ -516,7 +533,6 @@ 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