#!/bin/bash export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin #fonts color Red="\033[31m" Font="\033[0m" Blue="\033[36m" #root permission root(){ if [[ $EUID -ne 0 ]]; then echo "${Red}Error:请使用root运行该脚本!"${Font} 1>&2 exit 1 fi } #check system system(){ if [[ -f /etc/redhat-release ]]; then release="centos" elif cat /etc/issue | grep -Eqi "debian"; then release="debian" elif cat /etc/issue | grep -Eqi "ubuntu"; then release="ubuntu" elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then release="centos" elif cat /proc/version | grep -Eqi "debian"; then release="debian" elif cat /proc/version | grep -Eqi "ubuntu"; then release="ubuntu" elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then release="centos" fi } #check version version(){ if [[ -s /etc/redhat-release ]]; then version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'` else version=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1` fi echo -e "${Blue}正在为系统进行环境检测...${Font} " for EXE in grep cut xargs systemctl ip awk do if ! type -p ${EXE}; then echo -e "${Red}系统精简厉害,脚本自动退出${Font}" exit 1 fi done if [[ "${release}" = "centos" && ${version} -ge 7 ]];then echo -e "${Blue}当前系统为CentOS ${version},且符合安装要求!${Font} " elif [[ "${release}" = "debian" && ${version} -ge 8 ]];then echo -e "${Blue}当前系统为Debian ${version},且符合安装要求!${Font} " elif [[ "${release}" = "ubuntu" && `echo "${version}" | cut -d '.' -f1` -ge 16 ]];then echo -e "${Blue}当前系统为Ubuntu ${version},且符合安装要求!${Font} " else echo -e "${Red}当前系统为不在支持的系统列表内,安装中断!${Font} " exit 1 fi } #enter info enter(){ if [[ "${num}" = "2" ]]; then stty erase '^H' && read -p "请输入你的express-ffmpeg域名信息(如:xx.com):" domain [[ -z $domain ]] && echo -e "${Red}输入有误,请重新运行脚本! ${Font} "&& exit 1; fi stty erase '^H' && read -p "请输入express-ffmpeg后台路径(如后台为xx.com/www,则输入www即可,请不要输入admin):" url [[ -z $url ]] && echo -e "${Red}输入有误,请重新运行脚本! ${Font} "&& exit 1; stty erase '^H' && read -p "请输入express-ffmpeg管理员用户名:" usr [[ -z $usr ]] && echo -e "${Red}输入有误,请重新运行脚本! ${Font} "&& exit 1; stty erase '^H' && read -p "请输入express-ffmpeg管理员密码:" pass [[ -z $pass ]] && echo -e "${Red}输入有误,请重新运行脚本! ${Font} "&& exit 1; } #install repo repo(){ if [[ "${release}" = "centos" ]]; then rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install wget -y && wget -N --no-check-certificate http://yzm.pw/express-ffmpeg/mongodb.repo -P '/etc/yum.repos.d/' else apt update -y apt install curl -y if [[ "${version}" = "9" ]]; then curl https://www.mongodb.org/static/pgp/server-3.6.asc | apt-key add - echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/3.6 main" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list else apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.6 main" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list fi fi } #install depend(Redis、Mongodb) depend(){ echo -e "${Blue}开始安装Redis、Mongodb等依赖${Font}" if [[ "${release}" = "centos" ]]; then yum -y groupinstall "Development Tools" yum -y install mongodb-org cairo cairo-devel wget http://download.redis.io/releases/redis-5.0.2.tar.gz tar zxvf redis-5.0.2.tar.gz && rm -rf redis-5.0.2.tar.gz cd redis-5.0.2 make if [[ $? -ne 0 ]]; then echo -e "${Red}Redis安装失败,请重新检查!${Font}" exit 1 fi cp src/redis-server src/redis-cli /usr/local/bin cd .. rm -rf redis-5.0.2 sysctl -w vm.overcommit_memory=1 echo 512 > /proc/sys/net/core/somaxconn echo never > /sys/kernel/mm/transparent_hugepage/enabled echo "net.core.somaxconn= 1024" >> /etc/sysctl.conf sysctl -p else apt update -y apt-get install -y mongodb-org redis-server build-essential git libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev make fi if [[ $? -ne 0 ]]; then echo -e "${Red}Mongodb等依赖安装失败,请重新检查!${Font}" exit 1 else echo -e "${Blue}Mongodb等依赖安装成功!${Font}" fi systemctl start mongod } #install node node(){ if [[ "${release}" = "centos" ]]; then curl -sL https://rpm.nodesource.com/setup_8.x | bash - yum install nodejs -y else curl -sL https://deb.nodesource.com/setup_8.x | bash - apt-get install -y nodejs fi npm install -g pm2 express yarn } #install ffmpeg ffmpeg(){ bit=`uname -m` if [[ ${bit} = "x86_64" ]]; then KernelBit="64" else KernelBit="32" fi wget http://yzm.pw/ffmpeg/ffmpeg-git-${KernelBit}bit-static.tar.xz tar xvf ffmpeg-git-*-static.tar.xz && rm -rf ffmpeg-git-*-static.tar.xz mv ffmpeg-git-*/ffmpeg ffmpeg-git-*/ffprobe /usr/local/bin/ rm -rf ffmpeg-git-*-static } #install caddy caddy(){ echo -e "${Blue}正在安装Caddy!${Font}" curl https://getcaddy.com | bash -s personal EXEC="$(command -v caddy)" if [[ -n ${EXEC} ]]; then echo -e "${Blue}Caddy安装成功!${Font}" else echo -e "${Red}Caddy安装失败!${Font}" exit 1 fi mkdir /root/.caddy wget -N --no-check-certificate http://yzm.pw/express-ffmpeg/caddy.conf -P '/root/.caddy/' sed -i "s/moerats.com/${domain}/g" /root/.caddy/caddy.conf } #check domain domain(){ EXEC="$(command -v bc)" if [[ -z ${EXEC} ]]; then if [[ "${release}" = "centos" ]]; then yum -y install bc else apt install bc -y fi fi domain_ip=`ping ${domain} -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'` local_ip=`curl http://whatismyip.akamai.com` echo -e "域名dns解析IP:${domain_ip}" echo -e "本机IP: ${local_ip}" sleep 2 if [[ $(echo ${local_ip}|tr '.' '+'|bc) -eq $(echo ${domain_ip}|tr '.' '+'|bc) ]];then echo -e "${Blue}域名dns解析IP与本机IP匹配${Font}" sleep 2 else echo -e "${Red}域名dns解析还未生效,请稍后再试!${Font}" exit 1 fi } #open firewall firewall(){ if [[ "${release}" = "centos" ]]; then firewall-cmd --zone=public --add-port=3000/tcp --permanent firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=443/tcp --permanent firewall-cmd --reload fi } #set start up startup(){ echo -e "${Blue}正在为相关应用设置开机自启!${Font}" if [[ "${num}" = "2" ]]; then wget -N --no-check-certificate http://yzm.pw/express-ffmpeg/caddy.service -P '/etc/systemd/system/' systemctl start caddy systemctl enable caddy fi if [[ "${release}" = "centos" ]]; then wget -N --no-check-certificate http://yzm.pw/express-ffmpeg/redis-server.service -P '/etc/systemd/system/' fi systemctl start redis-server systemctl enable redis-server } #install express express(){ mkdir /www && cd /www git clone https://gitee.com/quazero/express-ffmpeg.git if [[ ! -d '/www/express-ffmpeg' ]]; then echo -e "${Red}由于某些国外机器网络波动,拉取码云上的express-ffmpeg失败,即将切换到Github上下载!${Font}" cd /www git clone https://github.com/bookyo/express-ffmpeg-new.git if [[ -d '/www/express-ffmpeg-new' ]]; then echo -e "${Blue}express-ffmpeg下载完成,即将安装...${Font}" mv express-ffmpeg-new express-ffmpeg else echo -e "${Red}看来Github也救不了你的网络了,下载依然失败,安装退出,请稍后重新运行脚本!${Font}" exit 1 fi fi cd express-ffmpeg && mkdir config cp *.ttf /usr/share/fonts/ cat > config/auth.js < mongodb.js <> /etc/mongod.conf fi systemctl restart mongod systemctl enable mongod pm2 start bin/www -i 0 pm2 save pm2 startup } #Complete info info(){ if [[ -z "${domain}" ]]; then ip=`curl http://whatismyip.akamai.com` echo -e "———————————————————————————————————————" echo -e "${Blue}express-ffmpeg安装完成!${Font}" echo -e "${Blue}前台地址:http://${ip}:3000${Font}" echo -e "${Blue}后台地址:http://${ip}:3000/${url}${Font}" echo -e "${Blue}管理员用户名:${usr}${Font}" echo -e "${Blue}管理员密码:${pass}${Font}" echo -e "${Blue}如果完成后,访问不了前台,可随时咨询!${Font}" echo -e "———————————————————————————————————————" else echo -e "———————————————————————————————————————" echo -e "${Blue}express-ffmpeg安装完成!${Font}" echo -e "${Blue}前台地址:https://${domain}${Font}" echo -e "${Blue}后台地址:https://${domain}/${url}${Font}" echo -e "${Blue}管理员用户名:${usr}${Font}" echo -e "${Blue}管理员密码:${pass}${Font}" echo -e "${Blue}如果完成后,访问不了前台,可随时咨询!${Font}" echo -e "———————————————————————————————————————" fi } #start menu main(){ root system version clear echo -e "—————————————————————————————————————————————————————" echo -e "${Blue}express-ffmpeg+CMS 一键脚本 for Debian 8+、CentOS 7、Ubuntu 16+${Font}" echo -e "${Blue}1、使用IP访问${Font}" echo -e "${Blue}2、使用域名访问(请提前解析好域名并生效,如果装了宝塔的不适合该选项)${Font}" echo -e "—————————————————————————————————————————————————————" read -p "请输入数字 [1-2]:" num case "$num" in 1) use_ip ;; 2) use_domain ;; *) clear echo -e "${Blue}请输入正确数字 [1-2]${Font}" sleep 2s main ;; esac } use_ip(){ enter repo firewall depend node ffmpeg express startup info } use_domain(){ enter domain repo firewall depend node ffmpeg express caddy startup info } main