# 如何升级 obproxy 到 obproxy-ce 3.2.3

由于开源 OBProxy 组件正式更名为 obproxy-ce，因此使用以下命令升级会报 `No such package obproxy-3.2.3` 错误。

```shell
obd cluster upgrade <deploy name> -c obproxy -V 3.2.3
```

您需在 OBD 的执行用户下执行下述 **脚本** 修改 meta 信息，而后使用以下命令对 OBProxy 进行升级。

```shell
obd cluster upgrade <deploy name> -c obproxy-ce -V 3.2.3
```

## 脚本

```bash
OBD_HOME=${OBD_HOME:-${HOME}}/.obd
obproxy_repository=${OBD_HOME}/repository/obproxy
obproxy_ce_repository=${OBD_HOME}/repository/obproxy-ce

function shadow_repo() {
    repository_path=$1
    ce_repository_path=$2
    [[ $repository_path =~ ^/  ]] && a=$repository_path || a=`pwd`/$repository_path
    while [ -h $a ]
    do
        b=`ls -ld $a|awk '{print $NF}'`
        c=`ls -ld $a|awk '{print $(NF-2)}'`
        [[ $real_patn =~ ^/ ]] && a=$b  || a=`dirname $c`/$b
    done
    instance_hash=`basename $a`
    ce_version_path=`dirname ${ce_repository_path}`
    ln -sf ${ce_version_path}/${instance_hash} ${ce_repository_path}
}

function copy_repository() {
    VS=(`ls $obproxy_repository`)
    for version in ${VS[@]}; do
        version_path="${obproxy_repository}/${version}"
        ce_version_path="${obproxy_ce_repository}/${version}"
        repositories=(`ls $version_path`)
        mkdir -p $ce_version_path
        for repository in ${repositories[@]}; do
            repository_path="${version_path}/${repository}"
            ce_repository_path="${ce_version_path}/${repository}"
            if [ -d "$ce_repository_path" ]; 
            then
                echo "${ce_repository_path} exist"
            else
                if [ -L ${repository_path} ];
                then 
                    shadow_repo ${repository_path} ${ce_repository_path}
                else
                    cp -r ${repository_path} ${ce_repository_path}
                fi
            fi
        done
    done
}

function change_cluster_meta() {
    cluster_home_path=${OBD_HOME}/cluster
    CS=(`ls ${cluster_home_path}`)
    for cluster in ${CS[@]}; do
        cluster_path=${cluster_home_path}/$cluster
        if [ -f ${cluster_path}/.data ]; then
            sed -i 's/^  obproxy:/  obproxy-ce:/g' ${cluster_path}/.data
        fi
        sed -i 's/^obproxy:/obproxy-ce:/' ${cluster_path}/*.yaml
    done
}

copy_repository && change_cluster_meta && echo 'ok'
```
