From 7656e970dea4575cad327794391cf763559e0a7b Mon Sep 17 00:00:00 2001 From: Alex Epstein Date: Thu, 6 Jul 2017 20:45:32 -0400 Subject: [PATCH] Getting rid of redundant code in install and unisntall --- install.sh | 204 ++++++++++----------------------------------------- uninstall.sh | 147 ++++++------------------------------- 2 files changed, 63 insertions(+), 288 deletions(-) diff --git a/install.sh b/install.sh index 72adff9..6d3aed9 100755 --- a/install.sh +++ b/install.sh @@ -2,118 +2,40 @@ # Author: Alexander Epstein https://github.com/alexanderepstein currentVersion="1.10.1" -if [[ $# == 0 ]]; then - - echo -n "Do you wish to install currency [Y/n]: " +askInstall() +{ + echo -n "Do you wish to install $1 [Y/n]: " read -r answer if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd currency || exit 1 + cd $1 || return 1 + ./install.sh || return 1 + cd .. || return 1 + fi +} + +updateTool() +{ + if [[ -f /usr/local/bin/$1 ]];then + cd $1 || exit 1 ./install.sh || exit 1 cd .. || exit 1 fi +} - unset answer - echo -n "Do you wish to install stocks [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd stocks || exit 1 - ./install.sh - cd .. || exit 1 - - fi - - unset answer - echo -n "Do you wish to install weather [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd weather || exit 1 - ./install.sh - cd .. || exit 1 - - fi - - unset answer - echo -n "Do you wish to install crypt [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd crypt || exit 1 - ./install.sh - cd .. || exit 1 - - fi - - unset answer - echo -n "Do you wish to install movies [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd movies || exit 1 - ./install.sh - cd .. || exit 1 - fi - - unset answer - echo -n "Do you wish to install taste [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd taste || exit 1 - ./install.sh - cd .. || exit 1 - fi - - unset answer - echo -n "Do you wish to install short [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd short || exit 1 - ./install.sh - cd .. || exit 1 - fi - - unset answer - echo -n "Do you wish to install geo [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd geo || exit 1 - ./install.sh - cd .. || exit 1 - fi - - unset answer - echo -n "Do you wish to install cheat [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd cheat || exit 1 - ./install.sh - cd .. || exit 1 - fi - - unset answer - echo -n "Do you wish to install ytview [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd ytview || exit 1 - ./install.sh - cd .. || exit 1 - fi - - unset answer - echo -n "Do you wish to install cloudup [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd cloudup || exit 1 - ./install.sh - cd .. || exit 1 - fi - - unset answer - echo -n "Do you wish to install qrify [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd qrify || exit 1 - ./install.sh - cd .. || exit 1 - fi +if [[ $# == 0 ]]; then + askInstall currency || exit 1 + askInstall stocks || exit 1 + askInstall weather || exit 1 + askInstall crypt || exit 1 + askInstall movies || exit 1 + askInstall taste || exit 1 + askInstall short || exit 1 + askInstall geo || exit 1 + askInstall cheat || exit 1 + askInstall ytview || exit 1 + askInstall cloudup || exit 1 + askInstall qrify || exit 1 fi if [[ $1 == "currency" ]];then @@ -203,66 +125,18 @@ elif [[ $1 == "all" ]];then cd .. || exit 1 elif [[ $1 == "update" ]]; then echo "Updating scripts..." - if [[ -f /usr/local/bin/currency ]];then - cd currency || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/stocks ]];then - cd stocks || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/weather ]];then - cd weather || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/crypt ]];then - cd crypt || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/movies ]];then - cd movies || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/taste ]];then - cd taste || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/short ]];then - cd short || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/geo ]];then - cd geo || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/cheat ]];then - cd cheat || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/ytview ]];then - cd ytview || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/cloudup ]];then - cd cloudup || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi - if [[ -f /usr/local/bin/qrify ]];then - cd qrify || exit 1 - ./install.sh || exit 1 - cd .. || exit 1 - fi + updateTool currency + updateTool stocks + updateTool weather + updateTool crypt + updateTool movies + updateTool taste + updateTool short + updateTool geo + updateTool cheat + updateTool ytview + updateTool cloudup + updateTool qrify fi echo -n "( •_•)" diff --git a/uninstall.sh b/uninstall.sh index 4ff4580..9ed4bc9 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,129 +1,30 @@ #!/bin/bash # Author: Alexander Epstein https://github.com/alexanderepstein -if [[ -f /usr/local/bin/currency ]];then - echo -n "Do you wish to uninstall currency [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd currency || exit 1 - ./uninstall.sh || exit 1 - cd .. || exit 1 +askUninstall() +{ + if [[ -f /usr/local/bin/$1 ]];then + echo -n "Do you wish to uninstall $1 [Y/n]: " + read -r answer + if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then + cd $1 || return 1 + ./uninstall.sh || return 1 + cd .. || return 1 + fi + unset answer fi - unset answer -fi +} -if [[ -f /usr/local/bin/stocks ]];then - echo -n "Do you wish to uninstall stocks [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd stocks || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi - unset answer -fi - -if [[ -f /usr/local/bin/weather ]];then - echo -n "Do you wish to uninstall weather [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd weather || exit 1 - ./uninstall.sh - cd .. || exit 1 - - fi - unset answer -fi - -if [[ -f /usr/local/bin/crypt ]];then - echo -n "Do you wish to uninstall crypt [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd crypt || exit 1 - ./uninstall.sh - cd .. || exit 1 - - fi - unset answer -fi - -if [[ -f /usr/local/bin/movies ]];then - echo -n "Do you wish to uninstall movies [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd movies || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi -fi - -if [[ -f /usr/local/bin/taste ]];then - echo -n "Do you wish to uninstall taste [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd taste || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi -fi - -if [[ -f /usr/local/bin/short ]];then - echo -n "Do you wish to uninstall short [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd short || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi -fi - -if [[ -f /usr/local/bin/geo ]];then - echo -n "Do you wish to uninstall geo [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd geo || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi -fi - -if [[ -f /usr/local/bin/cheat ]];then - echo -n "Do you wish to uninstall cheat [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd cheat || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi -fi - -if [[ -f /usr/local/bin/ytview ]];then - echo -n "Do you wish to uninstall ytview [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd ytview || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi -fi - -if [[ -f /usr/local/bin/cloudup ]];then - echo -n "Do you wish to uninstall cloudup [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd cloudup || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi -fi - -if [[ -f /usr/local/bin/qrify ]];then - echo -n "Do you wish to uninstall qrify [Y/n]: " - read -r answer - if [[ "$answer" == "Y" || "$answer" == "y" ]] ;then - cd qrify || exit 1 - ./uninstall.sh - cd .. || exit 1 - fi -fi +askUninstall currency || exit 1 +askUninstall stocks || exit 1 +askUninstall weather || exit 1 +askUninstall crypt || exit 1 +askUninstall movies || exit 1 +askUninstall taste || exit 1 +askUninstall short || exit 1 +askUninstall geo || exit 1 +askUninstall cheat || exit 1 +askUninstall ytview || exit 1 +askUninstall cloudup || exit 1 +askUninstall qrify || exit 1