cmake也可以设置proxy
- 比如:
cmake .. -DHTTP_PROXY=http://192.168.50.65:7890
看起来 直接使用windows主机ip 可以ping通
zhangbin@LAPTOP-DFV9CMRA:~$ cat setwinproxy.sh
#!/bin/sh
host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
export ALL_PROXY="http://192.168.50.65:7890"
echo "ALL PROXY " $ALL_PROXY
zhangbin@LAPTOP-DFV9CMRA:~$
zhangbin@LAPTOP-DFV9CMRA:~$
zhangbin@LAPTOP-DFV9CMRA:~$ sudo su
[sudo] password for zhangbin:
➜ zhangbin mkdir immersive
➜ zhangbin cd immersive
➜ immersive ls
➜ immersive git clone https://ghdl.feizhuqwq.cf/https://github.com/OpenVisualCloud/Immersive-Video-Sample.git
Cloning into 'Immersive-Video-Sample'...
remote: Enumerating objects: 6960, done.
remote: Counting objects: 100% (928/928), done.
remote: Compressing objects: 100% (361/361), done.
remote: Total 6960 (delta 608), reused 723 (delta 555), pack-reused 6032
Receiving objects: 100% (6960/6960), 148.49 MiB | 2.11 MiB/s, done.
Resolving deltas: 100% (4953/4953), done.
➜ immersive ls
Immersive-Video-Sample
➜ immersive cd Immersive-Video-Sample
➜ Immersive-Video-Sample git:(master) ls
CONTRIBUTING.md OMAF-Sample README.md Sample-Videos src WebRTC-Sample
➜ Immersive-Video-Sample git:(master) cd OMAF-Sample
➜ OMAF-Sample git:(master) ls
client README.md server
➜ OMAF-Sample git:(master) cd server
➜ server git:(master) ls
CMakeLists.txt deploy.yaml Dockerfile.runtime run.sh start.sh
deploy.sh Dockerfile.base nginx_conf service.yaml stop.sh
➜ server git:(master) mkdir build && cd build
➜ build git:(master) cat ../../../../../setwinproxy.sh
#!/bin/sh
host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
export ALL_PROXY="http://192.168.50.65:7890"
echo "ALL PROXY " $ALL_PROXY
➜ build git:(master) sourcet ../../../../../setwinproxy.sh
zsh: command not found: sourcet
➜ build git:(master) source ../../../../../setwinproxy.sh
ALL PROXY http://192.168.50.65:7890
➜ build git:(master) http://192.168.50.65:7890
➜ build git:(master) cmake .. -DHTTP_PROXY=http://192.168.50.65:7890
➜ build git:(master) ls
➜ build git:(master) pwd
/home/zhangbin/immersive/Immersive-Video-Sample/OMAF-Sample/server/build
➜ build git:(master) cmake .. -DHTTP_PROXY=http://192.168.50.65:7890
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at CMakeLists.txt:1 (CMAKE_MINIMUM_REQUIRED):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zhangbin/immersive/Immersive-Video-Sample/OMAF-Sample/server/build
➜ build git:(master)
使用WSL2的ip地址来配置代理
- 第一行会输出 主机的ip地址:
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
export https_proxy="http://${hostip}:7890";
export http_proxy="http://${hostip}:7890";
- 设置
-
source /home/zhangbin/setproxy.sh
测试 ,直接ping不行,还是curl实在
curl www.google.com
大神的 长期配置 脚本
这种配置方法适用于长期配置,也就是写一个脚本,然后可以通过命令启动代理。新建proxy.sh脚本如下:
#!/bin/sh
hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
wslip=$(hostname -I | awk '{print $1}')
port=7890
PROXY_HTTP="http://${hostip}:${port}"
set_proxy(){
export http_proxy="${PROXY_HTTP}"
export HTTP_PROXY="${PROXY_HTTP}"
export https_proxy="${PROXY_HTTP}"
export HTTPS_proxy="${PROXY_HTTP}"
export ALL_PROXY="${PROXY_SOCKS5}"
export all_proxy=${PROXY_SOCKS5}
git config --global http.https://github.com.proxy ${PROXY_HTTP}
git config --global https.https://github.com.proxy ${PROXY_HTTP}
echo "Proxy has been opened."
}
unset_proxy(){
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
unset ALL_PROXY
unset all_proxy
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy
echo "Proxy has been closed."
}
test_setting(){
echo "Host IP:" ${hostip}
echo "WSL IP:" ${wslip}
echo "Try to connect to Google..."
resp=$(curl -I -s --connect-timeout 5 -m 5 -w "%{http_code}" -o /dev/null www.google.com)
if [ ${resp} = 200 ]; then
echo "Proxy setup succeeded!"
else
echo "Proxy setup failed!"
fi
}
if [ "$1" = "set" ]
then
set_proxy
elif [ "$1" = "unset" ]
then
unset_proxy
elif [ "$1" = "test" ]
then
test_setting
else
echo "Unsupported arguments."
fi
- 注意:其中第4行的更换为自己的代理端口号。
source ./proxy.sh set:开启代理
source ./proxy.sh unset:关闭代理
source ./proxy.sh test:查看代理状态