# 使用 Ubuntu 12.04 作为基础镜像
FROM ubuntu:12.04

# 设置环境变量以避免交互式安装
ENV DEBIAN_FRONTEND=noninteractive

# 更新包列表并安装必要的软件包
RUN sed -i 's|http://archive.ubuntu.com/ubuntu|http://old-releases.ubuntu.com/ubuntu|g' /etc/apt/sources.list && \
    apt-get update && \
    apt-get install -y \
    openssh-client \
    bzip2 \
    build-essential \
    cmake \
    curl \
    g++ \
    gcc \
    git \
    gzip \
    libgcrypt11-dev \
    libglib2.0-dev \
    libgnutls-dev \
    libhiredis-dev \
    libidn11-dev \
    libssl-dev \
    libsctp-dev \
    libmysqlclient-dev \
    make \
    sed \
    sudo \
    tar \
    unzip \
    vim \
    wget \
    xz-utils \
    zlib1g-dev \
    autoconf \
    automake \
    libtool \
    #binutils \
    #libzstd-dev \
    libidn2-0-dev && \    
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 下载并编译 zstd 库
RUN wget https://github.com/facebook/zstd/archive/refs/tags/v1.4.9.tar.gz && \
    tar -xzf v1.4.9.tar.gz && \
    cd zstd-1.4.9 && \
    make && \
    make install && \
    cd .. && \
    rm -rf zstd-1.4.9 v1.4.9.tar.gz    

# 下载并编译 binutils 库
RUN wget https://ftp.gnu.org/gnu/binutils/binutils-2.36.1.tar.gz && \
    tar -xzf binutils-2.36.1.tar.gz && \
    cd binutils-2.36.1 && \
    ./configure && \
    make && \
    make install && \
    cd .. && \
    rm -rf binutils-2.36.1 binutils-2.36.1.tar.gz

# 创建一个用户并设置密码
RUN useradd -ms /bin/bash simon && echo "simon:admin123" | chpasswd && adduser simon sudo

# 生成 SSH 密钥对
RUN mkdir -p /home/simon/.ssh && \
    ssh-keygen -t ecdsa -b 521 -f /home/simon/.ssh/id_ecdsa -N "" -C "simon@ubuntu12.dev" && \
    ssh-keyscan -t ecdsa -H 192.168.2.166 >> /home/simon/.ssh/known_hosts && \
    chown -R simon:simon /home/simon/.ssh

# 打印公钥，方便添加到 Gitea 服务器
RUN cat /home/simon/.ssh/id_ecdsa.pub    

# 切换到新用户
USER simon
WORKDIR /home/simon

# 复制项目文件到容器中（如果有）
#COPY ../ocs.git /home/simon/

# 设置工作目录
WORKDIR /home/simon

# 默认命令
CMD ["/bin/bash"]
