Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux Shell 腳本自動化建立 SVN 倉庫:互動式輸入名稱、自動配置權限與認證

編輯:關於 Linux

手動建立 SVN 倉庫步驟繁瑣 (svnadmin create、編輯 svnserve.conf/passwd/authz)。本文提供一鍵自動化腳本:互動輸入倉庫名稱 → 建立倉庫 → 自動配置 svnserve.conf (關閉匿名、啟用密碼檔、授權檔) → 初始化 authz (開發群組讀寫權限) → 完成提示。

SVN 自動建立腳本流程示意圖

自動化腳本 create_svn_repo.sh

#!/bin/bash
# 自動建立 SVN 倉庫並配置基本權限
# 執行需 root 權限

read -p "Enter SVN repository name: " svn_name
REPO_ROOT="/svnroot"
REPO_PATH="${REPO_ROOT}/${svn_name}"

# 1. 建立倉庫
/usr/bin/svnadmin create "${REPO_PATH}"
if [ $? -ne 0 ]; then
  echo "Error: svnadmin create failed"
  exit 1
fi

# 2. 配置 svnserve.conf
CONF="${REPO_PATH}/conf/svnserve.conf"
sed -i 's/# anon-access = read/anon-access = none/' "${CONF}"
sed -i 's/# auth-access = write/auth-access = write/' "${CONF}"
sed -i 's|# password-db = passwd|password-db = /svnroot/conf/passwd|' "${CONF}"
sed -i 's/# authz-db = authz/authz-db = authz/' "${CONF}"

# 3. 初始化 authz (統一授權檔)
cat > "${REPO_PATH}/conf/authz" <

部署與使用

chmod +x create_svn_repo.sh
./create_svn_repo.sh
# 輸入名稱如: project_alpha
# 完成後啟動 svnserve
svnserve -d -r /svnroot
# 客戶端存取: svn checkout svn://server/project_alpha

進階擴充建議

  • 參數化:支援命令列參數 ./script.sh repo_name 非互動模式
  • 多專案授權:依專案建立獨立 authz 或使用 [/project_alpha] 路徑授權
  • 整合 LDAP/AD:配置 saslauthd 或 Apache mod_dav_svn + mod_authz_svn
  • 備份策略:svnadmin dump 定時熱備份 + 增量備份
Copyright © Windows教程網 All Rights Reserved