• 【软件】Ubuntu16.04安装repo全纪录,构建自己的repo仓库,最详细的步骤大全,以及踩坑大全


    1. 前言

    周六计划:花2小时写一个小项目
    实际情况:花了9个小时配置repo开发环境,程序完全没写。
    爬了太多坑,回头看一下,其实有几个关键步骤,配置就行,于是记录一下一天的收获,也希望对其他人有所帮助。

    2. 背景

    2.1 起因

    GIt可以用来做一个版本管理的,但是,当仓库很大的时候,git索引会变的很慢。这样问题怎么解决?
    之前写过一篇博客,解决GIT单个仓库过大的问题,几个主要方法:

    1. repo
    2. git submodule
    3. git lfs
    4. git 删除大节点

    其实最好用的就是repo。
    但是之前一直以为repo是需要服务器端提供repo服务的,所以一直没有尝试。
    最近在新公司搭建开发环境,和GIT仓库管理员聊了一下repo,确认云端是不需要搭配 repo 服务的,做本地配置就行了。于是信心满满地开始了配置工作。

    最终目标:
    把现有很多独立的git仓库,统一用repo来管理。
    一个项目的结构就可能是这样:

    root
      | ---- buildroot
      | ---- boot
      | ---- kernel
      | ---- package
      | ---- doc
      ....
      每个文件夹都是一个独立的git或者多个git
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2.2 repo介绍,有用的参考链接

    3. Linux 下安装repo步骤

    3.1 环境介绍

    我的服务器环境是 Ubuntu16.04 LTS
    预装的python 是 Python 2.7.12 和Python3.5.2。
    预装的git 是 git 2.7.4
    今天是2022年8月13日,拉取的repo 是v2.28

    3.2 关键步骤

    Ubuntu16.04 直接去拉repo遇到了N多问题,爬了各式各样很久的坑。
    最后总结一下,我直接把我认为最关键的点先列一下:
    1. python升级到3.7(我用的3.7.7),并在安装前要先装依赖库。
    2. git 升级到2.37.2

    3.3 所有步骤

    1. 拉取repo引导环境
    2. repo init 拉取manifest(拉一个谷歌默认的manifest自己改,或者直接拉自己改好的manifest的git库的文件),生成.repo文件夹
    3. 基于拉取的manifest 做repo sync,拉取真正的git仓库

    3.3.1 拉取repo引导文件

    3.3.1.1 新建一个空白文件夹保存repo引导文件

      mkdir ~/.bin
    
    • 1

    3.3.1.2 拉取引导文件,命名为repo

    cd ~/.bin
    curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
    chmod a+x ~/.bin/repo
    
    • 1
    • 2
    • 3

    这里我自己拉的就是清华的镜像库,其实官方地址是谷歌的,但是国内拉不动。
    其他链接或者教程里有让去git clone来拉的,拉官方库,拉清华镜像库,拉中科大镜像库,等等,类似这些,可以不用,直接去curl就行。

    git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo
    git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo
    git clone https://mirrors.ustc.edu.cn/aosp/git-repo
    
    • 1
    • 2
    • 3

    我推荐直接curl去拉国内镜像库。
    至于直接curl拉一个repo的python脚本,和git clone一整个git-repo仓库的区别,主要就是整个仓库里会存在这个启动器脚本文件,还有一些别的文件,而我们init的时候只用这个启动器脚本就行。

    3.3.1.3 添加临时环境变量或者添加到全局变量

    把放了repo的路径添加到环境变量
    把国内镜像源地址替换掉谷歌地址,不然拉不动。
    可以放到临时环境变量(直接运行)或者永久的环境变量 /etc/profile, ~/bashrc

    #1 添加环境变量
    export PATH=$PATH:~/.bin
    #2 替换国内源
    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
    
    • 1
    • 2
    • 3
    • 4
    3.3.1.4 验证repo
     repo --version
    
    • 1

    在这里插入图片描述
    如果看不到,不一定是repo没配好,有可能是python的支持有问题,先把python升级3.7了先。

    3.3.2 repo init 拉取manifest文件

    3.3.2.1 repo init 拉取现有的manifest

    repo 可以用了之后,我们要去拉取manifest文件,这个文件存在一个git库中,主要记录着repo管理的所有git库的地址,分支,信息等等。
    repo启动器只有很少的功能,大部分功能它要在线去拉真正的repo库,然后再实现。
    repo init命令是这样的:

    repo init -u git://xxx/xxx/manifest.git -b  -m 
    
    • 1

    比如:

    repo init -u https://android.googlesource.com/platform/manifest
    repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
    
    • 1
    • 2

    拉取完成后,在文件夹下会生成一个.repo隐藏文件夹,里面包含4个部分:
    在这里插入图片描述

    • manifests :repo init -u 所指的manifest的库,拉取一些manifest 配置文件
    • manifest.xml:可以本地项目再加一些仓库进去
    • repo : 就是第一步的时候 git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo拉下来的文件夹,包含了一些repo的工具。
    • manifest.git:管理 repo库中所有的git仓库的信息。

    注意:
    这个repo init步骤如果环境不对,会出很多问题。
    针对Ubuntu16.04,建议Python升级到3.7。
    git升级到最新(我是2.37.2)

    不然你会遇到N多问题,解决A的时候会新出现问题B,解决B的时候会出现C,套娃一样的解决无尽的问题。
    我在第4部分会记录升级这两个软件的步骤。

    3.3.2.2 repo init 拉取自己的manifest,如何写自己的manifest库

    有些时候,我们有一些现有的git仓库,想用自己的manifest库管理起来,就要repo init自己的manifest库。
    类似这样:

    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
    repo init -u https://codeup.aliyun.com/XXX/repo/manifest.git
    
    • 1
    • 2

    这个manifest的repo库要做什么样子呢?
    其实非常简单,在里面写一个default.xml即可。
    在这里插入图片描述
    让我们来做一个小实验。
    比如我有三个git仓库,他们的git地址和本地我希望的路径结构如下:

    .repo  manifest : https://codeup.aliyun.com/XXXX/repo/manifest.git
    Doc : https://codeup.aliyun.com/XXXX/repo/Doc.git
    Test
        | - SimpleTest : https://codeup.aliyun.com/XXXX/repo/SimpleTest.git
        | - SimpleTest2: https://codeup.aliyun.com/XXXX/repo/SimpleTest2.git
    
    • 1
    • 2
    • 3
    • 4
    • 5

    那我建立一个这样的manifest就行了

    
    
      
      
      
      
      
      
      
        
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    先把这个defualt.xml push上去,再用repo init 去拉取即可

    3.3.3 repo sync

    这个阶段就是repo 根据我们设置的manifest去拉取真正的git仓库。
    按理说只要repo init时的.repo文件夹生成,里面的文件都有,你的manifest没写错,就没什么问题。

    repo sync -j4
    
    • 1

    一个点是,如果你拉取的是ssh的库,记得提前传公钥

    ssh-keygen -t rsa   把生成的rsa.pub里的东西全部贴上去
    git config  --global user.name ‘AAAA’
    git config  --global user.email ‘AAA@CCC.com’
    
    • 1
    • 2
    • 3

    如果你拉取的是https的库,需要解决每个仓库都让你输一遍用户名和密码。
    解决方案

    git config --global credential.helper store
    #最后会在这个路径下生成你git相关信息
    cat ~/.git-credentials
    https://user:password@github.com
    
    • 1
    • 2
    • 3
    • 4

    3.3.4 正常享用repo

    下一步就是正常使用repo了,repo start,repo upload 这些
    我就不赘述了,改天再加一章专门写repo的命令。

    4. 依赖环境 - python - git

    这个单独写了一篇 Ubuntu16.04升级git最新版,升级python到3.7
    跳转这里食用吧,不然这一篇太长了。

    5. 遇到的各种问题

    这一节是我们8个小时的血汗凝结成的。
    刚开始的时候,没有意识到repo对git和python版本的需求。
    因为我之前用python2也能用的,所以没有做升级。
    遇到各种各样的诡异的问题,解都解不完。
    Ubuntu做主力机的时候真的需要一点点耐心。

    5.1 在2.3.2.1步骤里,curl拉取repo拉不动

    curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
    
    • 1

    错误关键字
    curl performs SSL certificate verification by default, using a “bundle”
    of Certificate Authority (CA) public keys (CA certs). If the default
    bundle file isn’t adequate, you can specify an alternate file
    using the --cacert option.
    在这里插入图片描述

    解决方法:加入-k跳过检查
    curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo -k

    5.2 使用清华源之后,鉴权不通过:server certificate verification failed

    错误关键字

    fatal: unable to access ‘https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/’: server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
    在这里插入图片描述

    解决方法:
    关闭验证

    git config --global http.sslverify false
    
    • 1

    5.3 在2.3.2.2步骤 repo init 超时

    在这里插入图片描述
    解决:被墙,更换国内源。

    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
    
    • 1

    5.4 在2.3.2.2 步骤 repo init 拉取谷歌 manifest的时候报错

    关键字:

    fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
    在这里插入图片描述
    解决:被墙,更换国内源。

    export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
    
    • 1

    5.5 更换国内源后依然无法repo init: fatal: error unknown url type : https

    错误关键字

    fatal: error unknown url type : https
    在这里插入图片描述

    这个问题就麻烦了。
    搜到repo init失败的问题99%都是让你换清华源
    根据报错的提示,是识别不了https,最后搜到是因为没有安装ssl

    这个依赖库还需要在build python之前装。。于是只能重来一遍,这也是为什么我在安装python的时候强调,要先装依赖库。

    5.6 重装3.7.7 的python 和 依赖之后, 依然repo init失败,报错error.GitError

    错误关键字

    error.GitError: manifests ls-remote: usage: git ls-remote [--heads] [--tags]  [--upload-pack=]
                         [-q | --quiet] [--exit-code] [--get-url] [ [...]]
    
    • 1
    • 2

    在这里插入图片描述
    解释在这里
    升级git才行,不然不支持 --symref。

    5.7 使用python3.7 和 git 2.37 ,再次repo init,还是拉不动:port 443: 连接超时

    错误关键字

    error.GitError: manifests ls-remote: fatal: 无法访问 ‘https://android.googlesource.com/platform/manifest/’:Failed to connect to android.googlesource.com port 443: 连接超时

    在这里插入图片描述
    谷歌还是拉不动,换一个url拉

    repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
    
    • 1

    5.8 from git_config import RepoConfig

    在这里插入图片描述

    5.9 ModuleNotFoundError: No module named ‘_ctypes’

    关键字:

    3.9 ModuleNotFoundError: No module named ‘_ctypes’在这里插入图片描述

    解决方案:

    sudo apt-get install libffi-dev
    sudo apt install python3-pip
    pip3 install sklearn
    
    • 1
    • 2
    • 3
  • 相关阅读:
    Windows系统服务器配置SSH服务
    TCP 和 UDP 可以同时绑定相同的端口吗?
    Linux驱动开发:深入理解I2C时序
    java开放式实验室预约系统计算机毕业设计MyBatis+系统+LW文档+源码+调试部署
    逆波兰算法、中缀表达式转后缀表达式
    什么是正向代理和反向代理
    Python均匀分布和三角形分布
    Linux基础指令(下)
    JUC并发编程——阻塞队列(基于狂神说的学习笔记)
    5分钟攻略Spring-Retry框架实现经典重试场景
  • 原文地址:https://blog.csdn.net/tao475824827/article/details/126326366