#!/usr/bin/env bash
#安装本地Web服务器
echo "正在安装Nginx..."
#添加Nginx的源
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
#安装Nginx
yum install -y nginx wget


echo "生成本地仓库服务的配置，这里使用的是repo.car-house.net，记得修改成实际的域名"
echo "
server {
    listen       80;
    server_name  repo.car-house.net;

    charset utf8;
    access_log  /var/log/nginx/access_cdh_repo.log  main;

    location / {
        root /home/repo;
        index index.html;
    }
}
" > /etc/nginx/conf.d/repo.conf

echo "启动Nginx并设置开机自动运行..."
systemctl start nginx
systemctl enable nginx

echo "仓库的文件比较大，需要比较长的时间，建议使用第三方工具下载！"
#4.创建本地MySQL仓库的文件夹
mkdir -p /home/repo/mysql
#5.下载MySQL的驱动文件
wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.46/mysql-connector-java-5.1.46.jar -P /home/repo/mysql

#7.下载Cloudera的文件(这一步的时间比较久，一般都是几个到十几个小时)
wget --recursive --no-parent --no-host-directories  --continue https://archive.cloudera.com/cm6/6.3.0/redhat7/ -P /home/repo
wget https://archive.cloudera.com/cm6/6.3.0/allkeys.asc -P /home/repo/cm6/6.3.0/

wget --recursive --no-parent --no-host-directories  --continue https://archive.cloudera.com/cdh6/6.3.0/redhat7/ -P /home/repo
wget --recursive --no-parent --no-host-directories  --continue https://archive.cloudera.com/cdh6/6.3.0/parcels/ -P /home/repo
wget --recursive --no-parent --no-host-directories  --continue https://archive.cloudera.com/gplextras6/6.3.0/parcels/ -P /home/repo
#8.对本地仓库目录进行授权
chmod -R ugo+rX /home/repo/cm6
chmod -R ugo+rX /home/repo/cdh6
chmod -R ugo+rX /home/repo/gplextras6


## 使用方式：
#添加Cloudera Manager的本地仓库
echo "
[cloudera-cm]
name=Cloudera Manager 6.3.0
baseurl=https://repo.car-house.net/cm6/6.3.0/redhat7/yum/
gpgcheck=1
enabled=1
" > /etc/yum.repos.d/cloudera-cm.repo
#添加Cloudera CDH的本地仓库
echo "
[cloudera-cdh]
name=Cloudera CDH, Version 6.3.0
baseurl=https://repo.car-house.net/cdh6/6.3.0/redhat7/yum
gpgcheck=1
enabled=1
" > /etc/yum.repos.d/cloudera-cdh.repo
#清除和更新缓存
yum clean all
yum makecache