From 8f0095c8fe9924ed4fe360a77a1a25125c78beb4 Mon Sep 17 00:00:00 2001 From: Wu Yufei Date: Fri, 30 Aug 2019 23:18:52 +0800 Subject: [PATCH] Update README and add disable WLAN function --- README.md | 41 ++++++++++++++++++++++++++++-------- README.zh.md | 58 +++++++++++++++++++++++++++++++++++++++++++-------- lib/vpn.sh | 12 +++++------ lib/wlan.sh | 30 ++++++++++++++++++++------ lib/zjunet.sh | 55 +++++++++++++++++++++++++++--------------------- 5 files changed, 142 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 6099912..9462536 100644 --- a/README.md +++ b/README.md @@ -26,37 +26,60 @@ Command Line Scripts for ZJU (VPN / WLAN / DNS) - `dig` (Different package on different platform) -## Install +## Installation + +If you meet any problem during or after the installation, check Troubleshooting section below in this documentation. ### Debian / Ubuntu (deb) -#### Install .deb package directly +1. Configure ZJU mirrors using [浙大源配置生成器](https://mirrors.zju.edu.cn/#generator). +2. Run these command. -Download .deb package from [Release Page](https://github.com/QSCTech/zjunet/releases), -Click or run `sudo apt-get install ./zjunet__all.deb` to install. +``` bash +curl https://dl.zjuqsc.com/linux/qsc.public.key | sudo apt-key add - +curl https://dl.zjuqsc.com/linux/debian/qsc.list | sudo tee /etc/apt/sources.list.d/qsc.list +sudo apt-get update +sudo apt-get install zjunet +``` + +3. The installation has completed. +4. If you are setting up a server, we suggest you run `zjunet wlan disable` to disable WLAN capability. ### Fedora / CentOS (rpm) -#### Install .rpm package directly +1. Configure ZJU mirrors using [浙大源配置生成器](https://mirrors.zju.edu.cn/#generator). +2. Configure [EPEL of ZJU mirrors](https://mirrors.zju.edu.cn/epel/) (Taking CentOS installation as an example) + 1. Run `yum install epel-release` to install EPEL. + 2. Edit `/etc/yum.repos.d/epel.repo` , uncomment lines begin with `#baseurl=` (Remove leading `#` sign) and comment lines begin with `mirrorlist=` (Prepend `#` sign) + 3. Edit `/etc/yum.repos.d/epel.repo` , replace `https://download.fedoraproject.org/pub` with `https://mirrors.zju.edu.cn` . -Download .rpm package from [Release Page](https://github.com/QSCTech/zjunet/releases), -Click or run `sudo yum localinstall zjunet-.noarch.rpm` to install. +3. Run these command. -**ATTENTION** In CentOS 7, *xl2tpd* requires epel. +```bash +curl https://dl.zjuqsc.com/linux/qsc.public.key | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-QSC-COMP66 +curl https://dl.zjuqsc.com/linux/yum/qsc.repo | sudo tee /etc/yum.repos.d/qsc.repo +sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-QSC-COMP66 +sudo yum install zjunet +``` + +4. The installation has completed. +5. If you are setting up a server, we suggest you run `zjunet wlan disable` to disable WLAN capability. ### OpenWrt (opk) Download .opk package from [Release Page](https://github.com/QSCTech/zjunet/releases) (onto your router), Run `opkg install ./zjunet__all.opk`. -### Other linux (Source Code) +### Other Linux (Build from source code) ```bash +xl2tpd -v; curl -V; dig -v # Check installation of dependencies. There should be 3 version numbers. # Under proper directory git clone https://github.com/QSCTech/zjunet.git cd zjunet sudo ./install.sh # If update is necessary, run `git pull` and `sudo ./install.sh` +# If you are setting up a server, we suggest you run `zjunet wlan disable` to disable WLAN capability. ``` **ATTENTION** Requirement check will **NOT** be done running `./install.sh`. diff --git a/README.zh.md b/README.zh.md index 6579ee3..41c423e 100644 --- a/README.zh.md +++ b/README.zh.md @@ -26,42 +26,82 @@ ## 安装 +根据发行版的不同,安装方式略有区别。为了更好的为您提供服务,建议您从求是潮网站的仓库下载。 +(求是潮网站在校内也可以访问,安装时不需要先从仓库手动下载。) + +考虑到需要安装 zjunet 的机器通常没有办法访问外网,建议配合 [浙大源](https://mirrors.zju.edu.cn/) 安装。 + +下面将按照不同的发行版分别列出安装步骤。如果你在安装前后遇到任何问题,请向下浏览本文件的“疑难解答”部分。 + ### Debian / Ubuntu (deb) -#### 直接安装 deb 包 +1. 使用 [浙大源配置生成器](https://mirrors.zju.edu.cn/#generator) 生成需要的浙大源配置,并按照提示将 `/etc/apt/sources.list` 替换为显示的内容。 +2. 依次输入并执行下列命令: -从 [Releases 页](https://github.com/QSCTech/zjunet/releases) 下载 deb 包, -双击安装或运行 `sudo apt-get install ./zjunet_(版本)_all.deb` 。 +``` bash +curl https://dl.zjuqsc.com/linux/qsc.public.key | sudo apt-key add - +curl https://dl.zjuqsc.com/linux/debian/qsc.list | sudo tee /etc/apt/sources.list.d/qsc.list +sudo apt-get update +sudo apt-get install zjunet +``` + +3. 安装结束!您可以输入 `zjunet version` 查看安装的版本,输入 `zjunet usage` 查看用法。 +4. 如果你是服务器用户,建议运行 `zjunet wlan disable` 来彻底禁用 WLAN 功能。 ### Fedora / CentOS (rpm) -#### 直接安装 rpm 包 +1. 使用 [浙大源配置生成器](https://mirrors.zju.edu.cn/#generator) 生成需要的浙大源配置,并按照提示修改 `/etc/yum.repos.d` 中的文件。 +2. 执行这些步骤以使用 [浙大源 EPEL](https://mirrors.zju.edu.cn/epel/) (以 CentOS 为例): + 1. 运行 `yum install epel-release` 以安装 EPEL 。 + 2. 编辑 `/etc/yum.repos.d/epel.repo` ,将所有以 `#baseurl=` 开头的行取消注释(删除行首 `#` 符号)并注释以 `mirrorlist=` 开头的行(在行首添加 `#` 符号) + 3. 继续编辑 `/etc/yum.repos.d/epel.repo` ,将所有 `https://download.fedoraproject.org/pub` 替换为 `https://mirrors.zju.edu.cn`。 -从 [Releases 页](https://github.com/QSCTech/zjunet/releases) 下载 rpm 包, -双击安装或运行 `sudo yum localinstall zjunet-(版本).noarch.rpm` 。 +3. 依次输入并执行下列命令: -**注意** CentOS 7 中需要 epel 源提供 xl2tpd 。 +```bash +curl https://dl.zjuqsc.com/linux/qsc.public.key | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-QSC-COMP66 +curl https://dl.zjuqsc.com/linux/yum/qsc.repo | sudo tee /etc/yum.repos.d/qsc.repo +sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-QSC-COMP66 +sudo yum install zjunet +``` + +4. 安装结束!您可以输入 `zjunet version` 查看安装的版本,输入 `zjunet usage` 查看用法。 +5. 如果你是服务器用户,建议运行 `zjunet wlan disable` 来彻底禁用 WLAN 功能。 ### OpenWrt (opk) 从 [Releases 页](https://github.com/QSCTech/zjunet/releases) 下载 opk 包到路由器上, 运行 `opkg install ./zjunet_(版本)_all.opk` 。 -### Other linux (源代码安装) +### 其他 Linux (源代码安装) ```bash +xl2tpd -v; curl -V; dig -v # 检查依赖命令的安装情况。这句命令将输出三个版本号。 # 在合适的目录下 git clone https://github.com/QSCTech/zjunet.git cd zjunet sudo ./install.sh # 如果想要更新请在 zjunet 目录下运行 git pull 并再次 sudo ./install.sh +# 如果你是服务器用户,建议运行 `zjunet wlan disable` 来彻底禁用 WLAN 功能。 ``` **注意** 运行 `./install.sh` 时 **不会** 确认必要依赖是否已经安装。 -您应当运行 `xl2tpd -v` 、 `curl -V` 和 `dig -v` 确认安装。 +您应当先运行 `xl2tpd -v` 、 `curl -V` 和 `dig -v` 确认安装。 ## 疑难解答 +### 出现了 `xl2tpd-control: command not found` 的提示但直接运行 `xl2tpd-control` 有效 + +出现这种情况通常是由于 `sudo` 的 `secure path` 被启用。 + +请编辑 `/etc/sudoers` 并在 `Defaults secure_path=xxxxxxx` 行添加 `xl2tpd-control` 所在路径(运行 `which xl2tpd-control` 查看)。编辑后的这行类似这样: + +``` +Defaults secure_path="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin" +``` + +你可以运行 `sudo env | grep PATH` 来验证配置。显示的内容应当包括刚才添加的路径。 + ### 丢包 这是一个已知问题。在同时连接 VPN 和 ZJUWLAN 时, diff --git a/lib/vpn.sh b/lib/vpn.sh index dfa1466..593dbc3 100755 --- a/lib/vpn.sh +++ b/lib/vpn.sh @@ -65,18 +65,18 @@ connect() { case "$1" in - -d) + d|-d|disconnect) disconnect ;; - disconnect) - disconnect - ;; - - *) + ""|c|-c|connect) disconnect sleep 3 connect ;; + *) + echo Invalid subcommand \"$1\" for \`zjunet vpn\`. Run \`zjunet usage\` for help. + ;; + esac diff --git a/lib/wlan.sh b/lib/wlan.sh index 6e03c9a..7d41e07 100755 --- a/lib/wlan.sh +++ b/lib/wlan.sh @@ -24,11 +24,18 @@ BASEDIR=$(dirname $0) +DISABLE_CHECK=${BASEDIR}/.disable-wlan + USER="${BASEDIR}/user.sh" USERNAME=$($USER get) PASSWORD=$($USER getpwd $USERNAME) +if [[ -f "${DISABLE_CHECK}" ]]; then + echo WLAN function has been disabled.; + exit 1; +fi + logout() { USERNAME=$1 PASSWORD=$2 @@ -94,7 +101,11 @@ login() { ;; *) echo "Login: failed." >&2 - echo "Login: ${RESPONSE}" >&2 + if [[ -z "${RESPONSE}" ]]; then + echo "Login: (Empty response)" >&2 + else + echo "Login: ${RESPONSE}" >&2 + fi exit 1 ;; esac @@ -102,15 +113,22 @@ login() { case "$1" in - disconnect) + d|-d|disconnect) logout $USERNAME $PASSWORD ;; - -d) - logout $USERNAME $PASSWORD - ;; - *) + + ""|c|-c|connect) login $USERNAME $PASSWORD ;; + + disable) + "${BASEDIR}/sudo.sh" touch "${DISABLE_CHECK}" + exit 0 + ;; + + *) + echo Invalid subcommand \"$1\" for \`zjunet wlan\`. Run \`zjunet usage\` for help. + ;; esac "${BASEDIR}/sudo.sh" "${BASEDIR}/route.sh" diff --git a/lib/zjunet.sh b/lib/zjunet.sh index 41d619d..7d4d4c7 100755 --- a/lib/zjunet.sh +++ b/lib/zjunet.sh @@ -22,54 +22,61 @@ BASEDIR=$(dirname $0) MISCELLDIR="$BASEDIR/../../share/zjunet" case "$1" in - route) + r|route) "${BASEDIR}/sudo.sh" "${BASEDIR}/route.sh" ;; - user) + u|user) "${BASEDIR}/user.sh" $2 ;; - all) + a|all) "${BASEDIR}/wlan.sh" $2 "${BASEDIR}/vpn.sh" $2 ;; - wlan) + w|wlan) "${BASEDIR}/wlan.sh" $2 ;; - vpn) + v|vpn) "${BASEDIR}/vpn.sh" $2 ;; - dns) + d|dns) "${BASEDIR}/dns.sh" $2 ;; - version|--version) + -v|version|--version) version_full=`cat "${MISCELLDIR}/VERSION"` version=$(echo $version_full | sed 's/-.*//') echo "zjunet version: $version (${version_full})" ;; *) cat <