一键安装OneIndex by caddy,才学shell,拿着两位大佬的脚本杂交了一下,结果不能运行。求指点
报错信息:./OneIndex.sh:行193: install_caddy: 未找到命令
- #!/usr/bin/env bash
- PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
- export PATH
- file="/usr/local/caddy/"
- caddy_file="/usr/local/caddy/caddy"
- caddy_conf_file="/usr/local/caddy/caddyconf"
- Info_font_prefix="\033[32m" && Error_font_prefix="\033[31m" && Info_background_prefix="\033[42;37m" && Error_background_prefix="\033[41;37m" && Font_suffix="\033[0m"
- Check_root(){
- [[ $EUID != 0 ]] && echo -e "${Error} 当前非ROOT账号(或没有ROOT权限),无法继续操作,请更换ROOT账号或使用 ${Green_background_prefix}sudo su${Font_color_suffix} 命令获取临时ROOT权限(执行后可能会提示输入当前账号的密码)。" && exit 1
- }
- Check_sys(){
- if [[ -f /etc/redhat-release ]]; then
- release="centos"
- elif cat /etc/issue | grep -q -E -i "debian"; then
- release="debian"
- elif cat /etc/issue | grep -q -E -i "ubuntu"; then
- release="ubuntu"
- elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
- release="centos"
- elif cat /proc/version | grep -q -E -i "debian"; then
- release="debian"
- elif cat /proc/version | grep -q -E -i "ubuntu"; then
- release="ubuntu"
- elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
- release="centos"
- fi
- bit=$(uname -m)
- }
- Check_installed_status(){
- [[ ! -e ${caddy_file} ]] && echo -e "${Error_font_prefix}[错误]${Font_suffix} Caddy 没有安装,请检查 !" && exit 1
- }
- Download_caddy(){
- [[ ! -e ${file} ]] && mkdir "${file}"
- cd "${file}"
- PID=$(ps -ef |grep "caddy" |grep -v "grep" |grep -v "init.d" |grep -v "service" |grep -v "caddy_install" |awk ‘{print $2}’)
- [[ ! -z ${PID} ]] && kill -9 ${PID}
- [[ -e "caddy_linux*.tar.gz" ]] && rm -rf "caddy_linux*.tar.gz"
- if [[ ! -z ${extension} ]]; then
- extension_all="?plugins=${extension}&license=personal"
- else
- extension_all="?license=personal"
- fi
- if [[ ${bit} == "x86_64" ]]; then
- wget –no-check-certificate -O "caddy_linux.tar.gz" "https://caddyserver.com/download/linux/amd64${extension_all}"
- elif [[ ${bit} == "i386" || ${bit} == "i686" ]]; then
- wget –no-check-certificate -O "caddy_linux.tar.gz" "https://caddyserver.com/download/linux/386${extension_all}"
- elif [[ ${bit} == "armv7l" ]]; then
- wget –no-check-certificate -O "caddy_linux.tar.gz" "https://caddyserver.com/download/linux/arm7${extension_all}"
- else
- echo -e "${Error_font_prefix}[错误]${Font_suffix} 不支持 [${bit}] ! 请向本站反馈[]中的名称,我会看看是否可以添加支持。" && exit 1
- fi
- [[ ! -e "caddy_linux.tar.gz" ]] && echo -e "${Error_font_prefix}[错误]${Font_suffix} Caddy 下载失败 !" && exit 1
- tar zxf "caddy_linux.tar.gz"
- rm -rf "caddy_linux.tar.gz"
- [[ ! -e ${caddy_file} ]] && echo -e "${Error_font_prefix}[错误]${Font_suffix} Caddy 解压失败或压缩文件错误 !" && exit 1
- rm -rf LICENSES.txt
- rm -rf README.txt
- rm -rf CHANGES.txt
- rm -rf "init/"
- chmod +x caddy
- }
- Service_caddy(){
- if [[ ${release} = "centos" ]]; then
- if ! wget –no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/service/caddy_centos -O /etc/init.d/caddy; then
- echo -e "${Error_font_prefix}[错误]${Font_suffix} Caddy服务 管理脚本下载失败 !" && exit 1
- fi
- chmod +x /etc/init.d/caddy
- chkconfig –add caddy
- chkconfig caddy on
- else
- if ! wget –no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/service/caddy_debian -O /etc/init.d/caddy; then
- echo -e "${Error_font_prefix}[错误]${Font_suffix} Caddy服务 管理脚本下载失败 !" && exit 1
- fi
- chmod +x /etc/init.d/caddy
- update-rc.d -f caddy defaults
- fi
- }
- Install_dependencies(){
- apt-get update -y
- apt-get install gcc g++ make zip lrzsz psmisc autoconf curl git dnsutils php7.0 php7.0-cgi php7.0-fpm php7.0-curl php7.0-common php7.0-gd php7.0-zip -y
- service php7.0-fpm start
- }
- Set_conf(){
- echo && stty erase ‘^H’ && read -p "输入域名(请提前绑定到vps IP): " domain
- [[ -z ${domain} ]] && echo "域名为空" && exit 0
- echo "正在检查输入域名是否解析IP"
- IP=`dig $domain | grep $domain | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"`
- IP_VPS=`curl http://whatismyip.akamai.com`
- [[ ${IP} != ${IP_VPS} ]] && echo "解析暂未生效,请稍候重试" && exit 0
- echo "
- $domain {
- root ${caddy_file}/$domain
- gzip
- fastcgi / /run/php/php7.0-fpm.sock {
- ext .php
- split .php
- index index.php
- }
- rewrite {
- to {path} {path}/ /index.php?{query}
- }
- }
- " >> ${caddy_conf_file}
- ulimit -n 51200
- nohup caddy -conf=${caddy_conf_file} -agree >> /tmp/caddy.log 2>&1 &
- cd ${caddy_file}/$domain
- git clone https://github.com/donwa/oneindex.git
- mv oneindex/* .
- rm -rf oneindex
- chmod +x -R cache config
- clear
- }
- Install_all(){
- Check_root
- if [[ -e ${caddy_file} ]]; then
- echo && echo -e "${Error_font_prefix}[信息]${Font_suffix} 检测到 Caddy 已安装,是否继续安装(覆盖更新)?[y/N]"
- read -e -p "(默认: n):" yn
- [[ -z ${yn} ]] && yn="n"
- if [[ ${yn} == [Nn] ]]; then
- echo && echo "已取消…" && exit 1
- fi
- fi
- Download_caddy
- Service_caddy
- Install_dependencies
- Set_conf
- echo && echo -e " 安装完毕,访问域名 https://$domain
- 请自行访问域名进行设置
- 请自行添加计划任务刷新缓存
- crontab -e
- */5 * * * * php ${caddy_file}/$domain/one.php cache:refresh
- 脚本已经内置去除/?/伪静态,如有需要请在后台设置
- PHP.ini /etc/php/7.0/fpm/php.ini
- Caddy 使用命令:${caddy_conf_file}
- 日志文件:cat /tmp/caddy.log
- 使用说明:service caddy start | stop | restart | status
- 或者使用:/etc/init.d/caddy start | stop | restart | status
- ${Info_font_prefix}[信息]${Font_suffix} Caddy 安装完成!" && echo
- }
- Uninstall_caddy(){
- Check_installed_status
- echo && echo "确定要卸载 Caddy ? [y/N]"
- read -e -p "(默认: n):" unyn
- [[ -z ${unyn} ]] && unyn="n"
- if [[ ${unyn} == [Yy] ]]; then
- PID=`ps -ef |grep "caddy" |grep -v "grep" |grep -v "init.d" |grep -v "service" |grep -v "caddy_install" |awk ‘{print $2}’`
- [[ ! -z ${PID} ]] && kill -9 ${PID}
- if [[ ${release} = "centos" ]]; then
- chkconfig –del caddy
- else
- update-rc.d -f caddy remove
- fi
- [[ -s /tmp/caddy.log ]] && rm -rf /tmp/caddy.log
- rm -rf ${caddy_file}
- rm -rf ${caddy_conf_file}
- rm -rf /etc/init.d/caddy
- [[ ! -e ${caddy_file} ]] && echo && echo -e "${Info_font_prefix}[信息]${Font_suffix} Caddy 卸载完成 !" && echo && exit 1
- echo && echo -e "${Error_font_prefix}[错误]${Font_suffix} Caddy 卸载失败 !" && echo
- else
- echo && echo "卸载已取消…" && echo
- fi
- }
- Check_sys
- action=$1
- extension=$2
- [[ -z $1 ]] && action=install
- case "$action" in
- install|uninstall)
- ${action}_caddy
- ;;
- *)
- echo "输入错误 !"
- echo "用法: {install | uninstall}"
- ;;
- esac
复制代码
江苏网友:
运行下看哪报错了
上海网友:没有,用错词语了,立马修改了。不好意思
四川网友:你贴出来的好像没有193行??
install_caddy这个函数没有~~~
黑龙江网友:
这就是全部代码,vps里面运行就是这么报错的,确实没有install_caddy
河北网友:为什么不是报186行的错……
你都知道没有install_caddy函数了,还不赶紧写一个……
湖北网友:./OneIndex.sh:行193: install_caddy: 未找到命令
这是报错。不会弄了,所以来求教
河南网友:
报错说的很清楚了,没有install_caddy函数
你自己组合两个脚本也要一小部分一小部分慢慢挪啊,而且至少先搞懂哪一部分是干什么的再组合
—
install_caddy函数从原来两个脚本里找,还要看里面有没有用到其它函数
或者把Install_all改为install_caddy试试
青海网友:
大佬可否详细指点,谢谢
关键是我找不到哪里使用了install_caddy
山西网友:install_caddy函数从原来两个脚本里找,还要看里面有没有用到其它函数
或者把Install_all改为install_caddy试试
福建网友:install_caddy函数从原来两个脚本里找,还要看里面有没有用到其它函数
或者把Install_all改为install_caddy试试
广西网友: