一键安装现代化Linux命令(GPT写的)

佬的这个很好用

但是一个一个装太慢了,我GPT写了几个安装脚本,在 Ubuntu-22.04-x64测试还不错,有什么报错或者啥不兼容,我再去找GPT修改

git clone  https://github.com/dong-dong6/LinuxInstall.git && chmod +x LinuxInstall/* && cd LinuxInstall && ./install.sh
完整代码
安装母脚本
#!/bin/bash

# 定义颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # 无颜色

# 打印消息函数
print_message() {
    COLOR=$1
    MESSAGE=$2
    echo -e "${COLOR}${MESSAGE}${NC}"
}

# 安装依赖
print_message $BLUE "正在安装依赖..."
source install_dependencies.sh
if [ $? -ne 0 ]; then
    print_message $RED "安装依赖失败"
    exit 1
fi
print_message $GREEN "依赖安装成功"

# 软件列表
software_list=(
    "btop"
    "duf"
    "dust"
    "lsd"
)

# 显示软件列表
print_message $YELLOW "请选择要安装的软件 (直接回车表示全部安装):"
for i in "${!software_list[@]}"; do
    echo "$((i+1)). ${software_list[$i]}"
done
read -p "输入编号 (例如: 1 2 3 或直接回车): " user_choice

# 将用户输入转换为数组
if [ -z "$user_choice" ]; then
    # 用户直接回车, 安装全部软件
    selected_software=("${software_list[@]}")
else
    # 根据用户输入筛选需要安装的软件
    selected_software=()
    for choice in $user_choice; do
        if [[ $choice =~ ^[0-9]+$ ]] && [ $choice -ge 1 ] && [ $choice -le ${#software_list[@]} ]; then
            selected_software+=("${software_list[$((choice-1))]}")
        else
            print_message $RED "无效的选择: $choice"
            exit 1
        fi
    done
fi

# 安装选择的软件
for software in "${selected_software[@]}"; do
    script="install_${software}.sh"
    if [ -f "$script" ]; then
        print_message $BLUE "正在安装 $software ..."
        source "$script"
        if [ $? -ne 0 ]; then
            print_message $RED "$software 安装失败"
            exit 1
        fi
        print_message $GREEN "$software 安装成功"
    else
        print_message $RED "找不到安装脚本: $script"
        exit 1
    fi
done

print_message $GREEN "所有软件安装完成"
依赖安装
#!/bin/bash

# 定义依赖库集合
DEPENDENCIES=("curl" "git" "wget" "make" "bzip2")

# 检测操作系统类型
if [ -f /etc/debian_version ]; then
    OS="Debian"
    INSTALL_CMD="sudo apt-get install -y"
    CHECK_CMD="command -v"
elif [ -f /etc/redhat-release ]; then
    OS="RedHat"
    INSTALL_CMD="sudo yum install -y"
    CHECK_CMD="command -v"
else
    echo "不支持的操作系统类型"
    exit 1
fi

echo "检测到操作系统:$OS 系"

# 安装依赖库
for DEP in "${DEPENDENCIES[@]}"; do
    echo "检查 $DEP 是否已安装..."
    if $CHECK_CMD $DEP &>/dev/null; then
        echo "$DEP 已安装"
    else
        echo "$DEP 未安装。正在安装 $DEP..."
        $INSTALL_CMD $DEP
        if [ $? -eq 0 ]; then
            echo "$DEP 安装成功"
        else
            echo "安装 $DEP 失败"
            exit 1
        fi
    fi
done

echo "所有依赖库已检查并在必要时安装完毕。"

安装btop
#!/bin/bash

# 定义颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # 无颜色

# 打印消息函数
print_message() {
    COLOR=$1
    MESSAGE=$2
    echo -e "${COLOR}${MESSAGE}${NC}"
}

# 获取最新的发布版本
LATEST_VERSION=$(curl -s https://api.github.com/repos/aristocratos/btop/releases/latest | jq -r '.tag_name')
if [ -z "$LATEST_VERSION" ]; then
    print_message $RED "无法获取最新版本信息"
    exit 1
fi
print_message $BLUE "最新版本: $LATEST_VERSION"

# 检测 CPU 架构
ARCH=$(uname -m)
case $ARCH in
    x86_64)
        FILE="btop-x86_64-linux-musl.tbz"
        ;;
    aarch64)
        FILE="btop-aarch64-linux-musl.tbz"
        ;;
    armv7l)
        FILE="btop-armv7l-linux-musleabihf.tbz"
        ;;
    i686)
        FILE="btop-i686-linux-musl.tbz"
        ;;
    *)
        print_message $RED "不支持的 CPU 架构: $ARCH"
        exit 1
        ;;
esac
print_message $BLUE "检测到 CPU 架构: $ARCH"

# 下载对应架构的 btop
URL="https://github.com/aristocratos/btop/releases/download/$LATEST_VERSION/$FILE"
print_message $YELLOW "下载 $URL ..."
wget $URL -O $FILE
if [ $? -ne 0 ]; then
    print_message $RED "下载失败"
    exit 1
fi
print_message $GREEN "下载成功"

# 解压文件
print_message $YELLOW "解压 $FILE ..."
tar -xvf $FILE
if [ $? -ne 0 ]; then
    print_message $RED "解压失败"
    exit 1
fi
print_message $GREEN "解压成功"

# 安装 btop
cd btop || { print_message $RED "进入目录失败"; exit 1; }
print_message $YELLOW "安装 btop ..."
sudo ./install.sh
if [ $? -ne 0 ]; then
    print_message $RED "安装失败"
    exit 1
fi
print_message $GREEN "安装成功"

# 清理文件
cd ..
rm -rf btop $FILE
print_message $BLUE "安装完成并清理临时文件"


安装duf
#!/bin/bash

# 定义颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # 无颜色

# 打印消息函数
print_message() {
    COLOR=$1
    MESSAGE=$2
    echo -e "${COLOR}${MESSAGE}${NC}"
}

print_message $YELLOW "更新包列表..."
sudo apt-get update

print_message $YELLOW "安装 duf..."
if sudo apt-get install -y duf; then
    print_message $GREEN "duf 安装成功!"
else
    print_message $RED "duf 安装失败,请检查您的包管理器配置。"
    exit 1
fi

安装dust
#!/bin/bash

# 定义颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # 无颜色

# 打印消息函数
print_message() {
    COLOR=$1
    MESSAGE=$2
    echo -e "${COLOR}${MESSAGE}${NC}"
}

# 获取最新的发布版本
LATEST_VERSION=$(curl -s https://api.github.com/repos/bootandy/dust/releases/latest | jq -r '.tag_name')
if [ -z "$LATEST_VERSION" ]; then
    print_message $RED "无法获取最新版本信息"
    exit 1
fi
print_message $BLUE "最新版本: $LATEST_VERSION"

# 检测 CPU 架构
ARCH=$(uname -m)
case $ARCH in
    x86_64)
        FILE="dust-${LATEST_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
        ;;
    aarch64)
        FILE="dust-${LATEST_VERSION}-aarch64-unknown-linux-gnu.tar.gz"
        ;;
    armv7l)
        FILE="dust-${LATEST_VERSION}-arm-unknown-linux-musleabi.tar.gz"
        ;;
    i686)
        FILE="dust-${LATEST_VERSION}-i686-unknown-linux-gnu.tar.gz"
        ;;
    *)
        print_message $RED "不支持的 CPU 架构: $ARCH"
        exit 1
        ;;
esac
print_message $BLUE "检测到 CPU 架构: $ARCH"

# 下载对应架构的 dust
URL="https://github.com/bootandy/dust/releases/download/$LATEST_VERSION/$FILE"
print_message $YELLOW "下载 $URL ..."
wget $URL -O $FILE
if [ $? -ne 0 ]; then
    print_message $RED "下载失败"
    exit 1
fi
print_message $GREEN "下载成功"

# 解压文件
print_message $YELLOW "解压 $FILE ..."
tar -xvf $FILE
if [ $? -ne 0 ]; then
    print_message $RED "解压失败"
    exit 1
fi
print_message $GREEN "解压成功"

# 移动二进制文件到 /usr/local/bin/
DIR_NAME=$(basename $FILE .tar.gz)
cd $DIR_NAME || { print_message $RED "进入目录失败"; exit 1; }
print_message $YELLOW "移动 dust 二进制文件到 /usr/local/bin/ ..."
sudo mv dust /usr/local/bin/
if [ $? -ne 0 ]; then
    print_message $RED "移动文件失败"
    exit 1
fi
print_message $GREEN "移动文件成功"

# 清理文件
cd ..
rm -rf $DIR_NAME $FILE
print_message $BLUE "安装完成并清理临时文件"

安装lsd
#!/bin/bash

# 定义颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # 无颜色

# 打印消息函数
print_message() {
    COLOR=$1
    MESSAGE=$2
    echo -e "${COLOR}${MESSAGE}${NC}"
}

# 获取最新的发布版本
LATEST_VERSION=$(curl -s https://api.github.com/repos/lsd-rs/lsd/releases/latest | jq -r '.tag_name')
if [ -z "$LATEST_VERSION" ]; then
    print_message $RED "无法获取最新版本信息"
    exit 1
fi
print_message $BLUE "最新版本: $LATEST_VERSION"

# 检测 CPU 架构
ARCH=$(uname -m)
case $ARCH in
    x86_64)
        FILE="lsd-${LATEST_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
        ;;
    aarch64)
        FILE="lsd-${LATEST_VERSION}-aarch64-unknown-linux-gnu.tar.gz"
        ;;
    armv7l)
        FILE="lsd-${LATEST_VERSION}-arm-unknown-linux-gnueabihf.tar.gz"
        ;;
    i686)
        FILE="lsd-${LATEST_VERSION}-i686-unknown-linux-gnu.tar.gz"
        ;;
    *)
        print_message $RED "不支持的 CPU 架构: $ARCH"
        exit 1
        ;;
esac
print_message $BLUE "检测到 CPU 架构: $ARCH"

# 下载对应架构的 lsd
URL="https://github.com/lsd-rs/lsd/releases/download/$LATEST_VERSION/$FILE"
print_message $YELLOW "下载 $URL ..."
wget $URL -O $FILE
if [ $? -ne 0 ]; then
    print_message $RED "下载失败"
    exit 1
fi
print_message $GREEN "下载成功"

# 解压文件
print_message $YELLOW "解压 $FILE ..."
tar -xzf $FILE
if [ $? -ne 0 ]; then
    print_message $RED "解压失败"
    exit 1
fi
print_message $GREEN "解压成功"

# 安装 lsd
print_message $YELLOW "安装 lsd ..."
sudo install -m 755 lsd*/lsd /usr/local/bin/lsd
if [ $? -ne 0 ]; then
    print_message $RED "安装失败"
    exit 1
fi
print_message $GREEN "安装成功"

# 配置 zsh 别名
print_message $YELLOW "配置 zsh 别名 ..."
{
    echo "alias ls='lsd'"
    echo "alias ll='lsd -alh'"
    echo "alias tree='lsd --tree'"
} >> ~/.zshrc
if [ $? -ne 0 ]; then
    print_message $RED "配置别名失败"
    exit 1
fi
print_message $GREEN "配置别名成功"

# 使 zsh 配置生效
source ~/.zshrc
if [ $? -ne 0 ]; then
    print_message $RED "使配置生效失败"
    exit 1
fi
print_message $GREEN "配置生效成功"

# 清理文件
rm -rf lsd* $FILE
print_message $BLUE "安装完成并清理临时文件"

8 Likes

优雅!

1 Like

GPT好牛

1 Like

优雅啊

1 Like

感谢

1 Like

gpt助理工程师

1 Like

linux.do论坛终于正经聊起了linux

1 Like