diff --git a/README.md b/README.md index 59b467f..9a9dc6f 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,20 @@ Command Line Scripts for ZJU (VPN / WLAN / DNS) ## Install +### From source + ```bash git clone https://github.com/QSCTech/zjunet.git cd zjunet sudo ./install.sh ``` +## Openwrt + +Install xl2tpd: + +https://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/packages/ + ## Dev QSCer 可以直接向这个 repo push 而不用发 pull request。 diff --git a/build/openwrt/build.sh b/build/openwrt/build.sh new file mode 100755 index 0000000..b6537ea --- /dev/null +++ b/build/openwrt/build.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# lib +mkdir -p ./debian/usr/lib/zjunet +cp ../../lib/* ./debian/usr/lib/zjunet + +# bin +mkdir -p ./debian/usr/bin +echo '/usr/lib/zjunet/zjunet.sh "$@"' >> ./debian/usr/bin/zjunet +chmod +x ./debian/usr/bin/zjunet + +# contorl file +mkdir -p debian/DEBIAN +find ./debian -type d | xargs chmod 755 +cp control/* debian/DEBIAN + +# dpkg-deb +dpkg-deb --build debian +mv debian.deb zjunet_0.1-1_all.deb + +# remove debian/ +rm -rf ./debian diff --git a/build/openwrt/control/control b/build/openwrt/control/control new file mode 100644 index 0000000..f7e03da --- /dev/null +++ b/build/openwrt/control/control @@ -0,0 +1,9 @@ +Package: zjunet +Version: 0.1-1 +Section: base +Priority: optional +Architecture: all +Depends: xl2tpd (>= 1.3.1), curl +Maintainer: Zeno Zeng +Description: Command Line Scripts for ZJU + This script provides a VPN / WLAN / NEXTHOP for ZJUer. diff --git a/build/openwrt/control/postinst b/build/openwrt/control/postinst new file mode 100755 index 0000000..184c64c --- /dev/null +++ b/build/openwrt/control/postinst @@ -0,0 +1,4 @@ +#!/bin/sh +[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0 +. ${IPKG_INSTROOT}/lib/functions.sh +default_postinst $0 $@ diff --git a/build/openwrt/control/prerm b/build/openwrt/control/prerm new file mode 100755 index 0000000..8e303e7 --- /dev/null +++ b/build/openwrt/control/prerm @@ -0,0 +1,3 @@ +#!/bin/sh +. ${IPKG_INSTROOT}/lib/functions.sh +default_prerm $0 $@ diff --git a/build/openwrt/opkg-buildpackage b/build/openwrt/opkg-buildpackage deleted file mode 100755 index 719c9a5..0000000 --- a/build/openwrt/opkg-buildpackage +++ /dev/null @@ -1,223 +0,0 @@ -#!/bin/sh -# -# Author: Oliver Kurth -# -# Description: -# builds an opkg package from a source tarball using opkg-build. Idea stolen -# from Debian dpkg-buildpackage. -# -# - unpack the source tarball. -# - cd to the source distribution, change whatever you need to make the -# package compile and work on the ipaq. -# - create a directory 'opkg' -# - put all files which go to the 'CONTROL' directory of the root of the -# installed package into opkg. -# - the version (Version field in control) should match the version of the -# source tarball, optionally with a digit (eg. -1) appended. -# - additionally, put a file there called 'rules' which is a shell script -# accepting arguments 'build', 'install' and 'clean'. It can be a -# Makefile starting with the line '#!/usr/bin/make -f' -# * the build target does things like ./configure and make. -# * the install target installs to a temporary directory (make -# DESTDIR=/tmp/package) and removes unnecessary items (eg. man pages) -# * clean cleans ;-) -# -# You should run this with fakeroot (1) or as root. -# If all went well, you will find a diff file and an *.opk file in the -# directory above. - -set -e - -SCRIPTDIR=/usr/local/bin - -SCRIPTNAME=`basename $0` - -opkg_extract_value() { - sed -e "s/^[^:]*:[[:space:]]*//" -} - -required_field() { - field=$1 - - value=`grep "^$field:" < $CONTROL/control | opkg_extract_value` - if [ -z "$value" ]; then - echo "opkg-build: Error: $CONTROL/control is missing field $field" ; - PKG_ERROR=1 - fi - echo $value -} - -pkg_appears_sane_control() { - local pkg_dir=$1 - - local owd=`pwd` - cd $pkg_dir - - if [ ! -f "$CONTROL/control" ]; then - echo "opkg-build: Error: Control file $pkg_dir/$CONTROL/control not found." - cd $owd - return 1 - fi - - pkg=`required_field Package` - version=`required_field Version | sed 's/.*://;'` - arch=`required_field Architecture` - required_field Maintainer >/dev/null - required_field Description >/dev/null - - if echo $pkg | grep '[^a-z0-9.+-]'; then - echo "opkg-build: Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])" - PKG_ERROR=1; - fi - - local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'` - if [ -n "$bad_fields" ]; then - bad_fields=`echo $bad_fields` - echo "opkg-build: Error: The following fields in $CONTROL/control are missing a ':'" - echo " $bad_fields" - echo "opkg-build: This may be due to a missing initial space for a multi-line field value" - PKG_ERROR=1 - fi - - cd $owd - return $PKG_ERROR -} - -pkg_appears_sane_scripts() { - local pkg_dir=$1 - - local owd=`pwd` - cd $pkg_dir - - for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do - if [ -f $script -a ! -x $script ]; then - echo "opkg-build: Error: package script $script is not executable" - PKG_ERROR=1 - fi - done - - cd $owd - return $PKG_ERROR -} - -pkg_dir_abs=`pwd` -pkg_dir_base=`basename ${pkg_dir_abs}` - -pkg_dir=. - -[ -d ./CONTROL ] && CONTROL=./CONTROL -[ -d ./opkg ] && CONTROL=./opkg -if [ -z "$CONTROL" ]; then - echo "${SCRIPT_NAME}: Error: Directory $pkg_dir has no opkg or CONTROL subdirectory." - exit 1 -fi - -if ! pkg_appears_sane_control $pkg_dir && pkg_appears_sane_control $pkg_dir; then - echo "Please fix the above errors and try again." - exit 1 -fi - -echo "Package = $pkg" -echo "Version = $version" -version_up=`echo ${version} | sed "s/\-[0-9]\+//"` -echo "Upstream Version = $version_up" -pkg_upname=${pkg}-${version_up} -echo "Package Name = $pkg_upname" -pkg_tarball=${pkg_upname}.tar.gz -echo "Tarball Name = $pkg_tarball" - -if [ ! -x ${CONTROL}/rules ]; then - echo "${CONTROL}/rules not found or not executable." - exit 1 -fi - -# -# unpack upstream tarball and make diff -# -if [ -e ../${pkg_tarball} ] ; then - ( - set +e - - cd .. - - rm -rf ${pkg_upname}.tmp - rm -rf ${pkg_upname}.orig - - mkdir ${pkg_upname}.tmp - cd ${pkg_upname}.tmp - echo "unpacking source tarball ${pkg_tarball}" - tar zxf ${pkg_dir_abs}/../${pkg_tarball} - dir=`find . -maxdepth 1 -name "*" -type d` - cnt=`echo $dir | wc -l` - if [ ${cnt} != 1 ] ; then - echo "Arrghh !!!!" - echo "upstream package contains more than one top level directory" - echo "giving up..." - exit 1 - fi - mv ${dir} ${pkg_upname}.orig - mv ${pkg_upname}.orig .. - cd .. - echo "creating diff" - diff -uNr ${pkg_upname}.orig ${pkg_dir_base} > ${pkg}-${version}.diff - rm -f ${pkg}-${version}.diff.gz - echo "gzipping ${pkg}-${version}.diff" - gzip ${pkg}-${version}.diff - - echo "Removing temporary source directorys" - rm -rf ${pkg_upname}.tmp - rm -rf ${pkg_upname}.orig - ) -fi - -# build package -if ! ${CONTROL}/rules build; then - echo "Build failed" - exit 1 -fi - -# install it to tmp directory -if ! ${CONTROL}/rules install; then - echo "Install failed" - exit 1 -fi - -# copy contents of control directory -mkdir /tmp/${pkg}/CONTROL - -files_required="control" -files_optional="preinst postinst prerm postrm" - -for i in ${files_required} ; do - file=${CONTROL}/$i - - if [ -e ${file} ] ; then - cp $file /tmp/${pkg}/CONTROL - else - echo "required file ${file} missing" - fi -done - -for i in ${files_optional} ; do - file=${CONTROL}/$i - - if [ -e ${file} ] ; then - cp $file /tmp/${pkg}/CONTROL - fi -done - -# build the opk package -owd=`pwd` -cd .. -opkg-build /tmp/${pkg} || exit 1 - -rm -rf /tmp/${pkg} - -cd $owd -if ! ${CONTROL}/rules clean; then - echo "Clean failed" - exit 1 -fi - -# Yep. That's it! -exit 0 diff --git a/lib/route.sh b/lib/route.sh index e629359..39f89a3 100755 --- a/lib/route.sh +++ b/lib/route.sh @@ -68,24 +68,24 @@ case "$gateway" in *) # 内网静态路由 # See also: #18 (thanks Hexcles Ma) - ip route replace 10.0.0.0/8 via $gateway + ip route replace 10.0.0.0/8 via $gateway # Some classroom computers (especially East 6,7) - ip route replace 58.196.192.0/19 via $gateway - ip route replace 58.196.224.0/20 via $gateway - ip route replace 58.200.100.0/24 via $gateway + ip route replace 58.196.192.0/19 via $gateway + ip route replace 58.196.224.0/20 via $gateway + ip route replace 58.200.100.0/24 via $gateway # The public CERNET IP of most ZJU servers, which can be reached directly in the Intranet. # Most of them do have a 10.* IP, but sometimes school DNS just returns the public ones. - ip route replace 210.32.0.0/20 via $gateway - ip route replace 210.32.128.0/19 via $gateway - ip route replace 210.32.160.0/21 via $gateway - ip route replace 210.32.168.0/22 via $gateway - ip route replace 210.32.172.0/23 via $gateway - ip route replace 210.32.176.0/20 via $gateway + ip route replace 210.32.0.0/20 via $gateway + ip route replace 210.32.128.0/19 via $gateway + ip route replace 210.32.160.0/21 via $gateway + ip route replace 210.32.168.0/22 via $gateway + ip route replace 210.32.172.0/23 via $gateway + ip route replace 210.32.176.0/20 via $gateway # 玉泉和我们 vpn 后的 ip - ip route replace 222.205.0.0/17 via $gateway + ip route replace 222.205.0.0/17 via $gateway ;; esac