caddy.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_Caddy() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. id -g ${run_group} >/dev/null 2>&1
  13. [ $? -ne 0 ] && groupadd ${run_group}
  14. id -u ${run_user} >/dev/null 2>&1
  15. [ $? -ne 0 ] && useradd -g ${run_group} -M -s /sbin/nologin ${run_user}
  16. #unzip caddy_${caddy_ver}_linux_amd64.zip
  17. tar xzf caddy-${caddy_ver}.tar.gz
  18. #move caddy to /usr/local/caddy/bin
  19. [ ! -d "${caddy_install_dir}/bin" ] && mkdir -p ${caddy_install_dir}/bin
  20. /bin/cp caddy ${caddy_install_dir}/bin
  21. chmod +x ${caddy_install_dir}/bin/caddy
  22. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=${caddy_install_dir}/bin:\$PATH" >> /etc/profile
  23. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep ${caddy_install_dir} /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${caddy_install_dir}/bin:\1@" /etc/profile
  24. . /etc/profile
  25. #make soft link
  26. # [ ! -L "/usr/local/bin/caddy" ] && ln -s ${caddy_install_dir}/bin/caddy /usr/local/bin/caddy
  27. #move caddyfile to /usr/local/caddy/conf
  28. [ ! -d "${caddy_install_dir}/conf/vhost" ] && mkdir -p ${caddy_install_dir}/conf/vhost
  29. /bin/cp ../config/Caddyfile ${caddy_install_dir}/conf/
  30. sed -i "s@/usr/local/caddy@${caddy_install_dir}@g" ${caddy_install_dir}/conf/Caddyfile
  31. #move caddy.service to /lib/systemd/system
  32. /bin/cp ../init.d/caddy.service /lib/systemd/system/
  33. #modify caddy.service
  34. sed -i "s@/usr/local/caddy@${caddy_install_dir}@g" /lib/systemd/system/caddy.service
  35. #设置caddy开机启动
  36. systemctl enable caddy
  37. #reload systemd
  38. systemctl daemon-reload
  39. #start caddy service
  40. systemctl start caddy
  41. echo "${CSUCCESS}Caddy installed successfully! ${CEND}"
  42. }