#!/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 } #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 depend(){ echo -e "${Blue}开始安装Mongodb${Font}" if [[ "${release}" = "centos" ]]; then yum -y groupinstall "Development Tools" yum -y install mongodb-org cairo cairo-devel curl if [[ $? -ne 0 ]]; then echo -e "${Red}Mongodb安装失败,请重新检查!${Font}" exit 1 fi else apt update -y apt-get install -y mongodb-org build-essential git libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev make curl 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 yarn -g } #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 } #open firewall firewall(){ if [[ "${release}" = "centos" ]]; then firewall-cmd --zone=public --add-port=7001/tcp --permanent firewall-cmd --reload fi } #install express express(){ mkdir /movies cd / wget --http-user=bzmyx --http-passwd=wwfewfeh http://yzm.pw/gaijicjbyzmcjb/oneacg.tar.gz && tar zxvf oneacg.tar.gz && rm -rf eoneacg.tar.gz cd /oneacg cp *.ttf /usr/share/fonts/ cat > mongodb.js <> /etc/mongod.conf fi systemctl restart mongod systemctl enable mongod npm start } #set start up startup(){ if [[ "${release}" = "centos" ]]; then echo "cd /oneacg && /usr/bin/npm start" >> /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local elif [ -s /etc/rc.local ]; then echo "cd /oneacg && /usr/bin/npm start" >> /etc/rc.local chmod +x /etc/rc.local else echo -e "${Blue}检测到系统无rc.local自启,正在为其配置... ${Font} " echo "[Unit] Description=/etc/rc.local ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target " > /etc/systemd/system/rc-local.service echo "#!/bin/sh # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. " > /etc/rc.local echo "cd /oneacg && /usr/bin/npm start" >> /etc/rc.local chmod +x /etc/rc.local systemctl start rc-local systemctl enable rc-local fi } #Complete info info(){ ip=`curl http://whatismyip.akamai.com` echo -e "————————————————————————————————————————————————" echo -e "${Blue}纯净版云转码安装完成!${Font}" echo -e "${Blue}后台地址:http://${ip}:7001/admin ${Font}" echo -e "${Blue}管理员用户名:admin@admin.com ${Font}" echo -e "${Blue}管理员密码:adminadmin ${Font}" echo -e "————————————————————————————————————————————————" } #start menu main(){ root system version clear echo -e "———————————————————————————————————————————————————————————" echo -e "${Blue}云转码纯净版 一键脚本 for Debian 8+、CentOS 7、Ubuntu 16+${Font}" echo -e "———————————————————————————————————————————————————————————" stty erase '^H' && read -p "请输入任意字母,Enter开始安装(不输入则退出!):" az [[ -z $az ]] && echo -e "${Red}退出安装! ${Font} "&& exit 1; ip_install } ip_install(){ repo depend node ffmpeg express firewall startup info } main