127 lines
3.5 KiB
Bash
Executable File
127 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# 定义版本变量和下载链接
|
||
GO_VERSION="1.21.4"
|
||
APPTAINER_VERSION="1.2.5"
|
||
GO_URL="https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
|
||
GO_ARCHIVE="/tmp/go${GO_VERSION}.linux-amd64.tar.gz"
|
||
APPTAINER_URL="https://github.com/apptainer/apptainer/archive/refs/tags/v${APPTAINER_VERSION}.tar.gz"
|
||
APPTAINER_ARCHIVE="/tmp/apptainer-${APPTAINER_VERSION}.tar.gz"
|
||
APPTAINER_DIR="apptainer-${APPTAINER_VERSION}"
|
||
|
||
# 安装系统依赖
|
||
install_dependencies() {
|
||
if grep -q 'PRETTY_NAME="Deepin 23"' /etc/os-release || [[ -f /etc/debian_version ]]; then
|
||
# Debian/Ubuntu/Deepin 系统依赖安装
|
||
echo "安装 Debian/Ubuntu/Deepin 依赖"
|
||
sudo apt-get update
|
||
sudo apt-get install -y build-essential libseccomp-dev pkg-config uidmap squashfs-tools squashfuse fuse2fs fuse-overlayfs fakeroot cryptsetup curl wget git
|
||
elif [[ -f /etc/redhat-release ]]; then
|
||
# RHEL/CentOS 系统依赖安装
|
||
echo "安装 RHEL/CentOS 依赖"
|
||
sudo yum groupinstall -y 'Development Tools'
|
||
sudo yum install -y epel-release
|
||
sudo yum install -y libseccomp-devel squashfs-tools squashfuse fuse-overlayfs fakeroot /usr/*bin/fuse2fs cryptsetup wget git
|
||
elif [[ -f /etc/SuSE-release ]]; then
|
||
# SLES/openSUSE 系统依赖安装
|
||
echo "安装 SLES/openSUSE 依赖"
|
||
sudo zypper install -y libseccomp-devel libuuid-devel openssl-devel cryptsetup sysuser-tools gcc go
|
||
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_apptainer() {
|
||
if [ ! -f "$APPTAINER_ARCHIVE" ]; then
|
||
wget -O "$APPTAINER_ARCHIVE" "$APPTAINER_URL"
|
||
fi
|
||
if [ ! -d "$APPTAINER_DIR" ]; then
|
||
mkdir "$APPTAINER_DIR"
|
||
tar -xzf "$APPTAINER_ARCHIVE" -C "$APPTAINER_DIR" --strip-components=1
|
||
fi
|
||
}
|
||
|
||
# 编译和安装 Apptainer
|
||
compile_apptainer() {
|
||
cd "$APPTAINER_DIR"
|
||
./mconfig
|
||
make -C builddir
|
||
sudo make -C builddir install
|
||
}
|
||
|
||
# 卸载 Apptainer
|
||
uninstall_apptainer() {
|
||
echo "正在卸载 Apptainer..."
|
||
sudo rm -rf /usr/local/bin/apptainer
|
||
sudo rm -rf /usr/local/libexec/apptainer
|
||
sudo rm -rf /usr/local/var/apptainer
|
||
sudo rm -rf /usr/local/etc/apptainer
|
||
sudo rm -rf /usr/local/lib/apptainer
|
||
echo "Apptainer 卸载完成。"
|
||
}
|
||
|
||
# 静默安装
|
||
silent_install() {
|
||
install_dependencies
|
||
install_go
|
||
download_apptainer
|
||
compile_apptainer
|
||
echo "Apptainer 安装完成。"
|
||
}
|
||
|
||
# 交互式菜单
|
||
interactive_menu() {
|
||
echo "选择操作:"
|
||
echo "1) 安装 Apptainer"
|
||
echo "2) 卸载 Apptainer"
|
||
echo "3) 退出"
|
||
read -p "请输入选项(1、2或3): " choice
|
||
|
||
case "$choice" in
|
||
1)
|
||
silent_install
|
||
;;
|
||
2)
|
||
uninstall_apptainer
|
||
;;
|
||
3)
|
||
exit 0
|
||
;;
|
||
*)
|
||
echo "无效的选项。"
|
||
exit 1
|
||
;;
|
||
esac
|
||
}
|
||
|
||
# 处理传入参数
|
||
if [[ $# -gt 0 ]]; then
|
||
case "$1" in
|
||
install)
|
||
silent_install
|
||
;;
|
||
uninstall)
|
||
uninstall_apptainer
|
||
;;
|
||
*)
|
||
echo "无效的参数。可用参数: install, uninstall"
|
||
exit 1
|
||
;;
|
||
esac
|
||
else
|
||
interactive_menu
|
||
fi
|