111
\n
222
#!/bin/bash
# exit 0
# 技术支持 QQ1713829947 https://www.yuque.com/lwmacct
if [ -d "/root/.local/share/code-server" ]; then
# 在宿主机命令行模式下,执行本文件, 如果目录存在, 那则认定为, 还在容器内部
_container_id=$(grep devices </proc/self/cgroup | grep -Po '[0-9a-z]{64}' | cut -c1-12)
_root_path="$(nsenter --mount=/host/1/ns/mnt docker inspect "$_container_id" -f '{{.HostConfig.Binds}}' | grep -Eo '\s.*:/root' | awk -F ':' '{print $1}' | awk '{print $NF}')"
_workspace_path="$(echo "$0" | awk -F '/root/' '{print $NF}')"
_host_path="${_root_path}/$_workspace_path"
nsenter --mount=/host/1/ns/mnt --net=/host/1/ns/net /bin/bash "${_host_path}" "$@"
exit
fi
__init_var_before() {
_var0=$0
_build_workspace="${_var0%/*}/build"
mkdir -p "$_build_workspace"
_images_name_simple=$(echo "$_build_workspace" | awk -F '/' '{print $(NF-2)":"$(NF-1)}')
}
__init_var_after() {
_currTime=$(date +"%Y%m%d%H%m%S")
sed -i "s/SED_REPLACE/$_images_name_simple/g" Dockerfile
}
__write_dockerfile() {
cd "$_build_workspace" || exit 0
cat >./Dockerfile <<"AEOF"
FROM registry.cn-hangzhou.aliyuncs.com/lwmacct/ubuntu:v20.04-t2022060301
RUN apt-get update && apt-get install sysstat; \
sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
RUN rm -rf /etc/cron.d/; \
ln -sf /apps/shell/cron.d/ /etc/cron.d; \
ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''; \
cat /root/.ssh/id_rsa.pub; \
echo "StrictHostKeyChecking no" >> /root/.ssh/config; \
echo "alias host='nsenter --mount=/host/1/ns/mnt --net=/host/1/ns/net bash'" >> /root/.bashrc
RUN echo "安装 zabbix_agent"; \
mkdir -p /opt/zabbix_agent; \
curl -Lo - https://cdn.zabbix.com/zabbix/binaries/stable/6.0/6.0.4/zabbix_agent-6.0.4-linux-3.0-amd64-static.tar.gz | tar zxf - -C /opt/zabbix_agent; \
ln -sf /opt/zabbix_agent/bin/* /usr/local/bin/; \
ln -sf /opt/zabbix_agent/sbin/* /usr/local/bin/;
RUN echo "安装 frp"; \
mkdir -p /opt/frp; \
curl -Lo - https://github.com/fatedier/frp/releases/download/v0.42.0/frp_0.42.0_linux_amd64.tar.gz | tar zxf - -C /opt/frp --strip-components 1; \
ln -sf /opt/frp/frpc /usr/bin/; \
ln -sf /opt/frp/frps /usr/bin/; \
mkdir -p /etc/frp/; \
cp -rf /opt/frp/*.ini /etc/frp
ADD ip2region/ /opt/ip2region
ADD apps/ /apps/
ENTRYPOINT ["bash", "/apps/entrypoint.sh"]
ADD Dockerfile /srv/dockerfile/SED_REPLACE
AEOF
}
__bulid_default() {
_registry="registry.cn-hangzhou.aliyuncs.com/" # 后面必须要有 /
_user="bd"
_images_name_full="${_registry}${_user}/${_images_name_simple}"
echo "$_images_name_full"
docker build -t "${_images_name_full}" "${_build_workspace}" # --no-cache
docker push "$_images_name_full"
}
__main() {
__init_var_before
__write_dockerfile
__init_var_after
__bulid_default
}
__main
__help() {
cat >/dev/null <<"EOF"
registry.cn-hangzhou.aliyuncs.com/bd/rce:baidu-xcdn
bash /root/workspace/dockerfile/rce/baidu-xcdn/build.sh
EOF
}