1. 111
    2. \n
    3. 222
    4. #!/bin/bash
    5. # exit 0
    6. # 技术支持 QQ1713829947 https://www.yuque.com/lwmacct
    7. if [ -d "/root/.local/share/code-server" ]; then
    8. # 在宿主机命令行模式下,执行本文件, 如果目录存在, 那则认定为, 还在容器内部
    9. _container_id=$(grep devices </proc/self/cgroup | grep -Po '[0-9a-z]{64}' | cut -c1-12)
    10. _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}')"
    11. _workspace_path="$(echo "$0" | awk -F '/root/' '{print $NF}')"
    12. _host_path="${_root_path}/$_workspace_path"
    13. nsenter --mount=/host/1/ns/mnt --net=/host/1/ns/net /bin/bash "${_host_path}" "$@"
    14. exit
    15. fi
    16. __init_var_before() {
    17. _var0=$0
    18. _build_workspace="${_var0%/*}/build"
    19. mkdir -p "$_build_workspace"
    20. _images_name_simple=$(echo "$_build_workspace" | awk -F '/' '{print $(NF-2)":"$(NF-1)}')
    21. }
    22. __init_var_after() {
    23. _currTime=$(date +"%Y%m%d%H%m%S")
    24. sed -i "s/SED_REPLACE/$_images_name_simple/g" Dockerfile
    25. }
    26. __write_dockerfile() {
    27. cd "$_build_workspace" || exit 0
    28. cat >./Dockerfile <<"AEOF"
    29. FROM registry.cn-hangzhou.aliyuncs.com/lwmacct/ubuntu:v20.04-t2022060301
    30. RUN apt-get update && apt-get install sysstat; \
    31. sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
    32. RUN rm -rf /etc/cron.d/; \
    33. ln -sf /apps/shell/cron.d/ /etc/cron.d; \
    34. ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''; \
    35. cat /root/.ssh/id_rsa.pub; \
    36. echo "StrictHostKeyChecking no" >> /root/.ssh/config; \
    37. echo "alias host='nsenter --mount=/host/1/ns/mnt --net=/host/1/ns/net bash'" >> /root/.bashrc
    38. RUN echo "安装 zabbix_agent"; \
    39. mkdir -p /opt/zabbix_agent; \
    40. 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; \
    41. ln -sf /opt/zabbix_agent/bin/* /usr/local/bin/; \
    42. ln -sf /opt/zabbix_agent/sbin/* /usr/local/bin/;
    43. RUN echo "安装 frp"; \
    44. mkdir -p /opt/frp; \
    45. 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; \
    46. ln -sf /opt/frp/frpc /usr/bin/; \
    47. ln -sf /opt/frp/frps /usr/bin/; \
    48. mkdir -p /etc/frp/; \
    49. cp -rf /opt/frp/*.ini /etc/frp
    50. ADD ip2region/ /opt/ip2region
    51. ADD apps/ /apps/
    52. ENTRYPOINT ["bash", "/apps/entrypoint.sh"]
    53. ADD Dockerfile /srv/dockerfile/SED_REPLACE
    54. AEOF
    55. }
    56. __bulid_default() {
    57. _registry="registry.cn-hangzhou.aliyuncs.com/" # 后面必须要有 /
    58. _user="bd"
    59. _images_name_full="${_registry}${_user}/${_images_name_simple}"
    60. echo "$_images_name_full"
    61. docker build -t "${_images_name_full}" "${_build_workspace}" # --no-cache
    62. docker push "$_images_name_full"
    63. }
    64. __main() {
    65. __init_var_before
    66. __write_dockerfile
    67. __init_var_after
    68. __bulid_default
    69. }
    70. __main
    71. __help() {
    72. cat >/dev/null <<"EOF"
    73. registry.cn-hangzhou.aliyuncs.com/bd/rce:baidu-xcdn
    74. bash /root/workspace/dockerfile/rce/baidu-xcdn/build.sh
    75. EOF
    76. }