caddy.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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" ] && mkdir -p ${caddy_install_dir}/conf
  29. /bin/cp ../config/Caddyfile ${caddy_install_dir}/conf/
  30. #move caddy.service to /lib/systemd/system
  31. /bin/cp ../init.d/caddy.service /lib/systemd/system/
  32. #modify caddy.service
  33. sed -i "s@/usr/local/caddy@${caddy_install_dir}@g" /lib/systemd/system/caddy.service
  34. #设置caddy开机启动
  35. systemctl enable caddy
  36. #reload systemd
  37. systemctl daemon-reload
  38. #start caddy service
  39. systemctl start caddy
  40. echo "${CSUCCESS}Caddy installed successfully! ${CEND}"
  41. }