X-OpenWrt/Scripts/diy-script.sh

146 lines
6.2 KiB
Bash
Raw Normal View History

2020-09-16 15:21:52 +00:00
#!/bin/bash
2020-09-16 15:45:32 +00:00
# https://github.com/Hyy2001X/AutoBuild-Actions
# AutoBuild Module by Hyy2001
2020-09-16 15:21:52 +00:00
# AutoBuild Actions
Diy_Core() {
Author=Hyy2001
2020-10-24 15:41:40 +00:00
Default_Device=d-team_newifi-d2
}
Diy-Part1() {
2020-11-17 14:23:58 +00:00
[ -e feeds.conf.default ] && sed -i "s/#src-git helloworld/src-git helloworld/g" feeds.conf.default
2020-11-17 06:11:49 +00:00
[ ! -d package/lean ] && mkdir -p package/lean
Replace_File mac80211.sh package/kernel/mac80211/files/lib/wifi
Replace_File system package/base-files/files/etc/config
Replace_File AutoUpdate.sh package/base-files/files/bin
Replace_File banner package/base-files/files/etc
ExtraPackages svn network/services dnsmasq https://github.com/openwrt/openwrt/trunk/package/network/services
ExtraPackages svn network/services dropbear https://github.com/openwrt/openwrt/trunk/package/network/services
2020-12-29 12:38:09 +00:00
ExtraPackages svn network/services ppp https://github.com/openwrt/openwrt/trunk/package/network/services
ExtraPackages svn network/services hostapd https://github.com/openwrt/openwrt/trunk/package/network/services
# ExtraPackages svn kernel mt76 https://github.com/openwrt/openwrt/trunk/package/kernel
2020-11-29 02:29:53 +00:00
ExtraPackages git lean luci-app-autoupdate https://github.com/Hyy2001X main
ExtraPackages git lean luci-theme-argon https://github.com/jerrykuku 18.06
2020-11-27 01:33:44 +00:00
ExtraPackages git other luci-app-argon-config https://github.com/jerrykuku master
ExtraPackages git other luci-app-adguardhome https://github.com/Hyy2001X master
ExtraPackages svn other luci-app-smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages svn other smartdns https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
ExtraPackages git other OpenClash https://github.com/vernesong master
ExtraPackages git other luci-app-serverchan https://github.com/tty228 master
2020-11-29 00:19:16 +00:00
ExtraPackages svn other luci-app-socat https://github.com/project-openwrt/openwrt/trunk/package/lienol
# [UPX 压缩] ExtraPackages git other openwrt-upx https://github.com/Hyy2001X master
2020-11-29 00:19:16 +00:00
# [应用过滤] ExtraPackages git OAF openwrt-OpenAppFilter https://github.com/Lienol master
# [AdGuardHome 核心] ExtraPackages svn other AdGuardHome https://github.com/project-openwrt/openwrt/trunk/package/ntlf9t
}
Diy-Part2() {
GET_TARGET_INFO
2020-12-29 12:38:09 +00:00
# Replace_File mwan3 package/feeds/packages/mwan3/files/etc/config
2020-12-25 03:14:20 +00:00
sed -i 's/143/143,25,5222/' package/feeds/helloworld/luci-app-ssr-plus/root/etc/init.d/shadowsocksr
2020-11-25 23:02:28 +00:00
# ExtraPackages svn feeds/packages mwan3 https://github.com/openwrt/packages/trunk/net
echo "Author: $Author"
echo "Openwrt Version: $Openwrt_Version"
echo "AutoUpdate Version: $AutoUpdate_Version"
echo "Router: $TARGET_PROFILE"
sed -i "s?$Lede_Version?$Lede_Version Compiled by $Author [$Display_Date]?g" $Default_File
2020-11-17 06:11:49 +00:00
echo "$Openwrt_Version" > package/base-files/files/etc/openwrt_info
sed -i "s?Openwrt?Openwrt $Openwrt_Version / AutoUpdate $AutoUpdate_Version?g" package/base-files/files/etc/banner
}
2020-09-16 15:45:32 +00:00
Diy-Part3() {
GET_TARGET_INFO
Default_Firmware=openwrt-$TARGET_BOARD-$TARGET_SUBTARGET-$TARGET_PROFILE-squashfs-sysupgrade.bin
AutoBuild_Firmware=AutoBuild-$TARGET_PROFILE-Lede-${Openwrt_Version}.bin
AutoBuild_Detail=AutoBuild-$TARGET_PROFILE-Lede-${Openwrt_Version}.detail
mkdir -p bin/Firmware
echo "Firmware: $AutoBuild_Firmware"
mv bin/targets/$TARGET_BOARD/$TARGET_SUBTARGET/$Default_Firmware bin/Firmware/$AutoBuild_Firmware
echo "[$(date "+%H:%M:%S")] Calculating MD5 and SHA256 ..."
Firmware_MD5=$(md5sum bin/Firmware/$AutoBuild_Firmware | cut -d ' ' -f1)
Firmware_SHA256=$(sha256sum bin/Firmware/$AutoBuild_Firmware | cut -d ' ' -f1)
echo -e "MD5: $Firmware_MD5\nSHA256: $Firmware_SHA256"
touch bin/Firmware/$AutoBuild_Detail
echo -e "\nMD5:$Firmware_MD5\nSHA256:$Firmware_SHA256" >> bin/Firmware/$AutoBuild_Detail
2020-09-16 15:21:52 +00:00
}
2020-09-19 07:37:55 +00:00
GET_TARGET_INFO() {
2020-10-24 15:41:40 +00:00
Diy_Core
2020-11-17 14:23:58 +00:00
[ -e $GITHUB_WORKSPACE/Openwrt.info ] && . $GITHUB_WORKSPACE/Openwrt.info
AutoUpdate_Version=$(awk 'NR==6' package/base-files/files/bin/AutoUpdate.sh | awk -F '[="]+' '/Version/{print $2}')
Default_File="package/lean/default-settings/files/zzz-default-settings"
Lede_Version=$(egrep -o "R[0-9]+\.[0-9]+\.[0-9]+" $Default_File)
Openwrt_Version="$Lede_Version-$Compile_Date"
TARGET_PROFILE=$(egrep -o "CONFIG_TARGET.*DEVICE.*=y" .config | sed -r 's/.*DEVICE_(.*)=y/\1/')
[ -z "$TARGET_PROFILE" ] && TARGET_PROFILE="$Default_Device"
TARGET_BOARD=$(awk -F '[="]+' '/TARGET_BOARD/{print $2}' .config)
TARGET_SUBTARGET=$(awk -F '[="]+' '/TARGET_SUBTARGET/{print $2}' .config)
2020-09-19 07:37:55 +00:00
}
2020-09-16 15:21:52 +00:00
ExtraPackages() {
PKG_PROTO=$1
PKG_DIR=$2
PKG_NAME=$3
REPO_URL=$4
REPO_BRANCH=$5
2020-11-27 01:33:44 +00:00
[ -d package/$PKG_DIR ] && mkdir -p package/$PKG_DIR
[ -d package/$PKG_DIR/$PKG_NAME ] && rm -rf package/$PKG_DIR/$PKG_NAME
[ -d $PKG_NAME ] && rm -rf $PKG_NAME
2020-10-02 03:07:36 +00:00
Retry_Times=3
2020-11-18 07:32:22 +00:00
while [ ! -e $PKG_NAME/Makefile ]
2020-09-16 15:21:52 +00:00
do
2020-11-17 06:11:49 +00:00
echo "[$(date "+%H:%M:%S")] Checking out package [$PKG_NAME] ..."
case $PKG_PROTO in
2020-10-16 15:58:52 +00:00
git)
git clone -b $REPO_BRANCH $REPO_URL/$PKG_NAME $PKG_NAME > /dev/null 2>&1
2020-10-16 15:58:52 +00:00
;;
svn)
svn checkout $REPO_URL/$PKG_NAME $PKG_NAME > /dev/null 2>&1
2020-10-16 15:58:52 +00:00
esac
2020-11-17 14:23:58 +00:00
if [ -e $PKG_NAME/Makefile ] || [ -e $PKG_NAME/README* ];then
2020-11-21 01:32:06 +00:00
echo "[$(date "+%H:%M:%S")] Package [$PKG_NAME] is detected!"
mv $PKG_NAME package/$PKG_DIR
2020-09-16 15:21:52 +00:00
break
else
[ $Retry_Times -lt 1 ] && echo "[$(date "+%H:%M:%S")] Skip check out package [$PKG_NAME] ..." && break
2020-11-17 06:11:49 +00:00
echo "[$(date "+%H:%M:%S")] [Error] [$Retry_Times] Checkout failed,retry in 3s ..."
2020-10-02 03:07:36 +00:00
Retry_Times=$(($Retry_Times - 1))
rm -rf $PKG_NAME > /dev/null 2>&1
2020-09-16 15:21:52 +00:00
sleep 3
fi
done
}
Replace_File() {
FILE_NAME=$1
PATCH_DIR=$GITHUB_WORKSPACE/openwrt/$2
FILE_RENAME=$3
2020-11-21 01:32:06 +00:00
[ ! -d $PATCH_DIR ] && mkdir -p $PATCH_DIR
if [ -f $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
if [ -e $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
echo "[$(date "+%H:%M:%S")] Customize File [$FILE_NAME] is detected!"
if [ -z $FILE_RENAME ];then
[ -e $PATCH_DIR/$FILE_NAME ] && rm -f $PATCH_DIR/$FILE_NAME
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR/$1
else
[ -e $PATCH_DIR/$FILE_NAME ] && rm -f $PATCH_DIR/$3
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR/$3
fi
2020-10-05 09:51:03 +00:00
else
2020-11-21 01:32:06 +00:00
echo "[$(date "+%H:%M:%S")] Customize File [$FILE_NAME] is not detected,skip move ..."
2020-10-05 09:51:03 +00:00
fi
2020-09-25 15:54:23 +00:00
else
2020-11-21 01:32:06 +00:00
if [ -d $GITHUB_WORKSPACE/Customize/$FILE_NAME ];then
echo "[$(date "+%H:%M:%S")] Customize Folder [$FILE_NAME] is detected !"
mv -f $GITHUB_WORKSPACE/Customize/$FILE_NAME $PATCH_DIR
else
echo "[$(date "+%H:%M:%S")] Customize Folder [$FILE_NAME] is not detected,skip move ..."
fi
2020-09-25 15:54:23 +00:00
fi
}