Add package build script

This commit is contained in:
Nick Peng
2019-12-14 15:46:18 +08:00
parent 8433729186
commit cc93156ee3
8 changed files with 481 additions and 185 deletions

View File

@@ -680,6 +680,10 @@ https://github.com/pymumu/smartdns/releases
bind [::]:6053 -no-speed-check -group office -no-rule-addr bind [::]:6053 -no-speed-check -group office -no-rule-addr
``` ```
## 编译
smartdns包含了编译软件包的脚本支持编译lucidebianopenwrtoptare安装包可执行`package/build-pkg.sh`编译。
## Donate ## Donate
如果你觉得此项目对你有帮助,请捐助我们,以使项目能持续发展,更加完善。 如果你觉得此项目对你有帮助,请捐助我们,以使项目能持续发展,更加完善。

View File

@@ -677,6 +677,10 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
bind [::]:6053 -no-speed-check -group office -no-rule-addr bind [::]:6053 -no-speed-check -group office -no-rule-addr
``` ```
## Compile
smartdns contains scripts for compiling packages, supports compiling luci, debian, openwrt, opare installation packages, and can execute `package/build-pkg.sh` compilation.
## [Donate](#Donate) ## [Donate](#Donate)
If you feel that this project is helpful to you, please donate to us so that the project can continue to develop and be more perfect. If you feel that this project is helpful to you, please donate to us so that the project can continue to develop and be more perfect.

180
package/build-pkg.sh Normal file
View File

@@ -0,0 +1,180 @@
#!/bin/sh
# Copyright (C) 2018-2019 Nick Peng (pymumu@gmail.com)
CURR_DIR=$(cd $(dirname $0);pwd)
VER="`date +"1.%Y.%m.%d-%H%M"`"
CODE_DIR="$CURR_DIR/.."
IS_BUILD_SMARTDNS=1
OUTPUTDIR=$CURR_DIR
export CC
export STRIP
showhelp()
{
echo "Usage: $0 [OPTION]"
echo "Options:"
echo " --platform [luci|debian|openwrt|optware|linux] build for platform. "
echo " --arch [all|armhf|arm64|x86_64|...] build for architecture, e.g. "
echo " --cross-tool [cross-tool] cross compiler, e.g. mips-openwrt-linux-"
echo ""
echo "Advance Options:"
echo " --static static link smartdns"
echo " --only-package only package, not build source"
echo " --filearch [arch] output file arch, default: equal --arch"
echo " --outputdir [dir] output package to specific directory"
echo " "
echo "Example:"
echo " build luci:"
echo " $0 --platform luci"
echo " build debian:"
echo " $0 --platform debian --arch x86_64"
echo " build raspbian pi:"
echo " $0 --platform debian --arch armhf"
echo " build optware mips:"
echo " $0 --platform optware --arch mipsbig"
echo " build openwrt mips:"
echo " $0 --platform openwrt --arch mips_24kc"
echo " build generic linux:"
echo " $0 --platform linux --arch x86_64"
}
build_smartdns()
{
if [ "$PLATFORM" != "luci" ]; then
make -C $CODE_DIR/src clean
make -C $CODE_DIR/src all -j8 VER=$VER $MAKE_ARGS
if [ $? -ne 0 ]; then
echo "make smartdns failed"
exit 1
fi
fi
$STRIP -d $CODE_DIR/src/smartdns >/dev/null 2>&1
return 0
}
build()
{
echo "build package for $PLATFORM"
if [ $IS_BUILD_SMARTDNS -eq 1 ]; then
build_smartdns
if [ $? -ne 0 ]; then
return 1
fi
fi
chmod +x $CODE_DIR/package/$PLATFORM/make.sh
$CODE_DIR/package/$PLATFORM/make.sh -o $CURR_DIR --arch $ARCH --ver $VER --filearch $FILEARCH -o $OUTPUTDIR
if [ $? -ne 0 ]; then
echo "build package for $PLATFORM failed"
return 1
fi
echo "build package for $PLATFORM success."
return 0
}
main()
{
OPTS=`getopt -o o:h --long arch:,filearch:,ver:,platform:,cross-tool:,static,only-package,outputdir: \
-n "" -- "$@"`
if [ "$#" -le "1" ]; then
showhelp
exit 1
fi
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;;
--filearch)
FILEARCH="$2"
shift 2;;
--platform)
PLATFORM="$2"
shift 2;;
--cross-tool)
CROSS_TOOL="$2"
shift 2;;
--static)
export STATIC="yes"
shift 1;;
--only-package)
IS_BUILD_SMARTDNS=0
shift 1;;
--outputdir)
OUTPUTDIR="$2"
shift 2;;
--ver)
VER="$2"
shift 2;;
-h | --help )
showhelp
return 0
shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [ -z "$PLATFORM" ]; then
echo "please input platform"
echo "run $0 -h for help."
return 1
fi
if [ "$PLATFORM" = "luci" ]; then
ARCH="all"
fi
if [ -z "$ARCH" ]; then
echo "please input arch."
echo "run $0 -h for help."
return 1
fi
if [ -z "$FILEARCH" ]; then
FILEARCH="$ARCH"
fi
if [ -z "$OUTPUTDIR" ]; then
OUTPUTDIR=$CURR_DIR
fi
if [ ! -z "$CROSS_TOOL" ]; then
CC="${CROSS_TOOL}gcc"
STRIP="${CROSS_TOOL}strip"
fi
if [ -z "$CC" ]; then
CC="gcc"
fi
if [ -z "$STRIP" ]; then
if [ ! -z "`echo $CC | grep '\-gcc'`" ]; then
STRIP="`echo "$CC" | sed 's/-gcc\$/-strip/g'`"
else
STRIP="strip"
fi
fi
if [ ! -e "`which $CC`" ]; then
echo "Cannot find compiler $CC"
return 1
fi
build
}
main $@
exit $?

View File

@@ -14,7 +14,6 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
CURR_DIR=$(cd $(dirname $0);pwd) CURR_DIR=$(cd $(dirname $0);pwd)
VER="`date +"1.%Y.%m.%d-%H%M"`" VER="`date +"1.%Y.%m.%d-%H%M"`"
SMARTDNS_DIR=$CURR_DIR/../../ SMARTDNS_DIR=$CURR_DIR/../../
@@ -52,6 +51,10 @@ build()
cp $SMARTDNS_DIR/etc/default/smartdns $ROOT/etc/default/ cp $SMARTDNS_DIR/etc/default/smartdns $ROOT/etc/default/
cp $SMARTDNS_DIR/systemd/smartdns.service $ROOT/lib/systemd/system/ cp $SMARTDNS_DIR/systemd/smartdns.service $ROOT/lib/systemd/system/
cp $SMARTDNS_DIR/src/smartdns $ROOT/usr/sbin cp $SMARTDNS_DIR/src/smartdns $ROOT/usr/sbin
if [ $? -ne 0 ]; then
echo "copy smartdns file failed."
return 1
fi
chmod +x $ROOT/usr/sbin/smartdns chmod +x $ROOT/usr/sbin/smartdns
dpkg -b $ROOT $OUTPUTDIR/smartdns.$VER.$FILEARCH.deb dpkg -b $ROOT $OUTPUTDIR/smartdns.$VER.$FILEARCH.deb

98
package/linux/make.sh Normal file
View File

@@ -0,0 +1,98 @@
#!/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
showhelp()
{
echo "Usage: make [OPTION]"
echo "Options:"
echo " -o output directory."
echo " --arch archtecture."
echo " --ver version."
echo " -h show this message."
}
build()
{
PKG_ROOT=/tmp/smartdns-linux
rm -fr $PKG_ROOT
mkdir -p $PKG_ROOT/smartdns
cd $PKG_ROOT/
# Generic x86_64
mkdir $PKG_ROOT/smartdns/src -p
mkdir $PKG_ROOT/smartdns/package -p
cd $SMARTDNS_DIR
cp package/windows $PKG_ROOT/smartdns/package/ -a
cp etc systemd *.md LICENSE install $PKG_ROOT/smartdns/ -a
cp src/smartdns $PKG_ROOT/smartdns/src -a
if [ $? -ne 0 ]; then
echo "copy smartdns file failed"
rm -fr $PKG_ROOT
exit 1
fi
cd $PKG_ROOT
tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.tar.gz smartdns
if [ $? -ne 0 ]; then
echo "create package failed"
rm -fr $PKG_ROOT
exit 1
fi
cd $CURR_DIR
rm -fr $PKG_ROOT
}
main()
{
OPTS=`getopt -o o:h --long arch:,ver:,filearch: \
-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;;
--filearch)
FILEARCH="$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 "$FILEARCH" ]; then
FILEARCH=$ARCH
fi
if [ -z "$OUTPUTDIR" ]; then
OUTPUTDIR=$CURR_DIR;
fi
build
}
main $@
exit $?

View File

@@ -14,7 +14,6 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
CURR_DIR=$(cd $(dirname $0);pwd) CURR_DIR=$(cd $(dirname $0);pwd)
VER="`date +"1.%Y.%m.%d-%H%M"`" VER="`date +"1.%Y.%m.%d-%H%M"`"
@@ -63,7 +62,7 @@ build()
cp $ROOT/files/etc $ROOT/root/ -af cp $ROOT/files/etc $ROOT/root/ -af
INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`" INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control sed -i "s/^Architecture.*/Architecture: all/g" $ROOT/control/control
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
if [ ! -z "$INST_SIZE" ]; then if [ ! -z "$INST_SIZE" ]; then

View File

@@ -14,7 +14,6 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
CURR_DIR=$(cd $(dirname $0);pwd) CURR_DIR=$(cd $(dirname $0);pwd)
VER="`date +"1.%Y.%m.%d-%H%M"`" VER="`date +"1.%Y.%m.%d-%H%M"`"
@@ -53,6 +52,11 @@ build()
cp $CUSTOM_CONF $ROOT/root/etc/smartdns/ cp $CUSTOM_CONF $ROOT/root/etc/smartdns/
cp $CURR_DIR/files/etc $ROOT/root/ -af cp $CURR_DIR/files/etc $ROOT/root/ -af
cp $SMARTDNS_BIN $ROOT/root/usr/sbin cp $SMARTDNS_BIN $ROOT/root/usr/sbin
if [ $? -ne 0 ]; then
echo "copy smartdns file failed."
rm -fr $ROOT/
return 1
fi
chmod +x $ROOT/root/etc/init.d/smartdns chmod +x $ROOT/root/etc/init.d/smartdns
INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`" INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"

View File

@@ -14,7 +14,6 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
CURR_DIR=$(cd $(dirname $0);pwd) CURR_DIR=$(cd $(dirname $0);pwd)
VER="`date +"1.%Y.%m.%d-%H%M"`" VER="`date +"1.%Y.%m.%d-%H%M"`"
SMARTDNS_DIR=$CURR_DIR/../../ SMARTDNS_DIR=$CURR_DIR/../../
@@ -48,6 +47,11 @@ build()
cp $SMARTDNS_OPT $ROOT/opt/etc/smartdns/ cp $SMARTDNS_OPT $ROOT/opt/etc/smartdns/
cp $CURR_DIR/S50smartdns $ROOT/opt/etc/init.d/ cp $CURR_DIR/S50smartdns $ROOT/opt/etc/init.d/
cp $SMARTDNS_BIN $ROOT/opt/usr/sbin cp $SMARTDNS_BIN $ROOT/opt/usr/sbin
if [ $? -ne 0 ]; then
echo "copy smartdns file failed."
rm -fr $ROOT/
return 1
fi
sed -i "s/# *server-name smartdns/server-name smartdns/g" $ROOT/opt/etc/smartdns/smartdns.conf sed -i "s/# *server-name smartdns/server-name smartdns/g" $ROOT/opt/etc/smartdns/smartdns.conf
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control