commit 3b31da03ea422160a5d1e86330460d46ab59ae2b
parent 3be44e65b18aa0ae972dbbc334645e37c3cf0918
Author: finwo <finwo@pm.me>
Date: Sat, 28 Jan 2023 21:41:42 +0100
Added support for loading pkg locations from repositories
Diffstat:
5 files changed, 70 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
@@ -16,11 +16,13 @@ Commands:
a(dd) Add a new dependency to the project
i(nstall) Install all the project's dependencies
h(elp) [topic] Show this help or the top-level info about a command
+ r(epo(sitory)) Repository management
Help topics:
global This help text
add More detailed explanation on the add command
install More detailed explanation on the install command
+ repository More detailed explanation on the repository command
```
Installation
diff --git a/dist/dep b/dist/dep
@@ -74,13 +74,42 @@ function arg_a {
return $?
}
function arg_add {
- if [ $# != 2 ]; then
+
+ # Check if name exists in the repositories
+ # Returns if found
+ mkdir -p "${HOME}/.config/finwo/dep/repositories.d"
+ while read repo; do
+
+ # Trim whitespace
+ repo=${repo##*( )}
+ repo=${repo%%*( )}
+
+ # Remove comments and empty lines
+ if [[ "${repo:0:1}" == '#' ]] || [[ "${repo:0:1}" == ';' ]] || [[ "${#repo}" == 0 ]]; then
+ continue
+ fi
+
+ while read line; do
+ pkgname="${line%%=*}"
+ pkgloc="${line##*=}"
+ # If found, return it
+ if [ "${pkgname}" == "$1" ]; then
+ CMD_ADD_SRC="${pkgloc}"
+ break 2
+ fi
+ done < <(curl --location --silent "${repo}")
+ done < <(find "${HOME}/.config/finwo/dep/repositories.d" -type f -name '*.cnf' | xargs -n 1 -P 1 cat)
+
+ # Need 2 arguments from here on out
+ if [ -z "${CMD_ADD_SRC}" ] && [ $# != 2 ]; then
echo "Add command requires 2 arguments" >&2
exit 1
fi
CMD_ADD_PKG="$1"
- CMD_ADD_SRC="$2"
+ if [ -z "${CMD_ADD_SRC}" ]; then
+ CMD_ADD_SRC="$2"
+ fi
return 0
}
@@ -286,7 +315,7 @@ function cmd_install_dep {
# Download the assumed tarball
mkdir -p "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}"
if [ ! -f "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-pkg" ]; then
- curl --location --progress-bar "${SRC}" --output "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-pkg"
+ curl --location --progress-bar "${origin}" --output "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-pkg"
fi
# Extract tarball
tar --extract --directory "${CMD_INSTALL_PKG_DEST}/${name}/" --strip-components 1 --file="${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-pkg"
diff --git a/src/command/add/index.sh b/src/command/add/index.sh
@@ -12,13 +12,42 @@ function arg_a {
return $?
}
function arg_add {
- if [ $# != 2 ]; then
+
+ # Check if name exists in the repositories
+ # Returns if found
+ mkdir -p "${HOME}/.config/finwo/dep/repositories.d"
+ while read repo; do
+
+ # Trim whitespace
+ repo=${repo##*( )}
+ repo=${repo%%*( )}
+
+ # Remove comments and empty lines
+ if [[ "${repo:0:1}" == '#' ]] || [[ "${repo:0:1}" == ';' ]] || [[ "${#repo}" == 0 ]]; then
+ continue
+ fi
+
+ while read line; do
+ pkgname="${line%%=*}"
+ pkgloc="${line##*=}"
+ # If found, return it
+ if [ "${pkgname}" == "$1" ]; then
+ CMD_ADD_SRC="${pkgloc}"
+ break 2
+ fi
+ done < <(curl --location --silent "${repo}")
+ done < <(find "${HOME}/.config/finwo/dep/repositories.d" -type f -name '*.cnf' | xargs -n 1 -P 1 cat)
+
+ # Need 2 arguments from here on out
+ if [ -z "${CMD_ADD_SRC}" ] && [ $# != 2 ]; then
echo "Add command requires 2 arguments" >&2
exit 1
fi
CMD_ADD_PKG="$1"
- CMD_ADD_SRC="$2"
+ if [ -z "${CMD_ADD_SRC}" ]; then
+ CMD_ADD_SRC="$2"
+ fi
return 0
}
diff --git a/src/command/install/index.sh b/src/command/install/index.sh
@@ -85,7 +85,7 @@ function cmd_install_dep {
# Download the assumed tarball
mkdir -p "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}"
if [ ! -f "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/tarball-pkg" ]; then
- curl --location --progress-bar "${SRC}" --output "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/tarball-pkg"
+ curl --location --progress-bar "${origin}" --output "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/tarball-pkg"
fi
# Extract tarball
tar --extract --directory "${CMD_INSTALL_PKG_DEST}/${name}/" --strip-components 1 --file="${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/tarball-pkg"
diff --git a/src/command/repo/index.sh b/src/command/repo/index.sh
@@ -45,12 +45,12 @@ function cmd_repo {
function cmd_repository {
case "${CMD_REPO_CMD}" in
add)
- mkdir -p "${HOME}/.config/finwo/dep/repositories.d"
- echo "${CMD_REPO_LOC}" >> "${HOME}/.config/finwo/dep/repositories.d/${CMD_REPO_NAME}.cnf"
+ mkdir -p "${HOME}/.config/finwo/__NAME/repositories.d"
+ echo "${CMD_REPO_LOC}" >> "${HOME}/.config/finwo/__NAME/repositories.d/${CMD_REPO_NAME}.cnf"
;;
del)
- mkdir -p "${HOME}/.config/finwo/dep/repositories.d"
- rm -f "${HOME}/.config/finwo/dep/repositories.d/${CMD_REPO_NAME}.cnf"
+ mkdir -p "${HOME}/.config/finwo/__NAME/repositories.d"
+ rm -f "${HOME}/.config/finwo/__NAME/repositories.d/${CMD_REPO_NAME}.cnf"
;;
*)
echo "Unknown command: ${CMD_REPO_CMD}" >&2