Files
apptainerce_build/install.sh
2023-12-21 16:16:55 +08:00

128 lines
4.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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://mirror.ghproxy.com/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 grep -q 'PRETTY_NAME="Deepin 23"' /etc/os-release; then
# Deepin 23 系统依赖安装
# 在这里添加Deepin 23的依赖安装命令
echo "安装Deepin 23依赖"
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
# wget http://ftp.hk.debian.org/debian/pool/main/s/squashfs-tools-ng/squashfs-tools-ng_1.2.0-1_amd64.deb
# wget http://ftp.hk.debian.org/debian/pool/main/s/squashfs-tools-ng/libsquashfs1_1.2.0-1_amd64.deb
# sudo dpkg -i ./libsquashfs1_1.2.0-1_amd64.deb
# sudo dpkg -i ./squashfs-tools-ng_1.2.0-1_amd64.deb
# rm ./libsquashfs1_1.2.0-1_amd64.deb
# rm ./squashfs-tools-ng_1.2.0-1_amd64.deb
elif [[ -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
}
# 下载并解压 singularity 源码
download_singularity() {
if [ ! -f "$SINGULARITY_ARCHIVE" ]; then
wget -O "$SINGULARITY_ARCHIVE" "$SINGULARITY_URL"
if [ $? -ne 0 ]; then
echo "Failed to download $SINGULARITY_ARCHIVE"
exit 1
fi
fi
if [ -d "$SINGULARITY_DIR" ]; then
echo "Removing existing directory: $SINGULARITY_DIR"
rm -rf "$SINGULARITY_DIR"
fi
echo "Creating directory: $SINGULARITY_DIR"
mkdir "$SINGULARITY_DIR"
echo "Extracting archive: $SINGULARITY_ARCHIVE to $SINGULARITY_DIR"
tar -xzf "$SINGULARITY_ARCHIVE" -C "$SINGULARITY_DIR" --strip-components=1
if [ $? -ne 0 ]; then
echo "Failed to extract $SINGULARITY_ARCHIVE"
exit 1
fi
}
# 编译和安装 singularity
compile_singularity() {
cd "$SINGULARITY_DIR"
./mconfig
make -C builddir
sudo make -C builddir install
}
# 卸载 singularity
uninstall_singularity() {
echo "正在卸载 singularity..."
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 "singularity 卸载完成。"
}
# 交互式菜单
interactive_menu() {
echo "选择操作:"
echo "1) 安装 singularity"
echo "2) 卸载 singularity"
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