From cfa14d6fc3f8df928bc6df4406e5a091023b8894 Mon Sep 17 00:00:00 2001 From: NekoRectifier Date: Tue, 12 Dec 2023 20:32:17 +0800 Subject: [PATCH] feat: improve env command injecting --- scripts/functions.bash | 20 ++++++++++++++++++ scripts/functions.fish | 21 +++++++++++++++++++ setup.sh | 47 ++++++++++++++++++++---------------------- 3 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 scripts/functions.bash create mode 100644 scripts/functions.fish diff --git a/scripts/functions.bash b/scripts/functions.bash new file mode 100644 index 0000000..3baef12 --- /dev/null +++ b/scripts/functions.bash @@ -0,0 +1,20 @@ +function proxy_on() { + export http_proxy=http://127.0.0.1:7890 + export https_proxy=http://127.0.0.1:7890 + export no_proxy=127.0.0.1,localhost + export HTTP_PROXY=http://127.0.0.1:7890 + export HTTPS_PROXY=http://127.0.0.1:7890 + export NO_PROXY=127.0.0.1,localhost + echo -e "\033[32m[√] 已开启代理\033[0m" +} + +# 关闭系统代理 +function proxy_off(){ + unset http_proxy + unset https_proxy + unset no_proxy + unset HTTP_PROXY + unset HTTPS_PROXY + unset NO_PROXY + echo -e "\033[31m[×] 已关闭代理\033[0m" +} \ No newline at end of file diff --git a/scripts/functions.fish b/scripts/functions.fish new file mode 100644 index 0000000..b003dac --- /dev/null +++ b/scripts/functions.fish @@ -0,0 +1,21 @@ +# 开启系统代理 +function proxy_on + export http_proxy=http://127.0.0.1:7890 + export https_proxy=http://127.0.0.1:7890 + export no_proxy=127.0.0.1,localhost + export HTTP_PROXY=http://127.0.0.1:7890 + export HTTPS_PROXY=http://127.0.0.1:7890 + export NO_PROXY=127.0.0.1,localhost + echo -e "\033[32m[√] 已开启代理\033[0m" +end + +# 关闭系统代理 +function proxy_off + set -e http_proxy + set -e https_proxy + set -e no_proxy + set -e HTTP_PROXY + set -e HTTPS_PROXY + set -e NO_PROXY + echo -e "\033[31m[×] 已关闭代理\033[0m" +end \ No newline at end of file diff --git a/setup.sh b/setup.sh index 9e88812..2a3c577 100755 --- a/setup.sh +++ b/setup.sh @@ -1,32 +1,29 @@ #!/bin/bash -echo -e "Run this with root permission!\n" +Server_Dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) +fish_func_path=$Server_Dir/scripts/functions.fish +bash_func_path=$Server_Dir/scripts/functions.bash -# 添加环境变量(root权限) -cat>/etc/profile.d/clash.fish<> ~/.config/fish/config.fish + fi +elif [ "$shell_name" = "bash" ]; then + if ! grep -q "$bash_func_path" ~/.bashrc; then + echo "source $bash_func_path" >> ~/.bashrc + fi +elif [ "$shell_name" = "zsh" ]; then + if ! grep -q "$bash_func_path" ~/.zshrc; then + echo "source $bash_func_path" >> ~/.zshrc + fi +fi + +echo -e "环境变量已注入\n" echo -e "请执行以下命令开启系统代理: proxy_on\n" echo -e "若要临时关闭系统代理,请执行: proxy_off\n"