Skip to content

Commit

Permalink
Separate docker-build-and-push workflow - 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Saporetti Junior committed Jan 2, 2024
1 parent abd05ad commit dd52f35
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
28 changes: 9 additions & 19 deletions bin/apps/bash/hhs-app/plugins/hspm/hspm.bash
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function execute() {

if [[ -z "${HHS_MY_OS_PACKMAN}" ]]; then
for pkg_man in "${KNOWN_PCG_MANAGERS[@]}"; do
command -v "${pkg_man}" &>/dev/null && HHS_MY_OS_PACKMAN="${HHS_MY_OS_PACKMAN:-"${pkg_man}"}"
command -v "${pkg_man}" &> /dev/null && HHS_MY_OS_PACKMAN="${HHS_MY_OS_PACKMAN:-"${pkg_man}"}"
done
[[ -z "${OS_APP_MAN}" ]] && quit 1 "hspm.bash: no suitable tool found to install software on this machine. Tried: ${KNOWN_PCG_MANAGERS[*]}"
fi
Expand Down Expand Up @@ -161,7 +161,7 @@ function execute() {
# @purpose: Add a package to the breadcrumb file
function add_breadcrumb() {
local package="${1}" os="${HHS_MY_OS_RELEASE}"
grep -qxF "${os}:${package}" "${BREADCRUMB_FILE}" || echo "${os}:${package}" >>"${BREADCRUMB_FILE}"
grep -qxF "${os}:${package}" "${BREADCRUMB_FILE}" || echo "${os}:${package}" >> "${BREADCRUMB_FILE}"
}

# @purpose: Remove a package to the breadcrumb file
Expand Down Expand Up @@ -222,12 +222,6 @@ function install_recipe() {
source "${RECIPES_DIR}/${HHS_MY_OS}/default.recipe"
package=$(basename "${recipe%\.*}")

# Check if the package is already installed
if _which_ "${package}"; then
echo -e "${YELLOW}Package \"${package}\" is already installed!\n"
quit 0
fi

if [[ -f "${recipe}" ]]; then
source "${recipe}"
echo -e "${BLUE}Using recipe for \"${package}\""
Expand All @@ -237,9 +231,10 @@ function install_recipe() {

echo -e "${BLUE}Installing \"${package}\", please wait ..."

if _depends_ && _install_ "${package}" >>"${LOGFILE}" 2>&1 && _which_ "${package}"; then
if _depends_ && _install_ "${package}" 1>> "${LOGFILE}"; then
echo -e "${GREEN}Installation successful => \"${package}\" ${NC}"
add_breadcrumb "${package}"
_which_ "${package}" || echo -e "${YELLOW}WARN: Package \"${package}\" did not provide a known binary!${NC}"
else
quit 1 "${PLUGIN_NAME}: Failed to install \"${package}\"! Please type __hhs logs hspm to find out details\n"
fi
Expand All @@ -257,12 +252,6 @@ function uninstall_recipe() {
source "${RECIPES_DIR}/${HHS_MY_OS}/default.recipe"
package=$(basename "${recipe%\.*}")

# Check if the package is already installed
if ! _which_ "${package}"; then
echo -e "${YELLOW}Package \"${package}\" is not installed!\n"
quit 0
fi

if [[ -f "${recipe}" ]]; then
source "${recipe}"
echo -e "${BLUE}Using recipe for \"${package}\""
Expand All @@ -272,9 +261,10 @@ function uninstall_recipe() {

echo -e "${BLUE}Uninstalling \"${package}\", please wait ..."

if _uninstall_ "${package}" >>"${LOGFILE}" 2>&1 && ! _which_ "${package}"; then
if _uninstall_ "${package}" 1>> "${LOGFILE}"; then
echo -e "${GREEN}Uninstallation successful => \"${package}\" ${NC}"
del_breadcrumb "${package}"
_which_ "${package}" && echo -e "${YELLOW}WARN: Package \"${package}\" is yet a known binary !${NC}"
else
quit 1 "${PLUGIN_NAME}: Failed to uninstall \"${package}\" ! Please type __hhs logs hspm to find out details\n"
fi
Expand Down Expand Up @@ -308,10 +298,10 @@ function recover_packages() {
if [[ -n "${RECOVER_INSTALL}" ]]; then
for pkg in "${all_packages[@]}"; do
package="${pkg#*:}"
if ! command -v "${package}" &>/dev/null; then
if ! command -v "${package}" &> /dev/null; then
printf '%3s - %s' "${index}" "${BLUE}Installing package ${package} ${NC}"
printf '%*.*s' 0 $((pad_len - ${#package})) "${pad}"
if install_recipe "${package}" &>/dev/null; then
if install_recipe "${package}" &> /dev/null; then
echo -e " [ ${GREEN}OK${NC} ]"
else
echo -e " [ ${RED}FAILED${NC} ]"
Expand All @@ -324,7 +314,7 @@ function recover_packages() {
package="${pkg#*:}"
printf '%3s - %s' "${index}" "${BLUE}${package} "
printf '%*.*s' 0 $((pad_len - ${#package})) "${pad}"
command -v "${package}" &>/dev/null && echo -e "${GREEN} INSTALLED${NC}" || echo -e "${RED} NOT INSTALLED${NC}"
command -v "${package}" &> /dev/null && echo -e "${GREEN} INSTALLED${NC}" || echo -e "${RED} NOT INSTALLED${NC}"
index=$((index + 1))
done
fi
Expand Down
18 changes: 6 additions & 12 deletions bin/apps/bash/hhs-app/plugins/hspm/recipes/Darwin/default.recipe
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2068

function _about_() {
echo "This is the default recipe and will be used when no recipe is found the specified package"
Expand All @@ -7,24 +8,21 @@ function _about_() {

function _which_() {

packman="${HHS_MY_OS_PACKMAN}"

if command -v "${1}" &>/dev/null || "${packman}" list "${1}" &>/dev/null; then
if command -v ${@} &>/dev/null; then
return 0
fi

return 1
}

function _depends_() {

return 0
}

function _install_() {

packman="${HHS_MY_OS_PACKMAN}"

if "${packman}" install "$@" "${1}"; then
if "${HHS_MY_OS_PACKMAN}" install ${@}; then
return 0
fi

Expand All @@ -33,12 +31,8 @@ function _install_() {

function _uninstall_() {

packman="${HHS_MY_OS_PACKMAN}"

if "${packman}" uninstall "$@"; then
if "${packman}" deps "$@" | xargs "${packman}" remove --ignore-dependencies; then
return 0
fi
if "${HHS_MY_OS_PACKMAN}" uninstall ${@}; then
return 0
fi

return 1
Expand Down
33 changes: 25 additions & 8 deletions bin/apps/bash/hhs-app/plugins/hspm/recipes/Linux/default.recipe
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
#!/usr/bin/env bash
# shellcheck disable=SC2068

function _about_() {

echo "This is the default recipe and will be used when no recipe is found the specified package"

return 0
}

function _which_() {
if command -v "${1}" &>/dev/null; then

if command -v ${@} &>/dev/null; then
return 0
fi

return 1
}

function _depends_() {

return 0
}

function _install_() {

command -v sudo &> /dev/null && SUDO=sudo

if ${SUDO} "${HHS_MY_OS_PACKMAN}" -y install "$@"; then
return $?
if [[ ${HHS_MY_OS_PACKMAN} == 'apk' ]]; then
if ${SUDO} "${HHS_MY_OS_PACKMAN}" add --no-cache ${@}; then
return 0
fi
else
if ${SUDO} "${HHS_MY_OS_PACKMAN}" -y install ${@}; then
return 0
fi
fi

return 1
Expand All @@ -31,10 +43,15 @@ function _uninstall_() {

command -v sudo &> /dev/null && SUDO=sudo

packman="${HHS_MY_OS_PACKMAN}"

${SUDO} command "${packman}" uninstall "$@" \
&& ${SUDO} command "${packman}" deps "$@" | xargs "${packman}" remove --ignore-dependencies
if [[ ${HHS_MY_OS_PACKMAN} == 'apk' ]]; then
if ${SUDO} "${HHS_MY_OS_PACKMAN}" del ${@}; then
return 0
fi
else
if ${SUDO} "${HHS_MY_OS_PACKMAN}" uninstall ${@}; then
return 0
fi
fi

return $?
return 1
}
10 changes: 5 additions & 5 deletions install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -346,30 +346,30 @@ Usage: $APP_NAME [OPTIONS] <args>
has sudo &>/dev/null && SUDO=sudo

# macOS
if has 'brew'; then
if [[ "${MY_OS}" == "Darwin" ]]; then
OS_TYPE='macOS'
OS_APP_MAN=brew
DEPENDENCIES+=('sudo' 'xcode-select')
install="${SUDO} brew install -y"
# Debian or Ubuntu
# Debian: Ubuntu
elif has 'apt-get'; then
OS_TYPE='Debian'
OS_APP_MAN='apt-get'
DEPENDENCIES+=('sudo' 'file' 'build-essential' 'python3' 'python3-pip')
install="${SUDO} apt-get install -y"
# Fedora, CentOS, or Red Hat
# RedHat: Fedora, CentOS
elif has 'yum'; then
OS_TYPE='RedHat'
OS_APP_MAN='yum'
DEPENDENCIES+=('sudo' 'file' 'make' 'automake' 'gcc' 'gcc-c++' 'kernel-devel' 'python3' 'python3-pip')
install="${SUDO} yum install -y"
# Alpine (busybox)
# Alpine: Busybox
elif has 'apk'; then
OS_TYPE='Alpine'
OS_APP_MAN='apk'
install="apk add --no-cache"
DEPENDENCIES+=('file' 'python3' 'pip3')
# Arch Linux
# ArchLinux
elif has 'pacman'; then
OS_TYPE='ArchLinux'
OS_APP_MAN='pacman'
Expand Down

0 comments on commit dd52f35

Please sign in to comment.