diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..41eb6a7 --- /dev/null +++ b/install.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +# 定义版本变量和下载链接 +GO_VERSION="1.21.4" +SINGULARITY_VERSION="4.0.2" +GO_URL="https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" +GO_ARCHIVE="/tmp/go${GO_VERSION}.linux-amd64.tar.gz" +SINGULARITY_URL="https://github.com/sylabs/singularity/releases/download/v${SINGULARITY_VERSION}/singularity-ce-${SINGULARITY_VERSION}.tar.gz" +SINGULARITY_ARCHIVE="/tmp/singularity-ce-${SINGULARITY_VERSION}.tar.gz" +SINGULARITY_DIR="singularity" + +# 安装系统依赖 +install_dependencies() { + if [[ -f /etc/debian_version ]]; then + # Debian/Ubuntu 系统依赖安装 + sudo apt-get update + sudo apt-get install -y autoconf automake cryptsetup git libfuse-dev libglib2.0-dev libseccomp-dev libtool pkg-config runc squashfs-tools squashfs-tools-ng uidmap wget zlib1g-dev + elif [[ -f /etc/redhat-release ]]; then + # RHEL/CentOS 系统依赖安装 + sudo yum groupinstall -y 'Development Tools' + sudo yum install -y autoconf automake crun cryptsetup fuse3-devel git glib2-devel libseccomp-devel libtool squashfs-tools wget zlib-devel + elif [[ -f /etc/SuSE-release ]]; then + # SLES/openSUSE 系统依赖安装 + sudo zypper in autoconf automake cryptsetup fuse3-devel gcc gcc-c++ git glib2-devel libseccomp-devel libtool make pkg-config runc squashfs wget zlib-devel + else + echo "不支持的操作系统。" + exit 1 + fi +} + +# 安装 Go +install_go() { + if [ ! -f "$GO_ARCHIVE" ]; then + wget -O "$GO_ARCHIVE" "$GO_URL" + fi + sudo rm -rf /usr/local/go + sudo tar -C /usr/local -xzf "$GO_ARCHIVE" + echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc + source ~/.bashrc +} + +# 下载并解压 Apptainer 源码 +download_singularity() { + if [ ! -f "$SINGULARITY_ARCHIVE" ]; then + wget -O "$SINGULARITY_ARCHIVE" "$SINGULARITY_URL" + fi + if [ ! -d "$SINGULARITY_DIR" ]; then + mkdir "$SINGULARITY_DIR" + tar -xzf "$SINGULARITY_ARCHIVE" -C "$SINGULARITY_DIR" --strip-components=1 + fi +} + +# 编译和安装 Apptainer +compile_singularity() { + cd "$SINGULARITY_DIR" + ./mconfig + make -C builddir + sudo make -C builddir install +} + +# 卸载 Apptainer +uninstall_singularity() { + echo "正在卸载 Apptainer..." + sudo rm -rf /usr/local/bin/singularity + sudo rm -rf /usr/local/libexec/singularity + sudo rm -rf /usr/local/var/singularity + sudo rm -rf /usr/local/etc/singularity + sudo rm -rf /usr/local/lib/singularity + echo "Apptainer 卸载完成。" +} + +# 交互式菜单 +interactive_menu() { + echo "选择操作:" + echo "1) 安装 Apptainer" + echo "2) 卸载 Apptainer" + echo "3) 退出" + read -p "请输入选项(1、2或3): " choice + + case "$choice" in + 1) + install_dependencies + install_go + download_singularity + compile_singularity + ;; + 2) + uninstall_singularity + ;; + 3) + exit 0 + ;; + *) + echo "无效的选项。" + exit 1 + ;; + esac +} + +interactive_menu \ No newline at end of file