From afe35f9198b8cb656b5d3d86ca99866b7c86c794 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 18 Dec 2024 07:22:26 +0000 Subject: [PATCH] feat(node): ask to install libstdc++ on Alpine --- node/install.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/node/install.sh b/node/install.sh index 52573679a..117633b04 100644 --- a/node/install.sh +++ b/node/install.sh @@ -43,4 +43,58 @@ pkg_done_message() { b_dst="$(fn_sub_home "${pkg_dst}")" echo "" echo " Installed $(t_pkg 'node') and $(t_pkg 'npm') at $(t_path "${b_dst}/")" + + if command -v apk > /dev/null; then + if ! apk info | grep -F 'libstdc++' > /dev/null; then + echo "" + echo " $(t_pkg 'WARNING'): $(t_pkg 'libstdc++') is required for $(t_pkg 'node'), but not installed" >&2 + if command -v sudo > /dev/null; then + cmd_sudo='sudo ' + fi + _install_webi_essentials_apk "${cmd_sudo}" 'libstdc++' + fi + fi } + +_install_webi_essentials_apk() { ( + cmd_sudo="${1}" + b_pkgs="${2}" + + #echo " $(t_dim 'Running') $(t_cmd "${cmd_sudo}apk add --no-cache")" + fn_polite_sudo "${cmd_sudo}" " $(t_cmd "apk add --no-cache ${b_pkgs}")" + # shellcheck disable=SC2086 + ${cmd_sudo} apk add --no-cache ${b_pkgs} +); } + +fn_polite_sudo() { ( + a_sudo="${1}" + a_cmds="${2}" + + # no sudo needed, so don't ask + if test -z "${a_sudo}"; then + return 0 + fi + + # this is scripted, not user-interactive, continue + if test -z "${WEBI_TTY}"; then + return 0 + fi + + # this is user interactive, ask the user,defaulting to yes + echo "" + #shellcheck disable=SC2005 # echo for newline + printf '%s\n' "$(t_attn 'Use sudo to run the following? [Y/n] ')" + echo "${a_cmds}" + read -r b_yes < /dev/tty + + b_yes="$( + echo "${b_yes}" | + tr '[:upper:]' '[:lower:]' | + tr -d '[:space:]' + )" + if test -z "${b_yes}" || test "${b_yes}" = "y" || test "${b_yes}" = "yes"; then + return 0 + fi + echo " aborted" + return 1 +); }