#!/bin/bash
set -e
#更新ubuntu源
apt-get update -y
red='\33[5m\033[31m'
green='\033[32m'
#开启防火墙
ufw=`ufw status|awk '{print $2}'`
if [ $ufw == inactive ]; then
echo y | ufw enable
ufw default deny incoming
ufw default allow outgoing
ufw allow 80
ufw allow 22
fi
#设置中文环境
language=`dpkg -l | grep language-pack-zh-hans`
if [ -z "$language" ]; then
apt-get install -y language-pack-zh-hans
if [ "$?" -ne 0 ]; then
echo -e "${red}apt中文包失败\033[0m"
exit
fi
else
echo "${green}已安装中文包\033[0m"
fi
apt-get install -y fonts-droid-fallback ttf-wqy-zenhei ttf-wqy-microhei fonts-arphic-ukai fonts-arphic-uming
if [ "$?" -ne 0 ]; then
echo -e "${red}err.apt中文环境失败\033[0m"
exit
fi
LANG=`grep "LANG="zh_CN.UTF-8"" /etc/environment`
if [ -z "$LANG" ]; then
echo LANG="zh_CN.UTF-8">> /etc/environment
fi
LANGUAGE=`grep "LANGUAGE="zh_CN:zh:en_US:en"" /etc/environment`
if [ -z "$LANGUAGE" ]; then
echo LANGUAGE="zh_CN:zh:en_US:en">>/etc/environment
fi
local='/var/lib/locales/supported.d/local'
zhCN=`grep "zh_CN.UTF-8 UTF-8" $local`
if [ -z "$zhCN" ]; then
echo en_US.UTF-8 UTF-8>>$local
echo zh_CN.UTF-8 UTF-8>>$local
echo zh_CN.GBK GBK>>$local
echo zh_CN GB2312>>$local
fi
#更新本地文件
locale-gen
#安装nginx
nginx=`dpkg -l |grep nginx`
if [ -n "$nginx" ]; then
echo 已安装
else
apt-get install nginx -y
if [ $? -ne 0 ]; then
echo "${red}err.apt nginx失败\033[0m"
fi
fi
php=`dpkg -l |grep php`
if [ -n "$php" ]; then
echo 已安装
else
apt-get install php7.0 -y
if [ $? -ne 0 ];then
echo "${red}err.apt php7.0失败\033[0m"
fi
fi
MYSQL="mysql -uroot -p"
mariadb=`dpkg -l |grep mariadb`
if [ -n "$mariadb" ]; then
echo 已安装
else
apt-get install mariadb-server -y
if [ $? -ne 0 ]; then
echo "${red}err.apt mariadb失败\033[0m"
else
$MYSQL -e "grant all PRIVILEGES on *.* to root@'%' identified by '111111' WITH GRANT OPTION;"
$MYSQL -e "flush privileges;"
$MYSQL -e "grant all PRIVILEGES on *.* to root@'localhost' identified by '111111' WITH GRANT OPTION;"
$MYSQL -e "flush privileges;"
fi
fi