代码之家  ›  专栏  ›  技术社区  ›  Dimitrios Desyllas

宅地传递参数到后.sh对于xdebug自动配置

  •  0
  • Dimitrios Desyllas  · 技术社区  · 7 年前

    after.sh 要自动配置Xdebug表单项目:

    #!/bin/sh
    
    
    echo "Configuring Xdebug"
    ip=$(netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10)
    xdebug_config="/etc/php/$(php -v | head -n 1 | awk '{print $2}'|cut -c 1-3)/mods-available/xdebug.ini"
    
    echo "IP for the xdebug to connect back: ${ip}"
    echo "Xdebug Configuration path: ${xdebug_config}"
    echo "Port for the Xdebug to connect back: ${XDEBUG_PORT}"
    echo "Optimize for ${IDE} ide"
    
    if [ $IDE=='atom' ]; then
      echo "Configuring xdebug for ATOM ide"
    
      if [ -z ${xdebug_config} ]; then
    
        sudo touch ${xdebug_config}
      fi
    
      sudo cat <<EOL >${xdebug_config}
    zend_extension = xdebug.so
    xdebug.remote_enable = 1
    xdebug.remote_host=${ip}
    xdebug.remote_port = ${XDEBUG_PORT}
    xdebug.max_nesting_level = 1000
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_autostart=true
    xdebug.remote_log=xdebug.log
    EOL
    
    fi
    

    我还有以下设置 Homestead.yaml

    ip: 192.168.10.10
    memory: 2048
    cpus: 1
    provider: virtualbox
    authorize: ~/.ssh/id_rsa.pub
    timeout: 120
    
    keys:
        - ~/.ssh/id_rsa
    folders:
        -
            map: /home/pcmagas/Kwdikas/php/apps/ellakcy_member_app/
            to: /home/vagrant/code
    sites:
        -
            map: homestead.test
            to: /home/vagrant/code/web
            type: symfony
    
    databases:
        - homestead
        - homestead-test
    
    variables:
      - key: database_host
        value: 127.0.0.1
      - key: database_port
        value: 3306
      - key: database_name
        value: homestead
      - key: database_user
        value: homestead
      - key: database_password
        value: secret
      - key: smtp_host
        value: localhost
      - key: smtp_port
        value: 1025
      - key: smtp_user
        value: no-reply@example.com
      - key: IDE
        value: atom
      - key: XDEBUG_PORT
        value: 9091
    
    name: ellakcy-member-app
    hostname: ellakcy-member-app
    

    但由于某些原因,它无法从中定义的环境变量中读取值 Homestead.yml 如以下输出所示:

    ellakcy成员应用程序:xdebug连接回的IP:10.0.2.2

    ellakcy成员app:Xdebug配置路径:/etc/php/7.2/mods-available/xdebug.ini文件

    ellakcy成员应用程序:为ATOM ide配置xdebug

    如您所见,它无法从 IDE XDEBUG_PORT 你知道我为什么和怎样才能解决这个问题吗?

    1 回复  |  直到 5 年前
        1
  •  1
  •   José Pérez Aniorte    6 年前

    #!/bin/sh
    parse_yaml() {
       local prefix=$2
       local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
       sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
            -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p"  $1 |
       awk -F$fs '{
          indent = length($1)/2;
          vname[indent] = $2;
          for (i in vname) {if (i > indent) {delete vname[i]}}
          if (length($3) > 0) {
             vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
             printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
          }
       }'
    }
    

    进入后.sh

    #!/bin/sh
    
    # include parse_yaml function
    . parse_yaml.sh
    
    # read yaml file
    eval $(parse_yaml zconfig.yml "config_")
    
    # access yaml content
    echo $config_development_database
    

    谢谢-> https://gist.github.com/pkuczynski/8665367

        2
  •  0
  •   Dimitrios Desyllas    6 年前

    在我的例子中,我尝试了将文件命名为 xdebug.conf 我把默认的xdebug.conf 需要重写:

    zend_extension = xdebug.so
    xdebug.remote_enable = 1
    xdebug.remote_host = $ip
    xdebug.remote_port = 9091
    xdebug.max_nesting_level = 1000
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_autostart=true
    xdebug.remote_log=xdebug.log
    

    $ip 指示自动替换为正确ip的值,以便xdebug连接到。实际上用适当的值更新xdebug配置的脚本是我的 after.sh

    #!/bin/sh
    code_path="/home/vagrant/code"
    cd $code_path
    
    # Some other bootstrapping
    
    echo "Configuring Xdebug"
    ip=$(netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10)
    xdebug_config="/etc/php/$(php -v | head -n 1 | awk '{print $2}'|cut -c 1-3)/mods-available/xdebug.ini"
    
    echo "Xdebug config file ${xdebug_config}"
    
    if [ -f "${code_path}/xdebug.conf" ]; then
    
      echo "Specifying the ip with ${ip}"
      sed "s/\$ip/${ip}/g" xdebug.conf > xdebug.conf.tmp
    
      echo "Moving Into ${xdebug_config}"
      cat xdebug.conf.tmp
      sudo cp ./xdebug.conf.tmp ${xdebug_config}
    else
      echo "File not found"
    fi
    

    最后一步是 .gitignore 任何 xdebug.conf* 文件。所以现在开发人员必须创建自己的 xdebug.conf文件 .