dep

Package manager for embedded C libraries
git clone git://git.finwo.net/app/dep
Log | Files | Refs | README | LICENSE

commit 3be44e65b18aa0ae972dbbc334645e37c3cf0918
parent 37f03ba9c9d78331770237987b7c8e318da99ec9
Author: finwo <finwo@pm.me>
Date:   Sat, 28 Jan 2023 21:14:58 +0100

Added repo command for basic repository management

Diffstat:
Mdist/dep | 43+++++++++++++++++++++++++++++++++++--------
Msrc/command/help/topic/global.txt | 2++
Asrc/command/repo/help.txt | 6++++++
Asrc/command/repo/index.sh | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/main.sh | 1+
5 files changed, 108 insertions(+), 8 deletions(-)

diff --git a/dist/dep b/dist/dep @@ -12,11 +12,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 EOF HELP_TOPIC=global @@ -275,7 +277,21 @@ function cmd_install_dep { # Fetch package.ini for the dependency mkdir -p "${CMD_INSTALL_PKG_DEST}/${name}" - curl --location --progress-bar "${origin}" --output "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" + case "${origin##*.}" in + ini) + # Download the package.ini for the dependency + curl --location --progress-bar "${origin}" --output "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" + ;; + *) + # 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" + fi + # Extract tarball + tar --extract --directory "${CMD_INSTALL_PKG_DEST}/${name}/" --strip-components 1 --file="${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-pkg" + ;; + esac # Fetch it's src (if present) SRC="$(ini_foreach ini_output_value "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" package.src)" @@ -283,19 +299,19 @@ function cmd_install_dep { # Download mkdir -p "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}" - if [ ! -f "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball" ]; then - curl --location --progress-bar "${SRC}" --output "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball" + if [ ! -f "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-src" ]; then + curl --location --progress-bar "${SRC}" --output "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-src" fi # Verify checksum HASH="$(ini_foreach ini_output_value "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" package.src-sha256)" - if [ ! -z "${HASH}" ] && [ "${HASH}" != "$(sha256sum "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball" | awk '{print $1}')" ]; then + if [ ! -z "${HASH}" ] && [ "${HASH}" != "$(sha256sum "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-src" | awk '{print $1}')" ]; then echo "The tarball for '${name}' failed it's checksum!" >&2 exit 1 fi # Extract tarball - tar --extract --directory "${CMD_INSTALL_PKG_DEST}/${name}/" --strip-components 1 --file="${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball" + tar --extract --directory "${CMD_INSTALL_PKG_DEST}/${name}/" --strip-components 1 --file="${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/tarball-src" fi # Handle fetching extra files @@ -333,7 +349,6 @@ function cmd_install_dep { ln -fs "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}" done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "export.") } - read -r -d '' help_topics[repository] <<- EOF Usage: dep [global options] repository <command> <argument> @@ -384,8 +399,20 @@ function cmd_repo { return $? } function cmd_repository { - mkdir -p "${HOME}/.config/finwo/dep/repositories.d" - echo "${CMD_REPO_LOC}" >> "${HOME}/.config/finwo/dep/repositories.d/${CMD_REPO_NAME}.cnf" + 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" + ;; + del) + mkdir -p "${HOME}/.config/finwo/dep/repositories.d" + rm -f "${HOME}/.config/finwo/dep/repositories.d/${CMD_REPO_NAME}.cnf" + ;; + *) + echo "Unknown command: ${CMD_REPO_CMD}" >&2 + exit 1 + ;; + esac } cmds[${#cmds[*]}]="r" diff --git a/src/command/help/topic/global.txt b/src/command/help/topic/global.txt @@ -7,8 +7,10 @@ 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 diff --git a/src/command/repo/help.txt b/src/command/repo/help.txt @@ -0,0 +1,6 @@ +Usage: __NAME [global options] repository <command> <argument> + +Commands: + + add <name> <manifest-url> Add a repository to include during dependency adds + del <name> Delete a repository from your dependency adds diff --git a/src/command/repo/index.sh b/src/command/repo/index.sh @@ -0,0 +1,64 @@ +read -r -d '' help_topics[repository] <<- EOF +# #include "help.txt" +EOF + +CMD_REPO_CMD= +CMD_REPO_NAME= +CMD_REPO_LOC= + +function arg_r { + arg_repository "$@" + return $? +} +function arg_repo { + arg_repository "$@" + return $? +} +function arg_repository { + CMD_REPO_CMD=$1 + CMD_REPO_NAME=$2 + + case "${CMD_REPO_CMD}" in + add) + CMD_REPO_LOC=$3 + ;; + del) + # Intentionally empty + ;; + *) + echo "Unknown command: ${CMD_REPO_CMD}" >&2 + exit 1 + ;; + esac + + return 0 +} + +function cmd_r { + cmd_repository "$@" + return $? +} +function cmd_repo { + cmd_repository "$@" + return $? +} +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" + ;; + del) + mkdir -p "${HOME}/.config/finwo/dep/repositories.d" + rm -f "${HOME}/.config/finwo/dep/repositories.d/${CMD_REPO_NAME}.cnf" + ;; + *) + echo "Unknown command: ${CMD_REPO_CMD}" >&2 + exit 1 + ;; + esac +} + +cmds[${#cmds[*]}]="r" +cmds[${#cmds[*]}]="repo" +cmds[${#cmds[*]}]="repository" diff --git a/src/main.sh b/src/main.sh @@ -2,6 +2,7 @@ cmds=("") # #include "command/help/index.sh" # #include "command/add/index.sh" # #include "command/install/index.sh" +# #include "command/repo/index.sh" function main { cmd=help