commit 3ec717b1380ab476bfad27641c619b7901fc6e63
parent a18cadf97f4dc56842353bb71bb28bac2edd70ff
Author: finwo <finwo@pm.me>
Date: Sat, 2 Mar 2024 22:58:54 +0100
Added support for github-based packages from the repository
Diffstat:
3 files changed, 225 insertions(+), 307 deletions(-)
diff --git a/dist/dep b/dist/dep
@@ -177,43 +177,6 @@ function arg_a {
}
function arg_add {
CMD_ADD_ARGS=("$@")
-
- # # 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"
- # if [ -z "${CMD_ADD_SRC}" ]; then
- # CMD_ADD_SRC="$2"
- # fi
-
return 0
}
@@ -251,11 +214,11 @@ function cmd_add {
# 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
+ URL_TAG="https://codeload.github.com/${PKGGH}/tar.gz/refs/tags/${PKG[1]}"
+ URL_BRANCH="https://codeload.github.com/${PKGGH}/tar.gz/refs/heads/${PKG[1]}"
+ CODE_TAG=$(curl -X HEAD --fail --dump-header - -o /dev/null "${URL_TAG}" 2>/dev/null | head -1 | awk '{print $2}')
+ CODE_BRANCH=$(curl -X HEAD --fail --dump-header - -o /dev/null "${URL_BRANCH}" 2>/dev/null | head -1 | awk '{print $2}')
+ if [ "${CODE_TAG}" != "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
@@ -293,6 +256,9 @@ Description:
dependencies as well.
EOF
+CMD_INSTALL_PKG_NAME=
+CMD_INSTALL_PKG_DEST="lib"
+
function arg_i {
arg_install "$@"
return $?
@@ -314,158 +280,151 @@ function cmd_install {
exit 1
fi
- ini_foreach cmd_install_parse_ini_main "${PACKAGE_PATH}"
- cmd_install_execute
+ # Fetch where to install dependencies
+ CMD_INSTALL_PKG_DEST=$(ini_foreach ini_output_value "${PACKAGE_PATH}" "package.deps")
+ if [ -z "${CMD_INSTALL_PKG_DEST}" ]; then CMD_INSTALL_PKG_DEST="lib"; fi
+
+ # Reset working directory
+ rm -rf "${CMD_INSTALL_PKG_DEST}/.dep"
+ mkdir -p "${CMD_INSTALL_PKG_DEST}/.dep/include"
+ echo "INCLUDES+=-I${CMD_INSTALL_PKG_DEST}/.dep/include" > "${CMD_INSTALL_PKG_DEST}/.dep/config.mk"
+ echo "" > "${CMD_INSTALL_PKG_DEST}/.dep/exported"
+
+ # Install all dependencies
+ ini_foreach cmd_install_parse_ini "${PACKAGE_PATH}"
echo "Done"
}
cmds[${#cmds[*]}]="i"
cmds[${#cmds[*]}]="install"
-CMD_INSTALL_PKG_NAME=
-CMD_INSTALL_PKG_DEST="lib"
declare -A CMD_INSTALL_DEPS
-function cmd_install_parse_ini_main {
+function cmd_install_parse_ini {
case "$1" in
- package.)
- case "$2" in
- name)
- CMD_INSTALL_PKG_NAME="$3"
- ;;
- deps)
- CMD_INSTALL_PKG_DEST="$3"
- ;;
- esac
- ;;
dependencies.)
- CMD_INSTALL_DEPS["$2"]="$3"
+ cmd_install_dep "$2" "$3"
;;
esac
-}
-function cmd_install_execute {
- cmd_install_reset_generated
- for key in "${!CMD_INSTALL_DEPS[@]}"; do
- cmd_install_dep "$key" "${CMD_INSTALL_DEPS[$key]}"
- done
-}
+ # package.)
+ # case "$2" in
+ # name)
+ # CMD_INSTALL_PKG_NAME="$3"
+ # ;;
+ # deps)
+ # CMD_INSTALL_PKG_DEST="$3"
+ # ;;
+ # esac
+ # ;;
+ # dependencies.)
+ # CMD_INSTALL_DEPS["$2"]="$3"
+ # ;;
+ # esac
-function cmd_install_reset_generated {
- rm -rf "${CMD_INSTALL_PKG_DEST}/.dep"
- mkdir -p "${CMD_INSTALL_PKG_DEST}/.dep/include"
- echo "INCLUDES+=-I${CMD_INSTALL_PKG_DEST}/.dep/include" > "${CMD_INSTALL_PKG_DEST}/.dep/config.mk"
- echo "" > "${CMD_INSTALL_PKG_DEST}/.dep/exported"
}
-function cmd_install_dep {
- local name=$1
- local origin=$2
-
- # Full install if missing
- local ISNEW=
- if [ ! -d "${CMD_INSTALL_PKG_DEST}/${name}" ]; then
- ISNEW="yes"
-
- # Fetch package.ini for the dependency
- mkdir -p "${CMD_INSTALL_PKG_DEST}/${name}"
- 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 "${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"
- ;;
- esac
+# function cmd_install_execute {
+# cmd_install_reset_generated
+# for key in "${!CMD_INSTALL_DEPS[@]}"; do
+# cmd_install_dep "$key" "${CMD_INSTALL_DEPS[$key]}"
+# done
+# }
- # Fetch it's src (if present)
- SRC="$(ini_foreach ini_output_value "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" package.src)"
- if [ ! -z "${SRC}" ]; then
+function cmd_install_dep {
+ PKGNAME=$1
+ PKGVER=$2
- # Download
- mkdir -p "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}"
- 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
+ # Skip if already installed
+ if [ -d "${CMD_INSTALL_PKG_DEST}/${PKGNAME}" ]; then
+ return 0
+ 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-src" | awk '{print $1}')" ]; then
- echo "The tarball for '${name}' failed it's checksum!" >&2
- exit 1
- fi
+ # Fetch versioned ini
+ PKGINIB="${HOME}/.config/finwo/dep/packages/${PKGNAME}/package.ini"
+ PKGINIV="${HOME}/.config/finwo/dep/packages/${PKGNAME}/${PKGVER}/package.ini"
+ PKGINI=
+ if [ -f "${PKGINIB}" ]; then PKGINI="${PKGINIB}"; fi
+ if [ -f "${PKGINIV}" ]; then PKGINI="${PKGINIV}"; fi
+ if [ -z "${PKGINI}" ]; then
+ echo "No package configuration found for ${PKGNAME}" >&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-src"
+ # Copy repository's config for the package
+ PKG_SRC=$(dirname "${PKGINI}")
+ PKG_DIR="${CMD_INSTALL_PKG_DEST}/${PKGNAME}"
+ mkdir -p "$(dirname "${PKG_DIR}")"
+ cp -r "${PKG_SRC}" "${PKG_DIR}"
+ PKGINI="${PKG_DIR}/package.ini"
+
+ # Extended fetching detection
+ PKG_GH=$(ini_foreach ini_output_value "${PKGINI}" "repository.github")
+ PKG_TARBALL=$(ini_foreach ini_output_value "${PKGINI}" "package.src")
+
+ # Fetch target tarball from github repo
+ if [ ! -z "${PKG_GH}" ]; then
+ URL_TAG="https://codeload.github.com/${PKG_GH}/tar.gz/refs/tags/${PKGVER}"
+ URL_BRANCH="https://codeload.github.com/${PKG_GH}/tar.gz/refs/heads/${PKGVER}"
+ CODE_TAG=$(curl -X HEAD --fail --dump-header - -o /dev/null "${URL_TAG}" 2>/dev/null | head -1 | awk '{print $2}')
+ CODE_BRANCH=$(curl -X HEAD --fail --dump-header - -o /dev/null "${URL_BRANCH}" 2>/dev/null | head -1 | awk '{print $2}')
+ if [ "${CODE_TAG}" == "200" ]; then
+ PKG_TARBALL="${URL_TAG}"
+ elif [ "${CODE_BRANCH}" == "200" ]; then
+ PKG_TARBALL="${URL_BRANCH}"
fi
+ fi
- # Handle fetching extra files
- mkdir -p "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/fetch"
- while read line; do
- filename=${line%%=*}
- filesource=${line#*=}
-
- # Download the extra file into cache
- if [ ! -f "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/fetch/${filename}" ]; then
- curl --location --progress-bar "${filesource}" --create-dirs --output "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}/fetch/${filename}"
- fi
-
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "fetch.")
-
- # Copy the extra files into the target directory
- tar --create --directory "${CMD_INSTALL_PKG_DEST}/.dep/cache/${name}" "fetch" | \
- tar --extract --directory "${CMD_INSTALL_PKG_DEST}/${name}" --strip-components 1
+ # Fetch configured or detected tarball
+ if [ ! -z "${PKG_TARBALL}" ]; then
+ # Downloads a tarball and extracts if over the package in our dependency directory
+ # TARBALL_FILE="${HOME}/.config/finwo/dep/cache/${PKGNAME}/${PKGVER}.tar.gz"
+ TARBALL_FILE="${CMD_INSTALL_PKG_DEST}/.dep/cache/${PKGNAME}/${PKGVER}.tar.gz"
+ mkdir -p "$(dirname "${TARBALL_FILE}")"
+ if [ ! -f "${TARBALL_FILE}" ]; then
+ curl --location --progress-bar "${PKG_TARBALL}" --output "${TARBALL_FILE}"
+ fi
+ tar --extract --directory "${PKG_DIR}/" --strip-components 1 --file="${TARBALL_FILE}"
fi
- # Download package's dependencies
- while read line; do
- depname=${line%%=*}
- deplink=${line#*=}
- cmd_install_dep "$depname" "$deplink"
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "dependencies.")
+ # Handle the package's dependencies
+ ini_foreach cmd_install_parse_ini "${PKGINI}" "dependencies."
# Handle any global build-steps defined in the package.ini
- if [ ! -z "$ISNEW" ]; then
- while read line; do
- buildcmd=${line#*=}
- echo $buildcmd
- bash -c "cd ${CMD_INSTALL_PKG_DEST}/${name} ; ${buildcmd}"
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "build." | sort --human-numeric-sort)
- fi
+ while read line; do
+ buildcmd=${line#*=}
+ echo $buildcmd
+ bash -c "cd '${PKG_DIR}' ; ${buildcmd}"
+ done < <(ini_foreach ini_output_section "${PKGINI}" "build." | sort --human-numeric-sort)
# Handle any os-generic build-steps defined in the package.ini
- if [ ! -z "$ISNEW" ]; then
- while read line; do
- buildcmd=${line#*=}
- echo $buildcmd
- bash -c "cd ${CMD_INSTALL_PKG_DEST}/${name} ; ${buildcmd}"
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "build-$(ostype)." | sort --human-numeric-sort)
- fi
+ while read line; do
+ buildcmd=${line#*=}
+ echo $buildcmd
+ bash -c "cd '${PKG_DIR}' ; ${buildcmd}"
+ done < <(ini_foreach ini_output_section "${PKGINI}" "build-$(ostype)." | sort --human-numeric-sort)
# Build the package's exports
- if ! grep "${name}" "${CMD_INSTALL_PKG_DEST}/.dep/exported" &>/dev/null ; then
- echo "${name}" >> "${CMD_INSTALL_PKG_DEST}/.dep/exported"
+ if ! grep "${PKGNAME}" "${CMD_INSTALL_PKG_DEST}/.dep/exported" &>/dev/null ; then
+ echo "${PKGNAME}" >> "${CMD_INSTALL_PKG_DEST}/.dep/exported"
while read line; do
filetarget=${line%%=*}
filesource=${line#*=}
mkdir -p "$(dirname "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}")"
case "${filetarget}" in
+ exported|cache/*)
+ # Blocked
+ ;;
config.mk)
- cat "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" | sed "s|__DIRNAME|${CMD_INSTALL_PKG_DEST}/${name}|g" >> "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}"
+ cat "${PKG_DIR}/${filesource}" | sed "s|__DIRNAME|${PKG_DIR}|g" >> "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}"
;;
*)
# ls -sf "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}"
- cp "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}"
+ cp "${PKG_DIR}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.dep/${filetarget}"
;;
esac
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "export.")
+ done < <(ini_foreach ini_output_section "${PKGINI}" "export.")
fi
+
}
read -r -d '' help_topics[repository] <<- EOF
diff --git a/src/command/add/index.sh b/src/command/add/index.sh
@@ -12,43 +12,6 @@ function arg_a {
}
function arg_add {
CMD_ADD_ARGS=("$@")
-
- # # 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"
- # if [ -z "${CMD_ADD_SRC}" ]; then
- # CMD_ADD_SRC="$2"
- # fi
-
return 0
}
@@ -86,11 +49,11 @@ function cmd_add {
# 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
+ URL_TAG="https://codeload.github.com/${PKGGH}/tar.gz/refs/tags/${PKG[1]}"
+ URL_BRANCH="https://codeload.github.com/${PKGGH}/tar.gz/refs/heads/${PKG[1]}"
+ CODE_TAG=$(curl -X HEAD --fail --dump-header - -o /dev/null "${URL_TAG}" 2>/dev/null | head -1 | awk '{print $2}')
+ CODE_BRANCH=$(curl -X HEAD --fail --dump-header - -o /dev/null "${URL_BRANCH}" 2>/dev/null | head -1 | awk '{print $2}')
+ if [ "${CODE_TAG}" != "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
diff --git a/src/command/install/index.sh b/src/command/install/index.sh
@@ -5,6 +5,9 @@ read -r -d '' help_topics[install] <<- EOF
# #include "help.txt"
EOF
+CMD_INSTALL_PKG_NAME=
+CMD_INSTALL_PKG_DEST="lib"
+
function arg_i {
arg_install "$@"
return $?
@@ -26,156 +29,149 @@ function cmd_install {
exit 1
fi
- ini_foreach cmd_install_parse_ini_main "${PACKAGE_PATH}"
- cmd_install_execute
+ # Fetch where to install dependencies
+ CMD_INSTALL_PKG_DEST=$(ini_foreach ini_output_value "${PACKAGE_PATH}" "package.deps")
+ if [ -z "${CMD_INSTALL_PKG_DEST}" ]; then CMD_INSTALL_PKG_DEST="lib"; fi
+
+ # Reset working directory
+ rm -rf "${CMD_INSTALL_PKG_DEST}/.__NAME"
+ mkdir -p "${CMD_INSTALL_PKG_DEST}/.__NAME/include"
+ echo "INCLUDES+=-I${CMD_INSTALL_PKG_DEST}/.__NAME/include" > "${CMD_INSTALL_PKG_DEST}/.__NAME/config.mk"
+ echo "" > "${CMD_INSTALL_PKG_DEST}/.__NAME/exported"
+
+ # Install all dependencies
+ ini_foreach cmd_install_parse_ini "${PACKAGE_PATH}"
echo "Done"
}
cmds[${#cmds[*]}]="i"
cmds[${#cmds[*]}]="install"
-CMD_INSTALL_PKG_NAME=
-CMD_INSTALL_PKG_DEST="lib"
declare -A CMD_INSTALL_DEPS
-function cmd_install_parse_ini_main {
+function cmd_install_parse_ini {
case "$1" in
- package.)
- case "$2" in
- name)
- CMD_INSTALL_PKG_NAME="$3"
- ;;
- deps)
- CMD_INSTALL_PKG_DEST="$3"
- ;;
- esac
- ;;
dependencies.)
- CMD_INSTALL_DEPS["$2"]="$3"
+ cmd_install_dep "$2" "$3"
;;
esac
-}
-function cmd_install_execute {
- cmd_install_reset_generated
- for key in "${!CMD_INSTALL_DEPS[@]}"; do
- cmd_install_dep "$key" "${CMD_INSTALL_DEPS[$key]}"
- done
-}
+ # package.)
+ # case "$2" in
+ # name)
+ # CMD_INSTALL_PKG_NAME="$3"
+ # ;;
+ # deps)
+ # CMD_INSTALL_PKG_DEST="$3"
+ # ;;
+ # esac
+ # ;;
+ # dependencies.)
+ # CMD_INSTALL_DEPS["$2"]="$3"
+ # ;;
+ # esac
-function cmd_install_reset_generated {
- rm -rf "${CMD_INSTALL_PKG_DEST}/.__NAME"
- mkdir -p "${CMD_INSTALL_PKG_DEST}/.__NAME/include"
- echo "INCLUDES+=-I${CMD_INSTALL_PKG_DEST}/.__NAME/include" > "${CMD_INSTALL_PKG_DEST}/.__NAME/config.mk"
- echo "" > "${CMD_INSTALL_PKG_DEST}/.__NAME/exported"
}
+# function cmd_install_execute {
+# cmd_install_reset_generated
+# for key in "${!CMD_INSTALL_DEPS[@]}"; do
+# cmd_install_dep "$key" "${CMD_INSTALL_DEPS[$key]}"
+# done
+# }
+
function cmd_install_dep {
- local name=$1
- local origin=$2
-
- # Full install if missing
- local ISNEW=
- if [ ! -d "${CMD_INSTALL_PKG_DEST}/${name}" ]; then
- ISNEW="yes"
-
- # Fetch package.ini for the dependency
- mkdir -p "${CMD_INSTALL_PKG_DEST}/${name}"
- 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}/.__NAME/cache/${name}"
- if [ ! -f "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/tarball-pkg" ]; then
- 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"
- ;;
- esac
-
- # Fetch it's src (if present)
- SRC="$(ini_foreach ini_output_value "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" package.src)"
- if [ ! -z "${SRC}" ]; then
-
- # Download
- mkdir -p "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}"
- if [ ! -f "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/tarball-src" ]; then
- curl --location --progress-bar "${SRC}" --output "${CMD_INSTALL_PKG_DEST}/.__NAME/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}/.__NAME/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}/.__NAME/cache/${name}/tarball-src"
- fi
+ PKGNAME=$1
+ PKGVER=$2
- # Handle fetching extra files
- mkdir -p "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/fetch"
- while read line; do
- filename=${line%%=*}
- filesource=${line#*=}
+ # Skip if already installed
+ if [ -d "${CMD_INSTALL_PKG_DEST}/${PKGNAME}" ]; then
+ return 0
+ fi
- # Download the extra file into cache
- if [ ! -f "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/fetch/${filename}" ]; then
- curl --location --progress-bar "${filesource}" --create-dirs --output "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}/fetch/${filename}"
- fi
+ # Fetch versioned ini
+ PKGINIB="${HOME}/.config/finwo/__NAME/packages/${PKGNAME}/package.ini"
+ PKGINIV="${HOME}/.config/finwo/__NAME/packages/${PKGNAME}/${PKGVER}/package.ini"
+ PKGINI=
+ if [ -f "${PKGINIB}" ]; then PKGINI="${PKGINIB}"; fi
+ if [ -f "${PKGINIV}" ]; then PKGINI="${PKGINIV}"; fi
+ if [ -z "${PKGINI}" ]; then
+ echo "No package configuration found for ${PKGNAME}" >&2
+ exit 1
+ fi
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "fetch.")
+ # Copy repository's config for the package
+ PKG_SRC=$(dirname "${PKGINI}")
+ PKG_DIR="${CMD_INSTALL_PKG_DEST}/${PKGNAME}"
+ mkdir -p "$(dirname "${PKG_DIR}")"
+ cp -r "${PKG_SRC}" "${PKG_DIR}"
+ PKGINI="${PKG_DIR}/package.ini"
+
+ # Extended fetching detection
+ PKG_GH=$(ini_foreach ini_output_value "${PKGINI}" "repository.github")
+ PKG_TARBALL=$(ini_foreach ini_output_value "${PKGINI}" "package.src")
+
+ # Fetch target tarball from github repo
+ if [ ! -z "${PKG_GH}" ]; then
+ URL_TAG="https://codeload.github.com/${PKG_GH}/tar.gz/refs/tags/${PKGVER}"
+ URL_BRANCH="https://codeload.github.com/${PKG_GH}/tar.gz/refs/heads/${PKGVER}"
+ CODE_TAG=$(curl -X HEAD --fail --dump-header - -o /dev/null "${URL_TAG}" 2>/dev/null | head -1 | awk '{print $2}')
+ CODE_BRANCH=$(curl -X HEAD --fail --dump-header - -o /dev/null "${URL_BRANCH}" 2>/dev/null | head -1 | awk '{print $2}')
+ if [ "${CODE_TAG}" == "200" ]; then
+ PKG_TARBALL="${URL_TAG}"
+ elif [ "${CODE_BRANCH}" == "200" ]; then
+ PKG_TARBALL="${URL_BRANCH}"
+ fi
+ fi
- # Copy the extra files into the target directory
- tar --create --directory "${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${name}" "fetch" | \
- tar --extract --directory "${CMD_INSTALL_PKG_DEST}/${name}" --strip-components 1
+ # Fetch configured or detected tarball
+ if [ ! -z "${PKG_TARBALL}" ]; then
+ # Downloads a tarball and extracts if over the package in our dependency directory
+ # TARBALL_FILE="${HOME}/.config/finwo/__NAME/cache/${PKGNAME}/${PKGVER}.tar.gz"
+ TARBALL_FILE="${CMD_INSTALL_PKG_DEST}/.__NAME/cache/${PKGNAME}/${PKGVER}.tar.gz"
+ mkdir -p "$(dirname "${TARBALL_FILE}")"
+ if [ ! -f "${TARBALL_FILE}" ]; then
+ curl --location --progress-bar "${PKG_TARBALL}" --output "${TARBALL_FILE}"
+ fi
+ tar --extract --directory "${PKG_DIR}/" --strip-components 1 --file="${TARBALL_FILE}"
fi
- # Download package's dependencies
- while read line; do
- depname=${line%%=*}
- deplink=${line#*=}
- cmd_install_dep "$depname" "$deplink"
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "dependencies.")
+ # Handle the package's dependencies
+ ini_foreach cmd_install_parse_ini "${PKGINI}" "dependencies."
# Handle any global build-steps defined in the package.ini
- if [ ! -z "$ISNEW" ]; then
- while read line; do
- buildcmd=${line#*=}
- echo $buildcmd
- bash -c "cd ${CMD_INSTALL_PKG_DEST}/${name} ; ${buildcmd}"
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "build." | sort --human-numeric-sort)
- fi
+ while read line; do
+ buildcmd=${line#*=}
+ echo $buildcmd
+ bash -c "cd '${PKG_DIR}' ; ${buildcmd}"
+ done < <(ini_foreach ini_output_section "${PKGINI}" "build." | sort --human-numeric-sort)
# Handle any os-generic build-steps defined in the package.ini
- if [ ! -z "$ISNEW" ]; then
- while read line; do
- buildcmd=${line#*=}
- echo $buildcmd
- bash -c "cd ${CMD_INSTALL_PKG_DEST}/${name} ; ${buildcmd}"
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "build-$(ostype)." | sort --human-numeric-sort)
- fi
+ while read line; do
+ buildcmd=${line#*=}
+ echo $buildcmd
+ bash -c "cd '${PKG_DIR}' ; ${buildcmd}"
+ done < <(ini_foreach ini_output_section "${PKGINI}" "build-$(ostype)." | sort --human-numeric-sort)
# Build the package's exports
- if ! grep "${name}" "${CMD_INSTALL_PKG_DEST}/.__NAME/exported" &>/dev/null ; then
- echo "${name}" >> "${CMD_INSTALL_PKG_DEST}/.__NAME/exported"
+ if ! grep "${PKGNAME}" "${CMD_INSTALL_PKG_DEST}/.__NAME/exported" &>/dev/null ; then
+ echo "${PKGNAME}" >> "${CMD_INSTALL_PKG_DEST}/.__NAME/exported"
while read line; do
filetarget=${line%%=*}
filesource=${line#*=}
mkdir -p "$(dirname "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}")"
case "${filetarget}" in
+ exported|cache/*)
+ # Blocked
+ ;;
config.mk)
- cat "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" | sed "s|__DIRNAME|${CMD_INSTALL_PKG_DEST}/${name}|g" >> "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}"
+ cat "${PKG_DIR}/${filesource}" | sed "s|__DIRNAME|${PKG_DIR}|g" >> "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}"
;;
*)
# ls -sf "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}"
- cp "${CMD_INSTALL_PKG_DEST}/${name}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}"
+ cp "${PKG_DIR}/${filesource}" "${CMD_INSTALL_PKG_DEST}/.__NAME/${filetarget}"
;;
esac
- done < <(ini_foreach ini_output_section "${CMD_INSTALL_PKG_DEST}/${name}/package.ini" "export.")
+ done < <(ini_foreach ini_output_section "${PKGINI}" "export.")
fi
+
}