dep

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

commit a18cadf97f4dc56842353bb71bb28bac2edd70ff
parent 42ed562eb243b8418a01ce576a2585e293f695dc
Author: finwo <finwo@pm.me>
Date:   Sat,  2 Mar 2024 17:05:13 +0100

Can now add dependencies using the new repo structure

Diffstat:
Mdist/dep | 50++++++++++++++++++++++++++++++++------------------
Mpackage.ini | 1+
Msrc/command/add/index.sh | 50++++++++++++++++++++++++++++++++------------------
3 files changed, 65 insertions(+), 36 deletions(-)

diff --git a/dist/dep b/dist/dep @@ -223,34 +223,48 @@ function cmd_a { } function cmd_add { OLD_PKG=$(ini_foreach ini_output_full "package.ini") - CHANNEL=$(ini_foreach ini_output_value "package.ini" "package.channel" | tail -n 1) - # Get target & version - PKG=(${CMD_ADD_ARGS[0]//@/ }) - if [[ "${PKG[1]}" == "" ]]; then PKG[1]=$CHANNEL; fi + # TODO: Assume package name is github repo if missing? - # Find the package in the package cache - PKGINIV="${HOME}/.config/finwo/dep/packages/${PKG[0]}/${PKG[1]}/package.ini" + # Get target & main package file + PKG=(${CMD_ADD_ARGS[0]//@/ }) PKGINIB="${HOME}/.config/finwo/dep/packages/${PKG[0]}/package.ini" - PKGINI= - if [ -f "${PKGINIB}" ]; then PKGINI="${PKGINIB}"; fi - if [ -f "${PKGINIV}" ]; then PKGINI="${PKGINIV}"; fi - if [ -z "${PKGINI}" ]; then + if [ ! -f "${PKGINIB}" ]; then echo "Package not found. Did you update your repositories?" >&2 exit 1 fi + # Get the version to add + if [ -z "${PKG[1]}" ]; then PKG[1]=$(ini_foreach ini_output_value "${PKGINIB}" "package.channel" | tail -n 1); fi + if [ -z "${PKG[1]}" ]; then PKG[1]=$(ini_foreach ini_output_value "package.ini" "package.channel" | tail -n 1); fi + if [ -z "${PKG[1]}" ]; then + echo "Could not determine desired package version. Set 'package.channel' in your package.ini to select a fallback or use 'dep repository add ${PKG[0]}@<version>' to select a specific version." >&2 + exit 1 + fi - echo $CHANNEL - echo $PKGINIB - echo $PKGINIV - echo $PKGINI - echo ${PKG[0]} - echo ${PKG[1]} - + # Fetch the version-specific ini + PKGINIV="${HOME}/.config/finwo/dep/packages/${PKG[0]}/${PKG[1]}/package.ini" + PKGINI= + if [ -f "${PKGINIB}" ]; then PKGINI="${PKGINIB}"; fi + if [ -f "${PKGINIV}" ]; then PKGINI="${PKGINIV}"; fi + # Extension: Check release/branch on github + PKGGH=$(ini_foreach ini_output_value "${PKGINI}" "repository.github") + if [ ! -z "${PKGGH}" ]; then + RELEASEURL="https://api.github.com/repos/${PKGGH}/releases/tags/${PKG[1]}" + BRANCHURL="https://api.github.com/repos/${PKGGH}/branches/${PKG[1]}" + CODE_RELEASE=$(curl --fail --dump-header - -o /dev/null "${RELEASEURL}" 2>/dev/null | head -1 | awk '{print $2}') + CODE_BRANCH=$(curl --fail --dump-header - -o /dev/null "${BRANCHURL}" 2>/dev/null | head -1 | awk '{print $2}') + if [ "${CODE_RELEASE}" != "200" ] && [ "${CODE_BRANCH}" != "200" ]; then + echo "No release or branch '${PKG[1]}' found in the github repository ${PKGGH}." >&2 + echo "Check https://github.com/${PKGGH} to see the available releases and branches" >&2 + exit 1 + fi + fi - # (echo "dependencies.${CMD_ADD_PKG}=${CMD_ADD_SRC}" ; echo -e "${OLD_PKG}") | ini_write "package.ini" + # Add the package to the dependencies + (echo "dependencies.${PKG[0]}=${PKG[1]}" ; echo -e "${OLD_PKG}") | ini_write "package.ini" + echo "Added to your package.ini: ${PKG[0]}@${PKG[1]}" } cmds[${#cmds[*]}]="a" diff --git a/package.ini b/package.ini @@ -1,3 +1,4 @@ [package] +channel=edge deps=lib name=dep diff --git a/src/command/add/index.sh b/src/command/add/index.sh @@ -58,34 +58,48 @@ function cmd_a { } function cmd_add { OLD_PKG=$(ini_foreach ini_output_full "package.ini") - CHANNEL=$(ini_foreach ini_output_value "package.ini" "package.channel" | tail -n 1) - # Get target & version - PKG=(${CMD_ADD_ARGS[0]//@/ }) - if [[ "${PKG[1]}" == "" ]]; then PKG[1]=$CHANNEL; fi + # TODO: Assume package name is github repo if missing? - # Find the package in the package cache - PKGINIV="${HOME}/.config/finwo/__NAME/packages/${PKG[0]}/${PKG[1]}/package.ini" + # Get target & main package file + PKG=(${CMD_ADD_ARGS[0]//@/ }) PKGINIB="${HOME}/.config/finwo/__NAME/packages/${PKG[0]}/package.ini" - PKGINI= - if [ -f "${PKGINIB}" ]; then PKGINI="${PKGINIB}"; fi - if [ -f "${PKGINIV}" ]; then PKGINI="${PKGINIV}"; fi - if [ -z "${PKGINI}" ]; then + if [ ! -f "${PKGINIB}" ]; then echo "Package not found. Did you update your repositories?" >&2 exit 1 fi + # Get the version to add + if [ -z "${PKG[1]}" ]; then PKG[1]=$(ini_foreach ini_output_value "${PKGINIB}" "package.channel" | tail -n 1); fi + if [ -z "${PKG[1]}" ]; then PKG[1]=$(ini_foreach ini_output_value "package.ini" "package.channel" | tail -n 1); fi + if [ -z "${PKG[1]}" ]; then + echo "Could not determine desired package version. Set 'package.channel' in your package.ini to select a fallback or use 'dep repository add ${PKG[0]}@<version>' to select a specific version." >&2 + exit 1 + fi - echo $CHANNEL - echo $PKGINIB - echo $PKGINIV - echo $PKGINI - echo ${PKG[0]} - echo ${PKG[1]} - + # Fetch the version-specific ini + PKGINIV="${HOME}/.config/finwo/__NAME/packages/${PKG[0]}/${PKG[1]}/package.ini" + PKGINI= + if [ -f "${PKGINIB}" ]; then PKGINI="${PKGINIB}"; fi + if [ -f "${PKGINIV}" ]; then PKGINI="${PKGINIV}"; fi + # Extension: Check release/branch on github + PKGGH=$(ini_foreach ini_output_value "${PKGINI}" "repository.github") + if [ ! -z "${PKGGH}" ]; then + RELEASEURL="https://api.github.com/repos/${PKGGH}/releases/tags/${PKG[1]}" + BRANCHURL="https://api.github.com/repos/${PKGGH}/branches/${PKG[1]}" + CODE_RELEASE=$(curl --fail --dump-header - -o /dev/null "${RELEASEURL}" 2>/dev/null | head -1 | awk '{print $2}') + CODE_BRANCH=$(curl --fail --dump-header - -o /dev/null "${BRANCHURL}" 2>/dev/null | head -1 | awk '{print $2}') + if [ "${CODE_RELEASE}" != "200" ] && [ "${CODE_BRANCH}" != "200" ]; then + echo "No release or branch '${PKG[1]}' found in the github repository ${PKGGH}." >&2 + echo "Check https://github.com/${PKGGH} to see the available releases and branches" >&2 + exit 1 + fi + fi - # (echo "dependencies.${CMD_ADD_PKG}=${CMD_ADD_SRC}" ; echo -e "${OLD_PKG}") | ini_write "package.ini" + # Add the package to the dependencies + (echo "dependencies.${PKG[0]}=${PKG[1]}" ; echo -e "${OLD_PKG}") | ini_write "package.ini" + echo "Added to your package.ini: ${PKG[0]}@${PKG[1]}" } cmds[${#cmds[*]}]="a"