```shell
#!/bin/sh
set -o pipefail
export _ipv4Range=`curl --retry 10 --retry-delay 5 -s
https://www.cloudflare-cn.com/ips-v4`
if [[ $? -ne 0 ]]; then
export _ipv4Range=`curl --retry 10 --retry-delay 5 -s
https://www.cloudflare.com/ips-v4`
if [[ $? -ne 0 ]]; then
exit 1
fi
fi
export _ipv6Range=`curl --retry 10 --retry-delay 5 -s
https://www.cloudflare-cn.com/ips-v6`
if [[ $? -ne 0 ]]; then
export _ipv6Range=`curl --retry 10 --retry-delay 5 -s
https://www.cloudflare.com/ips-v6`
if [[ $? -ne 0 ]]; then
exit 1
fi
fi
#nginx real_ip
_tmpConf="/tmp/._$(date '+%Y-%m-%d-%H-%M')-$(cat /proc/sys/kernel/random/uuid).txt"
_target='/etc/nginx/conf.d/common/cloudflare/_real_ip_from-ip-set.conf'
{
echo "# Generated by ${0}"
echo "# At $(date)"
echo "# IPV4"
for i in ${_ipv4Range} ;do echo "set_real_ip_from ${i};" ;done
echo ""
echo "# IPV6"
for i in ${_ipv6Range} ;do echo "set_real_ip_from ${i};" ;done
echo ""
} |tee ${_tmpConf}
if [[ $? -eq 0 ]]; then
mv "${_tmpConf}" "${_target}"
nginx -t
if [[ $? -eq 0 ]]; then
echo "Nginx 配置正常,重载配置!"
nginx -s reload
else
/app/scripts/bin/
gotify.sh --title "${_target} 文件更新成功,但 Nginx 配置有误" "请修复后手动重载 Nginx !\n""nginx -s reload"
fi
fi
#nginx allow-ip-set
#sleep 1
_tmpConf="/tmp/._$(date '+%Y-%m-%d-%H-%M')-$(cat /proc/sys/kernel/random/uuid).txt"
_target='/etc/nginx/conf.d/common/cloudflare/_allow-ip-set.conf'
{
echo "# Generated by ${0}"
echo "# At $(date)"
echo "# IPV4"
for i in ${_ipv4Range} ;do echo "allow ${i};" ;done
echo ""
echo "# IPV6"
for i in ${_ipv6Range} ;do echo "allow ${i};" ;done
echo ""
} |tee ${_tmpConf}
if [[ $? -eq 0 ]]; then
mv "${_tmpConf}" "${_target}"
nginx -t
if [[ $? -eq 0 ]]; then
echo "Nginx 配置正常,重载配置!"
nginx -s reload
else
/app/scripts/bin/
gotify.sh --title "${_target} 文件更新成功,但 Nginx 配置有误" "请修复后手动重载 Nginx !\n""nginx -s reload"
fi
fi
```
我这边用来更新 allow ip 配置文件的脚本