该脚本可以解决 gitlab安装、配置访问网址、配置初始登录密码、配置系统的邮箱。
二、脚本内容#!/bin/bash
#下面是定义颜色变量,用来给输出变量定义
RED='e[1;31m' #输出为红色
GREEN='e[1;32m' #输出为绿色
YELLOW=' 33[1;33m'
BLUE='E[1;34m'
PINK='E[1;35m'
RES=' 33[0m'
#下面这个函数是gitlab的安装步骤
function install() {
#安装依赖
yum install curl wget policycoreutils policycoreutils-python openssh-server openssh-clients postfix -y >/dev/null
systemctl enable sshd
systemctl start sshd
sed -i 's/inet_interfaces = localhost/inet_interfaces = all/g' /etc/postfix/main.cf
#正式安装gitlab
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash > /dev/null
sed -i "s/baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/7/$basearch/baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever//g" /etc/yum.repos.d/gitlab_gitlab-ce.repo
yum makecache &>/dev/null
yum install gitlab-ce -y
#已经安装完成
#验证是否安装成功
right=$(yum list installed | grep gitlab-ce)
gitlab='gitlab-ce'
if [[ ${right} =~ "${gitlab}" ]];then
echo "gitlab-ce已经安装成功啦!"
else
echo "gitlab-ce没有安装成功,请重新检查!"
exit
fi
}
#此函数是修改gitlab的访问url
function url() {
until [[ $flag == "yes" || $flag == "YES" || $flag == "Y" || $flag == "y" || $flag == "NO" || $flag == "no" || $flag == "N" || $flag == "n" ]]
do
read -p "请问您是否使用您的ip+端口实现访问:(yes|no)" flag
case $flag in
yes|YES|Y|y)
until [[ $cloud == "云主机" || $cloud == "虚拟机" ]]
do
read -p "请输入您目前使用的机器:(云主机|虚拟机)" cloud
if [[ $cloud == "云主机" ]];then
line=$(wget -qO - ifconfig.co)
sed -i "s?'http://gitlab.example.com'?'http://$line:9418'?g" /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
gitlab-ctl stop > /dev/null
gitlab-ctl start > /dev/null
echo -e "n"
echo "此时访问http://$line:9418就可以显示gitlab的页面了"
echo -e "n"
echo -e " ${red} 如果此时页面显示502,请检查您的机器性能是否大于2核4G,或者等待一分钟后重新刷新,祝你好运!${RES}"
elif [[ $cloud == "虚拟机" ]];then
virtual=$(ifconfig | grep 'inet' | grep -v '127.0.0.1' | awk '{print $2}')
sed -i "s?http://gitlab.example.com?http://$virtual:9418?g" /etc/gitlab/gitlab.rb
restart > /dev/null
echo "此时访问http://$line:9418就可以显示gitlab的页面了"
else
echo "输入错误!"
fi
done
;;
no|NO|N|n)
echo "请确保您的域名申请成功!"
;;
*)
echo "您的输入不正确,请您重新输入"
continue
;;
esac
done
}
#此函数用来修改root的默认密码
function passwdction() {
while :
do
read -p "请输入您要设置的密码,最少需要八位:" passwd
if [[ ${#passwd} -ge 8 ]]; then
cd /opt/gitlab/bin
gitlab-rails console -e production <> /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
read -p "请输入一个用来接受测试邮件的地址:" accept
gitlab-rails console <



