Forráskód Böngészése

自动初始化repo的脚本

longjin 5 hónapja
szülő
commit
0a424c967e
2 módosított fájl, 178 hozzáadás és 0 törlés
  1. 56 0
      README.md
  2. 122 0
      scripts/init.sh

+ 56 - 0
README.md

@@ -1,2 +1,58 @@
 # manifest
 通过该仓库,使用repo工具管理其它仓库的源代码
+
+## 安装git和repo工具
+
+```shell
+sudo apt-get install git repo
+
+echo "export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'" >> ~/.$(basename $SHELL)rc
+source ~/.$(basename $SHELL)rc
+```
+
+## 克隆DragonOS的代码
+
+## 自动操作
+
+使用https克隆:
+
+```shell
+curl -sSL https://git.mirrors.dragonos.org.cn/DragonOS-Community/manifest/raw/master/scripts/init.sh | bash
+```
+
+使用ssh克隆(请先配置好github的SSH Key):
+
+```shell
+# 使用ssh克隆
+bash <(curl -sSL https://git.mirrors.dragonos.org.cn/DragonOS-Community/manifest/raw/master/scripts/init.sh) --use-ssh-after-clone
+```
+
+## 手动操作
+
+```shell
+# 新建文件夹
+mkdir DragonOS-workspace
+cd DragonOS-workspace
+```
+
+### 初始化repo
+
+您可以选择从镜像站或者是GitHub同步代码,镜像站的速度更快,但是GitHub的代码库更加新。
+
+```shell
+# 【推荐】使用ssh克隆,可以使用下面的命令(请先配置好github的SSH Key)
+repo init -u git@github.com:DragonOS-Community/manifest.git -b master
+
+# 使用https克隆
+repo init -u https://github.com/DragonOS-Community/manifest.git -b master
+
+# 使用镜像站克隆
+repo init -u https://git.mirrors.dragonos.org.cn/DragonOS-Community/manifest.git -b master
+```
+
+同步代码:
+    
+```shell
+repo sync -c
+```
+

+ 122 - 0
scripts/init.sh

@@ -0,0 +1,122 @@
+#!/bin/bash
+
+# This script is used to initialize the environment for the project.
+
+mkdir -p DragonOS-workspace || exit 1
+cd DragonOS-workspace || exit 1
+
+
+# 检查参数信息
+# -f 全部采用默认值
+# -m 使用国内镜像
+# -h 查看帮助
+# --repo 指定仓库地址
+# --branch 指定分支
+# --use-ssh-after-clone 克隆后,仓库使用ssh协议
+
+# 默认参数
+mirror=true
+GITHUB_URL=https://github.com/DragonOS-Community/manifest.git
+GITHUB_SSH_URL=git@github.com:DragonOS-Community/manifest.git
+MIRROR_URL=https://git.mirrors.dragonos.org.cn/DragonOS-Community/manifest.git
+USE_SSH_AFTER_CLONE=false
+BRANCH=master
+REPO_URL=$MIRROR_URL
+
+show_help() {
+    echo "Usage: init.sh [-f] [-m] [--repo <repo_url>]"
+    echo "Options:"
+    echo "  -f: Use the default value for all parameters."
+    echo "  -m: Use the mirror in China."
+    echo "  -h: Show this help message."
+    echo "  --repo <repo_url>: Specify the repository URL."
+    echo "  --branch <branch>: Specify the branch of manifest."
+    echo "  --use-ssh-after-clone: Use ssh protocol after clone."
+}
+
+# 修改manifest中的仓库地址
+# $1: 仓库地址
+change_manifest_remote() {
+    # 修改manifest中的仓库地址
+    echo "Changing manifest remote..."
+    local current=$(pwd)
+    echo "Current path: $current"
+    cd .repo/manifests || (echo "Change manifest remote failed." && exit 1)
+    git remote set-url origin "$1" || (echo "Change manifest remote failed." && exit 1)
+    cd "$current" || (echo "Change manifest remote failed." && exit 1)
+    echo "Change manifest remote success."
+    repo sync -c || (echo "repo sync failed." && exit 1)
+    echo "Syncing code success."
+}
+
+# 解析参数
+while [[ $# -gt 0 ]]; do
+    case "$1" in
+        -f)
+            mirror=true
+            REPO_URL=$MIRROR_URL
+            ;;
+        -m)
+            mirror=true
+            REPO_URL=$MIRROR_URL
+            ;;
+        -h)
+            show_help
+            exit 0
+            ;;
+        --repo)
+            REPO_URL="$2"
+            shift
+            ;;
+        --branch)
+            BRANCH="$2"
+            shift
+            ;;
+        --use-ssh-after-clone)
+            USE_SSH_AFTER_CLONE=true
+            ;;
+        *)
+            echo "Unknown option: $1"
+            show_help
+            exit 1
+            ;;
+    esac
+    shift
+done
+
+
+# 检查是否安装了repo
+if ! command -v repo &> /dev/null; then
+    echo "repo is not installed. Please install repo first."
+    exit 1
+fi
+
+# 检查是否安装了git
+if ! command -v git &> /dev/null; then
+    echo "git is not installed. Please install git first."
+    exit 1
+fi
+
+# 检查是否安装了curl
+if ! command -v curl &> /dev/null; then
+    echo "curl is not installed. Please install curl first."
+    exit 1
+fi
+
+echo "cwd: $(pwd)"
+
+# 初始化repo
+repo init -u "$REPO_URL" -b "$BRANCH" --repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/ --no-repo-verify || (echo "repo init failed." && exit 1)
+
+# 同步代码
+echo "Syncing code..."
+repo sync -c || (echo "repo sync failed." && exit 1)
+
+# 替换manifest中的仓库地址
+# 如果设置使用ssh协议,则替换为ssh协议
+if [[ "$USE_SSH_AFTER_CLONE" == true ]]; then
+    change_manifest_remote "$GITHUB_SSH_URL"
+else
+    change_manifest_remote "$GITHUB_URL"
+fi
+