Support openwrt
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=smarttdns
|
||||
PKG_VERSION:=2018.7.1.1607
|
||||
PKG_RELEASE:=$(PKG_SOURCE_VERSION)
|
||||
|
||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/smartdns
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
TITLE:=smartdns
|
||||
URL:=https://github.com/pymumu/smartdns
|
||||
MAINTAINER:=Nick Peng <pymumu@gmail.com>
|
||||
DEPENDS:=
|
||||
endef
|
||||
|
||||
define Package/smartdns/description
|
||||
smartdns server, find fastest ip.
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
mkdir -p $(PKG_BUILD_DIR)
|
||||
cp -r ../* $(PKG_BUILD_DIR)
|
||||
endef
|
||||
|
||||
define Package/smartdns/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/smartdns $(1)/usr/sbin
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage, smartdns))
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=smarttdns
|
||||
PKG_VERSION:=2018.7.1.1607
|
||||
PKG_RELEASE:=$(PKG_SOURCE_VERSION)
|
||||
|
||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/smartdns
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
TITLE:=smartdns
|
||||
URL:=https://github.com/pymumu/smartdns
|
||||
MAINTAINER:=Nick Peng <pymumu@gmail.com>
|
||||
DEPENDS:=
|
||||
endef
|
||||
|
||||
define Package/smartdns/description
|
||||
smartdns server, find fastest ip.
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
mkdir -p $(PKG_BUILD_DIR)
|
||||
cp -r ../* $(PKG_BUILD_DIR)
|
||||
endef
|
||||
|
||||
define Package/smartdns/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/smartdns $(1)/usr/sbin
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage, smartdns))
|
||||
|
||||
0
package/openwrt/address.conf
Normal file
0
package/openwrt/address.conf
Normal file
1
package/openwrt/control/conffiles
Normal file
1
package/openwrt/control/conffiles
Normal file
@@ -0,0 +1 @@
|
||||
/etc/config/smartdns
|
||||
11
package/openwrt/control/control
Normal file
11
package/openwrt/control/control
Normal file
@@ -0,0 +1,11 @@
|
||||
Package: smartdns
|
||||
Architecture: mipsbig
|
||||
Priority: optional
|
||||
Section: net
|
||||
Version: 2018.7.6-1921
|
||||
Maintainer: pymumu
|
||||
Source: http://127.0.0.1/
|
||||
Description: A smart dns server
|
||||
Suggests:
|
||||
Conflicts:
|
||||
Enabled: yes
|
||||
15
package/openwrt/control/postinst
Normal file
15
package/openwrt/control/postinst
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
chmod +x /usr/sbin/smartdns
|
||||
chmod +x /etc/init.d/smartdns
|
||||
|
||||
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
|
||||
. ${IPKG_INSTROOT}/lib/functions.sh
|
||||
default_postinst $0 $@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4
package/openwrt/control/prerm
Normal file
4
package/openwrt/control/prerm
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. ${IPKG_INSTROOT}/lib/functions.sh
|
||||
default_prerm $0 $@
|
||||
|
||||
1
package/openwrt/debian-binary
Normal file
1
package/openwrt/debian-binary
Normal file
@@ -0,0 +1 @@
|
||||
2.0
|
||||
2
package/openwrt/files/etc/config/smartdns
Normal file
2
package/openwrt/files/etc/config/smartdns
Normal file
@@ -0,0 +1,2 @@
|
||||
config 'smartdns'
|
||||
option 'enabled' '0'
|
||||
116
package/openwrt/files/etc/init.d/smartdns
Normal file
116
package/openwrt/files/etc/init.d/smartdns
Normal file
@@ -0,0 +1,116 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2008-2011 OpenWrt.org
|
||||
|
||||
START=50
|
||||
SERVICE_USE_PID=1
|
||||
SERVICE_WRITE_PID=1
|
||||
SERVICE_DAEMONIZE=1
|
||||
BASECONFIGFILE="/etc/smartdns/smartdns.conf"
|
||||
SMARTDNS_CONF="/var/etc/smartdns.conf"
|
||||
ADDRESS_CONF="/etc/smartdns/address.conf"
|
||||
SMARTDNS_CONF_TMP="${SMARTDNS_CONF}.tmp"
|
||||
|
||||
set_iptable()
|
||||
{
|
||||
IPS="`ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F: '{print $2}'`"
|
||||
for IP in $IPS
|
||||
do
|
||||
iptables -t nat -A PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
clear_iptable()
|
||||
{
|
||||
IPS="`ifconfig | grep "inet addr" | grep -v ":127" | grep "Bcast" | awk '{print $2}' | awk -F: '{print $2}'`"
|
||||
for IP in $IPS
|
||||
do
|
||||
iptables -t nat -D PREROUTING -p udp -d $IP --dport 53 -j REDIRECT --to-ports $SMARTDNS_PORT >/dev/null 2>&1
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
conf_append()
|
||||
{
|
||||
echo "$1 $2" >> $SMARTDNS_CONF_TMP
|
||||
}
|
||||
|
||||
load_server()
|
||||
{
|
||||
local section="$1"
|
||||
config_get "port" "$section" "port" "53"
|
||||
config_get "type" "$section" "type" "udp"
|
||||
config_get "ip" "$section" "ip" ""
|
||||
|
||||
if [ -z "$port" ] || [ -z "$ip" ] || [ -z "$type" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
SERVER="server"
|
||||
if [ "$type" = "tcp" ]; then
|
||||
SERVER="server-tcp"
|
||||
fi
|
||||
|
||||
if [ ! -z "`echo $ip | grep ":"`" ]; then
|
||||
if [ -z "`echo $ip | grep "\["`" ]; then
|
||||
ip="[$ip]"
|
||||
fi
|
||||
fi
|
||||
|
||||
conf_append "$SERVER" "$ip:$port"
|
||||
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local section="$1"
|
||||
args=""
|
||||
config_get "port" "$section" "port" "5353"
|
||||
conf_append "bind" "[::]:$port"
|
||||
SMARTDNS_PORT="$port"
|
||||
|
||||
config_get "cache_size" "$section" "cache_size" ""
|
||||
if [ ! -z "$cache_size" ]; then
|
||||
conf_append "cache-size" "$cache_size"
|
||||
fi
|
||||
|
||||
config_get "rr_ttl" "$section" "rr_ttl" ""
|
||||
if [ ! -z "$rr_ttl" ]; then
|
||||
conf_append "rr-ttl" "$rr_ttl"
|
||||
fi
|
||||
|
||||
config_get "rr_ttl_min" "$section" "rr_ttl_min" ""
|
||||
if [ ! -z "$rr_ttl_min" ]; then
|
||||
conf_append "rr-ttl-min" "$rr_ttl_min"
|
||||
fi
|
||||
|
||||
config_get "rr_ttl_max" "$section" "rr_ttl_max" ""
|
||||
if [ ! -z "$rr_ttl_max" ]; then
|
||||
conf_append "rr-ttl-max" "$rr_ttl_max"
|
||||
fi
|
||||
|
||||
clear_iptable
|
||||
config_get_bool "redirect" "$section" "redirect" '0'
|
||||
if [ "$redirect" -eq 1 ]; then
|
||||
set_iptable
|
||||
fi
|
||||
|
||||
config_foreach load_server "server"
|
||||
|
||||
echo "# address" >> $SMARTDNS_CONF_TMP
|
||||
grep "^ *address" $ADDRESS_CONF >> $SMARTDNS_CONF_TMP
|
||||
|
||||
config_get_bool "enabled" "$section" "enabled" '0'
|
||||
mv $SMARTDNS_CONF_TMP $SMARTDNS_CONF
|
||||
[ "$enabled" -gt 0 ] || return 1
|
||||
service_start /usr/sbin/smartdns $args -c $SMARTDNS_CONF
|
||||
}
|
||||
|
||||
start() {
|
||||
config_load "smartdns"
|
||||
config_foreach start_service "smartdns"
|
||||
}
|
||||
|
||||
stop() {
|
||||
service_stop /usr/sbin/smartdns
|
||||
}
|
||||
|
||||
99
package/openwrt/make.sh
Normal file
99
package/openwrt/make.sh
Normal file
@@ -0,0 +1,99 @@
|
||||
#/bin/sh
|
||||
|
||||
CURR_DIR=$(cd $(dirname $0);pwd)
|
||||
|
||||
VER="`date +"1.%Y.%m.%d-%H%M"`"
|
||||
SMARTDNS_DIR=$CURR_DIR/../../
|
||||
SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
|
||||
SMARTDNS_CONF=$SMARTDNS_DIR/etc/smartdns/smartdns.conf
|
||||
ADDRESS_CONF=$CURR_DIR/address.conf
|
||||
|
||||
showhelp()
|
||||
{
|
||||
echo "Usage: make [OPTION]"
|
||||
echo "Options:"
|
||||
echo " -o output directory."
|
||||
echo " --arch archtecture."
|
||||
echo " --ver version."
|
||||
echo " -h show this message."
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
ROOT=/tmp/smartdns-openwrt
|
||||
rm -fr $ROOT
|
||||
|
||||
mkdir -p $ROOT
|
||||
cp $CURR_DIR/* $ROOT/ -af
|
||||
cd $ROOT/
|
||||
mkdir $ROOT/root/usr/sbin -p
|
||||
mkdir $ROOT/root/etc/init.d -p
|
||||
mkdir $ROOT/root/etc/smartdns/ -p
|
||||
|
||||
cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
|
||||
cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
|
||||
cp $CURR_DIR/files/etc $ROOT/root/ -af
|
||||
cp $SMARTDNS_BIN $ROOT/root/usr/sbin
|
||||
|
||||
chmod +x $ROOT/root/etc/init.d/smartdns
|
||||
|
||||
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
|
||||
sed -i "s/^\(bind .*\):53/\1:5353/g" $ROOT/root/etc/smartdns/smartdns.conf
|
||||
|
||||
cd $ROOT/control
|
||||
chmod +x *
|
||||
tar zcf ../control.tar.gz ./
|
||||
cd $ROOT
|
||||
|
||||
tar zcf $ROOT/data.tar.gz -C root .
|
||||
tar zcf $OUTPUTDIR/smartdns.$VER.$ARCH.ipk control.tar.gz data.tar.gz debian-binary
|
||||
rm -fr $ROOT/
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
OPTS=`getopt -o o:h --long arch:,ver: \
|
||||
-n "" -- "$@"`
|
||||
|
||||
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
|
||||
|
||||
# Note the quotes around `$TEMP': they are essential!
|
||||
eval set -- "$OPTS"
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
--arch)
|
||||
ARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
-o )
|
||||
OUTPUTDIR="$2"
|
||||
shift 2;;
|
||||
-h | --help )
|
||||
showhelp
|
||||
return 0
|
||||
shift ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
|
||||
build
|
||||
}
|
||||
|
||||
main $@
|
||||
exit $?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user