0
|
1 #!/bin/bash
|
|
2
|
|
3 # 提示用户输入仓库名称
|
|
4 echo "请输入仓库名称(不要中文):"
|
|
5 read repo_name
|
|
6
|
|
7 # 创建仓库目录
|
|
8 repo_path="/var/hg/$repo_name"
|
|
9 mkdir -p "$repo_path"
|
|
10
|
|
11 # 检查目录是否创建成功
|
|
12 if [ ! -d "$repo_path" ]; then
|
|
13 echo "目录创建失败,请检查权限或磁盘空间。"
|
|
14 exit 1
|
|
15 fi
|
|
16
|
|
17 # 初始化Mercurial仓库
|
|
18 hg init "$repo_path"
|
|
19
|
|
20 # 更改仓库所有者为www-data
|
|
21 sudo chown -R www-data:www-data "$repo_path"
|
|
22
|
|
23 # 更改仓库权限为755
|
|
24 sudo chmod -R 755 "$repo_path"
|
|
25
|
|
26 # 提示用户输入description和contact的内容
|
|
27 echo "请输入description的内容:"
|
|
28 read description
|
|
29 echo "请输入contact的内容:"
|
|
30 read contact
|
|
31
|
|
32 # 构建hgrc文件内容
|
|
33 hgrc_content="[web]
|
|
34 description = $description
|
|
35 contact = $contact"
|
|
36
|
|
37 # 写入.hg/hgrc文件
|
|
38 hgrc_path="$repo_path/.hg/hgrc"
|
|
39 echo "$hgrc_content" | sudo tee "$hgrc_path" > /dev/null
|
|
40
|
|
41 echo "仓库已成功创建并配置在 $repo_path"
|
|
42 echo "hgrc文件已更新。" |