【Ubuntu 18.04安装Gitlab】

提示:本文原创作品,良心制作,干货为主,简洁清晰,一看就会

bash 复制代码
root@ubuntu:~# apt update
root@ubuntu:~# apt install ca-certificates curl openssh-server postfix tzdata perl
root@ubuntu:~# curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
root@ubuntu:~# ls
script.deb.sh
bash 复制代码
root@ubuntu:~# cat script.deb.sh 
#!/bin/bash
set -e

# Installation script for gitlab/gitlab-ce APT repository
#
# Usage:
#   curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
#
# With authentication:
#   username=myuser password=mypass ./script.deb.sh

username="${username:-}"
password="${password:-}"

fail_unsupported ()
{
  cat >&2 <<EOF
System configuration not recognized.
Set os= and dist= environment variables to override detection.
Reference: https://docs.gitlab.com/install/

Example: os=ubuntu dist=focal ./script.deb.sh

Contact support for assistance.
EOF
  exit 1
}

require_tool ()
{
  local tool=$1
  local pkg=$2

  if ! command -v "$tool" &> /dev/null; then
    apt-get install -y "$pkg" || {
      cat >&2 <<EOF
Failed to install $pkg. System package repositories may be misconfigured.
EOF
      exit 1
    }
  fi
}

setup_debian_keyring ()
{
  [ "${os,,}" != "debian" ] && return 0
  apt-get install -y debian-archive-keyring &> /dev/null
}

detect_system_info ()
{
  [ -n "$os" ] && [ -n "$dist" ] && return 0

  if [ -f /etc/os-release ]; then
    . /etc/os-release
    os=$ID
    if [ -n "$VERSION_CODENAME" ]; then
      dist=$VERSION_CODENAME
    elif [ -n "$VERSION_ID" ]; then
      dist=$VERSION_ID
    fi
  elif [ -f /etc/lsb-release ]; then
    . /etc/lsb-release
    if [ "$DISTRIB_ID" = "raspbian" ]; then
      os=$ID
      dist=$(cut -d. -f1 /etc/debian_version)
    else
      os=$DISTRIB_ID
      dist=$DISTRIB_CODENAME
      [ -z "$dist" ] && dist=$DISTRIB_RELEASE
    fi
  elif command -v lsb_release &> /dev/null; then
    dist=$(lsb_release -c | cut -f2)
    os=$(lsb_release -i | cut -f2 | awk '{print tolower($1)}')
  elif [ -f /etc/debian_version ]; then
    os=$(head -1 /etc/issue | awk '{print tolower($1)}')
    if grep -q '/' /etc/debian_version; then
      dist=$(cut -d/ -f1 /etc/debian_version)
    else
      dist=$(cut -d. -f1 /etc/debian_version)
    fi
  else
    fail_unsupported
  fi

  [ -z "$dist" ] && fail_unsupported
  os="${os// /}"
  os="${os,,}"
  dist="${dist// /}"
}

parse_apt_version ()
{
  local ver
  ver=$(apt-get -v 2>/dev/null | head -1 | awk '{print $2}') || {
    echo >&2 "Failed to detect apt version"
    exit 1
  }

  apt_version_major=$(echo "$ver" | cut -d. -f1)
  apt_version_minor=$(echo "$ver" | cut -d. -f2)
  apt_version_modified="${apt_version_major}${apt_version_minor}0"
}

fetch_repo_config ()
{
  local url=$1
  local dest=$2
  local curl_opts

  if [ -n "$username" ] && [ -n "$password" ]; then
    curl_opts=(-sSfL -u "${username}:${password}")
  else
    curl_opts=(-sSfL)
  fi

  curl "${curl_opts[@]}" "$url" > "$dest" || {
    local code=$?
    rm -f "$dest"

    case $code in
      22)
        cat >&2 <<EOF
Repository configuration unavailable at: $url
This OS/distribution may not be supported, or detection failed.
Override with: os=ubuntu dist=focal ./script.deb.sh
See: https://docs.gitlab.com/install/
EOF
        ;;
      35|60)
        cat >&2 <<EOF
TLS connection failed to https://packages.gitlab.com
Possible causes:
  - Missing ca-certificates package
  - Outdated libssl version
EOF
        ;;
      *)
        cat >&2 <<EOF
Failed to retrieve: $url
Verify curl is working correctly.
EOF
        ;;
    esac
    exit 1
  }
}

setup_gpg_key ()
{
  local key_url=$1
  local keyring_path=$2
  local keyring_dir=$3
  local old_path=$4
  local curl_opts

  if [ -n "$username" ] && [ -n "$password" ]; then
    curl_opts=(-fsSL -u "${username}:${password}")
  else
    curl_opts=(-fsSL)
  fi

  mkdir -p "$keyring_dir"
  curl "${curl_opts[@]}" "$key_url" | gpg --dearmor > "$keyring_path" || {
    local code=$?
    rm -f "$keyring_path"
    cat >&2 <<EOF
Failed to download or import GPG key from: $key_url
Exit code: $code
EOF
    exit 1
  }

  if [ ! -s "$keyring_path" ]; then
    rm -f "$keyring_path"
    cat >&2 <<EOF
GPG key download produced empty file from: $key_url
EOF
    exit 1
  fi

  chmod 0644 "$keyring_path"

  if [ "$apt_version_modified" -lt 110 ]; then
    mv "$keyring_path" "$old_path"
    chmod 0644 "$old_path"
    rmdir "$keyring_dir" 2>/dev/null || true
  fi
}

inject_credentials_to_source_file ()
{
  local source_file=$1

  if [ -n "$username" ] && [ -n "$password" ]; then
    sed -i "s|https://|https://${username}:${password}@|g" "$source_file"
  fi
}

main ()
{
  detect_system_info
  require_tool gpg gnupg
  parse_apt_version
  setup_debian_keyring
  apt-get install -y apt-transport-https &> /dev/null

  local key_url="https://packages.gitlab.com/gpgkey/gpg.key"
  local config_url="https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/${os}/${dist}/config_file.list"
  local source_file="/etc/apt/sources.list.d/gitlab_gitlab-ce.list"
  local keyring_dir="/etc/apt/keyrings"
  local keyring_file="${keyring_dir}/gitlab_gitlab-ce-archive-keyring.gpg"
  local old_keyring="/etc/apt/trusted.gpg.d/gitlab_gitlab-ce.gpg"

  fetch_repo_config "$config_url" "$source_file"
  inject_credentials_to_source_file "$source_file"
  setup_gpg_key "$key_url" "$keyring_file" "$keyring_dir" "$old_keyring"

  apt-get update || {
    cat >&2 <<EOF
Failed to update package lists. The repository may be misconfigured.
EOF
    exit 1
  }

  cat <<EOF
Repository configured successfully.
Ready to install packages.
EOF
}

main
bash 复制代码
root@ubuntu:~# bash script.deb.sh 

# 这一步如果超时了可以重试
root@ubuntu:~# apt -y install gitlab-ce

接下来的步骤和该文章4.2.2-4.2.4操作步骤一样

https://blog.csdn.net/m0_63756214/article/details/155339506?spm=1001.2014.3001.5501

注:

文中若有疏漏,欢迎大家指正赐教。

本文为100%原创,转载请务必标注原创作者,尊重劳动成果。

求赞、求关注、求评论!你的支持是我更新的最大动力,评论区等你~

相关推荐
hhhjhl2 天前
Undici 跨端三方库仓颉适配全流程
java·开发语言·ubuntu
~城南花已开~2 天前
Intel E810 SR-IOV VF Spoofcheck 防伪造测试-KVM3
服务器·网络·笔记·学习·ubuntu·etl工程师
十年磨一剑~2 天前
APT 仓库包查看方法文档
linux·ubuntu
技术小事2 天前
Surface 装 Ubuntu 双系统
linux·运维·ubuntu
五块钱的方便面2 天前
ubuntu下networkmanager不让管理解决办法
linux·运维·ubuntu
极小狐2 天前
极狐GitLab万人并发架构实践,大规模组织的扩容路线图
架构·gitlab·极狐gitlab
根目录下的猫2 天前
ArkTS 代码中如何添加作者信息
linux·运维·ubuntu
haermosi2 天前
Ubuntu 下 Flameshot 截图一直闪屏,已找到问题并解决
linux·ubuntu·gnome·问题排查·flameshot·linux 使用记录
2601_949847753 天前
bcrypt.js 跨端三方库仓颉适配全流程
linux·运维·ubuntu
靳某某。3 天前
Ubuntu安装php8.4 及redis ngin
linux·redis·ubuntu