From 23e9d01f0c83ae18faaab23eabc4d4ba18611146 Mon Sep 17 00:00:00 2001 From: Seppia Date: Sat, 2 Jun 2018 12:40:36 +0200 Subject: Function calls reorder and messages fix Call help function as the first option and uniformed error/warning messages. --- repo.sh | 77 ++++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/repo.sh b/repo.sh index afc85ee..dbddcce 100755 --- a/repo.sh +++ b/repo.sh @@ -15,7 +15,7 @@ add_package() { cd ${SRC_PATH} git clone ${CLONE_PREFIX}$1.git else - echo 'Package already present.' + echo 'WARNING: Package already present.' fi } @@ -24,7 +24,7 @@ clone_package() { cd ${SRC_PATH} git clone $1 else - echo 'Package already present.' + echo 'WARNING: Package already present.' fi } @@ -32,7 +32,7 @@ rm_package() { if [ -d "${SRC_PATH}/$1" ]; then rm -rf ${SRC_PATH}/$1 else - echo 'Package not present.' + echo 'WARNING: Package not present.' fi } @@ -40,7 +40,7 @@ check_package() { if [ -d "${SRC_PATH}/$1" ]; then ${EDITOR} ${SRC_PATH}/$1/PKGBUILD else - echo 'Package not found.' + echo 'WARNING: Package not found.' fi } @@ -90,7 +90,7 @@ install_package() { git pull makepkg -Csi else - echo 'Package not found.' + echo 'WARNING: Package not found.' fi } @@ -114,6 +114,19 @@ search_packages() { echo ${OUT_STR} | sed -e 's/\[ /\n/g' -e 's/ *\] /\n\t/g' -e 's/"*, /\//g' -e 's/"//g' } +set_variables() { + echo "WARNING: SRC_PATH variable not set." + echo + echo "You need to set the following variables in your profile:" + echo + echo " export SRC_PATH='/path/to/packages/sources'" + echo " export REPO_PATH='/path/to/archlinux/repo'" + echo " export REPO_NAME='repo_name'" + echo + echo "The REPO_PATH and REPO_NAME variables are only needed if you use the local repo feature." + echo "Just set the SRC_PATH if you don't intend to use it." +} + print_help() { echo 'repo.sh SEPPIOFISH repo tool' echo @@ -132,55 +145,65 @@ print_help() { echo ' search searches packages in AUR' echo ' help prints this help' echo + + if [ "${SRC_PATH}" == '' ];then + set_variables + fi } -if [ "${SRC_PATH}" == '' ];then - echo 'ERROR: SRC_PATH variable not set.' +if [ "$1" == 'help' ]; then + if [ "$2" != '' ]; then + echo 'ERROR: too many arguments.' + else + print_help + fi +elif [ "${SRC_PATH}" == '' ];then + set_variables elif [ ! -d "${SRC_PATH}" ]; then echo 'ERROR: SRC_PATH variable set to invalid path.' elif [ "$1" == '' ]; then echo 'warning: no command called.' elif [ "$1" == 'add' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "$2" == '' ]; then - echo 'error: missing argument.' + echo 'ERROR: missing argument.' else add_package $2 fi elif [ "$1" == 'clone' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "$2" == '' ]; then - echo 'error: missing argument.' + echo 'ERROR: missing argument.' else clone_package $2 fi elif [ "$1" == 'rm' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "$2" == '' ]; then - echo 'error: missing argument.' + echo 'ERROR: missing argument.' else rm_package $2 fi elif [ "$1" == 'check' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "$2" == '' ]; then - echo 'error: missing argument.' + echo 'ERROR: missing argument.' else check_package $2 fi elif [ "$1" == 'list' ]; then if [ "$2" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' else list_packages fi elif [ "$1" == 'update' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "${REPO_PATH}" == '' ];then echo 'ERROR: REPO_PATH variable not set.' elif [ ! -d "${REPO_PATH}" ]; then @@ -194,7 +217,7 @@ elif [ "$1" == 'update' ]; then fi elif [ "$1" == 'build' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "$2" != '' ]; then build_packages $2 else @@ -202,7 +225,7 @@ elif [ "$1" == 'build' ]; then fi elif [ "$1" == 'upgrade' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "$2" != '' ]; then upgrade_packages $2 else @@ -210,15 +233,15 @@ elif [ "$1" == 'upgrade' ]; then fi elif [ "$1" == 'install' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "$2" == '' ]; then - echo 'error: missing argument.' + echo 'ERROR: missing argument.' else install_package $2 fi elif [ "$1" == 'clean' ]; then if [ "$3" != '' ]; then - echo 'error: too many arguments.' + echo 'ERROR: too many arguments.' elif [ "$2" != '' ]; then clean_packages $2 else @@ -226,7 +249,7 @@ elif [ "$1" == 'clean' ]; then fi elif [ "$1" == 'search' ]; then if [ "$2" == '' ]; then - echo 'error: missing argument(s).' + echo 'ERROR: missing argument(s).' else N=2 while [ "${!N}" != '' ]; do @@ -235,12 +258,6 @@ elif [ "$1" == 'search' ]; then done search_packages keywords[@] fi -elif [ "$1" == 'help' ]; then - if [ "$2" != '' ]; then - echo 'error: too many arguments.' - else - print_help - fi else - echo 'error: unrecocnized command.' + echo 'ERROR: unrecocnized command.' fi -- cgit v1.2.3