From f849f35bdbffe7a22268df08cd906e134a5c5c9a Mon Sep 17 00:00:00 2001 From: Seppia Date: Sun, 3 Jun 2018 13:51:24 +0200 Subject: Support o multiple packages This completes the support for multiple packages commands, adding it to clean, update and upgrade functions. --- repo.sh | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/repo.sh b/repo.sh index e37984a..8edf35e 100755 --- a/repo.sh +++ b/repo.sh @@ -56,7 +56,10 @@ list_packages() { clean_packages() { if [ "$1" != '' ]; then - find ${SRC_PATH} -type f -iname "*$1*.pkg.tar.xz" -exec rm {} \; + declare -a pkg=("${!1}") + for i in "${pkg[@]}"; do + find ${SRC_PATH} -type f -iname "*$i*.pkg.tar.xz" -exec rm {} \; + done else find ${SRC_PATH} -type f -iname "*.pkg.tar.xz" -exec rm {} \; fi @@ -80,9 +83,12 @@ build_packages() { upgrade_packages() { if [ "$1" != '' ]; then - cd $(find ${SRC_PATH}/* -type d -prune -iname "*$1") - git pull - makepkg -Cs + declare -a pkg=("${!1}") + for i in "${pkg[@]}"; do + cd $(find ${SRC_PATH}/* -type d -prune -iname "*$i") + git pull + makepkg -Cs + done else for i in $(find ${SRC_PATH}/* -type d -prune) do @@ -108,8 +114,11 @@ install_package() { update_repo() { if [ "$1" != '' ]; then - find ${SRC_PATH} -type f -iname "*$1*pkg.tar.xz" -exec cp {} ${REPO_PATH}/x86_64/ \; - repo-add ${REPO_PATH}/x86_64/${REPO_NAME}.db.tar.gz ${REPO_PATH}/x86_64/*$1*.pkg.tar.xz + declare -a pkg=("${!1}") + for i in "${pkg[@]}"; do + find ${SRC_PATH} -type f -iname "*$i*pkg.tar.xz" -exec cp {} ${REPO_PATH}/x86_64/ \; + repo-add ${REPO_PATH}/x86_64/${REPO_NAME}.db.tar.gz ${REPO_PATH}/x86_64/*$i*.pkg.tar.xz + done else find ${SRC_PATH} -type f -iname "*pkg.tar.xz" -exec cp {} ${REPO_PATH}/x86_64/ \; repo-add ${REPO_PATH}/x86_64/${REPO_NAME}.db.tar.gz ${REPO_PATH}/x86_64/*.pkg.tar.xz @@ -223,16 +232,19 @@ elif [ "$1" == 'list' ]; then list_packages fi elif [ "$1" == 'update' ]; then - if [ "$3" != '' ]; then - echo 'ERROR: too many arguments.' - elif [ "${REPO_PATH}" == '' ];then + if [ "${REPO_PATH}" == '' ];then echo 'ERROR: REPO_PATH variable not set.' elif [ ! -d "${REPO_PATH}" ]; then echo 'ERROR: REPO_PATH variable set to invalid path.' elif [ "${REPO_NAME}" == '' ];then echo 'ERROR: REPO_NAME variable not set.' elif [ "$2" != '' ]; then - update_repo $2 + N=2 + while [ "${!N}" != '' ]; do + packages[$((N-2))]=${!N} + let N=N+1 + done + update_repo packages[@] else update_repo fi @@ -248,10 +260,13 @@ elif [ "$1" == 'build' ]; then build_packages fi elif [ "$1" == 'upgrade' ]; then - if [ "$3" != '' ]; then - echo 'ERROR: too many arguments.' - elif [ "$2" != '' ]; then - upgrade_packages $2 + if [ "$2" != '' ]; then + N=2 + while [ "${!N}" != '' ]; do + packages[$((N-2))]=${!N} + let N=N+1 + done + upgrade_packages packages[@] else upgrade_packages fi @@ -267,10 +282,13 @@ elif [ "$1" == 'install' ]; then install_package packages[@] fi elif [ "$1" == 'clean' ]; then - if [ "$3" != '' ]; then - echo 'ERROR: too many arguments.' - elif [ "$2" != '' ]; then - clean_packages $2 + if [ "$2" != '' ]; then + N=2 + while [ "${!N}" != '' ]; do + packages[$((N-2))]=${!N} + let N=N+1 + done + clean_packages packages[@] else clean_packages fi -- cgit v1.2.3