diff --git a/achar b/achar index 3e529b5..ce19e53 100644 --- a/achar +++ b/achar @@ -1,5 +1,5 @@ ## 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 +12,7 @@ ## USAGE ## ## From the bash terminal, type: -## $ achar {command} {hostname} +## $ achar {command} {context} ## ## COMMANDS ## @@ -22,6 +22,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 +30,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 +63,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 +73,6 @@ function achar_add { else echo "$username_and_hostname is already added!" >&2 - exit 1 fi @@ -148,7 +157,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 +211,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 +234,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 +302,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 +338,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 +357,6 @@ function validate_achar_installation { local achar_installation_error_code="" local what_test - what_test=$1 if [[ -d ~/.achar ]]; then @@ -373,7 +390,6 @@ function validate_achar_installation { else echo "File corrupt: ~/.achar/completions" >&2 - exit 1 fi @@ -465,7 +481,6 @@ function validate_host { if [[ -z $1 ]]; then echo "Unexpected Error!" - exit 1 fi @@ -476,7 +491,6 @@ function validate_host { if [[ ${#temp_array[@]} != 1 ]]; then echo "Invalid Hostname!" - exit 1 fi @@ -489,7 +503,6 @@ function validate_host { if [[ ${#temp_array[@]} != 2 ]]; then echo "Invalid Hostname!" - exit 1 fi @@ -508,7 +521,6 @@ function validate_host { else echo "Hostname is not an valid!" - exit 1 fi @@ -516,7 +528,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 diff --git a/src/achar.sh b/src/achar.sh index 3e529b5..ce19e53 100644 --- a/src/achar.sh +++ b/src/achar.sh @@ -1,5 +1,5 @@ ## 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 +12,7 @@ ## USAGE ## ## From the bash terminal, type: -## $ achar {command} {hostname} +## $ achar {command} {context} ## ## COMMANDS ## @@ -22,6 +22,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 +30,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 +63,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 +73,6 @@ function achar_add { else echo "$username_and_hostname is already added!" >&2 - exit 1 fi @@ -148,7 +157,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 +211,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 +234,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 +302,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 +338,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 +357,6 @@ function validate_achar_installation { local achar_installation_error_code="" local what_test - what_test=$1 if [[ -d ~/.achar ]]; then @@ -373,7 +390,6 @@ function validate_achar_installation { else echo "File corrupt: ~/.achar/completions" >&2 - exit 1 fi @@ -465,7 +481,6 @@ function validate_host { if [[ -z $1 ]]; then echo "Unexpected Error!" - exit 1 fi @@ -476,7 +491,6 @@ function validate_host { if [[ ${#temp_array[@]} != 1 ]]; then echo "Invalid Hostname!" - exit 1 fi @@ -489,7 +503,6 @@ function validate_host { if [[ ${#temp_array[@]} != 2 ]]; then echo "Invalid Hostname!" - exit 1 fi @@ -508,7 +521,6 @@ function validate_host { else echo "Hostname is not an valid!" - exit 1 fi @@ -516,7 +528,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