summaryrefslogtreecommitdiffstats
path: root/repofish
diff options
context:
space:
mode:
Diffstat (limited to 'repofish')
-rwxr-xr-xrepofish343
1 files changed, 343 insertions, 0 deletions
diff --git a/repofish b/repofish
new file mode 100755
index 0000000..8f3e4b8
--- /dev/null
+++ b/repofish
@@ -0,0 +1,343 @@
+#!/bin/sh
+
+## You can set these variables here or in your enviroment
+
+#SRC_PATH='/path/to/packages/sources'
+#REPO_PATH='/path/to/archlinux/repo'
+#REPO_NAME='repo_name'
+
+## Search variables
+URL_PREFIX='https://aur.archlinux.org/'
+SEARCH_STR='rpc/?v=5&type=search&by=name-desc&arg='
+
+add_packages() {
+ declare -a pkg=("${!1}")
+ for i in "${pkg[@]}"; do
+ if [ ! -d "${SRC_PATH}/$i" ]; then
+ cd ${SRC_PATH}
+ git clone ${URL_PREFIX}$i.git
+ else
+ echo 'WARNING: Package '"$i"' already present.'
+ fi
+ done
+}
+
+clone_package() {
+ if [ ! -d "${SRC_PATH}/$(echo $1 | awk -F '/' '{print $NF}' | cut -d '.' -f 1)" ]; then
+ cd ${SRC_PATH}
+ git clone $1
+ else
+ echo 'WARNING: Package already present.'
+ fi
+}
+
+rm_packages() {
+ declare -a pkg=("${!1}")
+ for i in "${pkg[@]}"; do
+ if [ -d "${SRC_PATH}/$i" ]; then
+ rm -rf ${SRC_PATH}/$i
+ else
+ echo 'WARNING: Package '"$i"' not present.'
+ fi
+ done
+}
+
+check_package() {
+ if [ -d "${SRC_PATH}/$1" ]; then
+ ${EDITOR} ${SRC_PATH}/$1/PKGBUILD
+ else
+ echo 'WARNING: Package '"$1"' not found.'
+ fi
+}
+
+list_packages() {
+ find ${SRC_PATH}/* -type d -prune | awk -F '/' '{print $NF}'
+}
+
+clean_packages() {
+ if [ "$1" != '' ]; then
+ 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
+}
+
+build_packages() {
+ if [ "$1" != '' ]; then
+ declare -a pkg=("${!1}")
+ for i in "${pkg[@]}"; do
+ cd $(find ${SRC_PATH}/* -type d -prune -iname "*$i")
+ makepkg -Cs
+ done
+ else
+ for i in $(find ${SRC_PATH}/* -type d -prune)
+ do
+ cd $i
+ makepkg -Cs
+ done
+ fi
+}
+
+upgrade_packages() {
+ if [ "$1" != '' ]; then
+ declare -a pkg=("${!1}")
+ for i in "${pkg[@]}"; do
+ cd $(find ${SRC_PATH}/* -type d -prune -iname "*$i")
+ git fetch
+ git diff origin/master
+ git merge
+ makepkg -Cs
+ done
+ else
+ for i in $(find ${SRC_PATH}/* -type d -prune)
+ do
+ cd $i
+ git fetch
+ git diff origin/master
+ git merge
+ makepkg -Cs
+ done
+ fi
+}
+
+update_packages() {
+ if [ "$1" != '' ]; then
+ declare -a pkg=("${!1}")
+ for i in "${pkg[@]}"; do
+ cd $(find ${SRC_PATH}/* -type d -prune -iname "*$i")
+ git fetch
+ git diff origin/master
+ git merge
+ done
+ else
+ for i in $(find ${SRC_PATH}/* -type d -prune)
+ do
+ cd $i
+ git fetch
+ git diff origin/master
+ git merge
+ done
+ fi
+}
+
+install_packages() {
+ declare -a pkg=("${!1}")
+ for i in "${pkg[@]}"; do
+ if [ -d "${SRC_PATH}/$i" ]; then
+ cd $(find ${SRC_PATH}/* -type d -prune -iname "*$i")
+ makepkg -Csi
+ else
+ echo 'WARNING: Package '"$i"' not found.'
+ fi
+ done
+}
+
+update_repo() {
+ if [ "$1" != '' ]; then
+ 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
+ fi
+}
+
+search_packages() {
+ declare -a key=("${!1}")
+ LIST_INST=$($0 list | tr '\n' '|')
+ CURL_JSN=$(curl -s $(echo ${URL_PREFIX}${SEARCH_STR}"${key[@]}" | sed -e 's/ /+/g'))
+ OUT_STR=$(jq -r '.results | .[] | [.Name, .Version], .Description' <<< ${CURL_JSN})
+ SEARCH_OUT=$(sed -e 's/\\//g' -e 's/\[/\\033\[1\;36m\[/g' -e 's/",/\\033\[1\;33m", \[\\033\[1\;32m/g' \
+ -e 's/\]/\\033\[1\;33m\]\\033\[1\;37m\]/g' <<< ${OUT_STR})
+ echo -ne ' \033[1;34m:: \033[1;37mYou searched using the following keywords (matching package name and/or description): "'
+ echo -ne \\033\[1\;33m${key[@]}\\033\[1\;37m\"
+ echo -e ${SEARCH_OUT} | sed -e 's/\[ /\n/g' -e 's/ *\] /\n\t/g' -e 's/", / /g' -e 's/"//g' | \
+ sed -E '/'"${LIST_INST::-1}"'[^-]/ s/$/ '"$(echo -e \\033\[1\;35m[ Installed ]\\033\[1\;37m)"'/'
+}
+
+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
+ echo ' USAGE: repo.sh COMMAND PKGNAME (default ALL)'
+ echo
+ echo ' add adds packages from from AUR'
+ echo ' clone (url) clones git package repository'
+ echo ' rm remove packages'
+ echo ' check check PKGBUILD'
+ echo ' list lists locally available packages'
+ echo ' update-repo updates the packages in the repo'
+ echo ' build builds the packages'
+ echo ' upgrade upgrades and builds the packages'
+ echo ' update updates the packages'
+ echo ' install builds and installs the package'
+ echo ' clean cleans the packages'
+ echo ' search searches packages in the AUR'
+ echo ' help prints this help'
+ echo
+
+ if [ "${SRC_PATH}" == '' ];then
+ set_variables
+ fi
+}
+
+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 [ "$2" == '' ]; then
+ echo 'ERROR: missing argument.'
+ else
+ N=2
+ while [ "${!N}" != '' ]; do
+ packages[$((N-2))]=${!N}
+ let N=N+1
+ done
+ add_packages packages[@]
+ fi
+elif [ "$1" == 'clone' ]; then
+ if [ "$3" != '' ]; then
+ echo 'ERROR: too many arguments.'
+ elif [ "$2" == '' ]; then
+ echo 'ERROR: missing argument.'
+ else
+ clone_package $2
+ fi
+elif [ "$1" == 'rm' ]; then
+ if [ "$2" == '' ]; then
+ echo 'ERROR: missing argument.'
+ else
+ N=2
+ while [ "${!N}" != '' ]; do
+ packages[$((N-2))]=${!N}
+ let N=N+1
+ done
+ rm_packages packages[@]
+ fi
+elif [ "$1" == 'check' ]; then
+ if [ "$3" != '' ]; then
+ echo 'ERROR: too many arguments.'
+ elif [ "$2" == '' ]; then
+ echo 'ERROR: missing argument.'
+ else
+ check_package $2
+ fi
+elif [ "$1" == 'list' ]; then
+ if [ "$2" != '' ]; then
+ echo 'ERROR: too many arguments.'
+ else
+ list_packages
+ fi
+elif [ "$1" == 'update-repo' ]; 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
+ N=2
+ while [ "${!N}" != '' ]; do
+ packages[$((N-2))]=${!N}
+ let N=N+1
+ done
+ update_repo packages[@]
+ else
+ update_repo
+ fi
+elif [ "$1" == 'build' ]; then
+ if [ "$2" != '' ]; then
+ N=2
+ while [ "${!N}" != '' ]; do
+ packages[$((N-2))]=${!N}
+ let N=N+1
+ done
+ build_packages packages[@]
+ else
+ build_packages
+ fi
+elif [ "$1" == 'upgrade' ]; then
+ if [ "$2" != '' ]; then
+ N=2
+ while [ "${!N}" != '' ]; do
+ packages[$((N-2))]=${!N}
+ let N=N+1
+ done
+ upgrade_packages packages[@]
+ else
+ upgrade_packages
+ fi
+elif [ "$1" == 'update' ]; then
+ if [ "$2" != '' ]; then
+ N=2
+ while [ "${!N}" != '' ]; do
+ packages[$((N-2))]=${!N}
+ let N=N+1
+ done
+ update_packages packages[@]
+ else
+ update_packages
+ fi
+elif [ "$1" == 'install' ]; then
+ if [ "$2" == '' ]; then
+ echo 'ERROR: missing argument.'
+ else
+ N=2
+ while [ "${!N}" != '' ]; do
+ packages[$((N-2))]=${!N}
+ let N=N+1
+ done
+ install_packages packages[@]
+ fi
+elif [ "$1" == 'clean' ]; then
+ if [ "$2" != '' ]; then
+ N=2
+ while [ "${!N}" != '' ]; do
+ packages[$((N-2))]=${!N}
+ let N=N+1
+ done
+ clean_packages packages[@]
+ else
+ clean_packages
+ fi
+elif [ "$1" == 'search' ]; then
+ if [ "$2" == '' ]; then
+ echo 'ERROR: missing argument(s).'
+ else
+ N=2
+ while [ "${!N}" != '' ]; do
+ keywords[$((N-2))]=${!N}
+ let N=N+1
+ done
+ search_packages keywords[@]
+ fi
+else
+ echo 'ERROR: unrecocnized command.'
+fi