#!/usr/bin/env bash
#1.安装Apache
echo "正在安装Apache..."
yum install -y httpd wget

#2.添加支持文件的类型
sed -i '/AddType application\/x-compress .Z/a\    AddType application/x-gzip .gz .tgz .parcel' /etc/httpd/conf/httpd.conf
echo "生成本地仓库服务的配置，这里使用的是repo.car-house.net，记得修改成实际的域名"

#3.启动服务
echo "启动Apache并设置开机自动运行..."
systemctl start httpd
systemctl enable httpd


echo "仓库的文件比较大，需要比较长的时间，建议使用第三方工具下载！"
#4.创建本地MySQL仓库的文件夹
mkdir -p /var/www/html/mysql

#5.下载MySQL的驱动文件
wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.46/mysql-connector-java-5.1.46.jar -P /var/www/html/mysql

#6.创建本地Cloudera仓库的文件夹
mkdir -p /var/www/html

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

wget --recursive --no-parent --no-host-directories https://archive.cloudera.com/cdh6/6.3.0/parcels/ -P /var/www/html
wget --recursive --no-parent --no-host-directories https://archive.cloudera.com/gplextras6/6.3.0/parcels/ -P /var/www/html

#8.对本地仓库目录进行授权
chmod -R ugo+rX /var/www/html/cm6
chmod -R ugo+rX /var/www/html/cdh6
chmod -R ugo+rX /var/www/html/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

