fix: fail mise-install when curl pipeline errors
Do not print success after a failed curl | sh install; enable pipefail and verify mise is on PATH before continuing.
This commit is contained in:
+13
-4
@@ -20,18 +20,28 @@ EOF
|
|||||||
|
|
||||||
dotfile_help_requested "${1:-}" && dotfile_show_help
|
dotfile_help_requested "${1:-}" && dotfile_show_help
|
||||||
|
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
YELLOW='\033[1;33m'
|
YELLOW='\033[1;33m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
|
mise_fail() {
|
||||||
|
echo -e "${RED}mise 安装失败,请检查错误信息${NC}" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
if ! command -v mise &>/dev/null; then
|
if ! command -v mise &>/dev/null; then
|
||||||
echo -e "${YELLOW}mise 未安装. 正在安装 mise...${NC}"
|
echo -e "${YELLOW}mise 未安装. 正在安装 mise...${NC}"
|
||||||
curl https://mise.run | sh
|
# 无 pipefail 时 curl 失败 sh 仍可能退出 0,会误报「安装完成」
|
||||||
|
curl -fL --retry 3 https://mise.run | sh || mise_fail
|
||||||
export PATH="$HOME/.local/bin:$PATH"
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
|
|
||||||
|
if ! command -v mise &>/dev/null; then
|
||||||
|
mise_fail
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f ~/.config/fish/config.fish ]; then
|
if [ -f ~/.config/fish/config.fish ]; then
|
||||||
if ! grep -q "mise activate" ~/.config/fish/config.fish; then
|
if ! grep -q "mise activate" ~/.config/fish/config.fish; then
|
||||||
echo -e "${YELLOW}正在为 fish shell 配置 mise...${NC}"
|
echo -e "${YELLOW}正在为 fish shell 配置 mise...${NC}"
|
||||||
@@ -72,6 +82,5 @@ fi
|
|||||||
if command -v mise &>/dev/null; then
|
if command -v mise &>/dev/null; then
|
||||||
echo -e "${GREEN}mise 安装成功!${NC}"
|
echo -e "${GREEN}mise 安装成功!${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${RED}mise 安装失败,请检查错误信息${NC}"
|
mise_fail
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user