|
| 1 | +#!/bin/bash |
| 2 | +# 在 DBeaver generic 插件中插入达梦( dameng_jdbc )驱动定义 |
| 3 | +# 用法: 从 cloudbeaver 仓库根目录的上一级执行;或传入 dbeaver 根目录 |
| 4 | +set -e |
| 5 | + |
| 6 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 7 | +if [ -n "$1" ]; then |
| 8 | + DBEAVER_ROOT="$1" |
| 9 | +else |
| 10 | + DBEAVER_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)/../dbeaver" |
| 11 | +fi |
| 12 | + |
| 13 | +PLUGIN_XML="${DBEAVER_ROOT}/plugins/org.jkiss.dbeaver.ext.generic/plugin.xml" |
| 14 | +if [ ! -f "$PLUGIN_XML" ]; then |
| 15 | + echo "DBeaver plugin.xml not found: $PLUGIN_XML" |
| 16 | + echo "Usage: $0 [dbeaver_root]" |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +if grep -q 'id="dameng_jdbc"' "$PLUGIN_XML"; then |
| 21 | + echo "Dameng driver already present in DBeaver plugin.xml, skip patch." |
| 22 | + exit 0 |
| 23 | +fi |
| 24 | + |
| 25 | +python3 - "$PLUGIN_XML" << 'PY' |
| 26 | +import sys |
| 27 | +path = sys.argv[1] |
| 28 | +# 在 <!-- CUBRID --> 前插入达梦驱动(兼容不同缩进) |
| 29 | +marker = "<!-- CUBRID -->" |
| 30 | +driver_block = ''' <driver |
| 31 | + id="dameng_jdbc" |
| 32 | + label="达梦(DM)" |
| 33 | + class="dm.jdbc.driver.DmDriver" |
| 34 | + sampleURL="jdbc:dm://{host}[:{port}]/[{database}]" |
| 35 | + defaultPort="5236" |
| 36 | + defaultDatabase="SYSDBA" |
| 37 | + defaultUser="SYSDBA" |
| 38 | + description="达梦数据库 JDBC 驱动" |
| 39 | + supportedConfigurationTypes="MANUAL,URL" |
| 40 | + categories="sql"> |
| 41 | + <file type="jar" path="drivers/dameng" bundle="drivers.dameng"/> |
| 42 | + </driver> |
| 43 | +
|
| 44 | + <!-- CUBRID -->''' |
| 45 | +
|
| 46 | +with open(path, "r", encoding="utf-8", errors="replace") as f: |
| 47 | + content = f.read() |
| 48 | +if marker not in content: |
| 49 | + sys.exit("Marker <!-- CUBRID --> not found in plugin.xml") |
| 50 | +# 只替换第一次出现,保留该行原有前导空白 |
| 51 | +new_content = content.replace(marker, driver_block, 1) |
| 52 | +with open(path, "w", encoding="utf-8") as f: |
| 53 | + f.write(new_content) |
| 54 | +print("Patched DBeaver plugin.xml: added dameng_jdbc driver.") |
| 55 | +PY |
| 56 | + |
| 57 | +echo "Done." |
0 commit comments