1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter.git synced 2025-02-12 11:21:55 +00:00
openmptcprouter/build.sh

327 lines
11 KiB
Bash
Raw Normal View History

2017-12-22 10:08:56 +00:00
#!/bin/sh
set -e
umask 0022
unset GREP_OPTIONS SED
2018-07-18 20:36:20 +00:00
_get_repo() (
mkdir -p "$1"
cd "$1"
[ -d .git ] || git init
if git remote get-url origin >/dev/null 2>/dev/null; then
git remote set-url origin "$2"
else
git remote add origin "$2"
fi
2019-08-22 07:03:52 +00:00
git fetch origin -f
git fetch origin --tags -f
2018-07-30 09:19:28 +00:00
git checkout -f "origin/$3" -B "build" 2>/dev/null || git checkout "$3" -B "build"
2018-07-18 20:36:20 +00:00
)
2017-12-22 10:08:56 +00:00
2018-02-02 10:23:20 +00:00
OMR_DIST=${OMR_DIST:-openmptcprouter}
OMR_HOST=${OMR_HOST:-$(curl -sS ifconfig.co)}
2017-12-22 10:08:56 +00:00
OMR_PORT=${OMR_PORT:-8000}
2018-01-26 21:53:41 +00:00
OMR_KEEPBIN=${OMR_KEEPBIN:-no}
2018-02-23 08:46:51 +00:00
OMR_IMG=${OMR_IMG:-yes}
#OMR_UEFI=${OMR_UEFI:-yes}
2020-06-09 20:40:38 +00:00
OMR_PACKAGES=${OMR_PACKAGES:-full}
2018-04-05 15:16:42 +00:00
OMR_ALL_PACKAGES=${OMR_ALL_PACKAGES:-no}
2017-12-22 10:08:56 +00:00
OMR_TARGET=${OMR_TARGET:-x86_64}
OMR_TARGET_CONFIG="config-$OMR_TARGET"
OMR_KERNEL=${OMR_KERNEL:-5.4}
2020-06-26 19:23:24 +00:00
#OMR_RELEASE=${OMR_RELEASE:-$(git describe --tags `git rev-list --tags --max-count=1` | sed 's/^\([0-9.]*\).*/\1/')}
2020-06-29 13:10:24 +00:00
OMR_RELEASE=${OMR_RELEASE:-$(git tag --sort=committerdate | tail -1)}
2020-07-15 13:02:35 +00:00
OMR_REPO=${OMR_REPO:-http://$OMR_HOST:$OMR_PORT/release/$OMR_RELEASE/$OMR_TARGET}
2017-12-22 10:08:56 +00:00
OMR_FEED_URL="${OMR_FEED_URL:-https://github.com/ysurac/openmptcprouter-feeds}"
2019-12-18 18:22:08 +00:00
OMR_FEED_SRC="${OMR_FEED_SRC:-develop}"
2017-12-22 10:08:56 +00:00
2020-08-03 14:53:41 +00:00
CUSTOM_FEED_URL="${CUSTOM_FEED_URL}"
2020-04-09 12:57:08 +00:00
OMR_OPENWRT=${OMR_OPENWRT:-default}
2017-12-22 10:08:56 +00:00
if [ ! -f "$OMR_TARGET_CONFIG" ]; then
echo "Target $OMR_TARGET not found !"
#exit 1
2017-12-22 10:08:56 +00:00
fi
2018-04-17 07:35:12 +00:00
if [ "$OMR_TARGET" = "rpi3" ]; then
2018-04-17 07:49:09 +00:00
OMR_REAL_TARGET="aarch64_cortex-a53"
2019-06-25 16:01:36 +00:00
elif [ "$OMR_TARGET" = "rpi4" ]; then
OMR_REAL_TARGET="aarch64_cortex-a72"
2018-05-18 13:38:15 +00:00
elif [ "$OMR_TARGET" = "rpi2" ]; then
OMR_REAL_TARGET="arm_cortex-a7_neon-vfpv4"
2018-12-23 13:10:39 +00:00
elif [ "$OMR_TARGET" = "wrt3200acm" ]; then
OMR_REAL_TARGET="arm_cortex-a9_vfpv3"
elif [ "$OMR_TARGET" = "wrt32x" ]; then
OMR_REAL_TARGET="arm_cortex-a9_vfpv3"
2018-08-28 10:14:12 +00:00
elif [ "$OMR_TARGET" = "bpi-r2" ]; then
OMR_REAL_TARGET="arm_cortex-a7_neon-vfpv4"
2020-07-10 20:20:19 +00:00
elif [ "$OMR_TARGET" = "bpi-r64" ]; then
OMR_REAL_TARGET="aarch64_cortex-a53"
elif [ "$OMR_TARGET" = "espressobin" ]; then
OMR_REAL_TARGET="aarch64_cortex-a53"
2019-10-23 15:06:10 +00:00
elif [ "$OMR_TARGET" = "x86" ]; then
OMR_REAL_TARGET="i386_pentium4"
2018-04-17 06:32:01 +00:00
else
2018-04-17 07:49:09 +00:00
OMR_REAL_TARGET=${OMR_TARGET}
2018-04-17 06:32:01 +00:00
fi
#_get_repo source https://github.com/ysurac/openmptcprouter-source "master"
2020-04-09 12:57:08 +00:00
if [ "$OMR_OPENWRT" = "default" ]; then
2020-09-10 19:08:15 +00:00
_get_repo "$OMR_TARGET/source" https://github.com/openwrt/openwrt "38f6d5d217ca0c42f7f42b08f835a8a9cee71ad7"
_get_repo feeds/packages https://github.com/openwrt/packages "7479b3ecfafa6732185080ddfca68b68e27993b2"
_get_repo feeds/luci https://github.com/openwrt/luci "b95ac83ffd4fcf268be964002c45beba17d6e5c1"
2020-04-09 12:57:08 +00:00
elif [ "$OMR_OPENWRT" = "master" ]; then
_get_repo "$OMR_TARGET/source" https://github.com/openwrt/openwrt "master"
_get_repo feeds/packages https://github.com/openwrt/packages "master"
_get_repo feeds/luci https://github.com/openwrt/luci "master"
else
_get_repo "$OMR_TARGET/source" https://github.com/openwrt/openwrt "${OMR_OPENWRT}"
_get_repo feeds/packages https://github.com/openwrt/packages "${OMR_OPENWRT}"
_get_repo feeds/luci https://github.com/openwrt/luci "${OMR_OPENWRT}"
fi
2017-12-22 10:08:56 +00:00
if [ -z "$OMR_FEED" ]; then
2017-12-22 10:16:59 +00:00
OMR_FEED=feeds/openmptcprouter
2017-12-22 10:08:56 +00:00
_get_repo "$OMR_FEED" "$OMR_FEED_URL" "$OMR_FEED_SRC"
fi
2020-08-03 14:53:41 +00:00
if [ -n "$CUSTOM_FEED_URL" ]; then
CUSTOM_FEED=feeds/${OMR_DIST}
_get_repo "$CUSTOM_FEED" "$CUSTOM_FEED_URL" "master"
fi
2017-12-22 10:08:56 +00:00
if [ -n "$1" ] && [ -f "$OMR_FEED/$1/Makefile" ]; then
OMR_DIST=$1
shift 1
fi
2018-01-26 21:58:20 +00:00
if [ "$OMR_KEEPBIN" = "no" ]; then
2018-02-21 14:09:20 +00:00
rm -rf "$OMR_TARGET/source/bin"
2018-01-26 21:58:20 +00:00
fi
2018-12-23 19:39:53 +00:00
rm -rf "$OMR_TARGET/source/files" "$OMR_TARGET/source/tmp"
2018-12-23 13:10:39 +00:00
#rm -rf "$OMR_TARGET/source/target/linux/mediatek/patches-4.14"
2018-02-21 14:09:20 +00:00
cp -rf root/* "$OMR_TARGET/source"
2017-12-22 10:08:56 +00:00
2018-02-21 16:06:07 +00:00
cat >> "$OMR_TARGET/source/package/base-files/files/etc/banner" <<EOF
2017-12-22 10:08:56 +00:00
-----------------------------------------------------
PACKAGE: $OMR_DIST
2018-03-06 16:13:43 +00:00
VERSION: $(git -C "$OMR_FEED" describe --tag --always)
2017-12-22 10:08:56 +00:00
BUILD REPO: $(git config --get remote.origin.url)
BUILD DATE: $(date -u)
-----------------------------------------------------
EOF
2018-02-21 16:06:07 +00:00
cat > "$OMR_TARGET/source/feeds.conf" <<EOF
2017-12-22 10:08:56 +00:00
src-link packages $(readlink -f feeds/packages)
src-link luci $(readlink -f feeds/luci)
src-link openmptcprouter $(readlink -f "$OMR_FEED")
EOF
2020-08-03 14:53:41 +00:00
if [ -n "$CUSTOM_FEED" ]; then
echo "src-link ${OMR_DIST} $(readlink -f ${CUSTOM_FEED})" >> "$OMR_TARGET/source/feeds.conf"
fi
if [ "$OMR_DIST" = "openmptcprouter" ]; then
cat > "$OMR_TARGET/source/package/system/opkg/files/customfeeds.conf" <<-EOF
src/gz openwrt_luci http://packages.openmptcprouter.com/${OMR_RELEASE}/${OMR_REAL_TARGET}/luci
src/gz openwrt_packages http://packages.openmptcprouter.com/${OMR_RELEASE}/${OMR_REAL_TARGET}/packages
src/gz openwrt_base http://packages.openmptcprouter.com/${OMR_RELEASE}/${OMR_REAL_TARGET}/base
src/gz openwrt_routing http://packages.openmptcprouter.com/${OMR_RELEASE}/${OMR_REAL_TARGET}/routing
src/gz openwrt_telephony http://packages.openmptcprouter.com/${OMR_RELEASE}/${OMR_REAL_TARGET}/telephony
EOF
else
cat > "$OMR_TARGET/source/package/system/opkg/files/customfeeds.conf" <<-EOF
src/gz openwrt_luci http://downloads.openwrt.org/snapshots/packages/${OMR_REAL_TARGET}/luci
src/gz openwrt_packages http://downloads.openwrt.org/snapshots/packages/${OMR_REAL_TARGET}/packages
src/gz openwrt_base http://downloads.openwrt.org/snapshots/packages/${OMR_REAL_TARGET}/base
src/gz openwrt_routing http://downloads.openwrt.org/snapshots/packages/${OMR_REAL_TARGET}/routing
src/gz openwrt_telephony http://downloads.openwrt.org/snapshots/packages/${OMR_REAL_TARGET}/telephony
EOF
fi
2019-04-22 15:11:52 +00:00
#cat > "$OMR_TARGET/source/package/system/opkg/files/customfeeds.conf" <<EOF
#src/gz openwrt_luci http://downloads.openwrt.org/releases/18.06.0/packages/${OMR_REAL_TARGET}/luci
#src/gz openwrt_packages http://downloads.openwrt.org/releases/18.06.0/packages/${OMR_REAL_TARGET}/packages
#src/gz openwrt_base http://downloads.openwrt.org/releases/18.06.0/packages/${OMR_REAL_TARGET}/base
#src/gz openwrt_routing http://downloads.openwrt.org/releases/18.06.0/packages/${OMR_REAL_TARGET}/routing
#src/gz openwrt_telephony http://downloads.openwrt.org/releases/18.06.0/packages/${OMR_REAL_TARGET}/telephony
#EOF
2018-04-17 06:32:01 +00:00
2018-05-18 08:26:49 +00:00
if [ -f "$OMR_TARGET_CONFIG" ]; then
cat "$OMR_TARGET_CONFIG" config -> "$OMR_TARGET/source/.config" <<-EOF
CONFIG_IMAGEOPT=y
CONFIG_VERSIONOPT=y
CONFIG_VERSION_DIST="$OMR_DIST"
CONFIG_VERSION_REPO="$OMR_REPO"
CONFIG_VERSION_NUMBER="$(git -C "$OMR_FEED" describe --tag --always)"
EOF
else
cat config -> "$OMR_TARGET/source/.config" <<-EOF
CONFIG_IMAGEOPT=y
CONFIG_VERSIONOPT=y
CONFIG_VERSION_DIST="$OMR_DIST"
CONFIG_VERSION_REPO="$OMR_REPO"
CONFIG_VERSION_NUMBER="$(git -C "$OMR_FEED" describe --tag --always)"
EOF
fi
2018-04-05 15:16:42 +00:00
if [ "$OMR_ALL_PACKAGES" = "yes" ]; then
echo 'CONFIG_ALL=y' >> "$OMR_TARGET/source/.config"
2020-05-14 14:49:19 +00:00
echo 'CONFIG_ALL_NONSHARED=y' >> "$OMR_TARGET/source/.config"
2018-04-05 15:16:42 +00:00
fi
2018-02-14 09:28:01 +00:00
if [ "$OMR_IMG" = "yes" ] && [ "$OMR_TARGET" = "x86_64" ]; then
2018-02-21 14:09:20 +00:00
echo 'CONFIG_VDI_IMAGES=y' >> "$OMR_TARGET/source/.config"
echo 'CONFIG_VMDK_IMAGES=y' >> "$OMR_TARGET/source/.config"
2019-05-28 19:24:16 +00:00
echo 'CONFIG_VHDX_IMAGES=y' >> "$OMR_TARGET/source/.config"
2018-02-14 09:28:01 +00:00
fi
2017-12-22 10:08:56 +00:00
2020-06-09 20:40:38 +00:00
if [ "$OMR_PACKAGES" = "full" ]; then
2020-07-21 19:50:18 +00:00
echo "CONFIG_PACKAGE_${OMR_DIST}-full=y" >> "$OMR_TARGET/source/.config"
2020-06-09 20:40:38 +00:00
fi
if [ "$OMR_PACKAGES" = "mini" ]; then
2020-07-21 19:50:18 +00:00
echo "CONFIG_PACKAGE_${OMR_DIST}-mini=y" >> "$OMR_TARGET/source/.config"
2020-06-09 20:40:38 +00:00
fi
2018-02-21 14:09:20 +00:00
cd "$OMR_TARGET/source"
2017-12-22 10:08:56 +00:00
#if [ "$OMR_UEFI" = "yes" ] && [ "$OMR_TARGET" = "x86_64" ]; then
# echo "Checking if UEFI patch is set or not"
# if [ "$(grep 'EFI_IMAGES' target/linux/x86/image/Makefile)" = "" ]; then
# patch -N -p1 -s < ../../patches/uefi.patch
# fi
# echo "Done"
#else
# if [ "$(grep 'EFI_IMAGES' target/linux/x86/image/Makefile)" != "" ]; then
# patch -N -R -p1 -s < ../../patches/uefi.patch
# fi
#fi
2018-02-27 20:54:33 +00:00
#if [ "$OMR_TARGET" = "x86_64" ]; then
# echo "Checking if Hyper-V patch is set or not"
# if ! patch -Rf -N -p1 -s --dry-run < ../../patches/images.patch; then
# patch -N -p1 -s < ../../patches/images.patch
# fi
# echo "Done"
#fi
2019-06-01 06:26:22 +00:00
2019-06-02 08:12:52 +00:00
echo "Checking if No check patch is set or not"
if ! patch -Rf -N -p1 -s --dry-run < ../../patches/nocheck.patch; then
2020-03-28 09:47:41 +00:00
echo "apply..."
2019-06-02 08:12:52 +00:00
patch -N -p1 -s < ../../patches/nocheck.patch
fi
echo "Done"
2019-12-19 08:40:20 +00:00
echo "Checking if Nanqinlang patch is set or not"
if ! patch -Rf -N -p1 -s --dry-run < ../../patches/nanqinlang.patch; then
2020-03-28 09:47:41 +00:00
echo "apply..."
2019-12-19 08:40:20 +00:00
patch -N -p1 -s < ../../patches/nanqinlang.patch
fi
echo "Done"
echo "Checking if smsc75xx patch is set or not"
if ! patch -Rf -N -p1 -s --dry-run < ../../patches/smsc75xx.patch; then
2020-03-28 09:47:41 +00:00
echo "apply..."
patch -N -p1 -s < ../../patches/smsc75xx.patch
fi
echo "Done"
2020-04-20 14:45:17 +00:00
#echo "Checking if ipt-nat patch is set or not"
#if ! patch -Rf -N -p1 -s --dry-run < ../../patches/ipt-nat6.patch; then
# echo "apply..."
# patch -N -p1 -s < ../../patches/ipt-nat6.patch
#fi
#echo "Done"
2020-04-17 13:04:15 +00:00
#echo "Checking if mvebu patch is set or not"
#if [ ! -d target/linux/mvebu/patches-5.4 ]; then
# echo "apply..."
# patch -N -p1 -s < ../../patches/mvebu-5.14.patch
#fi
#echo "Done"
echo "Checking if opkg install arguement too long patch is set or not"
if ! patch -Rf -N -p1 -s --dry-run < ../../patches/package-too-long.patch; then
echo "apply..."
patch -N -p1 -s < ../../patches/package-too-long.patch
fi
echo "Done"
echo "Download via IPv4"
2020-04-17 13:04:15 +00:00
if ! patch -Rf -N -p1 -s --dry-run < ../../patches/download-ipv4.patch; then
patch -N -p1 -s < ../../patches/download-ipv4.patch
fi
echo "Done"
2020-04-24 19:56:50 +00:00
if [ -f target/linux/mediatek/patches-5.4/0999-hnat.patch ]; then
rm -f target/linux/mediatek/patches-5.4/0999-hnat.patch
fi
2019-06-02 08:12:52 +00:00
2019-03-06 17:21:03 +00:00
#echo "Patch protobuf wrong hash"
#patch -N -R -p1 -s < ../../patches/protobuf_hash.patch
#echo "Done"
2018-12-23 13:10:39 +00:00
#echo "Remove gtime dependency"
#if ! patch -Rf -N -p1 -s --dry-run < ../../patches/gtime.patch; then
# patch -N -p1 -s < ../../patches/gtime.patch
#fi
#echo "Done"
2020-03-11 15:01:27 +00:00
if [ "$OMR_KERNEL" = "5.4" ]; then
echo "Set to kernel 5.4 for rpi arch"
find target/linux/bcm27xx -type f -name Makefile -exec sed -i 's%KERNEL_PATCHVER:=4.19%KERNEL_PATCHVER:=5.4%g' {} \;
echo "Done"
2020-03-11 15:01:27 +00:00
echo "Set to kernel 5.4 for x86 arch"
find target/linux/x86 -type f -name Makefile -exec sed -i 's%KERNEL_PATCHVER:=4.19%KERNEL_PATCHVER:=5.4%g' {} \;
echo "Done"
echo "Set to kernel 5.4 for mvebu arch (WRT)"
find target/linux/mvebu -type f -name Makefile -exec sed -i 's%KERNEL_PATCHVER:=4.19%KERNEL_PATCHVER:=5.4%g' {} \;
echo "Done"
2020-03-11 15:01:27 +00:00
echo "Set to kernel 5.4 for mediatek arch (BPI-R2)"
find target/linux/mediatek -type f -name Makefile -exec sed -i 's%KERNEL_PATCHVER:=4.19%KERNEL_PATCHVER:=5.4%g' {} \;
2019-05-31 16:56:59 +00:00
echo "Done"
fi
2019-04-22 15:11:52 +00:00
2020-07-10 20:20:19 +00:00
#rm -rf feeds/packages/libs/libwebp
2020-05-16 18:46:50 +00:00
2018-02-27 20:54:33 +00:00
echo "Update feeds index"
2020-06-11 06:35:21 +00:00
rm -rf feeds/luci/modules/luci-mod-network
2020-09-10 19:08:15 +00:00
[ -d feeds/${OMR_DIST}/luci-mod-status ] && rm -rf feeds/luci/modules/luci-mod-status
2020-06-11 06:35:21 +00:00
2017-12-22 10:08:56 +00:00
cp .config .config.keep
scripts/feeds clean
scripts/feeds update -a
2020-04-02 12:14:51 +00:00
2020-04-09 13:01:48 +00:00
#cd -
#echo "Checking if fullconenat-luci patch is set or not"
##if ! patch -Rf -N -p1 -s --dry-run < patches/fullconenat-luci.patch; then
# echo "apply..."
# patch -N -p1 -s < patches/fullconenat-luci.patch
#fi
#echo "Done"
#cd "$OMR_TARGET/source"
2020-04-02 12:14:51 +00:00
2018-04-05 15:16:42 +00:00
if [ "$OMR_ALL_PACKAGES" = "yes" ]; then
2020-05-14 14:49:19 +00:00
scripts/feeds install -a -d m -p packages
scripts/feeds install -a -d m -p luci
2018-04-05 15:16:42 +00:00
fi
2020-08-03 14:53:41 +00:00
if [ -n "$CUSTOM_FEED" ]; then
scripts/feeds install -a -d m -p openmptcprouter
scripts/feeds install -a -d y -f -p ${OMR_DIST}
else
scripts/feeds install -a -d y -f -p openmptcprouter
fi
2017-12-22 10:08:56 +00:00
cp .config.keep .config
2018-02-27 20:54:33 +00:00
echo "Done"
2017-12-22 10:08:56 +00:00
if [ ! -f "../../$OMR_TARGET_CONFIG" ]; then
echo "Target $OMR_TARGET not found ! You have to configure and compile your kernel manually."
exit 1
fi
2018-02-27 20:54:33 +00:00
echo "Building $OMR_DIST for the target $OMR_TARGET"
2017-12-22 10:08:56 +00:00
make defconfig
2018-04-17 06:32:01 +00:00
make IGNORE_ERRORS=m "$@"
2018-02-27 20:54:33 +00:00
echo "Done"